What is the LD_PRELOAD trick?

前端 未结 9 1188
攒了一身酷
攒了一身酷 2020-11-21 07:27

I came across a reference to it recently on proggit and (as of now) it is not explained.

I suspect this might be it, but I don\'t know for sure.

9条回答
  •  面向向阳花
    2020-11-21 07:54

    As many people mentioned, using LD_PRELOAD to preload library. BTW, you can CHECK if the setting is available by ldd command.

    Example: suppose you need to preload your own libselinux.so.1.

    > ldd /bin/ls
        ...
        libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f3927b1d000)
        libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f3927914000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f392754f000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f3927311000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f392710c000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f3927d65000)
        libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007f3926f07000)
    

    Thus, set your preload environment:

      export LD_PRELOAD=/home/patric/libselinux.so.1
    

    Check your library again:

    >ldd /bin/ls
        ...
        libselinux.so.1 =>
        /home/patric/libselinux.so.1 (0x00007fb9245d8000)
        ...
    

提交回复
热议问题