[BareMetal] Ensure that sysroot always comes after library paths
authorPetr Hosek <phosek@google.com>
Fri, 7 May 2021 06:05:39 +0000 (23:05 -0700)
committerPetr Hosek <phosek@google.com>
Fri, 7 May 2021 20:21:07 +0000 (13:21 -0700)
commit6b00b34b8a05896f79b18a1963811299b83d5b21
tree1a9e6984ec6ef2137dd6eecb1d1f92f5cdcce375
parentc04c66d705b4f6e95a6325ef6d6c647ebc622165
[BareMetal] Ensure that sysroot always comes after library paths

This addresses an issue introduced in D91559. We would invoke the
compiler with -Lpath/to/lib --sysroot=path/to/sysroot where both
locations contain libraries with the same name, but we expect linker
to pick up the library in path/to/lib since that version is more
specialized. This was the case before D91559 where the sysroot path
would be ignored, but after that change linker would now pick up the
library from the sysroot which resulted in unexpected behavior.

The sysroot path should always come after any user provided library
paths, followed by compiler runtime paths. We want for libraries in user
provided library paths to always take precedence over sysroot libraries.
This matches the behavior of other toolchains used with other targets.

Differential Revision: https://reviews.llvm.org/D102049
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/test/Driver/baremetal-sysroot.cpp