[llvm] r217202 - Fix pr20793.
Rafael Espindola
rafael.espindola at gmail.com
Thu Sep 4 16:03:58 PDT 2014
Author: rafael
Date: Thu Sep 4 18:03:58 2014
New Revision: 217202
URL: http://llvm.org/viewvc/llvm-project?rev=217202&view=rev
Log:
Fix pr20793.
With this patch the third field of llvm.global_ctors is also used on ELF.
Modified:
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/trunk/test/CodeGen/X86/constructor.ll
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=217202&r1=217201&r2=217202&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Thu Sep 4 18:03:58 2014
@@ -360,42 +360,66 @@ TargetLoweringObjectFileELF::getSectionF
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
Modified: llvm/trunk/test/CodeGen/X86/constructor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/constructor.ll?rev=217202&r1=217201&r2=217202&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/constructor.ll (original)
+++ llvm/trunk/test/CodeGen/X86/constructor.ll Thu Sep 4 18:03:58 2014
@@ -1,6 +1,8 @@
; RUN: llc -mtriple x86_64-pc-linux -use-ctors < %s | FileCheck --check-prefix=CTOR %s
; RUN: llc -mtriple x86_64-pc-linux < %s | FileCheck --check-prefix=INIT-ARRAY %s
- at llvm.global_ctors = appending global [2 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @f }, { i32, void ()* } { i32 15, void ()* @g }]
+ at llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null}, { i32, void ()*, i8* } { i32 15, void ()* @g, i8* @v }]
+
+ at v = weak_odr global i8 0
define void @f() {
entry:
@@ -12,14 +14,14 @@ entry:
ret void
}
-; CTOR: .section .ctors.65520,"aw", at progbits
+; CTOR: .section .ctors.65520,"aGw", at progbits,v,comdat
; CTOR-NEXT: .align 8
; CTOR-NEXT: .quad g
; CTOR-NEXT: .section .ctors,"aw", at progbits
; CTOR-NEXT: .align 8
; CTOR-NEXT: .quad f
-; INIT-ARRAY: .section .init_array.15,"aw", at init_array
+; INIT-ARRAY: .section .init_array.15,"aGw", at init_array,v,comdat
; INIT-ARRAY-NEXT: .align 8
; INIT-ARRAY-NEXT: .quad g
; INIT-ARRAY-NEXT: .section .init_array,"aw", at init_array
More information about the llvm-commits
mailing list