Page MenuHomePhabricator

[Driver] Make -static-libgcc imply static libunwind
AcceptedPublic

Authored by jkz on Mon, Nov 18, 6:21 PM.

Details

Summary

In the GNU toolchain, -static-libgcc implies that the unwindlib will be linked statically. However, when --unwindlib=libunwind, this flag is ignored, and a bare -lunwind is added to the linker args. Unfortunately, this means that if both libunwind.so, and libunwind.a are present in the library path, libunwind.so will be chosen in all cases where -static is not set.

This change makes -static-libgcc affect the -l flag produced by --unwindlib=libunwind. After this patch, providing -static-libgcc --unwindlib=libunwind will cause the driver to explicitly emit -l:libunwind.a to statically link libunwind. For all other cases it will emit -l:libunwind.so matching current behavior with a more explicit link line.

Diff Detail

Event Timeline

jkz created this revision.Mon, Nov 18, 6:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptMon, Nov 18, 6:21 PM
joerg added a subscriber: joerg.Mon, Nov 18, 9:56 PM

This is normally done by using -Bstatic/-Bdynamic around the library. See tools::addOpenMPRuntime.

This is normally done by using -Bstatic/-Bdynamic around the library. See tools::addOpenMPRuntime.

Historically, the unwind library is a little different. Gcc uses -llibgcc_eh for static links (which is only resolved by libgcc_eh.a) and libgcc_s.so for dynamic links (which is only resolved by libgcc_s.so, which in turn pulls in libgcc.a for certain things).

sivachandra accepted this revision.Tue, Nov 19, 9:20 AM

Please wait for saugustine's acceptance.

This revision is now accepted and ready to land.Tue, Nov 19, 9:20 AM
jkz added a comment.Wed, Nov 20, 12:31 PM

This is normally done by using -Bstatic/-Bdynamic around the library. See tools::addOpenMPRuntime.

-Bstatic/-Bdynamic wrapping does seem to be more common, but that will change the linkage for libraries that are added after the run-time libraries (e.g., -lpthread). We would need something like --push-state -Bstatic -lunwind --pop-state to preserve the "mode" of the link. (IMO, the existing usages of -Bstatic, -Bdynamic wrapping are wrong). The current approach is simpler.

Additionally, I think saugustine's reasoning makes sense here, and we should match the libgcc behavior of requiring a .a or .so depending on the "mode". I'd prefer to keep this patch the way it is.

saugustine accepted this revision.Fri, Nov 22, 10:41 AM