1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-26 13:10:46 +03:00

Make linker script INPUT command to look for a file from the script's directory

https://github.com/rui314/mold/pull/1217
This commit is contained in:
Rui Ueyama 2024-03-19 15:11:47 +09:00
parent dda521e2bc
commit 163975d82a
2 changed files with 19 additions and 0 deletions

View File

@ -170,6 +170,11 @@ static MappedFile<Context<E>> *resolve_path(Context<E> &ctx, std::string_view to
if (str.starts_with("-l"))
return find_library(ctx, str.substr(2));
if (!str.starts_with('/'))
if (MappedFile<Context<E>> *mf =
open_library(ctx, path_clean(ctx.script_file->name + "/../" + str)))
return mf;
if (MappedFile<Context<E>> *mf = open_library(ctx, str))
return mf;

14
test/elf/linker-script5.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
. $(dirname $0)/common.inc
mkdir -p $t/foo
cat <<EOF | $CC -o $t/foo/a.o -c -xc -
int main() {}
EOF
cat <<EOF > $t/foo/b.script
INPUT(a.o)
EOF
$CC -B. -o $t/exe $t/foo/b.script