In this article series, you will be told how to make an appimage file.
The first chapter will focus on running executables independently of the system. You should have intermediate knowledge of gnu/linux to understand this section clearly.
Static and dynamic binary concept
A statically compiled code can run without the need for any additional libraries. To understand whether a file is static or not, we need to look at that file with the ldd command.
$ ldd /bin/bash linux-vdso.so.1 (0x00007ffc8f136000) libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007ff10adcd000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff10adc7000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff10ac02000) /lib64/ld-linux-x86-64.so.2 (0x00007ff10af6c000)
As seen here, our file is compiled as dynamic, so its dependencies are listed. If our file was compiled as static, we should have obtained an output like the one below.
$ ldd test.bin not a dynamic executable
libc and interpreter concept
All dynamically compiled files are basically libc.so.6 ve ld-linux-x86-64.so.2 needs dependencies. from these files libc.so.6 It is a basic C library. Thanks to this library, the program becomes able to perform its basic functions. ld-linux-x86-64.so.2 is the interpreter and determines how the file will be run. To find which interpreter a file works with fillet We can use the command. linux-vdso.so.1 is provided by the kernel and is not available as any file.
$ file /bin/bash /bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU /Linux 3.2.0, stripped
The dependency of an executable must usually be installed on the system. However, in some cases, it may need to be located in a different location than the system directories. In similar cases LD_LIBRARY_PATH By defining the environmental variable, the location of the additional directory where the library will be searched is specified.
$ ldd test.bin linux-vdso.so.1 (0x00007ffc1c5c5000) libtest.so => not found libc.so.6 => /lib64/libc.so.6 (0x00007feaab862000) /lib64/ld-linux-x86-64 .so.2 (0x00007feaaba76000)
In the example above libtest.so We encountered a warning in our ldd output because the file could not be found in the system. Now let's try the same process again by defining our environmental variable.
$ export LD_LIBRARY_PATH=/home/user/test/libs/ $ ldd test.bin linux-vdso.so.1 (0x00007ffe22bbc000) libtest.so => /home/user/test/libs/libtest.so (0x00007f4c97790000) libc.so.6 => /lib64/libc.so.6 (0x00007f4c97583000) /lib64/ld-linux-x86-64.so.2 (0x00007f4c9779c000)
As you can see it found the library in the directory we defined.
In this way, if we copy all the dependencies of a file to a directory, we can run that file independently of the system.
$ ldd /bin/bash linux-vdso.so.1 (0x00007fff2c359000) libreadline.so.8 => /lib64/libreadline.so.8 (0x00007fce1e004000) libtinfo.so.6 => /lib64/libtinfo.so.6 ( 0x00007fce1dfc5000) libc.so.6 => /lib64/libc.so.6 (0x00007fce1ddcc000) libtinfow.so.6 => /lib64/libtinfow.so.6 (0x00007fce1dd8c000) /lib64/ld-linux-x86-64.so .2 (0x00007fce1e154000) # Now let's copy all the files to a directory called libs. $ mkdir libs $ ldd /bin/bash | cut -f3 -d" " | grep "^/" | sed "s/.*/install & libs\//g" | sh # You can use the above command to batch copy dependencies. $ ls libs libc.so.6 libreadline.so.8 libtinfo.so.6 libtinfow.so.6 # Now let's define our environmental variable. export LD_LIBRARY_PATH=/home/user/test/libs/ $ ldd /bin/bash linux-vdso.so.1 (0x00007ffdeddc6000) libreadline.so.8 => /home/user/test/libs/libreadline.so.8 ( 0x00007fd9ce7ea000) libtinfo.so.6 => /home/user/test/libs/libtinfo.so.6 (0x00007fd9ce7ab000) libc.so.6 => /home/user/test/libs/libc.so.6 (0x00007fd9ce5b2000) libtinfow.so.6 => /home/user/test/libs/libtinfow.so.6 (0x00007fd9ce572000) /lib64/ld-linux-x86-64.so.2 (0x00007fd9ce926000)
In the example above, we pulled all the dependencies from their location in the system and copied them to a separate directory and made them use it from that directory. If you have noticed here, we did not copy the interpreter. This is because the interpreter is called by the file when we run the file. To overcome this situation, let's also copy the interpreter and the file to be run and run it as follows.
$ install /bin/bash ./ $ install /lib64/ld-linux-x86-64.so.2 ./ $ ./ld-linux-x86-64.so.2 --library-path "/home/user /test/libs/" ./bash --version GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) ...
Now it is possible to run our program on any system with all its dependencies.
To the rest of our article here .