If LDFLAGS contains -Wl,--as-needed and Firefox 34.0a2 is configured with GTK3 widgets, xpcshell fails during the build, complaining about a symbol lookup error in libxul.so: /tmp/mozilla-central/obj-x86_64-unknown-linux-gnu/dist/bin/xpcshell: symbol lookup error: /tmp/mozilla-central/obj-x86_64-unknown-linux-gnu/dist/bin/libxul.so: undefined symbol: gtk_main_do_event Without --as-needed, libxul.so directly depends on libgtk-3.so.0, breaking the plugin-container (bug 1051209).
A common cause for this problem is misordering the libs on the ld command line. If lib A depends on lib B, lib A must be first on the command line, otherwise ld with --as-needed skips lib B as nothing depends on it.
Ah, my builds might trigger this bug because my LDFLAGS don't contain a literal "-Wl,--as-needed" (the build system checks for that), but the --as-needed is part of a longer -Wl, specifically "-Wl,-O1,--sort-common,--as-needed,-z,relro"
Just got a report on IRC of a gtk3-enabled build *building* successfully, but failing to *run*, with the same issue from comment 0 ("libxul.so: undefined symbol: gtk_main_do_event"). Marking as "confirmed" based on that report. (I think comment 0 is really a failure to *run*, not a failure to *build*. Even though it's part of the build process, if we're starting xpcshell & libxul, then we've already built gecko. Hence, generalizing summary to be about running instead of building.)
(In reply to Jan Steffens from comment #2) > Ah, my builds might trigger this bug because my LDFLAGS don't contain a > literal "-Wl,--as-needed" (the build system checks for that), but the > --as-needed is part of a longer -Wl, specifically > "-Wl,-O1,--sort-common,--as-needed,-z,relro" Yes, the build system looks for an independent -Wl,--as-needed in LDFLAGS to trigger using -Wl,--no-as-needed "appropriately".
I'm running into this in Ubuntu 15.04 and it looks like gcc is adding -Wl,--as-needed by default. Can we just unconditionally add -Wl,--no-as-needed?
We'd need to detect what the linker uses by default. Because -Wl,--no-as-needed affects all the following linked libraries, including those the compiler adds on its own. So the -Wl,--no-as-needed -llib -Wl,--as-needed pattern is needed, but then that would make all following libraries linked "as-needed" on no-as-needed builds. Or, we could just force -Wl,--as-needed on all our builds.
Created attachment 8637859 [details] [diff] [review] Unconditionally use -Wl,--no-as-needed when building with GNU ld/gold
2 years ago