diff options
author | Martin Storsjo <martin@martin.st> | 2017-11-28 08:07:18 +0000 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2017-11-28 08:07:18 +0000 |
commit | 04b68446eb13920e672d5a21acfeec51583521bf (patch) | |
tree | 9cc69abffe1546ca86321d1d7ac930b979030071 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | cf9b1b24ce6690bbb83ecbdec69096fe840b92b1 (diff) | |
download | llvm-04b68446eb13920e672d5a21acfeec51583521bf.zip llvm-04b68446eb13920e672d5a21acfeec51583521bf.tar.gz llvm-04b68446eb13920e672d5a21acfeec51583521bf.tar.bz2 |
[COFF] Implement constructor priorities
The priorities in the section name suffixes are zero padded,
allowing the linker to just do a lexical sort.
Add zero padding for .ctors sections in ELF as well.
Differential Revision: https://reviews.llvm.org/D40407
llvm-svn: 319150
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index d82e78a..910ca46 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -52,6 +52,7 @@ #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CodeGen.h" +#include "llvm/Support/Format.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" @@ -530,10 +531,8 @@ static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray, Name = ".ctors"; else Name = ".dtors"; - if (Priority != 65535) { - Name += '.'; - Name += utostr(65535 - Priority); - } + if (Priority != 65535) + raw_string_ostream(Name) << format(".%05u", 65535 - Priority); Type = ELF::SHT_PROGBITS; } @@ -1212,16 +1211,38 @@ void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx, } } +static MCSectionCOFF *getCOFFStaticStructorSection(MCContext &Ctx, + const Triple &T, bool IsCtor, + unsigned Priority, + const MCSymbol *KeySym, + MCSectionCOFF *Default) { + if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) + return Ctx.getAssociativeCOFFSection(Default, KeySym, 0); + + std::string Name = IsCtor ? ".ctors" : ".dtors"; + if (Priority != 65535) + raw_string_ostream(Name) << format(".%05u", 65535 - Priority); + + return Ctx.getAssociativeCOFFSection( + Ctx.getCOFFSection(Name, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | + COFF::IMAGE_SCN_MEM_READ | + COFF::IMAGE_SCN_MEM_WRITE, + SectionKind::getData()), + KeySym, 0); +} + MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection( unsigned Priority, const MCSymbol *KeySym) const { - return getContext().getAssociativeCOFFSection( - cast<MCSectionCOFF>(StaticCtorSection), KeySym, 0); + return getCOFFStaticStructorSection(getContext(), getTargetTriple(), true, + Priority, KeySym, + cast<MCSectionCOFF>(StaticCtorSection)); } MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection( unsigned Priority, const MCSymbol *KeySym) const { - return getContext().getAssociativeCOFFSection( - cast<MCSectionCOFF>(StaticDtorSection), KeySym, 0); + return getCOFFStaticStructorSection(getContext(), getTargetTriple(), false, + Priority, KeySym, + cast<MCSectionCOFF>(StaticDtorSection)); } void TargetLoweringObjectFileCOFF::emitLinkerFlagsForGlobal( |