Skip to content

Commit faf39f4

Browse files
authored
Revert "[LoongArch] Use R_LARCH_ALIGN with section symbol (#84741)"
This reverts commit 01f7989. This unusual special case has been discussed on the binutils mailing list. The approach will be revisited: https://sourceware.org/pipermail/binutils/2024-May/134092.html Pull Request: #92584
1 parent 1e9324a commit faf39f4

File tree

6 files changed

+15
-47
lines changed

6 files changed

+15
-47
lines changed

lld/ELF/InputSection.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,7 @@ void InputSection::copyRelocations(uint8_t *buf,
471471
addend += sec->getFile<ELFT>()->mipsGp0;
472472
}
473473

474-
if (config->emachine == EM_LOONGARCH && type == R_LARCH_ALIGN)
475-
// LoongArch psABI v2.30, the R_LARCH_ALIGN requires symbol index.
476-
// If it use the section symbol, the addend should not be changed.
477-
p->r_addend = addend;
478-
else if (RelTy::IsRela)
474+
if (RelTy::IsRela)
479475
p->r_addend = sym.getVA(addend) - section->getOutputSection()->addr;
480476
// For SHF_ALLOC sections relocated by REL, append a relocation to
481477
// sec->relocations so that relocateAlloc transitively called by

lld/test/ELF/loongarch-relax-align-ldr.s

Lines changed: 0 additions & 28 deletions
This file was deleted.

lld/test/ELF/loongarch-relax-emit-relocs.s

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# CHECK-NEXT: R_LARCH_PCALA_LO12 _start
2626
# CHECK-NEXT: R_LARCH_RELAX *ABS*
2727
# CHECK-NEXT: nop
28-
# CHECK-NEXT: R_LARCH_ALIGN .text+0x4
28+
# CHECK-NEXT: R_LARCH_ALIGN .Lla-relax-align0+0x4
2929
# CHECK-NEXT: nop
3030
# CHECK-NEXT: ret
3131

@@ -37,12 +37,11 @@
3737
# CHECKR-NEXT: R_LARCH_PCALA_LO12 _start
3838
# CHECKR-NEXT: R_LARCH_RELAX *ABS*
3939
# CHECKR-NEXT: nop
40-
# CHECKR-NEXT: R_LARCH_ALIGN .text+0x4
40+
# CHECKR-NEXT: R_LARCH_ALIGN .Lla-relax-align0+0x4
4141
# CHECKR-NEXT: nop
4242
# CHECKR-NEXT: nop
4343
# CHECKR-NEXT: ret
4444

45-
.text
4645
.global _start
4746
_start:
4847
la.pcrel $a0, _start

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,11 @@ bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(
226226
MCFixup::create(0, Dummy, MCFixupKind(LoongArch::fixup_loongarch_align));
227227
const MCSymbolRefExpr *MCSym = getSecToAlignSym()[Sec];
228228
if (MCSym == nullptr) {
229-
// Use section symbol directly.
230-
MCSym = MCSymbolRefExpr::create(Sec->getBeginSymbol(), Ctx);
229+
// Create a symbol and make the value of symbol is zero.
230+
MCSymbol *Sym = Ctx.createNamedTempSymbol("la-relax-align");
231+
Sym->setFragment(&*Sec->getBeginSymbol()->getFragment());
232+
Asm.registerSymbol(*Sym);
233+
MCSym = MCSymbolRefExpr::create(Sym, Ctx);
231234
getSecToAlignSym()[Sec] = MCSym;
232235
}
233236

llvm/test/MC/LoongArch/Relocations/relax-addsub.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# RELAX: Relocations [
3030
# RELAX-NEXT: Section ({{.*}}) .rela.text {
31-
# RELAX-NEXT: 0x4 R_LARCH_ALIGN .text 0x4
31+
# RELAX-NEXT: 0x4 R_LARCH_ALIGN {{.*}} 0x4
3232
# RELAX-NEXT: 0x10 R_LARCH_PCALA_HI20 .L1 0x0
3333
# RELAX-NEXT: 0x10 R_LARCH_RELAX - 0x0
3434
# RELAX-NEXT: 0x14 R_LARCH_PCALA_LO12 .L1 0x0

llvm/test/MC/LoongArch/Relocations/relax-align.s

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,17 @@ ret
6363
## Test the symbol index is different from .text.
6464
.section .text2, "ax"
6565
.p2align 4
66-
.p2align 4, , 4
6766
break 7
6867

6968
# RELOC: Relocations [
7069
# RELAX-RELOC-NEXT: Section ({{.*}}) .rela.text {
71-
# RELAX-RELOC-NEXT: 0x24 R_LARCH_ALIGN .text 0x4
72-
# RELAX-RELOC-NEXT: 0x34 R_LARCH_ALIGN .text 0x5
73-
# RELAX-RELOC-NEXT: 0x50 R_LARCH_ALIGN .text 0x4
74-
# RELAX-RELOC-NEXT: 0x60 R_LARCH_ALIGN .text 0xB04
75-
# RELAX-RELOC-NEXT: 0x70 R_LARCH_ALIGN .text 0x4
70+
# RELAX-RELOC-NEXT: 0x24 R_LARCH_ALIGN .Lla-relax-align0 0x4
71+
# RELAX-RELOC-NEXT: 0x34 R_LARCH_ALIGN .Lla-relax-align0 0x5
72+
# RELAX-RELOC-NEXT: 0x50 R_LARCH_ALIGN .Lla-relax-align0 0x4
73+
# RELAX-RELOC-NEXT: 0x60 R_LARCH_ALIGN .Lla-relax-align0 0xB04
74+
# RELAX-RELOC-NEXT: 0x70 R_LARCH_ALIGN .Lla-relax-align0 0x4
7675
# RELAX-RELOC-NEXT: }
7776
# RELAX-RELOC-NEXT: Section ({{.*}}) .rela.text2 {
78-
# RELAX-RELOC-NEXT: 0x0 R_LARCH_ALIGN .text2 0x4
79-
# RELAX-RELOC-NEXT: 0xC R_LARCH_ALIGN .text2 0x404
77+
# RELAX-RELOC-NEXT: 0x0 R_LARCH_ALIGN .Lla-relax-align1 0x4
8078
# RELAX-RELOC-NEXT: }
8179
# RELOC-NEXT: ]

0 commit comments

Comments
 (0)