1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[MC, COFF] Permit a variable to be redefined

Our assertions in WinCOFFStreamer had unexpected side effects resulting
in symbols getting unexpectedly marked as used.

This fixes PR28462.

llvm-svn: 274941
This commit is contained in:
David Majnemer 2016-07-08 21:54:16 +00:00
parent b8fbccd103
commit e0bacde5fb
2 changed files with 25 additions and 19 deletions

View File

@ -75,7 +75,8 @@ void MCWinCOFFStreamer::InitSections(bool NoExecStack) {
SwitchSection(getContext().getObjectFileInfo()->getTextSection());
}
void MCWinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
void MCWinCOFFStreamer::EmitLabel(MCSymbol *S) {
auto *Symbol = cast<MCSymbolCOFF>(S);
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
MCObjectStreamer::EmitLabel(Symbol);
}
@ -88,20 +89,16 @@ void MCWinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) {
llvm_unreachable("not implemented");
}
bool MCWinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
bool MCWinCOFFStreamer::EmitSymbolAttribute(MCSymbol *S,
MCSymbolAttr Attribute) {
assert(Symbol && "Symbol must be non-null!");
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
auto *Symbol = cast<MCSymbolCOFF>(S);
getAssembler().registerSymbol(*Symbol);
switch (Attribute) {
default: return false;
case MCSA_WeakReference:
case MCSA_Weak:
cast<MCSymbolCOFF>(Symbol)->setIsWeakExternal();
Symbol->setIsWeakExternal();
Symbol->setExternal(true);
break;
case MCSA_Global:
@ -118,11 +115,8 @@ void MCWinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
llvm_unreachable("not implemented");
}
void MCWinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
void MCWinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *S) {
auto *Symbol = cast<MCSymbolCOFF>(S);
if (CurSymbol)
Error("starting a new symbol definition without completing the "
"previous one");
@ -209,11 +203,9 @@ void MCWinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
DF->getContents().resize(DF->getContents().size() + 4, 0);
}
void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size,
unsigned ByteAlignment) {
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
auto *Symbol = cast<MCSymbolCOFF>(S);
const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
if (T.isKnownWindowsMSVCEnvironment()) {
@ -243,9 +235,9 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
}
}
void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
unsigned ByteAlignment) {
assert(!Symbol->isInSection() && "Symbol must not already have a section!");
auto *Symbol = cast<MCSymbolCOFF>(S);
MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
getAssembler().registerSection(*Section);

14
test/MC/COFF/pr28462.s Normal file
View File

@ -0,0 +1,14 @@
// RUN: llvm-mc -filetype=obj -triple i686-pc-windows-msvc < %s | llvm-readobj -s --section-data | FileCheck %s
.text
.set var, 42
.long var
.set var, 19
.long var
// CHECK:Sections [
// CHECK: Section {
// CHECK: Name: .text (2E 74 65 78 74 00 00 00)
// CHECK: SectionData (
// CHECK: 0000: 2A000000 13000000
// CHECK: )