Skip to content

Commit

Permalink
Fix relocations for POWER10
Browse files Browse the repository at this point in the history
With this change, all tests now pass on an actual POWER10 machine
(gcc120.fsffrance.org).
  • Loading branch information
rui314 committed Oct 13, 2023
1 parent 83ec409 commit 0f71471
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 60 deletions.
7 changes: 4 additions & 3 deletions elf/arch-ppc64v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ static u64 high(u64 x) { return (x >> 16) & 0xffff; }
static u64 higha(u64 x) { return ((x + 0x8000) >> 16) & 0xffff; }

static void write34(u8 *loc, u64 x) {
*(ul32 *)loc |= bits(x, 33, 16);
*(ul32 *)(loc + 4) |= bits(x, 15, 0);
ul32 *buf = (ul32 *)loc;
buf[0] = (buf[0] & 0xfffc'0000) | bits(x, 33, 16);
buf[1] = (buf[1] & 0xffff'0000) | bits(x, 15, 0);
}

// .plt is used only for lazy symbol resolution on PPC64. All PLT
Expand Down Expand Up @@ -539,7 +540,7 @@ void RangeExtensionThunk<E>::copy_buf(Context<E> &ctx) {

if (ctx.extra.is_power10) {
memcpy(buf, plt_thunk_power10, E::thunk_size);
write34(buf + 8, got - P - 8);
write34(buf + 8, got - P - 8);
} else {
i64 val = got - ctx.extra.TOC->value;
memcpy(buf, plt_thunk, E::thunk_size);
Expand Down
4 changes: 2 additions & 2 deletions test/elf/default-symver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ void foo() {}
EOF

$CC -B. -o $t/b.so -shared $t/a.o -Wl,-default-symver
readelf --dyn-syms $t/b.so | grep -q ' foo@@b\.so$'
readelf --dyn-syms $t/b.so | grep -q ' foo@@b\.so'

$CC -B. -o $t/b.so -shared $t/a.o \
-Wl,--soname=bar -Wl,-default-symver
readelf --dyn-syms $t/b.so | grep -q ' foo@@bar$'
readelf --dyn-syms $t/b.so | grep -q ' foo@@bar'
16 changes: 8 additions & 8 deletions test/elf/dynamic-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ EOF
$CC -B. -o $t/exe $t/a.o

readelf --dyn-syms $t/exe > $t/log
! grep -q ' foo$' $t/log || false
! grep -q ' bar$' $t/log || false
! grep -q ' foo' $t/log || false
! grep -q ' bar' $t/log || false

cat <<EOF > $t/dyn
{ foo; bar; };
Expand All @@ -20,17 +20,17 @@ EOF
$CC -B. -o $t/exe1 $t/a.o -Wl,-dynamic-list=$t/dyn

readelf --dyn-syms $t/exe1 > $t/log1
grep -q ' foo$' $t/log1
grep -q ' bar$' $t/log1
grep -q ' foo' $t/log1
grep -q ' bar' $t/log1

$CC -B. -o $t/exe2 $t/a.o -Wl,--export-dynamic-symbol-list=$t/dyn

readelf --dyn-syms $t/exe2 > $t/log2
grep -q ' foo$' $t/log2
grep -q ' bar$' $t/log2
grep -q ' foo' $t/log2
grep -q ' bar' $t/log2

$CC -B. -o $t/exe3 $t/a.o -Wl,--export-dynamic-symbol=foo,--export-dynamic-symbol=bar

readelf --dyn-syms $t/exe3 > $t/log3
grep -q ' foo$' $t/log3
grep -q ' bar$' $t/log3
grep -q ' foo' $t/log3
grep -q ' bar' $t/log3
16 changes: 8 additions & 8 deletions test/elf/dynamic-list2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ EOF
$CXX -B. -o $t/exe $t/a.o $t/b.o

readelf --dyn-syms $t/exe > $t/log
! grep -q ' foo$' $t/log || false
! grep -q ' bar$' $t/log || false
! grep -q ' foo' $t/log || false
! grep -q ' bar' $t/log || false

cat <<EOF > $t/dyn
{ foo; extern "C++" { "baz(int)"; }; };
Expand All @@ -24,13 +24,13 @@ EOF
$CC -B. -o $t/exe1 $t/a.o $t/b.o -Wl,-dynamic-list=$t/dyn

readelf --dyn-syms $t/exe1 > $t/log1
grep -q ' foo$' $t/log1
! grep -q ' bar$' $t/log1 || false
grep -q ' _Z3bazi$' $t/log1
grep -q ' foo' $t/log1
! grep -q ' bar' $t/log1 || false
grep -q ' _Z3bazi' $t/log1

$CC -B. -o $t/exe2 $t/a.o $t/b.o -Wl,--export-dynamic-symbol-list=$t/dyn

readelf --dyn-syms $t/exe2 > $t/log2
grep -q ' foo$' $t/log2
! grep -q ' bar$' $t/log2 || false
grep -q ' _Z3bazi$' $t/log2
grep -q ' foo' $t/log2
! grep -q ' bar' $t/log2 || false
grep -q ' _Z3bazi' $t/log2
24 changes: 12 additions & 12 deletions test/elf/dynamic-list3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ EOF
$CC -B. -Wl,--dynamic-list=$t/dyn -o $t/exe1 $t/b.o

readelf --dyn-syms $t/exe1 > $t/log1
grep -q ' xyz$' $t/log1
! grep -q ' foobarzx$' $t/log1 || false
grep -q ' foobarcx$' $t/log1
grep -q ' foo123bar456bx$' $t/log1
! grep -q ' foo123bar456c$' $t/log1 || false
! grep -q ' foo123bar456x$' $t/log1 || false
grep -q ' xyz' $t/log1
! grep -q ' foobarzx' $t/log1 || false
grep -q ' foobarcx' $t/log1
grep -q ' foo123bar456bx' $t/log1
! grep -q ' foo123bar456c' $t/log1 || false
! grep -q ' foo123bar456x' $t/log1 || false

$CC -B. -Wl,--export-dynamic-symbol-list=$t/dyn -o $t/exe2 $t/b.o

readelf --dyn-syms $t/exe2 > $t/log2
grep -q ' xyz$' $t/log2
! grep -q ' foobarzx$' $t/log2 || false
grep -q ' foobarcx$' $t/log2
grep -q ' foo123bar456bx$' $t/log2
! grep -q ' foo123bar456c$' $t/log2 || false
! grep -q ' foo123bar456x$' $t/log2 || false
grep -q ' xyz' $t/log2
! grep -q ' foobarzx' $t/log2 || false
grep -q ' foobarcx' $t/log2
grep -q ' foo123bar456bx' $t/log2
! grep -q ' foo123bar456c' $t/log2 || false
! grep -q ' foo123bar456x' $t/log2 || false
4 changes: 2 additions & 2 deletions test/elf/empty-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ EOF

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

readelf --dyn-syms $t/b.so | grep -q 'bar1$'
readelf --dyn-syms $t/b.so | grep -q 'bar2$'
readelf --dyn-syms $t/b.so | grep -q ' bar1'
readelf --dyn-syms $t/b.so | grep -q ' bar2'
2 changes: 1 addition & 1 deletion test/elf/lto-nostdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ void _start() {}
EOF

$CC -B. -o $t/exe -flto $t/a.o -nostdlib
readelf -Ws $t/exe | grep -Eq ' _start$'
readelf -Ws $t/exe | grep -Eq ' _start'
2 changes: 1 addition & 1 deletion test/elf/strip-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $CC -B. -o $t/exe $t/a.o -Wl,--strip-debug
readelf -W --sections $t/exe > $t/log
! grep -Fq .debug_info $t/log || false

readelf -W --symbols $t/exe | grep -q ' bar$'
readelf -W --symbols $t/exe | grep -q ' bar'
8 changes: 4 additions & 4 deletions test/elf/symbol-version2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ EOF
$CC -B. -o $t/c.so -shared $t/a.o -Wl,--version-script=$t/b.version
readelf -W --dyn-syms $t/c.so > $t/log

grep -q ' foo@TEST$' $t/log
grep -q ' bar@TEST$' $t/log
grep -q ' bar1$' $t/log
! grep -q ' foo@@TEST$' $t/log || false
grep -q ' foo@TEST' $t/log
grep -q ' bar@TEST' $t/log
grep -q ' bar1' $t/log
! grep -q ' foo@@TEST' $t/log || false
6 changes: 3 additions & 3 deletions test/elf/symbol-version3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EOF
$CC -B. -o $t/c.so -shared $t/a.o -Wl,--version-script=$t/b.version
readelf -W --dyn-syms $t/c.so > $t/log

grep -q ' foo@@TEST1$' $t/log
grep -q ' foo@TEST2$' $t/log
grep -q ' foo@TEST3$' $t/log
grep -q ' foo@@TEST1' $t/log
grep -q ' foo@TEST2' $t/log
grep -q ' foo@TEST3' $t/log
! grep -q ' foo$' $t/log || false
6 changes: 3 additions & 3 deletions test/elf/version-script11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ EOF
$CC -B. -shared -Wl,--version-script=$t/a.ver -o $t/c.so $t/b.o

readelf --dyn-syms $t/c.so > $t/log
grep -q 'foo@@VER_X1$' $t/log
! grep -q ' bar$' $t/log || false
! grep -q ' baz$' $t/log || false
grep -q 'foo@@VER_X1' $t/log
! grep -q ' bar' $t/log || false
! grep -q ' baz' $t/log || false
4 changes: 2 additions & 2 deletions test/elf/version-script12.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ EOF
$CC -B. -shared -Wl,--version-script=$t/a.ver -o $t/c.so $t/b.o

readelf --dyn-syms $t/c.so > $t/log
grep -q ' xyz$' $t/log
grep -q ' foo_bar$' $t/log
grep -q ' xyz' $t/log
grep -q ' foo_bar' $t/log
! grep -q ' foo$' $t/log || false
2 changes: 1 addition & 1 deletion test/elf/version-script13.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ EOF
$CC -B. -shared -Wl,--version-script=$t/a.ver -o $t/c.so $t/b.o

readelf --dyn-syms $t/c.so > $t/log
grep -q ' foobar$' $t/log
grep -q ' foobar' $t/log
! grep -q ' foo$' $t/log || false
12 changes: 6 additions & 6 deletions test/elf/version-script14.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ EOF
$CC -B. -shared -Wl,--version-script=$t/a.ver -o $t/c.so $t/b.o

readelf --dyn-syms $t/c.so > $t/log
grep -q ' xyz$' $t/log
! grep -q ' foobarzx$' $t/log || false
grep -q ' foobarcx$' $t/log
grep -q ' foo123bar456bx$' $t/log
! grep -q ' foo123bar456c$' $t/log || false
! grep -q ' foo123bar456x$' $t/log || false
grep -q ' xyz' $t/log
! grep -q ' foobarzx' $t/log || false
grep -q ' foobarcx' $t/log
grep -q ' foo123bar456bx' $t/log
! grep -q ' foo123bar456c' $t/log || false
! grep -q ' foo123bar456x' $t/log || false
8 changes: 4 additions & 4 deletions test/elf/version-script15.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EOF
$CC -B. -shared -Wl,--version-script=$t/a.ver -o $t/c.so $t/b.o

readelf --dyn-syms $t/c.so > $t/log
grep -q ' azZ$' $t/log
grep -q ' czZ$' $t/log
! grep -q ' azC$' $t/log || false
! grep -q ' aaZ$' $t/log || false
grep -q ' azZ' $t/log
grep -q ' czZ' $t/log
! grep -q ' azC' $t/log || false
! grep -q ' aaZ' $t/log || false

0 comments on commit 0f71471

Please sign in to comment.