[MC] Add a separate flag for skipping comdat constant sections for MinGW. NFC.

This actually has nothing to do with the associative comdat sections
that aren't supported by GNU binutils ld.

Clarify the comments from SVN r335918 and use a separate flag for it.

Differential Revision: https://reviews.llvm.org/D49645

llvm-svn: 337757
This commit is contained in:
Martin Storsjo 2018-07-23 22:15:25 +00:00
parent 100fc97051
commit db42d51ee3
3 changed files with 18 additions and 3 deletions

View File

@ -89,6 +89,10 @@ protected:
/// them. /// them.
bool HasCOFFAssociativeComdats = false; bool HasCOFFAssociativeComdats = false;
/// True if this is a non-GNU COFF target. For GNU targets, we don't generate
/// constants into comdat sections.
bool HasCOFFComdatConstants = false;
/// This is the maximum possible length of an instruction, which is needed to /// This is the maximum possible length of an instruction, which is needed to
/// compute the size of an inline asm. Defaults to 4. /// compute the size of an inline asm. Defaults to 4.
unsigned MaxInstLength = 4; unsigned MaxInstLength = 4;
@ -469,6 +473,7 @@ public:
bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; } bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; } bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
bool hasCOFFAssociativeComdats() const { return HasCOFFAssociativeComdats; } bool hasCOFFAssociativeComdats() const { return HasCOFFAssociativeComdats; }
bool hasCOFFComdatConstants() const { return HasCOFFComdatConstants; }
unsigned getMaxInstLength() const { return MaxInstLength; } unsigned getMaxInstLength() const { return MaxInstLength; }
unsigned getMinInstAlignment() const { return MinInstAlignment; } unsigned getMinInstAlignment() const { return MinInstAlignment; }
bool getDollarIsPC() const { return DollarIsPC; } bool getDollarIsPC() const { return DollarIsPC; }

View File

@ -1397,9 +1397,11 @@ MCSection *TargetLoweringObjectFileCOFF::getSectionForConstant(
const DataLayout &DL, SectionKind Kind, const Constant *C, const DataLayout &DL, SectionKind Kind, const Constant *C,
unsigned &Align) const { unsigned &Align) const {
if (Kind.isMergeableConst() && C && if (Kind.isMergeableConst() && C &&
getContext().getAsmInfo()->hasCOFFAssociativeComdats()) { getContext().getAsmInfo()->hasCOFFComdatConstants()) {
// GNU binutils doesn't support the kind of symbol with a null // This creates comdat sections with the given symbol name, but unless
// storage class that this generates. // AsmPrinter::GetCPISymbol actually makes the symbol global, the symbol
// will be created with a null storage class, which makes GNU binutils
// error out.
const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_READ |
COFF::IMAGE_SCN_LNK_COMDAT; COFF::IMAGE_SCN_LNK_COMDAT;

View File

@ -45,6 +45,11 @@ MCAsmInfoCOFF::MCAsmInfoCOFF() {
// If this is a COFF target, assume that it supports associative comdats. It's // If this is a COFF target, assume that it supports associative comdats. It's
// part of the spec. // part of the spec.
HasCOFFAssociativeComdats = true; HasCOFFAssociativeComdats = true;
// We can generate constants in comdat sections that can be shared,
// but in order not to create null typed symbols, we actually need to
// make them global symbols as well.
HasCOFFComdatConstants = true;
} }
void MCAsmInfoMicrosoft::anchor() {} void MCAsmInfoMicrosoft::anchor() {}
@ -58,4 +63,7 @@ MCAsmInfoGNUCOFF::MCAsmInfoGNUCOFF() {
// comdats for jump tables, unwind information, and other data associated with // comdats for jump tables, unwind information, and other data associated with
// a function. // a function.
HasCOFFAssociativeComdats = false; HasCOFFAssociativeComdats = false;
// We don't create constants in comdat sections for MinGW.
HasCOFFComdatConstants = false;
} }