This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Use normalized triples for multiarch runtime path
ClosedPublic

Authored by phosek on Aug 9 2018, 7:00 PM.

Details

Summary

Previously we used target triple as provided which matches the GCC
behavior, but it also means that all clients have to be consistent
in their spelling of target triples since e.g. x86_64-linux-gnu and
x86_64-unknown-linux-gnu will result in Clang driver looking at two
different paths when searching for runtime libraries.

Unfortunately, as it turned out many clients aren't consistent in
their spelling of target triples, e.g. many Linux distributions use
the shorter spelling but config.guess and rustc insist on using the
normalized variant which is causing issues. To avoid having to ship
multiple copies of runtimes for different triple spelling or rely on
symlinks which are not portable, we should use the normalized triple
when constructing paths for multiarch runtimes.

Diff Detail

Repository
rC Clang

Event Timeline

phosek created this revision.Aug 9 2018, 7:00 PM
rnk added a comment.Aug 13 2018, 4:57 PM

Would it be to much to check both the normalized and non-normalized?

phosek updated this revision to Diff 161031.Aug 16 2018, 7:51 AM
In D50547#1198218, @rnk wrote:

Would it be to much to check both the normalized and non-normalized?

Done, currently I'm only checking the provided target triple followed by the normalized one, I'm not checking the effective triple but it'd be easy to add if we decide to do that as well.

beanz accepted this revision.Aug 16 2018, 10:58 AM

LGTM!

This revision is now accepted and ready to land.Aug 16 2018, 10:58 AM
beanz added a comment.Aug 20 2018, 1:55 PM

Just want to bring an IRC conversation that I had with @phosek into the proper code review.

This patch is great as-is, but if we want to extend this to Darwin there are some problems because of how Darwin handles triples. Specifically Darwin has multiple potentially valid triples that can mean the same things. For example x86_64-apple-darwin17.7.0 and x86_64-apple-macos10.13.6 are 100% interchangeable (even down to referring to the same OS version). Things get even stranger when you start talking about the -simulator triples...

This means that to support this in Darwin we need to support iterating over a list of triples. We also probably want to cache that list so that we don't run getVFS().exists(...) over and over again. @phosek said on IRC he will update the patch to reflect our conversation.

Thanks @phosek for all the great work on this!

phosek updated this revision to Diff 161818.Aug 21 2018, 2:21 PM

I also need to create the following empty files for tests to pass (somehow those are not displayed by Phabricator):

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan-preinit.a
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan.so
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.builtins.a
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.fuzzer.a
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.scudo.so
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/i386-linux-gnu/lib/libclang_rt.builtins.a
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan-preinit.a
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan.so
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.builtins.a
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.fuzzer.a
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.scudo.so
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-linux-gnu/lib/libclang_rt.builtins.a
phosek updated this revision to Diff 161821.Aug 21 2018, 2:24 PM
phosek added inline comments.Aug 21 2018, 2:28 PM
clang/lib/Driver/ToolChain.cpp
363–364

One possible alternative I've considered would be to simply return -lclang_rt.<component>.<suffix> instead of returning the full path when getLibraryPaths() is not empty. That should work because we add all paths in this list as -L in AddFilePathLibArgs and it's more consistent with e.g. -lgcc_s.

beanz accepted this revision.Aug 22 2018, 1:44 PM

LGTM as-is

clang/lib/Driver/ToolChain.cpp
363–364

I'd prefer not doing that since Darwin doesn't call AddFilePathLibArgs, and adjusting to that is a larger change on the Darwin side.

This revision was automatically updated to reflect the committed changes.