Summary: | gcc & Firefox fail to build with -flto and --as-needed LDFLAGS | ||
---|---|---|---|
Product: | binutils | Reporter: | Octoploid <cryptooctoploid> |
Component: | ld | Assignee: | unassigned |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | cryptooctoploid, hjl.tools, rguenth |
Priority: | P2 | ||
Version: | 2.22 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Last reconfirmed: | 2011-03-11 19:20:55 | |
Attachments: |
mozconfig
Correct mozconfig (use this one) output_bad map_bad output_good map_good output_good map_good gcc_verbose_good gcc_verbose_bad |
Description
Octoploid
2011-03-09 19:45:33 UTC
Can you extra a small testcase? The problem comes from: "-Wl,-R/usr/lib64 -L/usr/lib64 -lplds4 -lplc4 -lnspr4 -lpthread -ldl -ldl" If I remove "-lnspr4" from above, ld links without any problem. When I remove the whole system library part: "-Wl,-R/usr/lib64 -L/usr/lib64 -lplds4 -lplc4 -lnspr4 -lpthread -ldl -ldl" ld still links fine. So it seems that ld gets irritated when you explicitly specify system libraries that it already figured out itself in the -flto/--as-needed case. (In reply to comment #2) > The problem comes from: > "-Wl,-R/usr/lib64 -L/usr/lib64 -lplds4 -lplc4 -lnspr4 -lpthread -ldl -ldl" > If I remove "-lnspr4" from above, ld links without any problem. > You have 2 very different libnspr4.soes. Please make sure that linker sees the correct one first. Created attachment 5285 [details]
mozconfig
No, there's only one libnspr4.so on my system.
# cd /
/ # find . -name "libnspr4*"
./usr/lib/libnspr4.so
./usr/lib/libnspr4.so.8
/ #
And I build Firefox with --with-system-nspr ...
I've attached my .mozconfig in case someone would like
to reproduce the issue. (Just run "make -f client.mk"
in the Firefox top directory)
Created attachment 5286 [details]
Correct mozconfig (use this one)
Please provide the output of -Wl,--verbose=2,-Map,map as well as map file. I need both working/non-working outputs. Created attachment 5287 [details]
output_bad
Created attachment 5288 [details]
map_bad
Created attachment 5289 [details]
output_good
Created attachment 5290 [details]
map_good
Everything is attached.
Good > without --as-needed
Bad > with --as-needed
I will take a look. Thanks. Unfortunately nothing obvious stands out in vimdiff. Created attachment 5292 [details]
output_good
This may be better for comparison:
removed:
"-Wl,-R/usr/lib64 -L/usr/lib64 -lplds4 -lplc4 -lnspr4 -lpthread -ldl -ldl"
Created attachment 5293 [details]
map_good
Now two lines stands out in "vimdiff verbose_good verbose_bad": libnspr4.so needed by ../../../../dist/bin/libxul.so found libnspr4.so at /usr/lib/libnspr4.so These two lines are missing in verbose_bad... Please show the output of "g++ -v ...". Created attachment 5294 [details]
gcc_verbose_good
Created attachment 5295 [details]
gcc_verbose_bad
[hjl@gnu-6 pr12557]$ cat x.c int x = 20; [hjl@gnu-6 pr12557]$ cat foo.c #include <stdio.h> extern int x; void foo () { printf ("%d\n", x); } [hjl@gnu-6 pr12557]$ cat main.c extern void foo (); int main () { foo (); return 0; } [hjl@gnu-6 pr12557]$ make g++ -shared -fPIC -o libx.so x.c g++ -shared -fPIC -o libfoo.so foo.c libx.so g++ -Wl,--as-needed -o x main.o -L. -lfoo -lx -Wl,-R,. main.o: In function `main': main.c:(.text+0xa): undefined reference to `foo' collect2: ld returned 1 exit status make: *** [x] Error 1 [hjl@gnu-6 pr12557]$ (In reply to comment #19) > [hjl@gnu-6 pr12557]$ cat x.c This test is wrong. Exactly which linker are you using? GNU ld (Linux/GNU Binutils) 2.21.51.0.7.20110306 I really need a small testcase. >I really need a small testcase.
Understood. I will take a deeper look.
Even gcc fails to build with the same combination (-flto and Wl,--as-needed): ... /var/tmp/gcc_build_dir/./prev-gcc/g++ -B/var/tmp/gcc_build_dir/./prev-gcc/ -B/usr/x86_64-pc-linux-gnu/bin/ -nostdinc++ -B/var/tmp/gcc_build_dir/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -I/var/tmp/gcc_build_dir/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu -I/var/tmp/gcc_build_dir/prev-x86_64-pc-linux-gnu/libstdc++-v3/include -I/var/tmp/gcc/libstdc++-v3/libsupc++ -L/var/tmp/gcc_build_dir/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -march=native -O2 -pipe -flto=jobserver -frandom-seed=1 -fprofile-use -DIN_GCC -W -Wall -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc gcov.o intl.o version.o errors.o ../libcpp/libcpp.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a -o gcov /lib64/libc.so.6: undefined reference to `_dl_argv@GLIBC_PRIVATE' /lib64/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE' /lib64/libc.so.6: undefined reference to `__tls_get_addr@GLIBC_2.3' /lib64/libc.so.6: undefined reference to `_rtld_global@GLIBC_PRIVATE' /lib64/libc.so.6: undefined reference to `__libc_enable_secure@GLIBC_PRIVATE' collect2: ld returned 1 exit status make[3]: *** [gcov] Error 1 make[3]: *** Waiting for unfinished jobs.... rm gfortran.pod cpp.pod gcov.pod gcc.pod fsf-funding.pod gfdl.pod make[3]: Leaving directory `/var/tmp/gcc_build_dir/gcc' make[2]: *** [all-stagefeedback-gcc] Error 2 make[2]: Leaving directory `/var/tmp/gcc_build_dir' make[1]: *** [stagefeedback-bubble] Error 2 make[1]: Leaving directory `/var/tmp/gcc_build_dir' make: *** [profiledbootstrap] Error 2 Configured with: ../gcc/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-lto --enable-nls --without-included-gettext --with-system-zlib --disable-werror --enable-build-with-cxx --enable-initfini-array --with-gold --enable-secureplt --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.6.0/python --enable-checking=release --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-multilib --enable-clocale=gnu --with-build-config=bootstrap-lto And build with: make -j4 BOOT_CFLAGS="-march=native -O2 -pipe" STAGE1_CFLAGS="-march=native -O2 -pipe" CFLAGS_FOR_TARGET="-march=native -O2 -pipe" LDFLAGS="-Wl,-O1,--hash-style=gnu,--as-needed" profiledbootstrap Hmm, the LDFLAGS are simply ignored by gcc. And gcc builds fine when I configure it with: --with-boot-ldflags=-Wl,-O1,--hash-style=gnu,--as-needed I have no problems with gcc bootstrap using .../configure --enable-clocale=gnu --with-system-zlib --with-demangler-in-ld --prefix=/usr/gcc-4.7.0 --with-local-prefix=/usr/local --enable-gnu-indirect-function --with-boot-ldflags=-Wl,-O1,--hash-style=gnu,--as-needed --with-build-config=bootstrap-lto --enable-cloog-backend=isl --with-ppl-include=/opt/gnu/include --with-ppl-lib=/opt/gnu/lib64 --with-cloog-include=/opt/gnu/include --with-cloog-lib=/opt/gnu/lib64 --with-fpmath=sse (In reply to comment #27) > I have no problems with gcc bootstrap using > > .../configure --enable-clocale=gnu --with-system-zlib --with-demangler-in-ld > --prefix=/usr/gcc-4.7.0 --with-local-prefix=/usr/local > --enable-gnu-indirect-function > --with-boot-ldflags=-Wl,-O1,--hash-style=gnu,--as-needed > --with-build-config=bootstrap-lto --enable-cloog-backend=isl > --with-ppl-include=/opt/gnu/include --with-ppl-lib=/opt/gnu/lib64 > --with-cloog-include=/opt/gnu/include --with-cloog-lib=/opt/gnu/lib64 > --with-fpmath=sse Yes, the problem only occurs when you configure gcc without "--with-boot-ldflags=-Wl,-O1,--hash-style=gnu,--as-needed". I've tested this a little further: /var/tmp/gcc_build_dir/./prev-gcc/g++ -B/lib -B/var/tmp/gcc_build_dir/./prev-gcc/ -B/usr/x86_64-pc-linux-gnu/bin/ -nostdinc++ -B/var/tmp/gcc_build_dir/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/var/tmp/gcc_build_dir/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -pipe -flto -frandom-seed=1 -DIN_GCC -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc gcov.o intl.o version.o errors.o ../libiberty/libiberty.a -o gcov /lib64/libc.so.6: undefined reference to `_dl_argv@GLIBC_PRIVATE' /lib64/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE' /lib64/libc.so.6: undefined reference to `__tls_get_addr@GLIBC_2.3' /lib64/libc.so.6: undefined reference to `_rtld_global@GLIBC_PRIVATE' /lib64/libc.so.6: undefined reference to `__libc_enable_secure@GLIBC_PRIVATE' collect2: ld returned 1 exit status Without -static-libstdc++ it compiles fine. Without -flto it also compiles fine. When I use xgcc instead of g++ there aren't any problems. When I use gold as linker there aren't any problems either. It is fixed by commit d81cd6bcc0c848feb3785987de8a16196092e943 on hjl/lto-mixed branch at http://git.kernel.org/?p=devel/binutils/hjl/x86.git;a=summary Thanks H.J.. Both issues are fixed now. Simple testcase double x; int main() { return x*x*x*x; } > gcc-4.6 -o t t.o -O -ffast-math -flto > gcc-4.6 -o t t.o -flto /tmp/ccIqK5i6.ltrans0.ltrans.o: In function `main': ccIqK5i6.ltrans0.o:(.text+0x19): undefined reference to `pow' collect2: ld returned 1 exit status > gcc-4.6 -o t t.o -flto -lm > gcc-4.6 -o t t.o -flto -Wl,--as-needed -lm which works for me with the 2.21.1 release. (In reply to comment #31) > Simple testcase > > double x; > int main() > { > return x*x*x*x; > } > > > gcc-4.6 -o t t.o -O -ffast-math -flto > > gcc-4.6 -o t t.o -flto > /tmp/ccIqK5i6.ltrans0.ltrans.o: In function `main': > ccIqK5i6.ltrans0.o:(.text+0x19): undefined reference to `pow' > collect2: ld returned 1 exit status > > gcc-4.6 -o t t.o -flto -lm > > gcc-4.6 -o t t.o -flto -Wl,--as-needed -lm > > which works for me with the 2.21.1 release. This looks like a GCC bug to me. If GCC turns x*x*x*x into pow, it should add -lm. Fixed a long time ago |