Skip to content

Commit a630ef7

Browse files
authored
ELFObjectWriter: Disable STT_SECTION adjustment for .reloc
... to match GNU Assembler. This generalizes the SHT_LLVM_CALL_GRAPH_PROFILE special case (which uses .reloc with BFD_RELOC_NONE https://reviews.llvm.org/D104080). Targets that want STT_SECTION adjustment cannot use FirstLiteralRelocationKind derived fixup kinds. Depends on the fix of #135521 Pull Request: #135519
1 parent c1fc4c6 commit a630ef7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,9 +1395,8 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13951395
if (UseSectionSym) {
13961396
UseSectionSym = useSectionSymbol(Asm, Target, SymA, C, Type);
13971397

1398-
// Disable STT_SECTION adjustment for CG Profile to help with --cg-profile.
1399-
const auto *Parent = cast<MCSectionELF>(Fragment->getParent());
1400-
UseSectionSym &= Parent->getType() != ELF::SHT_LLVM_CALL_GRAPH_PROFILE;
1398+
// Disable STT_SECTION adjustment for .reloc directives.
1399+
UseSectionSym &= Fixup.getKind() < FirstLiteralRelocationKind;
14011400
}
14021401

14031402
uint64_t Addend = UseSectionSym ? C + Asm.getSymbolOffset(*SymA) : C;

llvm/test/MC/ELF/reloc-directive.s

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@
88
# ASM-NEXT: .Ltmp1:
99
# ASM-NEXT: .reloc .Ltmp1-1, R_X86_64_NONE, foo
1010
# ASM-NEXT: .Ltmp2:
11-
# ASM-NEXT: .reloc 2+.Ltmp2, R_X86_64_NONE, foo
11+
# ASM-NEXT: .reloc 2+.Ltmp2, R_X86_64_NONE, local
1212
# ASM-NEXT: .reloc 1+foo+3, R_X86_64_NONE, data+1
1313
# ASM-NEXT: .Ltmp3:
1414
# ASM-NEXT: .reloc .Ltmp3, BFD_RELOC_NONE, unused
1515

1616
# CHECK: 0x2 R_X86_64_NONE foo 0x0
1717
# CHECK-NEXT: 0x0 R_X86_64_NONE foo 0x0
18-
# CHECK-NEXT: 0x3 R_X86_64_NONE foo 0x0
18+
# CHECK-NEXT: 0x3 R_X86_64_NONE local 0x0
1919
# CHECK-NEXT: 0x4 R_X86_64_NONE data 0x1
2020
# CHECK-NEXT: 0x1 R_X86_64_NONE unused 0x0
2121

2222
.text
2323
.globl foo
2424
foo:
25+
local:
2526
ret
2627
.reloc .+3-2, R_X86_64_NONE, foo
2728
.reloc .-1, R_X86_64_NONE, foo
28-
.reloc 2+., R_X86_64_NONE, foo
29+
.reloc 2+., R_X86_64_NONE, local
2930
.reloc 1+foo+3, R_X86_64_NONE, data+1
3031
.reloc ., BFD_RELOC_NONE, unused
3132

0 commit comments

Comments
 (0)