Skip to content

Commit

Permalink
Make sure to import versioned symbols
Browse files Browse the repository at this point in the history
Undefined versioned symbols are handled specially; they are resolved
at the very end of name resolution stage. When they are resolved, we
need to make sure that they are marked as imported symbols.

Fixes rui314#1057
  • Loading branch information
rui314 authored and VitalyAnkh committed Dec 23, 2023
1 parent b04aba8 commit 1a2b3d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions elf/passes.cc
Expand Up @@ -1262,6 +1262,7 @@ void claim_unresolved_symbols(Context<E> &ctx) {
Symbol<E> *sym2 = get_symbol(ctx, name);
if (sym2->file && sym2->file->is_dso && sym2->get_version() == ver) {
file->symbols[i] = sym2;
sym2->is_imported = true;
continue;
}
}
Expand Down
8 changes: 6 additions & 2 deletions test/elf/versioned-undef.sh
Expand Up @@ -9,10 +9,12 @@ cat <<EOF | $CC -fPIC -c -o $t/a.o -xc -
int foo1() { return 1; }
int foo2() { return 2; }
int foo3() { return 3; }
int bar3() { return 4; }
__asm__(".symver foo1, foo@VER1");
__asm__(".symver foo2, foo@VER2");
__asm__(".symver foo3, foo@@VER3");
__asm__(".symver bar3, bar@@VER3");
EOF

echo 'VER1 { local: *; }; VER2 { local: *; }; VER3 { local: *; };' > $t/b.ver
Expand All @@ -25,15 +27,17 @@ int foo1();
int foo2();
int foo3();
int foo();
int bar();
__asm__(".symver foo1, foo@VER1");
__asm__(".symver foo2, foo@VER2");
__asm__(".symver foo3, foo@VER3");
__asm__(".symver bar, bar@VER3");
int main() {
printf("%d %d %d %d\n", foo1(), foo2(), foo3(), foo());
printf("%d %d %d %d %d\n", foo1(), foo2(), foo3(), foo(), bar());
}
EOF

$CC -B. -o $t/exe $t/d.o $t/c.so
$QEMU $t/exe | grep -q '^1 2 3 3$'
$QEMU $t/exe | grep -q '^1 2 3 3 4$'

0 comments on commit 1a2b3d4

Please sign in to comment.