Search code examples
spotifyalsald-preload

Problems loading shared library using LD_PRELOAD


I have a legacy system that was working on a previous system but cannot get it working.

The system: I have a Asus Xonar 7,1 audio card. I previously had spotify for Linux running on it. What I had running before was the 7.1 card with all channels hooked up to a 8 channel amplifier. I used .asoundrc with multiple pcm devices representing each set of speakers i.e.

pcm.study {
    type route
    slave {
        pcm "hw:0,0"
        channels 8
    }
    ttable {
        0.2= 1
        1.3= 1
    }
}

This was repeated for each room. The original spotify for Linux did not let me select the audio device so I wrote a shared lib that intercepted the snd_pcm_open and modified the device name based on a value in a file then used

dlsym(RTLD_NEXT, "snd_pcm_open")

to open the desired device. I had a separate daemon to set the value in this file.

The original spotify for linux is no longer supported, so I have tried the snap package after installing debian 12 and have managed to get the separate pcm devices playing thru the desired outputs using aplay -D study.

I have written an app that plays a wave file to the default alsa device and used the LD_PRELOAD to preload my lib and it works Ok.

For all other apps I am getting various different problems. for spotify (snap install) and a few other apps using librespot I get

ld.so: object 'alsaselect.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

I have tried full paths to the lib and just the library name. I have used LD_DEBUG and strace on the load but cannot see why it is failing.

With vlc I can load the library but when I intercept snd_pcm_open the function dlsym(RTLD_NEXT, "snd_pcm_open") returns NULL

vlc can play the pcm devices Ok from it's device selection menu.

Am unsure whether to continue down this path. Is there another way to achieve this. I have very little trouble implementing this originally, but am unsure if something in the OS has changed (I think the original would be less than debian 8)


Solution

  • Ok resolved this via a different path.

    It appears the reason the LD_PRELOAD failed was that the new spotify app is a snap app and it appears the container system is stopping the preload. Likewise the other app I tried https://github.com/xou816/spot was distributed as a flatpak has the same issue.

    Do not really understand what is causing the load failure, as I would assume that it might load but fail to work, but I can ignore that.

    Solved it by cloning the spot repo and compiling it so I can run it as a local app. My original LD_PRELOAD now loads and works as before.