https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90229
Martin Liška <marxin at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|WAITING |NEW --- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> --- (In reply to H.J. Lu from comment #4) > I can't reproduce it with binutils master branch and GCC 9: > > [hjl@gnu-cfl-1 pr90229]$ cat x.ii > extern int FLAGS_verbose; > extern "C" void pthread_create(void); > > void a(const char *b...) { > if (FLAGS_verbose) { > __builtin_va_list ap; > __builtin_va_start(ap, b); > } > } > void a() { pthread_create(); } > int main() { a(""); return 0; } > [hjl@gnu-cfl-1 pr90229]$ cat lib.ii > int FLAGS_verbose; > [hjl@gnu-cfl-1 pr90229]$ make > /export/build/gnu/tools-build/gcc-wip-debug/build-x86_64-linux/gcc/xgcc > -B/export/build/gnu/tools-build/gcc-wip-debug/build-x86_64-linux/gcc/ -B./ > -g -flto -c -o x.o x.ii > /export/build/gnu/tools-build/gcc-wip-debug/build-x86_64-linux/gcc/xgcc > -B/export/build/gnu/tools-build/gcc-wip-debug/build-x86_64-linux/gcc/ -B./ > -g -c -o lib.o lib.ii > /export/build/gnu/tools-build/gcc-wip-debug/build-x86_64-linux/gcc/xgcc > -B/export/build/gnu/tools-build/gcc-wip-debug/build-x86_64-linux/gcc/ -B./ > -shared -g -o libx.so lib.o > /export/build/gnu/tools-build/gcc-wip-debug/build-x86_64-linux/gcc/xgcc > -B/export/build/gnu/tools-build/gcc-wip-debug/build-x86_64-linux/gcc/ -B./ > -pthread -g -o x x.o libx.so -Wl,--as-needed > [hjl@gnu-cfl-1 pr90229]$ I can confirm that with current trunk of both GCC and bintuils. You used a bit different build steps: 1) one needs g++ for: -shared -g -o libx.so lib.o 2) you forgot to add -O and -flto to last command line So please use following steps: bash -x ./todo + gcc -g -c -o lib.o lib.ii + g++ -shared -g -o libx.so lib.o + gcc -g -flto -c -o x.o x.ii -O + gcc -flto -O -pthread -g -o x x.ii libx.so -Wl,--as-needed /home/marxin/bin/binutils/bin/ld: /home/marxin/bin/gcc/lib64//libstdc++.so.6: undefined reference to `pthread_create' collect2: error: ld returned 1 exit status