Skip to content

Commit 6e857b4

Browse files
committed
MC: Move R_PPC64_TOC case to PowerPCAsmBackend
1 parent eb467a0 commit 6e857b4

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

llvm/include/llvm/MC/MCValue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class MCValue {
4646
void setSpecifier(uint32_t S) { Specifier = S; }
4747

4848
const MCSymbol *getAddSym() const { return SymA; }
49+
void setAddSym(const MCSymbol *A) { SymA = A; }
4950
const MCSymbol *getSubSym() const { return SymB; }
5051

5152
/// Is this an absolute (as opposed to relocatable) value.

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,8 +1350,6 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13501350
MCFixupKindInfo::FKF_IsPCRel;
13511351
uint64_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
13521352
uint64_t Addend = Target.getConstant();
1353-
// Handle special fixups like ADD/SUB relocation pairs.
1354-
13551353
if (auto *RefB = Target.getSubSym()) {
13561354
const auto &SymB = cast<MCSymbolELF>(*RefB);
13571355
if (SymB.isUndefined()) {
@@ -1397,12 +1395,6 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13971395
SymA = cast<MCSymbolELF>(SecA->getBeginSymbol());
13981396
SymA->setUsedInReloc();
13991397
} else {
1400-
// In PPC64 ELFv1, .quad .TOC.@tocbase in the .opd section is expected to
1401-
// reference the null symbol.
1402-
if (Type == ELF::R_PPC64_TOC &&
1403-
TargetObjectWriter->getEMachine() == ELF::EM_PPC64)
1404-
SymA = nullptr;
1405-
14061398
if (SymA) {
14071399
if (const MCSymbolELF *R = Renames.lookup(SymA))
14081400
SymA = R;

llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "MCTargetDesc/PPCFixupKinds.h"
10+
#include "MCTargetDesc/PPCMCExpr.h"
1011
#include "MCTargetDesc/PPCMCTargetDesc.h"
1112
#include "llvm/BinaryFormat/ELF.h"
1213
#include "llvm/BinaryFormat/MachO.h"
@@ -133,6 +134,18 @@ class PPCAsmBackend : public MCAsmBackend {
133134
: InfosBE)[Kind - FirstTargetFixupKind];
134135
}
135136

137+
bool addReloc(MCAssembler &Asm, const MCFragment &F, const MCFixup &Fixup,
138+
const MCValue &TargetVal, uint64_t &FixedValue, bool IsResolved,
139+
const MCSubtargetInfo *STI) override {
140+
// In PPC64 ELFv1, .quad .TOC.@tocbase in the .opd section is expected to
141+
// reference the null symbol.
142+
auto Target = TargetVal;
143+
if (Target.getSpecifier() == PPCMCExpr::VK_TOCBASE)
144+
Target.setAddSym(nullptr);
145+
return MCAsmBackend::addReloc(Asm, F, Fixup, Target, FixedValue, IsResolved,
146+
STI);
147+
}
148+
136149
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
137150
const MCValue &Target, MutableArrayRef<char> Data,
138151
uint64_t Value, bool IsResolved,

llvm/test/MC/PowerPC/ppc64-relocs-01.s

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llvm-mc -triple=powerpc64-unknown-linux-gnu -filetype=obj %s | \
2-
# RUN: llvm-readobj -r - | FileCheck %s
2+
# RUN: llvm-readobj -rs - | FileCheck %s
33

44
.section .opd,"aw",@progbits
55
access_int64:
@@ -44,3 +44,5 @@ number64:
4444
# CHECK-NEXT: }
4545

4646
# CHECK-NEXT: ]
47+
# CHECK: Symbols [
48+
# CHECK: .TOC.

0 commit comments

Comments
 (0)