diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-09-04 23:03:58 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-09-04 23:03:58 +0000 |
commit | c4b4253f7c63de8452eabf0105d87a17ff47748f (patch) | |
tree | b6b9e0714aebe729e0d62fda70bc16476ab2029a /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | fece4c6cd5db78642abcb7b3176b59ed9d3432c6 (diff) | |
download | llvm-c4b4253f7c63de8452eabf0105d87a17ff47748f.zip llvm-c4b4253f7c63de8452eabf0105d87a17ff47748f.tar.gz llvm-c4b4253f7c63de8452eabf0105d87a17ff47748f.tar.bz2 |
Fix pr20793.
With this patch the third field of llvm.global_ctors is also used on ELF.
llvm-svn: 217202
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index a89769f..971d0f9 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -360,42 +360,66 @@ TargetLoweringObjectFileELF::getSectionForConstant(SectionKind Kind, const MCSection *TargetLoweringObjectFileELF::getStaticCtorSection( unsigned Priority, const MCSymbol *KeySym) const { - // The default scheme is .ctor / .dtor, so we have to invert the priority - // numbering. - if (Priority == 65535) - return StaticCtorSection; + std::string Name; + unsigned Type; + unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE; + SectionKind Kind = SectionKind::getDataRel(); + StringRef COMDAT = KeySym ? KeySym->getName() : ""; + + if (KeySym) + Flags |= ELF::SHF_GROUP; if (UseInitArray) { - std::string Name = std::string(".init_array.") + utostr(Priority); - return getContext().getELFSection(Name, ELF::SHT_INIT_ARRAY, - ELF::SHF_ALLOC | ELF::SHF_WRITE, - SectionKind::getDataRel()); + Name = ".init_array"; + if (Priority != 65535) { + Name += '.'; + Name += utostr(Priority); + } + Type = ELF::SHT_INIT_ARRAY; } else { - std::string Name = std::string(".ctors.") + utostr(65535 - Priority); - return getContext().getELFSection(Name, ELF::SHT_PROGBITS, - ELF::SHF_ALLOC |ELF::SHF_WRITE, - SectionKind::getDataRel()); + // The default scheme is .ctor / .dtor, so we have to invert the priority + // numbering. + Name = std::string(".ctors"); + if (Priority != 65535) { + Name += '.'; + Name += utostr(65535 - Priority); + } + Type = ELF::SHT_PROGBITS; } + + return getContext().getELFSection(Name, Type, Flags, Kind, 0, COMDAT); } const MCSection *TargetLoweringObjectFileELF::getStaticDtorSection( unsigned Priority, const MCSymbol *KeySym) const { - // The default scheme is .ctor / .dtor, so we have to invert the priority - // numbering. - if (Priority == 65535) - return StaticDtorSection; + std::string Name; + unsigned Type; + unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE; + SectionKind Kind = SectionKind::getDataRel(); + StringRef COMDAT = KeySym ? KeySym->getName() : ""; + + if (KeySym) + Flags |= ELF::SHF_GROUP; if (UseInitArray) { - std::string Name = std::string(".fini_array.") + utostr(Priority); - return getContext().getELFSection(Name, ELF::SHT_FINI_ARRAY, - ELF::SHF_ALLOC | ELF::SHF_WRITE, - SectionKind::getDataRel()); + Name = ".fini_array"; + if (Priority != 65535) { + Name += '.'; + Name += utostr(Priority); + } + Type = ELF::SHT_FINI_ARRAY; } else { - std::string Name = std::string(".dtors.") + utostr(65535 - Priority); - return getContext().getELFSection(Name, ELF::SHT_PROGBITS, - ELF::SHF_ALLOC |ELF::SHF_WRITE, - SectionKind::getDataRel()); + // The default scheme is .ctor / .dtor, so we have to invert the priority + // numbering. + Name = ".dtors"; + if (Priority != 65535) { + Name += '.'; + Name += utostr(65535 - Priority); + } + Type = ELF::SHT_PROGBITS; } + + return getContext().getELFSection(Name, Type, Flags, Kind, 0, COMDAT); } void |