Skip to content

Commit

Permalink
[ELF] Allow linker script to define symbol aliases
Browse files Browse the repository at this point in the history
Fixes #610
  • Loading branch information
rui314 committed Aug 12, 2022
1 parent 5dd1227 commit f0e1237
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions elf/linker-script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ void parse_linker_script(Context<E> &ctx, MappedFile<Context<E>> *mf) {
tok = skip(ctx, tok, "{");
read_version_script(ctx, tok);
tok = skip(ctx, tok, "}");
} else if (tok.size() > 3 && tok[1] == "=" && tok[3] == ";") {
ctx.arg.defsyms.emplace_back(get_symbol(ctx, unquote(tok[0])),
get_symbol(ctx, unquote(tok[2])));
tok = tok.subspan(4);
} else if (tok[0] == ";") {
tok = tok.subspan(1);
} else {
Expand Down
25 changes: 25 additions & 0 deletions test/elf/linker-script-defsym.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
export LC_ALL=C
set -e
CC="${TEST_CC:-cc}"
CXX="${TEST_CXX:-c++}"
GCC="${TEST_GCC:-gcc}"
GXX="${TEST_GXX:-g++}"
OBJDUMP="${OBJDUMP:-objdump}"
MACHINE="${MACHINE:-$(uname -m)}"
testname=$(basename "$0" .sh)
echo -n "Testing $testname ... "
t=out/test/elf/$MACHINE/$testname
mkdir -p $t

cat <<EOF | $CC -o $t/a.o -c -xc -
void foo() {}
EOF

cat <<EOF > $t/script
bar = foo;
EOF

$CC -B. -o $t/b.so -shared $t/script $t/a.o

echo OK

0 comments on commit f0e1237

Please sign in to comment.