I am studying elf relocation and note that in our school’s container, compile the c file below:
int sum(int *a, int n)
{
return a[0]+a[1];
}
int array[2] = {1, 2};
int main()
{
int val = sum(array, 2);
return val;
}
the relocation entry type of the function sum
is R_X86_64_PC32
.
However when I try compiling the c file on another server, its type changes to R_X86_64_PLT32
.
I don’t know which factor decides the type of relocation entry.The kernel version? Or the configure options?
The whole process of compiling the file on school’s container is:
$> gcc -v -c -o main.o main.c
Using built-in specs.
COLLECT_GCC=gcc
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'main.o' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/7/cc1 -quiet -v -imultiarch x86_64-linux-gnu main.c -quiet -dumpbase main.c -mtune=generic -march=x86-64 -auxbase-strip main.o -version -fstack-protector-strong -Wformat -Wformat-security -o /tmp/ccSRwEz4.s
GNU C11 (Ubuntu 7.5.0-3ubuntu1~18.04) version 7.5.0 (x86_64-linux-gnu)
compiled by GNU C version 7.5.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C11 (Ubuntu 7.5.0-3ubuntu1~18.04) version 7.5.0 (x86_64-linux-gnu)
compiled by GNU C version 7.5.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b62ed4a2880cd4159476ea8293b72fa8
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'main.o' '-mtune=generic' '-march=x86-64'
as -v --64 -o main.o /tmp/ccSRwEz4.s
GNU assembler version 2.30 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.30
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'main.o' '-mtune=generic' '-march=x86-64'
$> uname -a
Linux jupyter-10235101439 5.10.134-16.1.al8.x86_64 #1 SMP Thu Dec 7 14:11:24 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
On another server:
$> gcc -v -c -o main.o main.c
Using built-in specs.
COLLECT_GCC=./bin/gcc-7.5.0/bin/gcc
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0 --with-gmp=/home/jizimo/lib/gmp --with-mpfr=/home/jizimo/lib/mpfr --with-mpc=/home/jizimo/lib/mpc
Thread model: posix
gcc version 7.5.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'main.o' '-mtune=generic' '-march=x86-64'
/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/libexec/gcc/x86_64-pc-linux-gnu/7.5.0/cc1 -quiet -v -imultiarch x86_64-linux-gnu main.c -quiet -dumpbase main.c -mtune=generic -march=x86-64 -auxbase-strip main.o -version -o /tmp/cc4SIMck.s
GNU C11 (GCC) version 7.5.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 7.5.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version none
warning: GMP header version 6.3.0 differs from library version 6.2.1.
warning: MPFR header version 4.2.1 differs from library version 4.1.0.
warning: MPC header version 1.3.1 differs from library version 1.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/lib/gcc/x86_64-pc-linux-gnu/7.5.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/lib/gcc/x86_64-pc-linux-gnu/7.5.0/include
/usr/local/include
/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/include
/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/lib/gcc/x86_64-pc-linux-gnu/7.5.0/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C11 (GCC) version 7.5.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 7.5.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version none
warning: GMP header version 6.3.0 differs from library version 6.2.1.
warning: MPFR header version 4.2.1 differs from library version 4.1.0.
warning: MPC header version 1.3.1 differs from library version 1.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: dcdda7853040608b660057cc697f1eb8
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'main.o' '-mtune=generic' '-march=x86-64'
as -v --64 -o main.o /tmp/cc4SIMck.s
GNU assembler version 2.38 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.38
COMPILER_PATH=/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/libexec/gcc/x86_64-pc-linux-gnu/7.5.0/:/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/libexec/gcc/x86_64-pc-linux-gnu/7.5.0/:/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/libexec/gcc/x86_64-pc-linux-gnu/:/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/lib/gcc/x86_64-pc-linux-gnu/7.5.0/:/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/lib/gcc/x86_64-pc-linux-gnu/7.5.0/:/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/lib/gcc/x86_64-pc-linux-gnu/7.5.0/../../../../lib64/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/:/home/jizimo/relocation-type-from-got-to-plt/bin/gcc-7.5.0/lib/gcc/x86_64-pc-linux-gnu/7.5.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'main.o' '-mtune=generic' '-march=x86-64'
$> uname -a
Linux solegpu2 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux