mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-23 16:19:52 +00:00
[MC] Common symbols weren't being checked for redeclaration which allowed an assembly file to generate an assertion in setCommon(): !isCommon(). This change allows redeclaration as long as the size and alignment match exactly, otherwise report a fatal error.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239227 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -258,6 +258,21 @@ public:
|
|||||||
return CommonAlign;
|
return CommonAlign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Declare this symbol as being 'common'.
|
||||||
|
///
|
||||||
|
/// \param Size - The size of the symbol.
|
||||||
|
/// \param Align - The alignment of the symbol.
|
||||||
|
/// \return True if symbol was already declared as a different type
|
||||||
|
bool declareCommon(uint64_t Size, unsigned Align) {
|
||||||
|
assert(isCommon() || getOffset() == 0);
|
||||||
|
if(isCommon()) {
|
||||||
|
if(CommonSize != Size || CommonAlign != Align)
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
setCommon(Size, Align);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Is this a 'common' symbol.
|
/// Is this a 'common' symbol.
|
||||||
bool isCommon() const { return CommonAlign != -1U; }
|
bool isCommon() const { return CommonAlign != -1U; }
|
||||||
|
|
||||||
|
|||||||
@@ -320,7 +320,9 @@ void MCELFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size,
|
|||||||
struct LocalCommon L = {Symbol, Size, ByteAlignment};
|
struct LocalCommon L = {Symbol, Size, ByteAlignment};
|
||||||
LocalCommons.push_back(L);
|
LocalCommons.push_back(L);
|
||||||
} else {
|
} else {
|
||||||
Symbol->setCommon(Size, ByteAlignment);
|
if(Symbol->declareCommon(Size, ByteAlignment))
|
||||||
|
report_fatal_error("Symbol: " + Symbol->getName() +
|
||||||
|
" redeclared as different type");
|
||||||
}
|
}
|
||||||
|
|
||||||
cast<MCSymbolELF>(Symbol)
|
cast<MCSymbolELF>(Symbol)
|
||||||
|
|||||||
5
test/MC/ELF/common-error3.s
Normal file
5
test/MC/ELF/common-error3.s
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux %s 2>&1 | FileCheck %s
|
||||||
|
|
||||||
|
# CHECK: Symbol: C redeclared as different type
|
||||||
|
.comm C,4,4
|
||||||
|
.comm C,8,4
|
||||||
5
test/MC/ELF/common-redeclare.s
Normal file
5
test/MC/ELF/common-redeclare.s
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux %s | llvm-objdump -t - | FileCheck %s
|
||||||
|
|
||||||
|
# CHECK: 0000000000000004 g *COM* 00000004 C
|
||||||
|
.comm C,4,4
|
||||||
|
.comm C,4,4
|
||||||
Reference in New Issue
Block a user