When an externally_visible function calls another externally_visible function, this gives R_X86_64_PC32 from ld.
-bash-3.2$ /opt/gcc/bin/gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.4.0/configure --prefix=/opt/gcc Thread model: posix gcc version 4.4.0 (GCC) -bash-3.2$ cat whole.c __attribute__((externally_visible)) int function(int a, int b) { return a + b; } __attribute__((externally_visible)) int test(int a, int b) { return function(a, b); } -bash-3.2$ /opt/gcc/bin/gcc -fPIC -O1 -shared -fwhole-program -save-temps -o whole.so whole.c /opt/binutils/bin/ld: whole.o: relocation R_X86_64_PC32 against symbol `function' can not be used when making a shared object; recompile with -fPIC /opt/binutils/bin/ld: final link failed: Bad value collect2: ld returned 1 exit status -bash-3.2$ cat whole.i # 1 "whole.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "whole.c" __attribute__((externally_visible)) int function(int a, int b) { return a + b; } __attribute__((externally_visible)) int test(int a, int b) { return function(a, b); } -bash-3.2$ mv whole.s wholebug.s -bash-3.2$ /opt/gcc/bin/gcc -fPIC -O1 -shared -save-temps -o whole.so whole.c -bash-3.2$ diff -u whole.s wholebug.s --- whole.s 2009-06-24 17:37:26.000000000 +0200 +++ wholebug.s 2009-06-24 17:37:21.000000000 +0200 @@ -15,10 +15,8 @@ test: .LFB1: .cfi_startproc - subq $8, %rsp - .cfi_def_cfa_offset 16 - call funct...@plt - addq $8, %rsp + call function + rep ret .cfi_endproc .LFE1: -- Summary: -fwhole-program -shared with externally_visible gives R_X86_64_PC32 errors Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gcc at natvig dot com GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40546