Add comdat key field to llvm.global_ctors and llvm.global_dtors

This allows us to put dynamic initializers for weak data into the same
comdat group as the data being initialized.  This is necessary for MSVC
ABI compatibility.  Once we have comdats for guard variables, we can use
the combination to help GlobalOpt fire more often for weak data with
guarded initialization on other platforms.

Reviewers: nlewycky

Differential Revision: http://reviews.llvm.org/D3499

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209015 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Kleckner
2014-05-16 20:39:27 +00:00
parent dedd6203ad
commit 1ce3088669
16 changed files with 289 additions and 69 deletions

View File

@ -339,8 +339,8 @@ getSectionForConstant(SectionKind Kind) const {
return DataRelROSection;
}
const MCSection *
TargetLoweringObjectFileELF::getStaticCtorSection(unsigned Priority) const {
const MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
unsigned Priority, const MCSymbol *KeySym, const MCSection *KeySec) const {
// The default scheme is .ctor / .dtor, so we have to invert the priority
// numbering.
if (Priority == 65535)
@ -359,8 +359,8 @@ TargetLoweringObjectFileELF::getStaticCtorSection(unsigned Priority) const {
}
}
const MCSection *
TargetLoweringObjectFileELF::getStaticDtorSection(unsigned Priority) const {
const MCSection *TargetLoweringObjectFileELF::getStaticDtorSection(
unsigned Priority, const MCSymbol *KeySym, const MCSection *KeySec) const {
// The default scheme is .ctor / .dtor, so we have to invert the priority
// numbering.
if (Priority == 65535)
@ -865,3 +865,32 @@ emitModuleFlags(MCStreamer &Streamer,
}
}
}
static const MCSection *getAssociativeCOFFSection(MCContext &Ctx,
const MCSection *Sec,
const MCSymbol *KeySym,
const MCSection *KeySec) {
// Return the normal section if we don't have to be associative.
if (!KeySym)
return Sec;
// Make an associative section with the same name and kind as the normal
// section.
const MCSectionCOFF *SecCOFF = cast<MCSectionCOFF>(Sec);
const MCSectionCOFF *KeySecCOFF = cast<MCSectionCOFF>(KeySec);
unsigned Characteristics =
SecCOFF->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT;
return Ctx.getCOFFSection(SecCOFF->getSectionName(), Characteristics,
SecCOFF->getKind(), KeySym->getName(),
COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE, KeySecCOFF);
}
const MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection(
unsigned Priority, const MCSymbol *KeySym, const MCSection *KeySec) const {
return getAssociativeCOFFSection(getContext(), StaticCtorSection, KeySym, KeySec);
}
const MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection(
unsigned Priority, const MCSymbol *KeySym, const MCSection *KeySec) const {
return getAssociativeCOFFSection(getContext(), StaticDtorSection, KeySym, KeySec);
}