Description of problem: When io_getevents() is called from a shared library. it fails, returning -14 (errno 0). When called directly from a program or from a static library, it works as expected. Also, if the io_getevents system call is called directly with syscall(), it works as expected, even from a shared library. Version-Release number of selected component (if applicable): libaio-0.3.106-3.2 kernel-2.6.18-89.el5 How reproducible: Always. Steps to Reproduce: 1. Untar the libaio_test.tgz (attached to bugzilla) 2. from the libaio_test directory, run #make 3. run # ./test Makefile # ./shared_test Makefile # ./static_test Makefile Actual results: [root@cypher-01 ~]# tar -xzvf libaio_test.tgz libaio_test/ libaio_test/test.c libaio_test/aio_func.c libaio_test/Makefile [root@cypher-01 ~]# cd libaio_test [root@cypher-01 libaio_test]# make gcc -o test test.c aio_func.c -laio gcc -fPIC -c aio_func.c ar rs libaio_func.a aio_func.o ar: creating libaio_func.a gcc -o static_test test.c libaio_func.a -laio gcc -shared -o libaio_func.so aio_func.o gcc -o shared_test test.c -laio -laio_func -Wl,-rpath,. -L. [root@cypher-01 libaio_test]# ./test Makefile It worked! [root@cypher-01 libaio_test]# ./static_test Makefile It worked! [root@cypher-01 libaio_test]# ./shared_test Makefile io_getevents returned -14 (0) Notice that the test that used a shared library was the only one to fail Expected results: io_getevents works correctly when called from a shared library. Additional info: To try the tests using a system call directly, edit the Makefile, uncommenting the line # RAW_SYSCALL = -DRAW_SYSCALL then run # make clean # make and try the tests again. In this case, all there test programs work. The linking for the shared_test is kinda ugly, to make it more self-contained. Just on a whim, I tried compiling and running it with libaio_func.so in /lib and ldconfig updated to see it, so id didn't need the linker options. It was just a broken that way too.
Created attachment 305551 [details] 3 libaio test programs. the shared_test fails
Thanks for narrowing this down and providing such a nice reproducer. I've looked into this a bit, and it turns out that the libaio library's io_getevents function is being called with incorrect parameters. Because of this, the kernel returns -EFAULT; the events parameter is 1 in my case, and the timeout is a stack address instead of NULL. It's worth noting that the stack address does not correspond to the address of the events variable. So, the first three parameters are OK, the last two are bogus. I'll keep you posted on the progress.
OK, I took a look at your makefile, and something jumped out at me. Apply this patch and all should work as expected. @@ -13,10 +13,10 @@ static_test: test.c libaio_func.a gcc -o static_test test.c libaio_func.a -laio shared_test: test.c libaio_func.so - gcc -o shared_test test.c -laio -laio_func -Wl,-rpath,. -L. + gcc -o shared_test test.c -laio_func -Wl,-rpath,. -L. libaio_func.so: aio_func.o - gcc -shared -o libaio_func.so aio_func.o + gcc -shared -fPIC -o libaio_func.so aio_func.o -laio libaio_func.a: aio_func.o ar rs libaio_func.a aio_func.o Give that a try and let me know how you make out.
Doh! Yup that fixes it for me.