Calls from a custom dynamic shared library call the wrong version of alsa functions in libasound
I had created a library that is a dynamic shared library. Within this library, calls are made to the ALSA Lib (libasound) but the wrong version of the call is being made. If a single step through, it will call __OLD_GET1(...). If my library is not a dynamic shared library then the correct call is made. Am I doing something wrong or is the dynamic linker resolving to the wrong version of the ALSA function call and there is not anything I can do?
The following is a useless program that demonstrates the issue
alibtest.h:
#ifndef _ALIBTEST_H_
#define _ALIBTEST_H_
int GetBufferTime(void);
#end
alibtest.cpp:
#include <alib/asoundlib.h>
#include "alibtest.h"
int GetBufferTime(void)
{
int direction;
unsigned int buffer_time;
int err;
snd_pcm_hw_params_t *params;
err =snd_pcm_hw_params_get_buffer_time_max(params,&buffer_time,&direction);
return err;
}
alsatest.cpp:
#include "alibtest.h"
int main()
{
int err;
err = GetBufferTime();
return 0;
}
g++ -fPIC -gstabs+ -O0 -Wall alibtest.cpp
g++ -shared -Wl,-soname,libalibtest.so.1 -o libalibtest.so.1.0.1 alibtest.o -lc ln -s libalibtest.so.1.0.1 libalibtest.so
ln -s libalibtest.so.1.0.1 libalibtest.so.1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
g++ -gstabs+ -O0 -o alsatest alsatest.cpp -lasound -lalibtest -L.
If you the program throught the debugger and step through the snd_pcm_hw_params_get_buffer_time_max, it will go to __OLD_GET1(snd_pcm_hw_params_get_buffer_time_max, unsigned int, unsigned int);
Thus it tries to return the buffer time versus setting the variable buffer_time and returning error.
If I do a nm on the shared library, it will show snd_pcm_hw_params_get_buffer_time_max. If I make a static library, it will show the same thing, but when it is linked, the executable will show snd_pcm_hw_params_get_buffer_time_max@@ALSA_0.9.0rc4
Thanks
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Quoted 8 lines · Linux Coder
I had created a library that is a dynamic shared library. Within this library, calls are made to the ALSA Lib (libasound) but the wrong version of the call is being made. If a single step through, it will call
__OLD_GET1(...). If my library is not a dynamic shared library then the correct call is made.
Am I doing something wrong or is the dynamic linker resolving to the wrong version of the ALSA function call and there is not anything I can do?
Well, you must have multiple ALSA version installed. What does ldd your_app say?
Lee
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
linux-gate.so.1 => (0xffffe000)
libasound.so.2 => /usr/lib/libasound.so.2 (0x4f9ca000)
libalibtest.so.1 => ./libalibtest.so.1 (0xb7fed000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x001ae000)
libm.so.6 => /lib/tls/libm.so.6 (0x00c4f000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00de9000)
libc.so.6 => /lib/tls/libc.so.6 (0x00b2c000)
libdl.so.2 => /lib/libdl.so.2 (0x00c49000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00d84000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00b13000)I thought that was the problem too and thus I made sure no where else on my hard drive was another version of alsa. I also downloaded the latest and rebuilt it.
Looking at the ALSA stuff, ALSA library supports an older API and thus the library has the current API and the "old" API. By setting some defines you can include the old API and use the old API calling structure. I made sure I was not including the old API but putting #warning in the pcm_old.h.
Since I can switch between shared and static and the problem only shows up in shared, the dynamic linker, I believe, is resolving to the wrong call.
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Quoted 2 lines · Lee Revell
Well, you must have multiple ALSA version installed. What does ldd
your_appsay?
the major of the alsa lib hasn't changed for years, so i doubt one can actually have several versions of this lib installed...
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Quoted 3 lines · Linux Coder
g++ -fPIC -gstabs+ -O0 -Wall alibtest.cpp
g++ -shared -Wl,-soname,libalibtest.so.1 -o libalibtest.so.1.0.1 alibtest.o -lc
Try add -lasound here, otherwise the linker won't add the necessary versions to external symbols.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Thank you. It works.
Quoted 10 lines · Jaroslav Kysela
Quoted 5 lines · Linux Coder
g++ -fPIC -gstabs+ -O0 -Wall alibtest.cpp
g++ -shared -Wl,-soname,libalibtest.so.1 -o libalibtest.so.1.0.1 alibtest.o -lc
Quoted 13 lines
Try add -lasound here, otherwise the linker won't add the necessary versions to external symbols.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf