This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Let the linker choose shared or static libunwind unless specified
ClosedPublic

Authored by phosek on Jun 10 2022, 12:22 PM.

Details

Summary

We shouldn't assume that libunwind.so is available. Rather can defer
the decision to the linker which defaults to libunwind.so, but if .so
isn't available, it'd pick libunwind.a. Users can use -static-libgcc
and -shared-libgcc to override this behavior and explicitly choose
the version they want.

Diff Detail

Event Timeline

phosek created this revision.Jun 10 2022, 12:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2022, 12:22 PM
Herald added a subscriber: mstorsjo. · View Herald Transcript
phosek requested review of this revision.Jun 10 2022, 12:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2022, 12:22 PM

We ran into this in the Fuchsia toolchain where we only ship libunwind.a on Linux, but Clang is forcing the use of libunwind.so unless you explicitly set -shared-libgcc. With this change, the linker will choose whichever library is available by default.

LGTM in general, but I'd leave it to the others to formally approve.

clang/lib/Driver/ToolChains/CommonArgs.cpp
1468

Previously, OPT_shared_libgcc would override the default for android, but now it no longer would. I guess that might be sensible, but it seems slightly outside of what the patch says it does. (I guess it's fine to include the change too, but I just wanted to raise it for discussion.)

phosek added inline comments.
clang/lib/Driver/ToolChains/CommonArgs.cpp
1468

I was going by the comment, but I'm fine preserving the existing behavior. @srhines do you know if -shared-libgcc should be supported on Android?

srhines added inline comments.Jun 14 2022, 12:04 PM
clang/lib/Driver/ToolChains/CommonArgs.cpp
1468

No, there's no such shared library to even depend on, so it wouldn't be supported previously or in the future.

saugustine accepted this revision.Jun 14 2022, 3:45 PM
This revision is now accepted and ready to land.Jun 14 2022, 3:45 PM
This revision was landed with ongoing or failed builds.Jun 15 2022, 11:22 AM
This revision was automatically updated to reflect the committed changes.