Skip to content

Commit

Permalink
Spread some const around for non-mutating uses of MCSymbolData.
Browse files Browse the repository at this point in the history
I discovered this const-hole while attempting to coalesnce the Symbol
and SymbolMap data structures. There's some pending issues with that,
but I figured this change was easy to flush early.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207124 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dwblaikie committed Apr 24, 2014
1 parent 25fb047 commit 45966fa
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 26 deletions.
8 changes: 7 additions & 1 deletion include/llvm/MC/MCAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,13 @@ class MCAssembler {
return SymbolMap.lookup(&Symbol) != nullptr;
}

MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
MCSymbolData &getSymbolData(const MCSymbol &Symbol) {
MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
assert(Entry && "Missing symbol data!");
return *Entry;
}

const MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
assert(Entry && "Missing symbol data!");
return *Entry;
Expand Down
2 changes: 1 addition & 1 deletion lib/MC/ELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
uint64_t
ELFObjectWriter::getSymbolIndexInSymbolTable(const MCAssembler &Asm,
const MCSymbol *S) {
MCSymbolData &SD = Asm.getSymbolData(*S);
const MCSymbolData &SD = Asm.getSymbolData(*S);
return SD.getIndex();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/MC/MCExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ static void AttemptToFoldSymbolOffsetDifference(const MCAssembler *Asm,
if (!Asm->getWriter().IsSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet))
return;

MCSymbolData &AD = Asm->getSymbolData(SA);
MCSymbolData &BD = Asm->getSymbolData(SB);
const MCSymbolData &AD = Asm->getSymbolData(SA);
const MCSymbolData &BD = Asm->getSymbolData(SB);

if (AD.getFragment() == BD.getFragment()) {
Addend += (AD.getOffset() - BD.getOffset());
Expand Down
4 changes: 2 additions & 2 deletions lib/MC/WinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,
Fixup.getLoc(),
Twine("symbol '") + A.getName() + "' can not be undefined");

MCSymbolData &A_SD = Asm.getSymbolData(A);
const MCSymbolData &A_SD = Asm.getSymbolData(A);

MCSectionData const *SectionData = Fragment->getParent();

Expand All @@ -703,7 +703,7 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,

if (SymB) {
const MCSymbol *B = &SymB->getSymbol();
MCSymbolData &B_SD = Asm.getSymbolData(*B);
const MCSymbolData &B_SD = Asm.getSymbolData(*B);
if (!B_SD.getFragment())
Asm.getContext().FatalError(
Fixup.getLoc(),
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void ARMAsmBackend::processFixupValue(const MCAssembler &Asm,
// the offset when the destination has the same MCFragment.
if (A && (unsigned)Fixup.getKind() == ARM::fixup_arm_thumb_bl) {
const MCSymbol &Sym = A->getSymbol().AliasedSymbol();
MCSymbolData &SymData = Asm.getSymbolData(Sym);
const MCSymbolData &SymData = Asm.getSymbolData(Sym);
IsResolved = (SymData.getFragment() == DF);
}
// We must always generate a relocation for BL/BLX instructions if we have
Expand Down
10 changes: 5 additions & 5 deletions lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,

// See <reloc.h>.
const MCSymbol *A = &Target.getSymA()->getSymbol();
MCSymbolData *A_SD = &Asm.getSymbolData(*A);
const MCSymbolData *A_SD = &Asm.getSymbolData(*A);

if (!A_SD->getFragment())
Asm.getContext().FatalError(Fixup.getLoc(),
Expand All @@ -170,7 +170,7 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
FixedValue += SecAddr;

if (const MCSymbolRefExpr *B = Target.getSymB()) {
MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());
const MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());

if (!B_SD->getFragment())
Asm.getContext().FatalError(Fixup.getLoc(),
Expand Down Expand Up @@ -259,7 +259,7 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,

// See <reloc.h>.
const MCSymbol *A = &Target.getSymA()->getSymbol();
MCSymbolData *A_SD = &Asm.getSymbolData(*A);
const MCSymbolData *A_SD = &Asm.getSymbolData(*A);

if (!A_SD->getFragment())
Asm.getContext().FatalError(Fixup.getLoc(),
Expand All @@ -272,7 +272,7 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
uint32_t Value2 = 0;

if (const MCSymbolRefExpr *B = Target.getSymB()) {
MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());
const MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());

if (!B_SD->getFragment())
Asm.getContext().FatalError(Fixup.getLoc(),
Expand Down Expand Up @@ -378,7 +378,7 @@ void ARMMachObjectWriter::RecordRelocation(MachObjectWriter *Writer,
}

// Get the symbol data, if any.
MCSymbolData *SD = 0;
const MCSymbolData *SD = 0;
if (Target.getSymA())
SD = &Asm.getSymbolData(Target.getSymA()->getSymbol());

Expand Down
6 changes: 3 additions & 3 deletions lib/Target/ARM64/MCTargetDesc/ARM64MachObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ void ARM64MachObjectWriter::RecordRelocation(
}
} else if (Target.getSymB()) { // A - B + constant
const MCSymbol *A = &Target.getSymA()->getSymbol();
MCSymbolData &A_SD = Asm.getSymbolData(*A);
const MCSymbolData &A_SD = Asm.getSymbolData(*A);
const MCSymbolData *A_Base = Asm.getAtom(&A_SD);

const MCSymbol *B = &Target.getSymB()->getSymbol();
MCSymbolData &B_SD = Asm.getSymbolData(*B);
const MCSymbolData &B_SD = Asm.getSymbolData(*B);
const MCSymbolData *B_Base = Asm.getAtom(&B_SD);

// Check for "_foo@got - .", which comes through here as:
Expand Down Expand Up @@ -267,7 +267,7 @@ void ARM64MachObjectWriter::RecordRelocation(
Type = MachO::ARM64_RELOC_SUBTRACTOR;
} else { // A + constant
const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
MCSymbolData &SD = Asm.getSymbolData(*Symbol);
const MCSymbolData &SD = Asm.getSymbolData(*Symbol);
const MCSymbolData *Base = Asm.getAtom(&SD);
const MCSectionMachO &Section = static_cast<const MCSectionMachO &>(
Fragment->getParent()->getSection());
Expand Down
6 changes: 3 additions & 3 deletions lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ bool PPCMachObjectWriter::RecordScatteredRelocation(

// See <reloc.h>.
const MCSymbol *A = &Target.getSymA()->getSymbol();
MCSymbolData *A_SD = &Asm.getSymbolData(*A);
const MCSymbolData *A_SD = &Asm.getSymbolData(*A);

if (!A_SD->getFragment())
report_fatal_error("symbol '" + A->getName() +
Expand All @@ -219,7 +219,7 @@ bool PPCMachObjectWriter::RecordScatteredRelocation(
uint32_t Value2 = 0;

if (const MCSymbolRefExpr *B = Target.getSymB()) {
MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());
const MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());

if (!B_SD->getFragment())
report_fatal_error("symbol '" + B->getSymbol().getName() +
Expand Down Expand Up @@ -324,7 +324,7 @@ void PPCMachObjectWriter::RecordPPCRelocation(

// this doesn't seem right for RIT_PPC_BR24
// Get the symbol data, if any.
MCSymbolData *SD = 0;
const MCSymbolData *SD = 0;
if (Target.getSymA())
SD = &Asm.getSymbolData(Target.getSymA()->getSymbol());

Expand Down
17 changes: 9 additions & 8 deletions lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ void X86MachObjectWriter::RecordX86_64Relocation(MachObjectWriter *Writer,
const MCSymbol *A = &Target.getSymA()->getSymbol();
if (A->isTemporary())
A = &A->AliasedSymbol();
MCSymbolData &A_SD = Asm.getSymbolData(*A);
const MCSymbolData &A_SD = Asm.getSymbolData(*A);
const MCSymbolData *A_Base = Asm.getAtom(&A_SD);

const MCSymbol *B = &Target.getSymB()->getSymbol();
if (B->isTemporary())
B = &B->AliasedSymbol();
MCSymbolData &B_SD = Asm.getSymbolData(*B);
const MCSymbolData &B_SD = Asm.getSymbolData(*B);
const MCSymbolData *B_Base = Asm.getAtom(&B_SD);

// Neither symbol can be modified.
Expand Down Expand Up @@ -220,7 +220,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(MachObjectWriter *Writer,
Type = MachO::X86_64_RELOC_SUBTRACTOR;
} else {
const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
MCSymbolData &SD = Asm.getSymbolData(*Symbol);
const MCSymbolData &SD = Asm.getSymbolData(*Symbol);
const MCSymbolData *Base = Asm.getAtom(&SD);

// Relocations inside debug sections always use local relocations when
Expand Down Expand Up @@ -369,7 +369,7 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,

// See <reloc.h>.
const MCSymbol *A = &Target.getSymA()->getSymbol();
MCSymbolData *A_SD = &Asm.getSymbolData(*A);
const MCSymbolData *A_SD = &Asm.getSymbolData(*A);

if (!A_SD->getFragment())
report_fatal_error("symbol '" + A->getName() +
Expand All @@ -382,7 +382,7 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
uint32_t Value2 = 0;

if (const MCSymbolRefExpr *B = Target.getSymB()) {
MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());
const MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());

if (!B_SD->getFragment())
report_fatal_error("symbol '" + B->getSymbol().getName() +
Expand Down Expand Up @@ -465,7 +465,7 @@ void X86MachObjectWriter::RecordTLVPRelocation(MachObjectWriter *Writer,
unsigned IsPCRel = 0;

// Get the symbol data.
MCSymbolData *SD_A = &Asm.getSymbolData(Target.getSymA()->getSymbol());
const MCSymbolData *SD_A = &Asm.getSymbolData(Target.getSymA()->getSymbol());
unsigned Index = SD_A->getIndex();

// We're only going to have a second symbol in pic mode and it'll be a
Expand All @@ -476,7 +476,8 @@ void X86MachObjectWriter::RecordTLVPRelocation(MachObjectWriter *Writer,
// If this is a subtraction then we're pcrel.
uint32_t FixupAddress =
Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset();
MCSymbolData *SD_B = &Asm.getSymbolData(Target.getSymB()->getSymbol());
const MCSymbolData *SD_B =
&Asm.getSymbolData(Target.getSymB()->getSymbol());
IsPCRel = 1;
FixedValue = (FixupAddress - Writer->getSymbolAddress(SD_B, Layout) +
Target.getConstant());
Expand Down Expand Up @@ -524,7 +525,7 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
}

// Get the symbol data, if any.
MCSymbolData *SD = 0;
const MCSymbolData *SD = 0;
if (Target.getSymA())
SD = &Asm.getSymbolData(Target.getSymA()->getSymbol());

Expand Down

0 comments on commit 45966fa

Please sign in to comment.