mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-25 17:20:48 +00:00
Revert r203962 and two revisions depending on it: r204028 and r204059.
The revision I'm reverting breaks handling of transitive aliases. This blocks us and breaks sanitizer bootstrap: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/2651 (and checked locally by Alexey). This revision is the result of: svn merge -r204059:204058 -r204028:204027 -r203962:203961 . + the regression test added to test/MC/ELF/alias.s Another way to reproduce the regression with clang: $ cat q.c void a1(); void a2() __attribute__((alias("a1"))); void a3() __attribute__((alias("a2"))); void a1() {} $ ~/work/llvm-build/bin/clang-3.5-good -c q.c && mv q.o good.o && \ ~/work/llvm-build/bin/clang-3.5-bad -c q.c && mv q.o bad.o && \ objdump -t good.o bad.o good.o: file format elf64-x86-64 SYMBOL TABLE: 0000000000000000 l df *ABS* 0000000000000000 q.c 0000000000000000 l d .text 0000000000000000 .text 0000000000000000 l d .data 0000000000000000 .data 0000000000000000 l d .bss 0000000000000000 .bss 0000000000000000 l d .comment 0000000000000000 .comment 0000000000000000 l d .note.GNU-stack 0000000000000000 .note.GNU-stack 0000000000000000 l d .eh_frame 0000000000000000 .eh_frame 0000000000000000 g F .text 0000000000000006 a1 0000000000000000 g F .text 0000000000000006 a2 0000000000000000 g F .text 0000000000000006 a3 bad.o: file format elf64-x86-64 SYMBOL TABLE: 0000000000000000 l df *ABS* 0000000000000000 q.c 0000000000000000 l d .text 0000000000000000 .text 0000000000000000 l d .data 0000000000000000 .data 0000000000000000 l d .bss 0000000000000000 .bss 0000000000000000 l d .comment 0000000000000000 .comment 0000000000000000 l d .note.GNU-stack 0000000000000000 .note.GNU-stack 0000000000000000 l d .eh_frame 0000000000000000 .eh_frame 0000000000000000 g F .text 0000000000000006 a1 0000000000000000 g F .text 0000000000000006 a2 0000000000000000 g .text 0000000000000000 a3 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204137 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -271,7 +271,6 @@ class ELFObjectWriter : public MCObjectWriter {
|
||||
/// \param RevGroupMap - Maps a signature symbol to the group section.
|
||||
/// \param NumRegularSections - Number of non-relocation sections.
|
||||
void ComputeSymbolTable(MCAssembler &Asm,
|
||||
const MCAsmLayout &Layout,
|
||||
const SectionIndexMapTy &SectionIndexMap,
|
||||
RevGroupMapTy RevGroupMap,
|
||||
unsigned NumRegularSections);
|
||||
@@ -463,47 +462,33 @@ void ELFObjectWriter::WriteSymbolEntry(MCDataFragment *SymtabF,
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ELFObjectWriter::SymbolValue(MCSymbolData &OrigData,
|
||||
uint64_t ELFObjectWriter::SymbolValue(MCSymbolData &Data,
|
||||
const MCAsmLayout &Layout) {
|
||||
MCSymbolData *Data = &OrigData;
|
||||
if (Data->isCommon() && Data->isExternal())
|
||||
return Data->getCommonAlignment();
|
||||
if (Data.isCommon() && Data.isExternal())
|
||||
return Data.getCommonAlignment();
|
||||
|
||||
const MCSymbol *Symbol = &Data->getSymbol();
|
||||
const bool IsThumbFunc = OrigData.getFlags() & ELF_Other_ThumbFunc;
|
||||
const MCSymbol &Symbol = Data.getSymbol();
|
||||
|
||||
uint64_t Res = 0;
|
||||
if (Symbol->isVariable()) {
|
||||
const MCExpr *Expr = Symbol->getVariableValue();
|
||||
MCValue Value;
|
||||
if (!Expr->EvaluateAsRelocatable(Value, &Layout))
|
||||
return 0;
|
||||
if (Value.getSymB())
|
||||
return 0;
|
||||
|
||||
Res = Value.getConstant();
|
||||
if (IsThumbFunc)
|
||||
Res |= 1;
|
||||
|
||||
const MCSymbolRefExpr *A = Value.getSymA();
|
||||
if (!A)
|
||||
return Res;
|
||||
|
||||
Symbol = &A->getSymbol();
|
||||
Data = &Layout.getAssembler().getSymbolData(*Symbol);
|
||||
if (Symbol.isAbsolute() && Symbol.isVariable()) {
|
||||
if (const MCExpr *Value = Symbol.getVariableValue()) {
|
||||
int64_t IntValue;
|
||||
if (Value->EvaluateAsAbsolute(IntValue, Layout))
|
||||
return (uint64_t)IntValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Symbol->isInSection())
|
||||
if (!Symbol.isInSection())
|
||||
return 0;
|
||||
|
||||
if (!Data->getFragment())
|
||||
return 0;
|
||||
|
||||
Res += Layout.getSymbolOffset(Data);
|
||||
if (IsThumbFunc || Data->getFlags() & ELF_Other_ThumbFunc)
|
||||
Res |= 1;
|
||||
if (Data.getFragment()) {
|
||||
if (Data.getFlags() & ELF_Other_ThumbFunc)
|
||||
return Layout.getSymbolOffset(&Data)+1;
|
||||
else
|
||||
return Layout.getSymbolOffset(&Data);
|
||||
}
|
||||
|
||||
return Res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
|
||||
@@ -584,9 +569,8 @@ void ELFObjectWriter::WriteSymbol(MCDataFragment *SymtabF,
|
||||
ELFSymbolData &MSD,
|
||||
const MCAsmLayout &Layout) {
|
||||
MCSymbolData &OrigData = *MSD.SymbolData;
|
||||
const MCSymbol *Base = OrigData.getSymbol().getBaseSymbol(Layout);
|
||||
const MCSymbolData &Data =
|
||||
Base ? Layout.getAssembler().getSymbolData(*Base) : OrigData;
|
||||
MCSymbolData &Data =
|
||||
Layout.getAssembler().getSymbolData(OrigData.getSymbol().AliasedSymbol());
|
||||
|
||||
bool IsReserved = Data.isCommon() || Data.getSymbol().isAbsolute() ||
|
||||
Data.getSymbol().isVariable();
|
||||
@@ -594,8 +578,6 @@ void ELFObjectWriter::WriteSymbol(MCDataFragment *SymtabF,
|
||||
// Binding and Type share the same byte as upper and lower nibbles
|
||||
uint8_t Binding = MCELF::GetBinding(OrigData);
|
||||
uint8_t Type = mergeTypeForSet(MCELF::GetType(OrigData), MCELF::GetType(Data));
|
||||
if (OrigData.getFlags() & ELF_Other_ThumbFunc)
|
||||
Type = ELF::STT_FUNC;
|
||||
uint8_t Info = (Binding << ELF_STB_Shift) | (Type << ELF_STT_Shift);
|
||||
|
||||
// Other and Visibility share the same byte with Visibility using the lower
|
||||
@@ -604,7 +586,7 @@ void ELFObjectWriter::WriteSymbol(MCDataFragment *SymtabF,
|
||||
uint8_t Other = MCELF::getOther(OrigData) << (ELF_STO_Shift - ELF_STV_Shift);
|
||||
Other |= Visibility;
|
||||
|
||||
uint64_t Value = SymbolValue(OrigData, Layout);
|
||||
uint64_t Value = SymbolValue(Data, Layout);
|
||||
uint64_t Size = 0;
|
||||
|
||||
assert(!(Data.isCommon() && !Data.isExternal()));
|
||||
@@ -915,11 +897,10 @@ void ELFObjectWriter::ComputeIndexMap(MCAssembler &Asm,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ELFObjectWriter::ComputeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
|
||||
const SectionIndexMapTy &SectionIndexMap,
|
||||
RevGroupMapTy RevGroupMap,
|
||||
unsigned NumRegularSections) {
|
||||
void ELFObjectWriter::ComputeSymbolTable(MCAssembler &Asm,
|
||||
const SectionIndexMapTy &SectionIndexMap,
|
||||
RevGroupMapTy RevGroupMap,
|
||||
unsigned NumRegularSections) {
|
||||
// FIXME: Is this the correct place to do this?
|
||||
// FIXME: Why is an undefined reference to _GLOBAL_OFFSET_TABLE_ needed?
|
||||
if (NeedsGOT) {
|
||||
@@ -967,33 +948,33 @@ ELFObjectWriter::ComputeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
|
||||
|
||||
ELFSymbolData MSD;
|
||||
MSD.SymbolData = it;
|
||||
const MCSymbol *BaseSymbol = Symbol.getBaseSymbol(Layout);
|
||||
const MCSymbol &RefSymbol = Symbol.AliasedSymbol();
|
||||
|
||||
// Undefined symbols are global, but this is the first place we
|
||||
// are able to set it.
|
||||
bool Local = isLocal(*it, isSignature, Used);
|
||||
if (!Local && MCELF::GetBinding(*it) == ELF::STB_LOCAL) {
|
||||
assert(BaseSymbol);
|
||||
MCSymbolData &SD = Asm.getSymbolData(*BaseSymbol);
|
||||
MCSymbolData &SD = Asm.getSymbolData(RefSymbol);
|
||||
MCELF::SetBinding(*it, ELF::STB_GLOBAL);
|
||||
MCELF::SetBinding(SD, ELF::STB_GLOBAL);
|
||||
}
|
||||
|
||||
if (!BaseSymbol) {
|
||||
MSD.SectionIndex = ELF::SHN_ABS;
|
||||
} else if (it->isCommon()) {
|
||||
if (RefSymbol.isUndefined() && !Used && WeakrefUsed)
|
||||
MCELF::SetBinding(*it, ELF::STB_WEAK);
|
||||
|
||||
if (it->isCommon()) {
|
||||
assert(!Local);
|
||||
MSD.SectionIndex = ELF::SHN_COMMON;
|
||||
} else if (BaseSymbol->isUndefined()) {
|
||||
} else if (Symbol.isAbsolute() || RefSymbol.isVariable()) {
|
||||
MSD.SectionIndex = ELF::SHN_ABS;
|
||||
} else if (RefSymbol.isUndefined()) {
|
||||
if (isSignature && !Used)
|
||||
MSD.SectionIndex = SectionIndexMap.lookup(RevGroupMap[&Symbol]);
|
||||
else
|
||||
MSD.SectionIndex = ELF::SHN_UNDEF;
|
||||
if (!Used && WeakrefUsed)
|
||||
MCELF::SetBinding(*it, ELF::STB_WEAK);
|
||||
} else {
|
||||
const MCSectionELF &Section =
|
||||
static_cast<const MCSectionELF&>(BaseSymbol->getSection());
|
||||
static_cast<const MCSectionELF&>(RefSymbol.getSection());
|
||||
MSD.SectionIndex = SectionIndexMap.lookup(&Section);
|
||||
if (MSD.SectionIndex >= ELF::SHN_LORESERVE)
|
||||
NeedsSymtabShndx = true;
|
||||
@@ -1579,8 +1560,8 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
unsigned NumRegularSections = NumUserSections + NumIndexedSections;
|
||||
|
||||
// Compute symbol table information.
|
||||
ComputeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap,
|
||||
NumRegularSections);
|
||||
ComputeSymbolTable(Asm, SectionIndexMap, RevGroupMap, NumRegularSections);
|
||||
|
||||
|
||||
WriteRelocations(Asm, const_cast<MCAsmLayout&>(Layout), RelMap);
|
||||
|
||||
|
Reference in New Issue
Block a user