1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-17 16:09:43 +03:00

Fix relocations for POWER10

With this change, all tests now pass on an actual POWER10 machine
(gcc120.fsffrance.org).
This commit is contained in:
Rui Ueyama 2023-10-13 10:11:35 +09:00
parent 83ec409426
commit 0f714710f0
15 changed files with 61 additions and 60 deletions

View File

@ -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
@ -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);

View File

@ -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'

View File

@ -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; };
@ -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

View File

@ -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)"; }; };
@ -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

View File

@ -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

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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