This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Use --push/pop-state with Sanitizer link deps
ClosedPublic

Authored by phosek on Nov 21 2018, 10:32 AM.

Details

Summary

Sanitizer runtime link deps handling passes --no-as-needed because of
PR15823, but it never undoes it and this flag may affect other libraries
that come later on the link line. To avoid this, wrap Sanitizer link
deps in --push/pop-state.

Diff Detail

Repository
rC Clang

Event Timeline

phosek created this revision.Nov 21 2018, 10:32 AM
This revision is now accepted and ready to land.Nov 21 2018, 11:39 AM
This revision was automatically updated to reflect the committed changes.
pcc added a subscriber: pcc.Nov 21 2018, 2:00 PM

Unfortunately it looks like the Android NDK uses some ancient version of gold that doesn't support --push-state, so we probably can't rely on being able to use it.
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-android/builds/17287/steps/run%20lit%20tests%20%5Bi686%2Ffugu-userdebug%2FN2G48C%5D/logs/stdio
As an alternative solution, could we add these flags at the start of the linker command line? That way, we're guaranteed that the linker will be in the --no-as-needed state.

MaskRay added a subscriber: MaskRay.EditedNov 21 2018, 2:47 PM
In D54805#1305749, @pcc wrote:

Unfortunately it looks like the Android NDK uses some ancient version of gold that doesn't support --push-state, so we probably can't rely on being able to use it.
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-android/builds/17287/steps/run%20lit%20tests%20%5Bi686%2Ffugu-userdebug%2FN2G48C%5D/logs/stdio
As an alternative solution, could we add these flags at the start of the linker command line? That way, we're guaranteed that the linker will be in the --no-as-needed state.

gold --push-state seems a new thing. It is available since Dec 2016 (version 1.14)

I'm also interested in the history of

// Force linking against the system libraries sanitizers depends on
// (see PR15823 why this is necessary).
CmdArgs.push_back("--no-as-needed");

PR15823 leans slightly toward the user-error side to me. Shouldn't the user ensure the use of -Wl,--as-needed is eventually closed so that system libraries start with the -Wl--no-as-needed state?

I have already reverted the change as r347430 after seeing the failure on sanitizer bots.