Skip to content

ELFObjectWriter: Disable STT_SECTION adjustment for .reloc #135519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions llvm/lib/MC/ELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,9 +1395,8 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
if (UseSectionSym) {
UseSectionSym = useSectionSymbol(Asm, Target, SymA, C, Type);

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

uint64_t Addend = UseSectionSym ? C + Asm.getSymbolOffset(*SymA) : C;
Expand Down
7 changes: 4 additions & 3 deletions llvm/test/MC/ELF/reloc-directive.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@
# ASM-NEXT: .Ltmp1:
# ASM-NEXT: .reloc .Ltmp1-1, R_X86_64_NONE, foo
# ASM-NEXT: .Ltmp2:
# ASM-NEXT: .reloc 2+.Ltmp2, R_X86_64_NONE, foo
# ASM-NEXT: .reloc 2+.Ltmp2, R_X86_64_NONE, local
# ASM-NEXT: .reloc 1+foo+3, R_X86_64_NONE, data+1
# ASM-NEXT: .Ltmp3:
# ASM-NEXT: .reloc .Ltmp3, BFD_RELOC_NONE, unused

# CHECK: 0x2 R_X86_64_NONE foo 0x0
# CHECK-NEXT: 0x0 R_X86_64_NONE foo 0x0
# CHECK-NEXT: 0x3 R_X86_64_NONE foo 0x0
# CHECK-NEXT: 0x3 R_X86_64_NONE local 0x0
# CHECK-NEXT: 0x4 R_X86_64_NONE data 0x1
# CHECK-NEXT: 0x1 R_X86_64_NONE unused 0x0

.text
.globl foo
foo:
local:
ret
.reloc .+3-2, R_X86_64_NONE, foo
.reloc .-1, R_X86_64_NONE, foo
.reloc 2+., R_X86_64_NONE, foo
.reloc 2+., R_X86_64_NONE, local
.reloc 1+foo+3, R_X86_64_NONE, data+1
.reloc ., BFD_RELOC_NONE, unused

Expand Down
Loading