[alsa-devel] Serious bug calling ALSA lib functions from .so vs. .o file
scott andrew franco
samiam at moorecad.com
Tue Jun 18 08:24:29 CEST 2019
Hi, I am having a strange issue calling snd_pcm_* alsa-lib functions from a .so file.
The example is a pretty run of the mill .wav file output example in C from the internet, which I have placed in playwav.c.
I put the routine that does the pcm play, alsaplaywave(), into a routine and have a duplicate in another external file, test2.c.
I named the one in playwav.c alsaplaywav1(), and the one in test2.c alsaplaywav().
The compile is done as follows:
gcc -g3 -Iinclude -fPIC -c test2.c -o test2.o
gcc -shared test2.o -o test2.so
#
# Compiling from .so causes bug, compiling from .o does not
#
gcc -g3 -Iinclude linux/playwav.c ./test2.so -lasound -o playwav
#gcc -g3 -Iinclude linux/playwav.c ./test2.o -lasound -o playwav
If the test2.so file is used, the playback has its parameters such as rate messed up, and the result is it plays
as fast as possible (series of chirps). If the above line is just changed to test2.o, the playback is fine.
Further, if the copy of alsaplaywav() local to the playwav.c file is executed, the playback is correct. It is only
when playing from the routine in the .so file that it messes up.
To find out what the key point of failure is, I put all of the preamble for the routine up until it does a
snd_pcm_hw_params_set_rate_near() at the calling point (in playwav.c) and commented that out in the routine.
The idea was to see exactly which alsa call being done inside the .so caused the malfunction.
The rate set appears to be the key. Do that outside the .so, it works, do it inside, it does not.
I note that snd_pcm_hw_params_set_rate_near() goes through a few macros in alsa-lib.
I think I could debug this better if I can get alsa symbols into gdb. As in the other message, I cannot figure out
where the libasound.so gets constructed in the build. I see libasound.a, but no libasound.so.
Apologies for not cutting the example down further, but the failure mode is quite complex and that is
difficult.
Find playwav.c and test2.c attached, and the compile instructions I used above or in cplaywav. The
files are fairly small.
Thanks for any help.
Scott Franco
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.c
Type: text/x-c
Size: 3649 bytes
Desc: not available
URL: <http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20190617/20fd921c/attachment.bin>
-------------- next part --------------
gcc -g3 -Iinclude -fPIC -c test2.c -o test2.o
gcc -shared test2.o -o test2.so
#
# Compiling from .so causes bug, compiling from .o does not
#
gcc -g3 -Iinclude linux/playwav.c ./test2.so -lasound -o playwav
#gcc -g3 -Iinclude linux/playwav.c ./test2.o -lasound -o playwav
-------------- next part --------------
A non-text attachment was scrubbed...
Name: playwav.c
Type: text/x-c
Size: 6636 bytes
Desc: not available
URL: <http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20190617/20fd921c/attachment-0001.bin>
More information about the Alsa-devel
mailing list