GCC doesn't put builtin function symbol references, which are defined in the shared C library, in the IR symbol table. As the result, --as-needed doesn't work with references to builtin functions: [hjl@gnu-cfl-3 as-needed]$ cat x.c #include <stdlib.h> int main() { abort (); return 0; } [hjl@gnu-cfl-3 as-needed]$ cat bar.c #include <stdlib.h> #include <stdio.h> void abort (void) { printf ("PASS\n"); exit (0); } [hjl@gnu-cfl-3 as-needed]$ make gcc -B./ -g -flto -c -o x.o x.c gcc -B./ -g -fPIC -c -o bar.o bar.c gcc -B./ -shared -o libbar.so bar.o gcc -B./ -Wl,--as-needed -o x x.o libbar.so -Wl,-R,. ./x make: *** [Makefile:12: all] Aborted (core dumped) [hjl@gnu-cfl-3 as-needed]$
Dup. *** This bug has been marked as a duplicate of bug 31482 ***