Skip to content

Commit

Permalink
Merge pull request #1335 from ywgrit/main
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Aug 27, 2024
2 parents ed617fe + 4da257e commit fe7237e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/arch-loongarch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
*(ul32 *)loc = 0x5000'0000; // B
else
*(ul32 *)loc = 0x5400'0000; // BL
write_k16(loc, (S + A - P) >> 2);
write_d10k16(loc, (S + A - P) >> 2);
}
break;
case R_LARCH_ADD_ULEB128:
Expand Down
16 changes: 9 additions & 7 deletions test/arch-loongarch64-relax-call36.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ cat <<'EOF' | $CC -o $t/a.o -c -xassembler -
.globl foo, bar
foo:
move $s0, $ra
.reloc ., R_LARCH_CALL36, foo2
.reloc ., R_LARCH_CALL36, print
.reloc ., R_LARCH_RELAX
pcaddu18i $t0, 0
jirl $ra, $t0, 0
move $ra, $s0
ret
bar:
.reloc ., R_LARCH_CALL36, bar2
.reloc ., R_LARCH_CALL36, print
.reloc ., R_LARCH_RELAX
pcaddu18i $t0, 0
jirl $zero, $t0, 0
Expand All @@ -22,8 +22,10 @@ cat <<EOF | $CC -o $t/b.o -c -xc -
#include <stdio.h>
void foo();
void bar();
void foo2() { printf("foo"); }
void bar2() { printf("bar"); }
void print() __attribute__ ((section(".print")));
void print() {
printf("beef");
}
int main() {
foo();
Expand All @@ -33,14 +35,14 @@ int main() {
EOF

$CC -B. -o $t/exe1 $t/a.o $t/b.o -Wl,--no-relax
$QEMU $t/exe1 | grep -q foobar
$QEMU $t/exe1 | grep -q beefbeef

$OBJDUMP -d $t/exe1 > $t/exe1.objdump
grep -A2 '<foo>:' $t/exe1.objdump | grep -wq pcaddu18i
grep -A2 '<bar>:' $t/exe1.objdump | grep -wq pcaddu18i

$CC -B. -o $t/exe2 $t/a.o $t/b.o -Wl,--relax
$QEMU $t/exe2 | grep -q foobar
$CC -B. -o $t/exe2 $t/a.o $t/b.o -Wl,--relax -Wl,-Ttext=0x10000 -Wl,--section-start=.print=0x100000
$QEMU $t/exe2 | grep -q beefbeef

$OBJDUMP -d $t/exe2 > $t/exe2.objdump
grep -A2 '<foo>:' $t/exe2.objdump | grep -wq bl
Expand Down

0 comments on commit fe7237e

Please sign in to comment.