Bug 446772 - io_getevents fails when called from a shared library
io_getevents fails when called from a shared library
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: libaio (Show other bugs)
All Linux
low Severity low
: rc
: ---
Assigned To: Jeff Moyer
Depends On:
  Show dependency treegraph
Reported: 2008-05-15 18:38 EDT by Ben Marzinski
Modified: 2008-05-20 15:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2008-05-20 15:38:57 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
3 libaio test programs. the shared_test fails (1.21 KB, application/x-gtar)
2008-05-15 18:38 EDT, Ben Marzinski
no flags Details

  None (edit)
Description Ben Marzinski 2008-05-15 18:38:38 EDT
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):

How reproducible:

Steps to Reproduce:
1. Untar the libaio_test.tgz (attached to bugzilla)
2. from the libaio_test directory, run 
3. run
# ./test Makefile
# ./shared_test Makefile
# ./static_test Makefile
Actual results:

[root@cypher-01 ~]# tar -xzvf libaio_test.tgz 
[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

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.
Comment 1 Ben Marzinski 2008-05-15 18:38:38 EDT
Created attachment 305551 [details]
3 libaio test programs. the shared_test fails
Comment 2 Jeff Moyer 2008-05-16 11:54:38 EDT
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.
Comment 3 Jeff Moyer 2008-05-16 11:59:53 EDT
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.
Comment 4 Ben Marzinski 2008-05-20 15:38:57 EDT
Doh! Yup that fixes it for me.

Note You need to log in before you can comment on or make changes to this bug.