forked from OSchip/llvm-project
simplify DarwinTargetAsmInfo::SelectSectionForGlobal a bit
and make it more aggressive, we now put: const int G2 __attribute__((weak)) = 42; into the text (readonly) segment like gcc, previously we put it into the data (readwrite) segment. llvm-svn: 77104
This commit is contained in:
parent
26ce308bbf
commit
5b42b45fb9
|
|
@ -127,37 +127,41 @@ bool DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV,
|
||||||
const Section*
|
const Section*
|
||||||
DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
|
DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
|
||||||
SectionKind Kind) const {
|
SectionKind Kind) const {
|
||||||
|
assert(!Kind.isTLS() && "Darwin doesn't support TLS");
|
||||||
|
|
||||||
// FIXME: Use sectionflags:linkonce instead of isWeakForLinker() here.
|
// FIXME: Use sectionflags:linkonce instead of isWeakForLinker() here.
|
||||||
bool isWeak = GV->isWeakForLinker();
|
bool isWeak = GV->isWeakForLinker();
|
||||||
bool isNonStatic = TM.getRelocationModel() != Reloc::Static;
|
bool isNonStatic = TM.getRelocationModel() != Reloc::Static;
|
||||||
|
|
||||||
|
if (Kind.isCode())
|
||||||
|
return isWeak ? TextCoalSection : TextSection;
|
||||||
|
|
||||||
|
// If this is weak/linkonce, put this in a coalescable section, either in text
|
||||||
|
// or data depending on if it is writable.
|
||||||
|
if (isWeak) {
|
||||||
|
if (Kind.isReadOnly())
|
||||||
|
return ConstTextCoalSection;
|
||||||
|
return DataCoalSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Alignment check should be handled by section classifier.
|
||||||
|
if (Kind.isMergableString())
|
||||||
|
return MergeableStringSection(cast<GlobalVariable>(GV));
|
||||||
|
|
||||||
switch (Kind.getKind()) {
|
switch (Kind.getKind()) {
|
||||||
case SectionKind::ThreadData:
|
|
||||||
case SectionKind::ThreadBSS:
|
|
||||||
llvm_unreachable("Darwin doesn't support TLS");
|
|
||||||
case SectionKind::Text:
|
|
||||||
if (isWeak)
|
|
||||||
return TextCoalSection;
|
|
||||||
return TextSection;
|
|
||||||
case SectionKind::Data:
|
case SectionKind::Data:
|
||||||
case SectionKind::DataRelLocal:
|
case SectionKind::DataRelLocal:
|
||||||
case SectionKind::DataRel:
|
case SectionKind::DataRel:
|
||||||
case SectionKind::BSS:
|
case SectionKind::BSS:
|
||||||
if (cast<GlobalVariable>(GV)->isConstant())
|
if (cast<GlobalVariable>(GV)->isConstant())
|
||||||
return isWeak ? ConstDataCoalSection : ConstDataSection;
|
return ConstDataSection;
|
||||||
return isWeak ? DataCoalSection : DataSection;
|
return DataSection;
|
||||||
|
|
||||||
case SectionKind::ROData:
|
case SectionKind::ROData:
|
||||||
case SectionKind::DataRelRO:
|
case SectionKind::DataRelRO:
|
||||||
case SectionKind::DataRelROLocal:
|
case SectionKind::DataRelROLocal:
|
||||||
return (isWeak ? ConstDataCoalSection :
|
return isNonStatic ? ConstDataSection : getReadOnlySection();
|
||||||
(isNonStatic ? ConstDataSection : getReadOnlySection()));
|
|
||||||
case SectionKind::RODataMergeStr:
|
|
||||||
return (isWeak ?
|
|
||||||
ConstTextCoalSection :
|
|
||||||
MergeableStringSection(cast<GlobalVariable>(GV)));
|
|
||||||
case SectionKind::RODataMergeConst: {
|
case SectionKind::RODataMergeConst: {
|
||||||
if (isWeak) return ConstDataCoalSection;
|
|
||||||
const Type *Ty = cast<GlobalVariable>(GV)->getInitializer()->getType();
|
const Type *Ty = cast<GlobalVariable>(GV)->getInitializer()->getType();
|
||||||
const TargetData *TD = TM.getTargetData();
|
const TargetData *TD = TM.getTargetData();
|
||||||
return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0);
|
return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,25 @@
|
||||||
; RUN: llvm-as < %s | llc -mtriple=i386-unknown-linux-gnu | FileCheck %s -check-prefix=LINUX
|
; RUN: llvm-as < %s | llc -mtriple=i386-unknown-linux-gnu | FileCheck %s -check-prefix=LINUX
|
||||||
|
; RUN: llvm-as < %s | llc -mtriple=i386-apple-darwin9.7 | FileCheck %s -check-prefix=DARWIN
|
||||||
|
|
||||||
|
|
||||||
|
; int G1;
|
||||||
@G1 = common global i32 0
|
@G1 = common global i32 0
|
||||||
|
|
||||||
; LINUX: .type G1,@object
|
; LINUX: .type G1,@object
|
||||||
; LINUX: .section .gnu.linkonce.b.G1,"aw",@nobits
|
; LINUX: .section .gnu.linkonce.b.G1,"aw",@nobits
|
||||||
; LINUX: .comm G1,4,4
|
; LINUX: .comm G1,4,4
|
||||||
|
|
||||||
|
; DARWIN: .comm _G1,4,2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; const int G2 __attribute__((weak)) = 42;
|
||||||
|
@G2 = weak_odr constant i32 42
|
||||||
|
|
||||||
|
|
||||||
|
; TODO: linux drops this into .rodata, we drop it into ".gnu.linkonce.r.G2"
|
||||||
|
|
||||||
|
; DARWIN: .section __TEXT,__const_coal,coalesced
|
||||||
|
; DARWIN: _G2:
|
||||||
|
; DARWIN: .long 42
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue