aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Target/ELFTargetAsmInfo.h1
-rw-r--r--lib/Target/DarwinTargetAsmInfo.cpp3
-rw-r--r--lib/Target/ELFTargetAsmInfo.cpp24
-rw-r--r--lib/Target/TargetAsmInfo.cpp27
-rw-r--r--lib/Target/X86/X86TargetAsmInfo.cpp7
5 files changed, 37 insertions, 25 deletions
diff --git a/include/llvm/Target/ELFTargetAsmInfo.h b/include/llvm/Target/ELFTargetAsmInfo.h
index 51cc72f621..6181e59a05 100644
--- a/include/llvm/Target/ELFTargetAsmInfo.h
+++ b/include/llvm/Target/ELFTargetAsmInfo.h
@@ -25,6 +25,7 @@ namespace llvm {
struct ELFTargetAsmInfo: public TargetAsmInfo {
explicit ELFTargetAsmInfo(const TargetMachine &TM);
+ SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV) const;
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
virtual std::string printSectionFlags(unsigned flags) const;
const Section* MergeableConstSection(const GlobalVariable *GV) const;
diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp
index b33155c345..927fdd2953 100644
--- a/lib/Target/DarwinTargetAsmInfo.cpp
+++ b/lib/Target/DarwinTargetAsmInfo.cpp
@@ -85,9 +85,6 @@ DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
else
return TextSection;
case SectionKind::Data:
- case SectionKind::DataRel:
- case SectionKind::DataRelRO:
- case SectionKind::DataRelROLocal:
case SectionKind::ThreadData:
case SectionKind::BSS:
case SectionKind::ThreadBSS:
diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp
index 8608d36747..3d24c023c6 100644
--- a/lib/Target/ELFTargetAsmInfo.cpp
+++ b/lib/Target/ELFTargetAsmInfo.cpp
@@ -44,6 +44,30 @@ ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
SectionFlags::Writeable);
}
+SectionKind::Kind
+ELFTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
+ SectionKind::Kind Kind = TargetAsmInfo::SectionKindForGlobal(GV);
+
+ if (Kind != SectionKind::Data)
+ return Kind;
+
+ // Decide, whether we need data.rel stuff
+ const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
+ if (GVar->hasInitializer()) {
+ Constant *C = GVar->getInitializer();
+ bool isConstant = GVar->isConstant();
+ unsigned Reloc = RelocBehaviour();
+ if (Reloc != Reloc::None && C->ContainsRelocations(Reloc))
+ return (C->ContainsRelocations(Reloc::Local) ?
+ (isConstant ?
+ SectionKind::DataRelROLocal : SectionKind::DataRelLocal) :
+ (isConstant ?
+ SectionKind::DataRelRO : SectionKind::DataRel));
+ }
+
+ return Kind;
+}
+
const Section*
ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
SectionKind::Kind Kind = SectionKindForGlobal(GV);
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index 0573a96e53..4d9ec334ac 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -220,18 +220,14 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
unsigned Reloc = RelocBehaviour();
// We already did a query for 'all' relocs, thus - early exits.
- if (Reloc == Reloc::LocalOrGlobal) {
- return (C->ContainsRelocations(Reloc::Local) ?
- SectionKind::DataRelROLocal : SectionKind::DataRelRO);
- } else if (Reloc == Reloc::None)
+ if (Reloc == Reloc::LocalOrGlobal)
+ return SectionKind::Data;
+ else if (Reloc == Reloc::None)
return SectionKind::ROData;
else {
// Ok, target wants something funny. Honour it.
- if (C->ContainsRelocations(Reloc)) {
- return (Reloc == Reloc::Local ?
- SectionKind::DataRelROLocal : SectionKind::DataRelRO);
- } else
- return SectionKind::ROData;
+ return (C->ContainsRelocations(Reloc) ?
+ SectionKind::Data : SectionKind::ROData);
}
} else {
// Check, if initializer is a null-terminated string
@@ -243,18 +239,7 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
}
// Variable either is not constant or thread-local - output to data section.
- if (isThreadLocal)
- return SectionKind::ThreadData;
-
- if (GVar->hasInitializer()) {
- Constant *C = GVar->getInitializer();
- unsigned Reloc = RelocBehaviour();
- if (Reloc != Reloc::None && C->ContainsRelocations(Reloc))
- return (C->ContainsRelocations(Reloc::Local) ?
- SectionKind::DataRelLocal : SectionKind::DataRel);
- }
-
- return SectionKind::Data;
+ return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
}
unsigned
diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp
index 641719a6bd..f1d97a3893 100644
--- a/lib/Target/X86/X86TargetAsmInfo.cpp
+++ b/lib/Target/X86/X86TargetAsmInfo.cpp
@@ -305,12 +305,17 @@ X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
switch (kind) {
case SectionKind::Text:
return ".text$linkonce" + GV->getName();
+ case SectionKind::Data:
+ case SectionKind::BSS:
+ case SectionKind::ThreadData:
+ case SectionKind::ThreadBSS:
+ return ".data$linkonce" + GV->getName();
case SectionKind::ROData:
case SectionKind::RODataMergeConst:
case SectionKind::RODataMergeStr:
return ".rdata$linkonce" + GV->getName();
default:
- return ".data$linkonce" + GV->getName();
+ assert(0 && "Unknown section kind");
}
return NULL;
}