Skip to content

Commit

Permalink
Make linker script INPUT command to look for a file from the script's…
Browse files Browse the repository at this point in the history
… directory

#1217
  • Loading branch information
rui314 committed Mar 19, 2024
1 parent dda521e commit 163975d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions elf/linker-script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 14 additions & 0 deletions test/elf/linker-script5.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 163975d

Please sign in to comment.