Setting my lib for LD_PRELOAD makes some processes produce loader errors

前端 未结 2 1831
隐瞒了意图╮
隐瞒了意图╮ 2021-02-05 19:33

I get the following error when I try to run a script I have only execution access for:

uname: symbol lookup error: /home/dumindara/random/sotest/a.out: undefined s

2条回答
  •  Happy的楠姐
    2021-02-05 20:21

    I assume that your a.out file is a shared object and not a executable and move on...

    dlsym() is a function from the libdl library, which usually resides in the libdl.so.2 shared object on modern Linux systems.

    I'll hazzard a guess that your a.out shared object is not linked to libdl. That means that when you preload in a simple binary like uname that does not pull in a lot of other libraries, libdl.so.2 may not be pulled in and you get an undefined symbol error.

    If, on the other hand, you preload it to a binary that is linked to and finally pulls in libdl.so.2, your shared object works fine.

    I'd check with ldd if your own shared object is linked against libdl as it should, and also what libraries are directly or indirectly pulled in when uname and ls run.

    EDIT:

    I just confirmed this. The way to fix this error is to link your shared object against libdl. Adding -ldl to its LDFLAGS should do the trick.

提交回复
热议问题