diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-07-26 00:51:36 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-07-26 00:51:36 +0000 |
| commit | e3577da6d969c7411736b5fcfe27ba355dd2d806 (patch) | |
| tree | 2ce0c83282ecf1694dd0db43fb8c7c4a78fc0725 /lib/Target | |
| parent | d60123983380532979c7ca5eef072c74b3185704 (diff) | |
| download | external_llvm-e3577da6d969c7411736b5fcfe27ba355dd2d806.zip external_llvm-e3577da6d969c7411736b5fcfe27ba355dd2d806.tar.gz external_llvm-e3577da6d969c7411736b5fcfe27ba355dd2d806.tar.bz2 | |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77104 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
| -rw-r--r-- | lib/Target/DarwinTargetAsmInfo.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp index 38cdc2e..6be9aa0 100644 --- a/lib/Target/DarwinTargetAsmInfo.cpp +++ b/lib/Target/DarwinTargetAsmInfo.cpp @@ -127,37 +127,41 @@ bool DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV, const Section* DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind) const { + assert(!Kind.isTLS() && "Darwin doesn't support TLS"); + // FIXME: Use sectionflags:linkonce instead of isWeakForLinker() here. bool isWeak = GV->isWeakForLinker(); 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()) { - 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::DataRelLocal: case SectionKind::DataRel: case SectionKind::BSS: if (cast<GlobalVariable>(GV)->isConstant()) - return isWeak ? ConstDataCoalSection : ConstDataSection; - return isWeak ? DataCoalSection : DataSection; + return ConstDataSection; + return DataSection; case SectionKind::ROData: case SectionKind::DataRelRO: case SectionKind::DataRelROLocal: - return (isWeak ? ConstDataCoalSection : - (isNonStatic ? ConstDataSection : getReadOnlySection())); - case SectionKind::RODataMergeStr: - return (isWeak ? - ConstTextCoalSection : - MergeableStringSection(cast<GlobalVariable>(GV))); + return isNonStatic ? ConstDataSection : getReadOnlySection(); case SectionKind::RODataMergeConst: { - if (isWeak) return ConstDataCoalSection; const Type *Ty = cast<GlobalVariable>(GV)->getInitializer()->getType(); const TargetData *TD = TM.getTargetData(); return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0); |
