summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/ELFTargetAsmInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/ELFTargetAsmInfo.cpp')
-rw-r--r--llvm/lib/Target/ELFTargetAsmInfo.cpp102
1 files changed, 55 insertions, 47 deletions
diff --git a/llvm/lib/Target/ELFTargetAsmInfo.cpp b/llvm/lib/Target/ELFTargetAsmInfo.cpp
index 927cb38b1de..cefcb5d21c1 100644
--- a/llvm/lib/Target/ELFTargetAsmInfo.cpp
+++ b/llvm/lib/Target/ELFTargetAsmInfo.cpp
@@ -27,28 +27,24 @@ using namespace llvm;
ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
: TargetAsmInfo(TM) {
- BSSSection_ = getUnnamedSection("\t.bss",
- SectionFlags::Writable | SectionFlags::BSS);
- ReadOnlySection = getNamedSection("\t.rodata", SectionFlags::None);
- TLSDataSection = getNamedSection("\t.tdata",
- SectionFlags::Writable | SectionFlags::TLS);
- TLSBSSSection = getNamedSection("\t.tbss",
- SectionFlags::Writable | SectionFlags::TLS | SectionFlags::BSS);
-
- DataRelSection = getNamedSection("\t.data.rel", SectionFlags::Writable);
+ ReadOnlySection = getNamedSection("\t.rodata", SectionKind::ReadOnly);
+ TLSDataSection = getNamedSection("\t.tdata", SectionKind::ThreadData);
+ TLSBSSSection = getNamedSection("\t.tbss", SectionKind::ThreadBSS);
+
+ DataRelSection = getNamedSection("\t.data.rel", SectionKind::DataRel);
DataRelLocalSection = getNamedSection("\t.data.rel.local",
- SectionFlags::Writable);
+ SectionKind::DataRelLocal);
DataRelROSection = getNamedSection("\t.data.rel.ro",
- SectionFlags::Writable);
+ SectionKind::ReadOnlyWithRel);
DataRelROLocalSection = getNamedSection("\t.data.rel.ro.local",
- SectionFlags::Writable);
+ SectionKind::ReadOnlyWithRelLocal);
MergeableConst4Section = getNamedSection(".rodata.cst4",
- SectionFlags::setEntitySize(SectionFlags::Mergeable, 4));
+ SectionKind::MergeableConst4);
MergeableConst8Section = getNamedSection(".rodata.cst8",
- SectionFlags::setEntitySize(SectionFlags::Mergeable, 8));
+ SectionKind::MergeableConst8);
MergeableConst16Section = getNamedSection(".rodata.cst16",
- SectionFlags::setEntitySize(SectionFlags::Mergeable, 16));
+ SectionKind::MergeableConst16);
}
@@ -98,28 +94,30 @@ ELFTargetAsmInfo::getSectionForMergeableConstant(SectionKind Kind) const {
/// getFlagsForNamedSection - If this target wants to be able to infer
/// section flags based on the name of the section specified for a global
/// variable, it can implement this.
-unsigned ELFTargetAsmInfo::getFlagsForNamedSection(const char *Name) const {
- unsigned Flags = 0;
- if (Name[0] != '.') return 0;
+SectionKind::Kind ELFTargetAsmInfo::getKindForNamedSection(const char *Name,
+ SectionKind::Kind K) const {
+ if (Name[0] != '.') return K;
// Some lame default implementation based on some magic section names.
if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
- Flags |= SectionFlags::BSS;
- else if (strcmp(Name, ".tdata") == 0 ||
- strncmp(Name, ".tdata.", 7) == 0 ||
- strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
- strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
- Flags |= SectionFlags::TLS;
- else if (strcmp(Name, ".tbss") == 0 ||
- strncmp(Name, ".tbss.", 6) == 0 ||
- strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
- strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
- Flags |= SectionFlags::BSS | SectionFlags::TLS;
+ return SectionKind::BSS;
+
+ if (strcmp(Name, ".tdata") == 0 ||
+ strncmp(Name, ".tdata.", 7) == 0 ||
+ strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
+ strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
+ return SectionKind::ThreadData;
- return Flags;
+ if (strcmp(Name, ".tbss") == 0 ||
+ strncmp(Name, ".tbss.", 6) == 0 ||
+ strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
+ strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
+ return SectionKind::ThreadBSS;
+
+ return K;
}
const char *
@@ -152,37 +150,36 @@ ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
if (Size <= 16) {
assert(getCStringSection() && "Should have string section prefix");
- // We also need alignment here
+ // We also need alignment here.
+ // FIXME: this is getting the alignment of the character, not the alignment
+ // of the string!!
unsigned Align = TD->getPrefTypeAlignment(Ty);
if (Align < Size)
Align = Size;
std::string Name = getCStringSection() + utostr(Size) + '.' + utostr(Align);
- unsigned Flags = SectionFlags::setEntitySize(SectionFlags::Mergeable |
- SectionFlags::Strings,
- Size);
- return getNamedSection(Name.c_str(), Flags);
+ return getNamedSection(Name.c_str(), SectionKind::MergeableCString);
}
return getReadOnlySection();
}
-void ELFTargetAsmInfo::getSectionFlags(unsigned Flags,
- SmallVectorImpl<char> &Str) const {
+void ELFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
+ SmallVectorImpl<char> &Str) const {
Str.push_back(',');
Str.push_back('"');
- if (!(Flags & SectionFlags::Debug))
+ if (!Kind.isMetadata())
Str.push_back('a');
- if (Flags & SectionFlags::Code)
+ if (Kind.isText())
Str.push_back('x');
- if (Flags & SectionFlags::Writable)
+ if (Kind.isWriteable())
Str.push_back('w');
- if (Flags & SectionFlags::Mergeable)
+ if (Kind.isMergeableConst() || Kind.isMergeableCString())
Str.push_back('M');
- if (Flags & SectionFlags::Strings)
+ if (Kind.isMergeableCString())
Str.push_back('S');
- if (Flags & SectionFlags::TLS)
+ if (Kind.isThreadLocal())
Str.push_back('T');
Str.push_back('"');
@@ -195,16 +192,27 @@ void ELFTargetAsmInfo::getSectionFlags(unsigned Flags,
Str.push_back('@');
const char *KindStr;
- if (Flags & SectionFlags::BSS)
+ if (Kind.isBSS())
KindStr = "nobits";
else
KindStr = "progbits";
Str.append(KindStr, KindStr+strlen(KindStr));
- if (unsigned entitySize = SectionFlags::getEntitySize(Flags)) {
+ if (Kind.isMergeableCString()) {
+ // TODO: Eventually handle multiple byte character strings. For now, all
+ // mergable C strings are single byte.
+ Str.push_back(',');
+ Str.push_back('1');
+ } else if (Kind.isMergeableConst4()) {
+ Str.push_back(',');
+ Str.push_back('4');
+ } else if (Kind.isMergeableConst8()) {
+ Str.push_back(',');
+ Str.push_back('8');
+ } else if (Kind.isMergeableConst16()) {
Str.push_back(',');
- std::string Size = utostr(entitySize);
- Str.append(Size.begin(), Size.end());
+ Str.push_back('1');
+ Str.push_back('6');
}
}
OpenPOWER on IntegriCloud