Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALSOFT_DLOPEN=ON ALSOFT_REQUIRE_OPENSL=ON builds not working at runtime inside Termux on random Android devices #1111

Open
robertkirkman opened this issue Feb 15, 2025 · 5 comments

Comments

@robertkirkman
Copy link

robertkirkman commented Feb 15, 2025

Hi I am sorry that this is such an obscure edge case to the point that I don't know whether this is actually a supported use case of openal-soft or not, I just don't know where else to ask if anyone has knowledge of what is happening, because this happens to openal-soft builds cloned from this repository and compiled manually inside Termux as well as to the openal-soft build that comes from pkg install openal-soft. If it only happened to the openal-soft build that comes from pkg install openal-soft then I would not open an issue here, but it is also happening to openal-soft from git clone https://github.com/kcat/openal-soft.git inside of Termux apps, so I thought that you might know what is causing this to happen.

Terminal emulator app: https://f-droid.org/en/packages/com.termux/

Bisection commit: 8767fdd

Devices affected so far that the issue is reproducible on:

  • Samsung Galaxy S7 SM-G930U (Android 8 OFW locked bootloader 64-bit ARM kernel 3.18)
  • Samsung Galaxy Tab S3 SM-T820 (Android 9 OFW locked bootloader 64-bit ARM kernel 3.18)
  • Samsung Galaxy S9 SM-G960U (Android 10 OFW locked bootloader 64-bit ARM kernel 4.9)
  • Samsung Galaxy S8+ SM-G955F (Android 14 LineageOS unlocked bootloader 64-bit ARM kernel 4.4)

Devices not affected so far that the issue is not reproducible on:

  • Samsung Galaxy S III SPH-L710 (Android 7 LineageOS unlocked bootloader 32-bit ARM kernel 3.4)
  • Samsung Galaxy A70 A705FN (Android 13 LineageOS unlocked bootloader 64-bit ARM kernel 4.14)
  • Valve Steam Deck OLED Galileo (Android 13 BlissOS unlocked bootloader 64-bit x86 kernel 6.6)
commands that reproduce the problem on the affected devices
yes | pkg upgrade -y
pkg install -y build-essential git

rm -rf openal-soft_*

git clone https://github.com/kcat/openal-soft.git openal-soft_src

cmake -S openal-soft_src -B openal-soft_build \
  -DCMAKE_INSTALL_PREFIX=$(pwd)/openal-soft_installation \
  -DALSOFT_UTILS=OFF \
  -DALSOFT_EXAMPLES=OFF \
  -DALSOFT_TESTS=OFF \
  -DALSOFT_REQUIRE_OPENSL=ON \
  -DOPENSL_LIBRARY=/system/lib$(uname -m | grep 64 > /dev/null && echo '64' || echo '')/libOpenSLES.so \
  -DALSOFT_DLOPEN=ON
cmake --build openal-soft_build
cmake --install openal-soft_build

cat > openal-soft_test.c << EOF
#include <stdio.h>

#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"

int main(void) {
    ALCdevice *device = alcOpenDevice(NULL);

    if (device) {
        printf("success!\n");
        alcCloseDevice(device);
        return 0;
    }

    printf("failure!\n");
    return 1;
}
EOF

clang openal-soft_test.c -o openal-soft_test \
  -I openal-soft_installation/include \
  -L openal-soft_installation/lib \
  -lopenal

export ALSOFT_LOGLEVEL=3 LD_LIBRARY_PATH=openal-soft_installation/lib/
./openal-soft_test
output of commands that reproduce the problem on affected devices
Checking availability of current mirror:
[*] https://packages.termux.dev/apt/termux-main: ok
Hit:1 https://turdl.kcubeterm.com tur-packages InRelease
Hit:2 https://packages.termux.dev/apt/termux-main stable InRelease
Hit:3 https://packages.termux.dev/apt/termux-x11 x11 InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Checking availability of current mirror:
[*] https://packages.termux.dev/apt/termux-main: ok
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (4.1).
git is already the newest version (2.48.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Cloning into 'openal-soft_src'...
remote: Enumerating objects: 60385, done.
remote: Counting objects: 100% (7406/7406), done.
remote: Compressing objects: 100% (537/537), done.
remote: Total 60385 (delta 7003), reused 6888 (delta 6869), pack-reused 52979 (from 4)
Receiving objects: 100% (60385/60385), 23.09 MiB | 8.81 MiB/s, done.
Resolving deltas: 100% (48254/48254), done.
-- The C compiler identification is Clang 19.1.7
-- The CXX compiler identification is Clang 19.1.7
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /data/data/com.termux/files/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /data/data/com.termux/files/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /data/data/com.termux/files/usr/bin/pkg-config (found version "0.29.2")
-- {fmt} version: 11.1.1
-- Build type: RelWithDebInfo
-- Performing Test HAVE_STDC_FORMAT_MACROS
-- Performing Test HAVE_STDC_FORMAT_MACROS - Success
-- Performing Test HAVE_LIBATOMIC
-- Performing Test HAVE_LIBATOMIC - Success
-- Looking for __android_log_print in log
-- Looking for __android_log_print in log - found
-- Performing Test HAVE_WNO_CXX20_ATTR_EXT
-- Performing Test HAVE_WNO_CXX20_ATTR_EXT - Success
-- Performing Test HAVE_WNO_INTERFERENCE_SIZE
-- Performing Test HAVE_WNO_INTERFERENCE_SIZE - Failed
-- Performing Test HAVE_FTRIVIAL_AUTO_VAR_INIT
-- Performing Test HAVE_FTRIVIAL_AUTO_VAR_INIT - Success
-- Performing Test HAVE_FNO_MATH_ERRNO
-- Performing Test HAVE_FNO_MATH_ERRNO - Success
-- Performing Test HAVE_GCC_PROTECTED_VISIBILITY
-- Performing Test HAVE_GCC_PROTECTED_VISIBILITY - Success
-- Performing Test HAVE_MSSE2_SWITCH
-- Performing Test HAVE_MSSE2_SWITCH - Failed
-- Looking for xmmintrin.h
-- Looking for xmmintrin.h - not found
-- Looking for emmintrin.h
-- Looking for emmintrin.h - not found
-- Looking for pmmintrin.h
-- Looking for pmmintrin.h - not found
-- Looking for smmintrin.h
-- Looking for smmintrin.h - not found
-- Looking for arm_neon.h
-- Looking for arm_neon.h - found
-- Performing Test HAVE_NEON_INTRINSICS
-- Performing Test HAVE_NEON_INTRINSICS - Success
-- Looking for cpuid.h
-- Looking for cpuid.h - not found
-- Looking for intrin.h
-- Looking for intrin.h - not found
-- Looking for guiddef.h
-- Looking for guiddef.h - not found
-- Looking for pow in m
-- Looking for pow in m - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for dlopen in dl
-- Looking for dlopen in dl - found
-- Looking for proc_pidpath
-- Looking for proc_pidpath - not found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test HAVE_PTHREAD
-- Performing Test HAVE_PTHREAD - Success
-- Looking for pthread_setschedparam
-- Looking for pthread_setschedparam - found
-- Looking for include files pthread.h, pthread_np.h
-- Looking for include files pthread.h, pthread_np.h - not found
-- Looking for pthread_setname_np
-- Looking for pthread_setname_np - found
-- Checking for module 'libpipewire-0.3>=0.3.23'
--   No package 'libpipewire-0.3' found
-- Could NOT find PulseAudio (missing: PULSEAUDIO_LIBRARY PULSEAUDIO_INCLUDE_DIR) 
-- Could NOT find ALSA (missing: ALSA_LIBRARY ALSA_INCLUDE_DIR) 
-- Could NOT find OSS (missing: OSS_INCLUDE_DIR) 
-- Could NOT find AudioIO (missing: AUDIOIO_INCLUDE_DIR) 
-- Could NOT find JACK (missing: JACK_LIBRARY JACK_INCLUDE_DIR) 
-- Could NOT find oboe (missing: oboe_DIR)
-- Could NOT find Oboe (missing: OBOE_LIBRARY OBOE_INCLUDE_DIR) 
-- Found OpenSL: /system/lib64/libOpenSLES.so
-- Could NOT find PortAudio (missing: PORTAUDIO_LIBRARY PORTAUDIO_INCLUDE_DIR) 
-- Found Git: /data/data/com.termux/files/usr/bin/git (found version "2.48.1")
-- 
-- Building OpenAL with support for the following backends:
--     OpenSL, WaveFile, Null
-- 
-- Building with support for CPU extensions:
--     Default, Neon
-- 
-- Embedding HRTF datasets
-- 
-- Installing library and headers
-- Installing sample configuration
-- Installing HRTF data files
-- Installing AmbDec presets
-- 
-- Configuring done (33.4s)
-- Generating done (0.2s)
-- Build files have been written to: /data/data/com.termux/files/home/openal-soft_build
[  1%] Building CXX object fmt-11.1.1/CMakeFiles/alsoft.fmt.dir/src/format.cc.o
[  2%] Building CXX object fmt-11.1.1/CMakeFiles/alsoft.fmt.dir/src/os.cc.o
[  2%] Built target alsoft.fmt
[  3%] Generating version_witness.txt
[  3%] Built target alsoft.build_version
[  4%] Building CXX object CMakeFiles/alsoft.common.dir/common/alassert.cpp.o
[  5%] Building CXX object CMakeFiles/alsoft.common.dir/common/alcomplex.cpp.o
[  6%] Building CXX object CMakeFiles/alsoft.common.dir/common/alsem.cpp.o
[  7%] Building CXX object CMakeFiles/alsoft.common.dir/common/alstring.cpp.o
[  8%] Building CXX object CMakeFiles/alsoft.common.dir/common/althrd_setname.cpp.o
[  9%] Building CXX object CMakeFiles/alsoft.common.dir/common/dynload.cpp.o
[ 10%] Building CXX object CMakeFiles/alsoft.common.dir/common/filesystem.cpp.o
[ 11%] Building CXX object CMakeFiles/alsoft.common.dir/common/pffft.cpp.o
[ 12%] Building CXX object CMakeFiles/alsoft.common.dir/common/polyphase_resampler.cpp.o
[ 13%] Building CXX object CMakeFiles/alsoft.common.dir/common/ringbuffer.cpp.o
[ 14%] Building CXX object CMakeFiles/alsoft.common.dir/common/strutils.cpp.o
[ 15%] Linking CXX static library libalsoft.common.a
[ 15%] Built target alsoft.common
[ 15%] Generating default_hrtf.txt
[ 16%] Building CXX object CMakeFiles/OpenAL.dir/al/auxeffectslot.cpp.o
[ 17%] Building CXX object CMakeFiles/OpenAL.dir/al/buffer.cpp.o
[ 18%] Building CXX object CMakeFiles/OpenAL.dir/al/debug.cpp.o
[ 19%] Building CXX object CMakeFiles/OpenAL.dir/al/effect.cpp.o
[ 20%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/autowah.cpp.o
[ 21%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/chorus.cpp.o
[ 22%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/compressor.cpp.o
[ 23%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/convolution.cpp.o
[ 24%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/dedicated.cpp.o
[ 25%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/distortion.cpp.o
[ 26%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/echo.cpp.o
[ 27%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/effects.cpp.o
[ 28%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/equalizer.cpp.o
[ 29%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/fshifter.cpp.o
[ 30%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/modulator.cpp.o
[ 31%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/null.cpp.o
[ 32%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/pshifter.cpp.o
[ 33%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/reverb.cpp.o
[ 34%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/vmorpher.cpp.o
[ 35%] Building CXX object CMakeFiles/OpenAL.dir/al/error.cpp.o
[ 36%] Building CXX object CMakeFiles/OpenAL.dir/al/event.cpp.o
[ 37%] Building CXX object CMakeFiles/OpenAL.dir/al/extension.cpp.o
[ 38%] Building CXX object CMakeFiles/OpenAL.dir/al/filter.cpp.o
[ 39%] Building CXX object CMakeFiles/OpenAL.dir/al/listener.cpp.o
[ 40%] Building CXX object CMakeFiles/OpenAL.dir/al/source.cpp.o
[ 41%] Building CXX object CMakeFiles/OpenAL.dir/al/state.cpp.o
[ 42%] Building CXX object CMakeFiles/OpenAL.dir/alc/alc.cpp.o
[ 43%] Building CXX object CMakeFiles/OpenAL.dir/alc/alu.cpp.o
[ 44%] Building CXX object CMakeFiles/OpenAL.dir/alc/alconfig.cpp.o
[ 45%] Building CXX object CMakeFiles/OpenAL.dir/alc/context.cpp.o
[ 46%] Building CXX object CMakeFiles/OpenAL.dir/alc/device.cpp.o
[ 47%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/autowah.cpp.o
[ 48%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/chorus.cpp.o
[ 50%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/compressor.cpp.o
[ 51%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/convolution.cpp.o
[ 52%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/dedicated.cpp.o
[ 53%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/distortion.cpp.o
[ 54%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/echo.cpp.o
[ 55%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/equalizer.cpp.o
[ 56%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/fshifter.cpp.o
[ 57%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/modulator.cpp.o
[ 58%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/null.cpp.o
[ 59%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/pshifter.cpp.o
[ 60%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/reverb.cpp.o
[ 61%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/vmorpher.cpp.o
[ 62%] Building CXX object CMakeFiles/OpenAL.dir/alc/events.cpp.o
[ 63%] Building CXX object CMakeFiles/OpenAL.dir/alc/panning.cpp.o
[ 64%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/base.cpp.o
[ 65%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/loopback.cpp.o
[ 66%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/null.cpp.o
[ 66%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/opensl.cpp.o
[ 67%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/wave.cpp.o
[ 68%] Building CXX object CMakeFiles/OpenAL.dir/core/ambdec.cpp.o
[ 69%] Building CXX object CMakeFiles/OpenAL.dir/core/ambidefs.cpp.o
[ 70%] Building CXX object CMakeFiles/OpenAL.dir/core/bformatdec.cpp.o
[ 71%] Building CXX object CMakeFiles/OpenAL.dir/core/bs2b.cpp.o
[ 72%] Building CXX object CMakeFiles/OpenAL.dir/core/bsinc_tables.cpp.o
[ 73%] Building CXX object CMakeFiles/OpenAL.dir/core/buffer_storage.cpp.o
[ 74%] Building CXX object CMakeFiles/OpenAL.dir/core/context.cpp.o
[ 75%] Building CXX object CMakeFiles/OpenAL.dir/core/converter.cpp.o
[ 76%] Building CXX object CMakeFiles/OpenAL.dir/core/cpu_caps.cpp.o
[ 77%] Building CXX object CMakeFiles/OpenAL.dir/core/cubic_tables.cpp.o
[ 78%] Building CXX object CMakeFiles/OpenAL.dir/core/devformat.cpp.o
[ 79%] Building CXX object CMakeFiles/OpenAL.dir/core/device.cpp.o
[ 80%] Building CXX object CMakeFiles/OpenAL.dir/core/effectslot.cpp.o
[ 81%] Building CXX object CMakeFiles/OpenAL.dir/core/except.cpp.o
[ 82%] Building CXX object CMakeFiles/OpenAL.dir/core/filters/biquad.cpp.o
[ 83%] Building CXX object CMakeFiles/OpenAL.dir/core/filters/nfc.cpp.o
[ 84%] Building CXX object CMakeFiles/OpenAL.dir/core/filters/splitter.cpp.o
[ 85%] Building CXX object CMakeFiles/OpenAL.dir/core/fpu_ctrl.cpp.o
[ 86%] Building CXX object CMakeFiles/OpenAL.dir/core/helpers.cpp.o
[ 87%] Building CXX object CMakeFiles/OpenAL.dir/core/hrtf.cpp.o
[ 88%] Building CXX object CMakeFiles/OpenAL.dir/core/logging.cpp.o
[ 89%] Building CXX object CMakeFiles/OpenAL.dir/core/mastering.cpp.o
[ 90%] Building CXX object CMakeFiles/OpenAL.dir/core/mixer.cpp.o
[ 91%] Building CXX object CMakeFiles/OpenAL.dir/core/storage_formats.cpp.o
[ 92%] Building CXX object CMakeFiles/OpenAL.dir/core/uhjfilter.cpp.o
[ 93%] Building CXX object CMakeFiles/OpenAL.dir/core/uiddefs.cpp.o
[ 94%] Building CXX object CMakeFiles/OpenAL.dir/core/voice.cpp.o
[ 95%] Building CXX object CMakeFiles/OpenAL.dir/core/dbus_wrap.cpp.o
[ 96%] Building CXX object CMakeFiles/OpenAL.dir/core/rtkit.cpp.o
[ 97%] Building CXX object CMakeFiles/OpenAL.dir/core/mixer/mixer_c.cpp.o
[ 98%] Building CXX object CMakeFiles/OpenAL.dir/core/mixer/mixer_neon.cpp.o
[100%] Linking CXX shared library libopenal.so
[100%] Built target OpenAL
-- Install configuration: "RelWithDebInfo"
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/libopenal.so.1.24.2
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/libopenal.so.1
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/libopenal.so
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/cmake/OpenAL/OpenALTargets.cmake
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/cmake/OpenAL/OpenALTargets-relwithdebinfo.cmake
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/al.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/alc.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/alext.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/efx-creative.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/efx-presets.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/efx.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/pkgconfig/openal.pc
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/cmake/OpenAL/OpenALConfig.cmake
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/alsoftrc.sample
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/hrtf
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/hrtf/Default HRTF.mhr
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/3D7.1.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/hex-quad.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/hexagon.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/itu5.1-nocenter.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/itu5.1.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/presets.txt
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/rectangle.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/square.ambdec
[ALSOFT] (II) Initializing library v1.24.2-c14554f4 master
[ALSOFT] (II) Supported backends: opensl, null, wave
[ALSOFT] (II) Loading config /etc/openal/alsoft.conf...
[ALSOFT] (II) Loading config /etc/xdg/alsoft.conf...
[ALSOFT] (II) Loading config /data/data/com.termux/files/home/.alsoftrc...
[ALSOFT] (II) Loading config /data/data/com.termux/files/home/.config/alsoft.conf...
[ALSOFT] (II) Got binary: "/data/data/com.termux/files/home", "openal-soft_test"
[ALSOFT] (II) Loading config /data/data/com.termux/files/home/alsoft.conf...
[ALSOFT] (II) Extensions: +NEON
[ALSOFT] (WW) Failed to load libOpenSLES.so
[ALSOFT] (WW) Failed to initialize backend "opensl"
[ALSOFT] (WW) No playback backend available!
[ALSOFT] (WW) No capture backend available!
[ALSOFT] (WW) Error generated on device 0x0, code 0xa004
failure!
commands that work around the problem
yes | pkg upgrade -y
pkg install -y build-essential git

rm -rf openal-soft_*

git clone https://github.com/kcat/openal-soft.git openal-soft_src

cmake -S openal-soft_src -B openal-soft_build \
  -DCMAKE_INSTALL_PREFIX=$(pwd)/openal-soft_installation \
  -DALSOFT_UTILS=OFF \
  -DALSOFT_EXAMPLES=OFF \
  -DALSOFT_TESTS=OFF \
  -DALSOFT_REQUIRE_OPENSL=ON \
  -DOPENSL_LIBRARY=/system/lib$(uname -m | grep 64 > /dev/null && echo '64' || echo '')/libOpenSLES.so \
  -DALSOFT_DLOPEN=OFF
cmake --build openal-soft_build
cmake --install openal-soft_build

cat > openal-soft_test.c << EOF
#include <stdio.h>

#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"

int main(void) {
    ALCdevice *device = alcOpenDevice(NULL);

    if (device) {
        printf("success!\n");
        alcCloseDevice(device);
        return 0;
    }

    printf("failure!\n");
    return 1;
}
EOF

clang openal-soft_test.c -o openal-soft_test \
  -I openal-soft_installation/include \
  -L openal-soft_installation/lib \
  -lopenal

export ALSOFT_LOGLEVEL=3 LD_LIBRARY_PATH=openal-soft_installation/lib/
./openal-soft_test
output of commands that work around the problem
Checking availability of current mirror:
[*] https://packages.termux.dev/apt/termux-main: ok
Hit:1 https://turdl.kcubeterm.com tur-packages InRelease
Hit:2 https://packages.termux.dev/apt/termux-main stable InRelease
Hit:3 https://packages.termux.dev/apt/termux-x11 x11 InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Checking availability of current mirror:
[*] https://packages.termux.dev/apt/termux-main: ok
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (4.1).
git is already the newest version (2.48.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Cloning into 'openal-soft_src'...
remote: Enumerating objects: 60385, done.
remote: Counting objects: 100% (7702/7702), done.
remote: Compressing objects: 100% (571/571), done.
remote: Total 60385 (delta 7273), reused 7150 (delta 7131), pack-reused 52683 (from 4)
Receiving objects: 100% (60385/60385), 23.06 MiB | 10.59 MiB/s, done.
Resolving deltas: 100% (48237/48237), done.
-- The C compiler identification is Clang 19.1.7
-- The CXX compiler identification is Clang 19.1.7
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /data/data/com.termux/files/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /data/data/com.termux/files/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /data/data/com.termux/files/usr/bin/pkg-config (found version "0.29.2")
-- {fmt} version: 11.1.1
-- Build type: RelWithDebInfo
-- Performing Test HAVE_STDC_FORMAT_MACROS
-- Performing Test HAVE_STDC_FORMAT_MACROS - Success
-- Performing Test HAVE_LIBATOMIC
-- Performing Test HAVE_LIBATOMIC - Success
-- Looking for __android_log_print in log
-- Looking for __android_log_print in log - found
-- Performing Test HAVE_WNO_CXX20_ATTR_EXT
-- Performing Test HAVE_WNO_CXX20_ATTR_EXT - Success
-- Performing Test HAVE_WNO_INTERFERENCE_SIZE
-- Performing Test HAVE_WNO_INTERFERENCE_SIZE - Failed
-- Performing Test HAVE_FTRIVIAL_AUTO_VAR_INIT
-- Performing Test HAVE_FTRIVIAL_AUTO_VAR_INIT - Success
-- Performing Test HAVE_FNO_MATH_ERRNO
-- Performing Test HAVE_FNO_MATH_ERRNO - Success
-- Performing Test HAVE_GCC_PROTECTED_VISIBILITY
-- Performing Test HAVE_GCC_PROTECTED_VISIBILITY - Success
-- Performing Test HAVE_MSSE2_SWITCH
-- Performing Test HAVE_MSSE2_SWITCH - Failed
-- Looking for xmmintrin.h
-- Looking for xmmintrin.h - not found
-- Looking for emmintrin.h
-- Looking for emmintrin.h - not found
-- Looking for pmmintrin.h
-- Looking for pmmintrin.h - not found
-- Looking for smmintrin.h
-- Looking for smmintrin.h - not found
-- Looking for arm_neon.h
-- Looking for arm_neon.h - found
-- Performing Test HAVE_NEON_INTRINSICS
-- Performing Test HAVE_NEON_INTRINSICS - Success
-- Looking for cpuid.h
-- Looking for cpuid.h - not found
-- Looking for intrin.h
-- Looking for intrin.h - not found
-- Looking for guiddef.h
-- Looking for guiddef.h - not found
-- Looking for pow in m
-- Looking for pow in m - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Looking for proc_pidpath
-- Looking for proc_pidpath - not found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test HAVE_PTHREAD
-- Performing Test HAVE_PTHREAD - Success
-- Looking for pthread_setschedparam
-- Looking for pthread_setschedparam - found
-- Looking for include files pthread.h, pthread_np.h
-- Looking for include files pthread.h, pthread_np.h - not found
-- Looking for pthread_setname_np
-- Looking for pthread_setname_np - found
-- Checking for module 'libpipewire-0.3>=0.3.23'
--   No package 'libpipewire-0.3' found
-- Could NOT find PulseAudio (missing: PULSEAUDIO_LIBRARY PULSEAUDIO_INCLUDE_DIR) 
-- Could NOT find ALSA (missing: ALSA_LIBRARY ALSA_INCLUDE_DIR) 
-- Could NOT find OSS (missing: OSS_INCLUDE_DIR) 
-- Could NOT find AudioIO (missing: AUDIOIO_INCLUDE_DIR) 
-- Could NOT find JACK (missing: JACK_LIBRARY JACK_INCLUDE_DIR) 
-- Could NOT find oboe (missing: oboe_DIR)
-- Could NOT find Oboe (missing: OBOE_LIBRARY OBOE_INCLUDE_DIR) 
-- Found OpenSL: /system/lib64/libOpenSLES.so
-- Could NOT find PortAudio (missing: PORTAUDIO_LIBRARY PORTAUDIO_INCLUDE_DIR) 
-- Found Git: /data/data/com.termux/files/usr/bin/git (found version "2.48.1")
-- 
-- Building OpenAL with support for the following backends:
--     OpenSL (linked), WaveFile, Null
-- 
-- Building with support for CPU extensions:
--     Default, Neon
-- 
-- Embedding HRTF datasets
-- 
-- Installing library and headers
-- Installing sample configuration
-- Installing HRTF data files
-- Installing AmbDec presets
-- 
-- Configuring done (30.4s)
-- Generating done (0.2s)
-- Build files have been written to: /data/data/com.termux/files/home/openal-soft_build
[  1%] Building CXX object fmt-11.1.1/CMakeFiles/alsoft.fmt.dir/src/format.cc.o
[  2%] Building CXX object fmt-11.1.1/CMakeFiles/alsoft.fmt.dir/src/os.cc.o
[  2%] Built target alsoft.fmt
[  3%] Building CXX object CMakeFiles/alsoft.common.dir/common/alassert.cpp.o
[  4%] Building CXX object CMakeFiles/alsoft.common.dir/common/alcomplex.cpp.o
[  5%] Building CXX object CMakeFiles/alsoft.common.dir/common/alsem.cpp.o
[  6%] Building CXX object CMakeFiles/alsoft.common.dir/common/alstring.cpp.o
[  7%] Building CXX object CMakeFiles/alsoft.common.dir/common/althrd_setname.cpp.o
[  8%] Building CXX object CMakeFiles/alsoft.common.dir/common/dynload.cpp.o
[  9%] Building CXX object CMakeFiles/alsoft.common.dir/common/filesystem.cpp.o
[ 10%] Building CXX object CMakeFiles/alsoft.common.dir/common/pffft.cpp.o
[ 11%] Building CXX object CMakeFiles/alsoft.common.dir/common/polyphase_resampler.cpp.o
[ 12%] Building CXX object CMakeFiles/alsoft.common.dir/common/ringbuffer.cpp.o
[ 13%] Building CXX object CMakeFiles/alsoft.common.dir/common/strutils.cpp.o
[ 14%] Linking CXX static library libalsoft.common.a
[ 14%] Built target alsoft.common
[ 15%] Generating version_witness.txt
[ 15%] Built target alsoft.build_version
[ 15%] Generating default_hrtf.txt
[ 16%] Building CXX object CMakeFiles/OpenAL.dir/al/auxeffectslot.cpp.o
[ 17%] Building CXX object CMakeFiles/OpenAL.dir/al/buffer.cpp.o
[ 18%] Building CXX object CMakeFiles/OpenAL.dir/al/debug.cpp.o
[ 19%] Building CXX object CMakeFiles/OpenAL.dir/al/effect.cpp.o
[ 20%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/autowah.cpp.o
[ 21%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/chorus.cpp.o
[ 22%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/compressor.cpp.o
[ 23%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/convolution.cpp.o
[ 24%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/dedicated.cpp.o
[ 25%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/distortion.cpp.o
[ 26%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/echo.cpp.o
[ 27%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/effects.cpp.o
[ 28%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/equalizer.cpp.o
[ 29%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/fshifter.cpp.o
[ 30%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/modulator.cpp.o
[ 31%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/null.cpp.o
[ 32%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/pshifter.cpp.o
[ 33%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/reverb.cpp.o
[ 34%] Building CXX object CMakeFiles/OpenAL.dir/al/effects/vmorpher.cpp.o
[ 35%] Building CXX object CMakeFiles/OpenAL.dir/al/error.cpp.o
[ 36%] Building CXX object CMakeFiles/OpenAL.dir/al/event.cpp.o
[ 37%] Building CXX object CMakeFiles/OpenAL.dir/al/extension.cpp.o
[ 38%] Building CXX object CMakeFiles/OpenAL.dir/al/filter.cpp.o
[ 39%] Building CXX object CMakeFiles/OpenAL.dir/al/listener.cpp.o
[ 40%] Building CXX object CMakeFiles/OpenAL.dir/al/source.cpp.o
[ 41%] Building CXX object CMakeFiles/OpenAL.dir/al/state.cpp.o
[ 42%] Building CXX object CMakeFiles/OpenAL.dir/alc/alc.cpp.o
[ 43%] Building CXX object CMakeFiles/OpenAL.dir/alc/alu.cpp.o
[ 44%] Building CXX object CMakeFiles/OpenAL.dir/alc/alconfig.cpp.o
[ 45%] Building CXX object CMakeFiles/OpenAL.dir/alc/context.cpp.o
[ 46%] Building CXX object CMakeFiles/OpenAL.dir/alc/device.cpp.o
[ 47%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/autowah.cpp.o
[ 48%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/chorus.cpp.o
[ 50%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/compressor.cpp.o
[ 51%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/convolution.cpp.o
[ 52%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/dedicated.cpp.o
[ 53%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/distortion.cpp.o
[ 54%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/echo.cpp.o
[ 55%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/equalizer.cpp.o
[ 56%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/fshifter.cpp.o
[ 57%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/modulator.cpp.o
[ 58%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/null.cpp.o
[ 59%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/pshifter.cpp.o
[ 60%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/reverb.cpp.o
[ 61%] Building CXX object CMakeFiles/OpenAL.dir/alc/effects/vmorpher.cpp.o
[ 62%] Building CXX object CMakeFiles/OpenAL.dir/alc/events.cpp.o
[ 63%] Building CXX object CMakeFiles/OpenAL.dir/alc/panning.cpp.o
[ 64%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/base.cpp.o
[ 65%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/loopback.cpp.o
[ 66%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/null.cpp.o
[ 66%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/opensl.cpp.o
[ 67%] Building CXX object CMakeFiles/OpenAL.dir/alc/backends/wave.cpp.o
[ 68%] Building CXX object CMakeFiles/OpenAL.dir/core/ambdec.cpp.o
[ 69%] Building CXX object CMakeFiles/OpenAL.dir/core/ambidefs.cpp.o
[ 70%] Building CXX object CMakeFiles/OpenAL.dir/core/bformatdec.cpp.o
[ 71%] Building CXX object CMakeFiles/OpenAL.dir/core/bs2b.cpp.o
[ 72%] Building CXX object CMakeFiles/OpenAL.dir/core/bsinc_tables.cpp.o
[ 73%] Building CXX object CMakeFiles/OpenAL.dir/core/buffer_storage.cpp.o
[ 74%] Building CXX object CMakeFiles/OpenAL.dir/core/context.cpp.o
[ 75%] Building CXX object CMakeFiles/OpenAL.dir/core/converter.cpp.o
[ 76%] Building CXX object CMakeFiles/OpenAL.dir/core/cpu_caps.cpp.o
[ 77%] Building CXX object CMakeFiles/OpenAL.dir/core/cubic_tables.cpp.o
[ 78%] Building CXX object CMakeFiles/OpenAL.dir/core/devformat.cpp.o
[ 79%] Building CXX object CMakeFiles/OpenAL.dir/core/device.cpp.o
[ 80%] Building CXX object CMakeFiles/OpenAL.dir/core/effectslot.cpp.o
[ 81%] Building CXX object CMakeFiles/OpenAL.dir/core/except.cpp.o
[ 82%] Building CXX object CMakeFiles/OpenAL.dir/core/filters/biquad.cpp.o
[ 83%] Building CXX object CMakeFiles/OpenAL.dir/core/filters/nfc.cpp.o
[ 84%] Building CXX object CMakeFiles/OpenAL.dir/core/filters/splitter.cpp.o
[ 85%] Building CXX object CMakeFiles/OpenAL.dir/core/fpu_ctrl.cpp.o
[ 86%] Building CXX object CMakeFiles/OpenAL.dir/core/helpers.cpp.o
[ 87%] Building CXX object CMakeFiles/OpenAL.dir/core/hrtf.cpp.o
[ 88%] Building CXX object CMakeFiles/OpenAL.dir/core/logging.cpp.o
[ 89%] Building CXX object CMakeFiles/OpenAL.dir/core/mastering.cpp.o
[ 90%] Building CXX object CMakeFiles/OpenAL.dir/core/mixer.cpp.o
[ 91%] Building CXX object CMakeFiles/OpenAL.dir/core/storage_formats.cpp.o
[ 92%] Building CXX object CMakeFiles/OpenAL.dir/core/uhjfilter.cpp.o
[ 93%] Building CXX object CMakeFiles/OpenAL.dir/core/uiddefs.cpp.o
[ 94%] Building CXX object CMakeFiles/OpenAL.dir/core/voice.cpp.o
[ 95%] Building CXX object CMakeFiles/OpenAL.dir/core/dbus_wrap.cpp.o
[ 96%] Building CXX object CMakeFiles/OpenAL.dir/core/rtkit.cpp.o
[ 97%] Building CXX object CMakeFiles/OpenAL.dir/core/mixer/mixer_c.cpp.o
[ 98%] Building CXX object CMakeFiles/OpenAL.dir/core/mixer/mixer_neon.cpp.o
[100%] Linking CXX shared library libopenal.so
[100%] Built target OpenAL
-- Install configuration: "RelWithDebInfo"
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/libopenal.so.1.24.2
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/libopenal.so.1
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/libopenal.so
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/cmake/OpenAL/OpenALTargets.cmake
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/cmake/OpenAL/OpenALTargets-relwithdebinfo.cmake
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/al.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/alc.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/alext.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/efx-creative.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/efx-presets.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/include/AL/efx.h
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/pkgconfig/openal.pc
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/lib/cmake/OpenAL/OpenALConfig.cmake
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/alsoftrc.sample
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/hrtf
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/hrtf/Default HRTF.mhr
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/3D7.1.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/hex-quad.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/hexagon.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/itu5.1-nocenter.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/itu5.1.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/presets.txt
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/rectangle.ambdec
-- Installing: /data/data/com.termux/files/home/openal-soft_installation/share/openal/presets/square.ambdec
[ALSOFT] (II) Initializing library v1.24.2-c14554f4 master
[ALSOFT] (II) Supported backends: opensl, null, wave
[ALSOFT] (II) Loading config /etc/openal/alsoft.conf...
[ALSOFT] (II) Loading config /etc/xdg/alsoft.conf...
[ALSOFT] (II) Loading config /data/data/com.termux/files/home/.alsoftrc...
[ALSOFT] (II) Loading config /data/data/com.termux/files/home/.config/alsoft.conf...
[ALSOFT] (II) Got binary: "/data/data/com.termux/files/home", "openal-soft_test"
[ALSOFT] (II) Loading config /data/data/com.termux/files/home/alsoft.conf...
[ALSOFT] (II) Extensions: +NEON
[ALSOFT] (II) Initialized backend "opensl"
[ALSOFT] (II) Added "opensl" for playback
[ALSOFT] (II) Added "opensl" for capture
[ALSOFT] (II) Opening default playback device
[ALSOFT] (II) Created device 0x71090eba00, "OpenSL"
success!
[ALSOFT] (II) Freeing device 0x71090eba00

The only difference between these two scripts is that when -DALSOFT_DLOPEN=ON is used (or -DALSOFT_DLOPEN is not specified), then the OpenSLES backend does not work on the affected devices, but when -DALSOFT_DLOPEN=OFF is used, it does work.

@robertkirkman
Copy link
Author

I have discovered that, on the affected devices, one possible application-side alternative workaround is to add the argument -Wl,--no-as-needed,-lOpenSLES,--as-needed to the clang command, like this:

clang openal-soft_test.c -o openal-soft_test \
  -I openal-soft_installation/include \
  -L openal-soft_installation/lib \
  -lopenal -Wl,--no-as-needed,-lOpenSLES,--as-needed

that causes the dlopen() call here to begin succeeding when name is libOpenSLES.so:

void *handle{dlopen(name, RTLD_NOW)};

however, this does not explain why it is only necessary on some devices and not other devices, and it also would require remembering to specify that linker argument with every application that is linked against libopenal.sos that were built with ALSOFT_DLOPEN=ON.

@kcat
Copy link
Owner

kcat commented Feb 17, 2025

I'm curious what the error actually is. If dlopen(name, RTLD_NOW) fails, dlerror() will return a string describing the error. In the code that's there currently, the message is lost since there's no logging functions available there. You could probably hack in a call to fprintf or something when err is non-null and see what it says, something like

    void *handle{dlopen(name, RTLD_NOW)};
    const char *err{dlerror()};
    if(err)
    {
        fprintf(stderr, "%s\n", name, err);
        handle = nullptr;
    }

@robertkirkman
Copy link
Author

Thank you for the good suggestion, I have added that into the reproduction script like this:

reproduction script with improved logging
yes | pkg upgrade -y
pkg install -y build-essential git

rm -rf openal-soft_*

git clone https://github.com/kcat/openal-soft.git openal-soft_src

git -C openal-soft_src apply -v --whitespace=fix << EOF
--- a/common/dynload.cpp
+++ b/common/dynload.cpp
@@ -22,13 +22,17 @@ void *GetSymbol(void *handle, const char *name)
 #elif defined(HAVE_DLFCN_H)
 
 #include <dlfcn.h>
+#include <stdio.h>
 
 void *LoadLib(const char *name)
 {
     dlerror();
     void *handle{dlopen(name, RTLD_NOW)};
     const char *err{dlerror()};
-    if(err) handle = nullptr;
+    if(err) {
+        fprintf(stderr, "dlopen(\"%s\") failed: %s\n", name, err);
+        handle = nullptr;
+    }
     return handle;
 }
 void CloseLib(void *handle)
EOF

cmake -S openal-soft_src -B openal-soft_build \
  -DCMAKE_INSTALL_PREFIX=$(pwd)/openal-soft_installation \
  -DALSOFT_UTILS=OFF \
  -DALSOFT_EXAMPLES=OFF \
  -DALSOFT_TESTS=OFF \
  -DALSOFT_REQUIRE_OPENSL=ON \
  -DOPENSL_LIBRARY=/system/lib$(uname -m | grep 64 > /dev/null && echo '64' || echo '')/libOpenSLES.so \
  -DALSOFT_DLOPEN=ON
cmake --build openal-soft_build
cmake --install openal-soft_build

cat > openal-soft_test.c << EOF
#include <stdio.h>

#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"

int main(void) {
    ALCdevice *device = alcOpenDevice(NULL);

    if (device) {
        printf("success!\n");
        alcCloseDevice(device);
        return 0;
    }

    printf("failure!\n");
    return 1;
}
EOF

clang openal-soft_test.c -o openal-soft_test \
  -I openal-soft_installation/include \
  -L openal-soft_installation/lib \
  -lopenal

export ALSOFT_LOGLEVEL=3 LD_LIBRARY_PATH=openal-soft_installation/lib/
./openal-soft_test

Using this, I have been able to observe the string that is stored into err on each of the affected devices.

It sort of makes sense this would be the case, but this reveals that the error message is slightly different on at least one of the affected devices, confirming that subtle, possibly unpredictable differences between the libOpenSLES.so files of each Android ROM are influencing the results, causing libopenal.so to hit a different error on each device, while presumably on the unaffected devices, it is lucky enough to "miss" all the possible errors and end up succeeding.

fprintf() results

  • Samsung Galaxy S7 SM-G930U:
    • dlopen("libOpenSLES.so") failed: dlopen failed: library "libavenhancements.so" not found
  • Samsung Galaxy S9 SM-G960U:
    • dlopen("libOpenSLES.so") failed: dlopen failed: library "libavenhancements.so" not found
  • Samsung Galaxy S8+ SM-G955F:
    • dlopen("libOpenSLES.so") failed: undefined symbol: swift_demangle

I had put the Samsung Galaxy Tab S3 away so it's not available at the moment, but if you would like to see the result of the additional log message on it as well, let me know and I will go retrieve it at the soonest opportunity. In the mean time, I hope the results from the other three affected devices I have are sufficient to show what you wanted to see.

@kcat
Copy link
Owner

kcat commented Feb 18, 2025

I'm not sure what I can do here. It seems to be an issue with libOpenSLES.so/Android that the lib requires something that's not available. I don't know why linking with --no-as-needed would let dlopen(name, RTLD_NOW) work, or how linking to libOpenSLES.so at build time without that switch makes it work when dlopen(name, RTLD_NOW) doesn't. Other code I've found that dynamically loads libOpenSLES.so doesn't do anything special either, loading with dlopen(name, RTLD_NOW) and without the --no-as-needed switch: https://github.com/BelledonneCommunications/mediastreamer2/blob/master/src/android/androidsound_opensles.cpp

@robertkirkman
Copy link
Author

robertkirkman commented Feb 25, 2025

I am sorry for the delay in response,

I suspect that it might be possible to carefully construct a crafted test case that would also cause the dlopen() call you linked in mediastreamer2 to fail,

and I believe that the Termux app .apk is not strictly necessary to reproduce the problem either, and that the issue could also be reproduced on the affected devices using a set of purely official Google-originated Android toolchains (like the official Android NDK) and entrypoints (like ADB shell or Java-Native Interface),

but it is just taking a long time to set up those things, and doing so will make it somewhat obvious that the crafted test case deviates so far from the environments that the creators of mediastreamer2 might have tested their software with, that it might be questionable whether it is reasonable to expect library developers to support such use cases on Android.

I believe that the major difference between environments where the problem is reproducible (on affected devices), and environments where it is not (on any devices), is that environments where the problem is not reproducible usually involve a large application with a main ELF .so containing most of the application's native code, often loaded and executed through the traditional Android Java-Native Interface, that is not just dynamically linked to libopenal.so, but which is also dynamically linked to at least one of a few other "higher-level" OS libraries in /system/lib64, which include libOpenSLES.so but also libjnigraphics.so, libGLESv2.so, libnativewindow.so, libmediautils.so and so on, which are all themselves dynamically linked to a very large "dependency tree" that may be "pulled in" by dynamically linking the executable to any of several different "nodes" of this tree, including libOpenSLES.so,

and that environments where the problem is reproducible usually involve a very minimal ELF file that has very few dependencies other than openal-soft itself, and which has been compiled using an Android toolchain in such a way that only the bare minimum of "lower-level" OS libraries in /system/lib64, which form the very barebones subset of Android necessary for executing C programs (or C++ - on Android, application code always bundles its own libc++.so/libc++.a, while libc.so is intended to be shared between all native binaries in the device that are not fully static) that are "headless" in that they do not use any graphics or audio functionality, are actually linked: libc.so, libm.so, libdl.so, ld-android.so .

That second type of binary, the type that is only dynamically linked to the very minimal set of "lower-level" OS libraries and then also to libopenal.so by itself, is the type that seems to have a chance of causing libopenal.so to fail to dlopen() libOpenSLES.so on some Android devices, but not on others, if libopenal.so itself is not dynamically linked into the "dependency tree".

I will update this further once I complete one of those two goals I mentioned at the start of this comment.

The Termux app maintainers have accepted -Wl,--no-as-needed,-lOpenSLES,--as-needed applied on a case-by-case basis to every affected application that depends on openal-soft, as their preferred workaround (as opposed to adding -DALSOFT_DLOPEN=OFF or equivalent to their openal-soft build configuration).
The former workaround causes the application binary to itself be dynamically linked into the large "dependency tree" of libraries in /system/lib64 that seems to be required to fulfill the dependencies of libOpenSLES.so on some devices,
while the latter workaround causes libopenal.so to be linked into that "dependency tree" instead, which is inherited by all software that is then dynamically linked to that libopenal.so (and that is the behavior that was default in openal-soft 1.24.1 and older)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants