1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-11 21:17:28 +03:00

[ELF] Fix absolute paths handling in linker scripts

With toolchains using a relative sysroot, like crosstool-ng, gcc/clang will call the linker
with something like "--sysroot=/path/bin/../machine/sysroot".
The is_in_sysroot detection wasn't working in this case.

Since to_abs_path() uses lexically_normal() for relative paths, it seems consistent to do
the same for absolute paths instead of modifying is_in_sysroot().
This commit is contained in:
Loïc Yhuel 2022-10-26 19:15:31 +02:00
parent 903fff7701
commit 467b08a782
2 changed files with 5 additions and 2 deletions

View File

@ -20,7 +20,7 @@ std::string path_clean(std::string_view path) {
std::filesystem::path to_abs_path(std::filesystem::path path) {
if (path.is_absolute())
return path;
return path.lexically_normal();
return (std::filesystem::current_path() / path).lexically_normal();
}

View File

@ -1,7 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc
mkdir -p $t/sysroot/foo
mkdir -p $t/bin $t/sysroot/foo
cat <<EOF > $t/a.script
INPUT(=/foo/x.o)
@ -37,3 +37,6 @@ EOF
$CC -B. -o $t/exe -Wl,--sysroot=$t/sysroot \
$t/a.script $t/sysroot/b.script $t/c.o
$CC -B. -o $t/exe -Wl,--sysroot=$(realpath $t)/bin/../sysroot \
$t/a.script $t/sysroot/b.script $t/c.o