1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00

Fix sysroot handling

Fix https://github.com/rui314/mold/issues/59
This commit is contained in:
Rui Ueyama 2021-07-01 17:40:44 +09:00
parent 18156f3965
commit 0fd62ce693
2 changed files with 6 additions and 4 deletions

View File

@ -142,15 +142,17 @@ read_output_format(Context<E> &ctx, std::span<std::string_view> tok) {
template <typename E>
static bool is_in_sysroot(Context<E> &ctx, std::string path) {
std::string sysroot = path_clean(ctx.arg.sysroot);
path = path_clean(path);
return std::string_view(sysroot).starts_with(path_dirname(path));
path = path_clean(path_to_absolute(path));
return path_dirname(path).starts_with(sysroot);
}
template <typename E>
static MemoryMappedFile<E> *resolve_path(Context<E> &ctx, std::string_view tok) {
std::string str(unquote(tok));
if (str.starts_with('/') && is_in_sysroot(ctx, str))
// GNU ld prepends the sysroot if a pathname starts with '/' and the
// script being processed is in the sysroot. We do the same.
if (str.starts_with('/') && is_in_sysroot(ctx, current_file<E>->name))
return MemoryMappedFile<E>::must_open(ctx, ctx.arg.sysroot + str);
if (str.starts_with("-l"))

View File

@ -22,6 +22,6 @@ void foo();
int main() { foo(); }
EOF
clang -o $t/exe $t/c.o -Wl,--sysroot=$t/ $t/foo/bar/b.script
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.o -Wl,--sysroot=$t/ $t/foo/bar/b.script
echo OK