diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2016-08-29 12:33:42 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2016-08-29 12:33:42 +0000 |
commit | 46fa231c520cd3083fecc76cc2e64dc72f29872e (patch) | |
tree | e2d5ae4d7ea2bec344b232db1abc8c9352ff7107 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | eab33cecf38c2f093d63d9881d87e8f6a542f078 (diff) | |
download | bcm5719-llvm-46fa231c520cd3083fecc76cc2e64dc72f29872e.tar.gz bcm5719-llvm-46fa231c520cd3083fecc76cc2e64dc72f29872e.zip |
Move code only used by codegen out of MC. NFC.
MC itself never needs to know about these sections.
llvm-svn: 279965
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 5f814c957e9..fdd8dca5b9f 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -446,13 +446,20 @@ const MCExpr *TargetLoweringObjectFileELF::lowerRelativeReference( void TargetLoweringObjectFileELF::InitializeELF(bool UseInitArray_) { UseInitArray = UseInitArray_; - if (!UseInitArray) + MCContext &Ctx = getContext(); + if (!UseInitArray) { + StaticCtorSection = Ctx.getELFSection(".ctors", ELF::SHT_PROGBITS, + ELF::SHF_ALLOC | ELF::SHF_WRITE); + + StaticDtorSection = Ctx.getELFSection(".dtors", ELF::SHT_PROGBITS, + ELF::SHF_ALLOC | ELF::SHF_WRITE); return; + } - StaticCtorSection = getContext().getELFSection( - ".init_array", ELF::SHT_INIT_ARRAY, ELF::SHF_WRITE | ELF::SHF_ALLOC); - StaticDtorSection = getContext().getELFSection( - ".fini_array", ELF::SHT_FINI_ARRAY, ELF::SHF_WRITE | ELF::SHF_ALLOC); + StaticCtorSection = Ctx.getELFSection(".init_array", ELF::SHT_INIT_ARRAY, + ELF::SHF_WRITE | ELF::SHF_ALLOC); + StaticDtorSection = Ctx.getELFSection(".fini_array", ELF::SHT_FINI_ARRAY, + ELF::SHF_WRITE | ELF::SHF_ALLOC); } //===----------------------------------------------------------------------===// @@ -464,6 +471,24 @@ TargetLoweringObjectFileMachO::TargetLoweringObjectFileMachO() SupportIndirectSymViaGOTPCRel = true; } +void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx, + const TargetMachine &TM) { + TargetLoweringObjectFile::Initialize(Ctx, TM); + if (!TM.isPositionIndependent()) { + StaticCtorSection = Ctx.getMachOSection("__TEXT", "__constructor", 0, + SectionKind::getData()); + StaticDtorSection = Ctx.getMachOSection("__TEXT", "__destructor", 0, + SectionKind::getData()); + } else { + StaticCtorSection = Ctx.getMachOSection("__DATA", "__mod_init_func", + MachO::S_MOD_INIT_FUNC_POINTERS, + SectionKind::getData()); + StaticDtorSection = Ctx.getMachOSection("__DATA", "__mod_term_func", + MachO::S_MOD_TERM_FUNC_POINTERS, + SectionKind::getData()); + } +} + /// emitModuleFlags - Perform code emission for module flags. void TargetLoweringObjectFileMachO:: emitModuleFlags(MCStreamer &Streamer, @@ -1052,6 +1077,31 @@ emitModuleFlags(MCStreamer &Streamer, } } +void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx, + const TargetMachine &TM) { + TargetLoweringObjectFile::Initialize(Ctx, TM); + const Triple &T = TM.getTargetTriple(); + if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) { + StaticCtorSection = + Ctx.getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | + COFF::IMAGE_SCN_MEM_READ, + SectionKind::getReadOnly()); + StaticDtorSection = + Ctx.getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | + COFF::IMAGE_SCN_MEM_READ, + SectionKind::getReadOnly()); + } else { + StaticCtorSection = Ctx.getCOFFSection( + ".ctors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | + COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE, + SectionKind::getData()); + StaticDtorSection = Ctx.getCOFFSection( + ".dtors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | + COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE, + SectionKind::getData()); + } +} + MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection( unsigned Priority, const MCSymbol *KeySym) const { return getContext().getAssociativeCOFFSection( |