86

You can do this with ldd command: NAME ldd - print shared library dependencies SYNOPSIS ldd [OPTION]... FILE... DESCRIPTION ldd prints the shared libraries required by each program or shared library specified on the command line. .... Example: $ ldd /bin/ls linux-vdso.so.1 => (0x00007fff87ffe000) libselinux....


66

readelf -d $executable | grep 'NEEDED' Can be used if you can't run the executable, e.g. if it was cross compiled, or if you don't trust it: In the usual case, ldd invokes the standard dynamic linker (see ld.so(8)) with the LD_TRACE_LOADED_OBJECTS environment variable set to 1, which causes the linker to display the library dependencies. Be ...


35

dlopen isn't a system call, it's a library function in the libdl library. Only system calls show up in strace. On Linux and on many other platforms (especially those that use the ELF format for executables), dlopen is implemented by opening the target library with open() and mapping it into memory with mmap(). mmap() is really the critical part here, it's ...


28

But why does it not do the same until it finds the expected version rather than accepting the first instance of library irrespective of its version? It does, as far as it’s aware. zlib.so.1.2.7 and zlib.so.1.2.8 both have an soname of zlib.so.1, so your alpha and bravo binaries say they need zlib.so.1. The dynamic loader loads the first matching library it ...


27

Shared libraries should be versioned according to the following scheme: blah.so.X.Y.Z where X = backwards incompatible ABI release Y = backwards compatible ABI release Z = Internal changes only - no change to the ABI Typically you only see the first digit like hello.so.1 because the first digit is the only thing needed to identify the "version" of the ...


27

The gold linker was designed as an ELF-specific linker, with the intention of producing a more maintainable and faster linker than BFD ld (the “traditional” GNU binutils linker). As a side-effect, it is indeed able to link very large programs using less memory than BFD ld, presumably because there are fewer layers of abstraction to deal with, and because the ...


26

The option is shown as "-l_library_" (no space) or "-l _library_" (with a space) and c is the library argument, see https://linux.die.net/man/1/gcc -lc will link libc (-lfoobar would link libfoobar etc.) General information about options and arguments UNIX commands often accept option arguments with or without whitespace. If you have an option o which ...


22

As mentioned in Why does a software package run just fine even when it is being upgraded?, the lock is placed on inode not on filename. When you load and execute a binary, the the file is marked as busy - which is why you get ETXTBSY (file busy) error when you try to write to it. Now, for shared libraries it is slightly different: the libraries get memory ...


19

ldd and lsof show the libraries loaded either directly or at a given moment. They do not account for libraries loaded via dlopen (or discarded by dlclose). You can get a better picture of this using strace, e.g., strace -e trace=open myprogram (since dlopen ultimately calls open - though you may of course have a system using different names for 64-bit ...


19

Yes, it links itself when it initialises. Technically the dynamic linker doesn’t need object resolution and relocation for itself, since it’s fully resolved as-is, but it does define symbols and it has to take care of those when resolving the binary it’s “interpreting”, and those symbols are updated to point to their implementations in the loaded libraries. ...


18

The paths to look for libraries in will be listed in the file /etc/ld.so.conf, the environment variable LD_LIBRARY_PATH and any RPATHs encoded into the ELF binary. The program ldd will tell you what libraries a specific application will load. Once you have a symbol you are curious about, you can use the program nm to dump symbols of .o and .a files and ...


18

The order is documented in the manual of the dynamic linker, which is ld.so. It is: directories from LD_LIBRARY_PATH; directories from /etc/ld.so.conf; /lib; /usr/lib. (I'm simplifying a little, see the manual for the full details.) The order makes sense when you consider that it's the only way to override a library in a default location with a custom ...


16

ldconfig can list all the libraries it has access to. These libraries are also stored in its cache. /sbin/ldconfig -v -N will crawl all the usual library paths, list all the available libraries, without reconstructing the cache (which is not possible if you're a non-root user). It does NOT take into account libraries in LD_LIBRARY_PATH (contrarily to what ...


16

As mentioned by @Kusalananda, usually upgrades are done by removing the old file, and creating a new one with the same name. This will actually create a new file with a new inode, leaving the system free to use the old one as long as it is open. As a simplified example, stuff like rm /bin/cat cp /new/version/of/cat /bin/cat will create a logically new ...


15

You probably don’t want to “solve” this problem; according to the Debian glibc manpage for ld.so, /etc/ld.so.nohwcap When this file is present the dynamic linker will load the non-optimized version of a library, even if the CPU supports the optimized version. It’s not installed by a package, it can be created by the system administrator to ...


15

This: $ file /usr/bin/wine /usr/bin/wine: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=eaf6de433d8196e746c95d352e0258fe2b65ae24, stripped Combined with this: $ ldd /usr/bin/wine /usr/bin/ldd: line 117: /usr/bin/wine: No such file or directory Strongly ...


13

Actually, you can install multiple versions of a shared library if it's done properly. Shared libraries are usually named as follows: lib<name>.so.<api-version>.<minor> Next, there are symlinks to the library under the following names: lib<name>.so lib<name>.so.<api-version> When a developer links against the library ...


13

The gold linker was written to make the link process considerably faster. According to the gold auther Ian Lance Taylor At the moment gold has only one significant advantage over the existing linker: it is faster. On large C++ programs, I have measured it as running five times faster. He is comparing gold linker performance with the traditional GNU ...


12

The following is a really good reference: http://www.ibm.com/developerworks/linux/library/l-dynamic-libraries/. It contains a bibliography at the end of a variety of different references at different levels. If you want to know every gory detail you can go straight to the source: http://www.akkadia.org/drepper/dsohowto.pdf. (Ulrich Drepper wrote the Linux ...


12

The path to the loader is compiled into the binary as you discovered with your hex editor. You actually got lucky that editing the binary directly worked because both /lib/ld-linux.so.2 and /home/chroot/ld.so are the same length. The lengths of those strings are also in the binary and you can cause subtle problems if you modify the strings directly. If you ...


11

System calls are implemented in the kernel, as mentioned in the answer to your followup question. vDSO, the virtual dynamic shared object, is a small virtual library, also implemented by the kernel, which the kernel maps into all processes. Like syscalls it is wrapped by the C library. The main difference between syscalls and the vDSO is one of privilege. ...


10

No, but the dynamic linker will ignore some environment variables when run with setuid as otherwise you could make it load and run any code as the target user. That goes for LD_LIBRARY_PATH, LD_PRELOAD and more. See ld.so(8).


10

The start address is the address of main(), right? Not really: The start of a program isn't really main(). By default, GCC will produce executables whose start address corresponds to the _start symbol. You can see that by doing a objdump --disassemble Q1. Here's the output on a simple program of mine that only does return 0; in main(): 0000000000400e30 <...


10

You can't usually run binary files in NixOS, they will either need some environment variables set or to be patched with patchElf. I assume you can install and run java using the nix package manager. You can probably also create a suitable environment to run it using myEnvFun.


10

lsof also can show you which libraries are being used for one particular process. i.e. $ pidof nginx 6920 6919 $ lsof -p 6919|grep mem nginx 6919 root mem REG 0,64 65960 43 /lib64/libnss_files-2.12.so nginx 6919 root mem REG 0,64 19536 36 /lib64/libdl-2.12.so nginx 6919 root mem REG ...


9

I think the answer to your question is no, although you can accomplish the same thing other ways. in man ld.so, I see no mention of being able to use custom .conf or .cache True, but there is mention of $LD_LIBRARY_PATH and and --library-path, the former being more generally useful. what's the point of the above two options of ldconfig then? So you ...


9

I found two ways to do this: Debian-specific, lists most deleted/replaced files held by processes (with the exception of certain files known to be transient, e.g. stuff in /tmp): The debian-goodies package contains checkrestart, which accomplishes something like what I've described by scraping the output of lsof to find open files that are gone or replaced ...


9

I don't have the same binary you have but I made a little test and it seems that patchelf can work here. I have a hello binary compiled with -Wl,-rpath=/home/ja/c/hello-puts/make/lib and libtest.so as a dependency: $ ldd hello linux-vdso.so.1 (0x00007ffedb4f0000) libtest.so => /home/ja/c/hello-puts/make/lib/libtest.so (0x00007f04a2437000)...


8

I suppose we're talking about x86 architecture. You cannot have Self-Modifying Code in protected mode, which is used by most UNIX-based operating systems (and not only) that I'm aware of, because the code segments are always read-only. A loader does not control that -it is something that is being handled by the memory management subsystem of the kernel. ...


8

A very similar question was asked on Stack Overflow: How to extract function prototype from an ELF file? In short: generally you can't. If the executable (or shared library) doesn't have debug information, the information on the number and type of arguments is not stored in the executable. If the shared object file does have debug information, then you ...


Only top voted, non community-wiki answers of a minimum length are eligible