1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Add hacky way to distinguish named and named sections. This will be generalized in the future.

llvm-svn: 53311
This commit is contained in:
Anton Korobeynikov 2008-07-09 13:25:26 +00:00
parent f08fab0af5
commit 933bf0ecc4
4 changed files with 81 additions and 46 deletions

View File

@ -53,6 +53,7 @@ namespace llvm {
TLS = 1 << 5, ///< Section contains thread-local data
Debug = 1 << 6, ///< Section contains debug data
Linkonce = 1 << 7, ///< Section is linkonce
Named = 1 << 8, ///< Section is named
// Some gap for future flags
EntitySize = 0xFF << 24 ///< Entity size for mergeable sections
};

View File

@ -193,36 +193,36 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
unsigned
TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
const char* name) const {
unsigned flags = SectionFlags::None;
const char* Name) const {
unsigned Flags = SectionFlags::None;
// Decode flags from global itself.
if (GV) {
SectionKind::Kind kind = SectionKindForGlobal(GV);
switch (kind) {
SectionKind::Kind Kind = SectionKindForGlobal(GV);
switch (Kind) {
case SectionKind::Text:
flags |= SectionFlags::Code;
Flags |= SectionFlags::Code;
break;
case SectionKind::ThreadData:
flags |= SectionFlags::TLS;
Flags |= SectionFlags::TLS;
// FALLS THROUGH
case SectionKind::Data:
flags |= SectionFlags::Writeable;
Flags |= SectionFlags::Writeable;
break;
case SectionKind::ThreadBSS:
flags |= SectionFlags::TLS;
Flags |= SectionFlags::TLS;
// FALLS THROUGH
case SectionKind::BSS:
flags |= SectionFlags::BSS;
Flags |= SectionFlags::BSS;
break;
case SectionKind::ROData:
// No additional flags here
break;
case SectionKind::RODataMergeStr:
flags |= SectionFlags::Strings;
Flags |= SectionFlags::Strings;
// FALLS THROUGH
case SectionKind::RODataMergeConst:
flags |= SectionFlags::Mergeable;
Flags |= SectionFlags::Mergeable;
break;
default:
assert(0 && "Unexpected section kind!");
@ -231,35 +231,35 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
if (GV->hasLinkOnceLinkage() ||
GV->hasWeakLinkage() ||
GV->hasCommonLinkage())
flags |= SectionFlags::Linkonce;
Flags |= SectionFlags::Linkonce;
}
// Add flags from sections, if any.
if (name) {
// Some lame default implementation
if (strcmp(name, ".bss") == 0 ||
strncmp(name, ".bss.", 5) == 0 ||
strncmp(name, ".gnu.linkonce.b.", 16) == 0 ||
strncmp(name, ".llvm.linkonce.b.", 17) == 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;
if (Name) {
Flags |= SectionFlags::Named;
// 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)
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 flags;
return Flags;
}
std::string
TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
unsigned Flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
std::string Name;
@ -275,28 +275,33 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Name = SelectSectionForGlobal(GV);
}
Name += PrintSectionFlags(flags);
// If section is named we need to switch into it via special '.section'
// directive and also append funky flags. Otherwise - section name is just
// some magic assembler directive.
if (Flags & SectionFlags::Named)
Name = SwitchToSectionDirective + Name + PrintSectionFlags(Flags);
return Name;
}
// Lame default implementation. Calculate the section name for global.
std::string
TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
SectionKind::Kind kind = SectionKindForGlobal(GV);
SectionKind::Kind Kind = SectionKindForGlobal(GV);
if (GV->hasLinkOnceLinkage() ||
GV->hasWeakLinkage() ||
GV->hasCommonLinkage())
return UniqueSectionForGlobal(GV, kind);
return UniqueSectionForGlobal(GV, Kind);
else {
if (kind == SectionKind::Text)
if (Kind == SectionKind::Text)
return getTextSection();
else if (kind == SectionKind::BSS && getBSSSection())
else if (Kind == SectionKind::BSS && getBSSSection())
return getBSSSection();
else if (getReadOnlySection() &&
(kind == SectionKind::ROData ||
kind == SectionKind::RODataMergeConst ||
kind == SectionKind::RODataMergeStr))
(Kind == SectionKind::ROData ||
Kind == SectionKind::RODataMergeConst ||
Kind == SectionKind::RODataMergeStr))
return getReadOnlySection();
}
@ -305,8 +310,8 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
std::string
TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind kind) const {
switch (kind) {
SectionKind::Kind Kind) const {
switch (Kind) {
case SectionKind::Text:
return ".gnu.linkonce.t." + GV->getName();
case SectionKind::Data:

View File

@ -335,11 +335,11 @@ X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
X86TargetAsmInfo(TM) {
bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
ReadOnlySection = "\t.section\t.rodata";
FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
CStringSection = "\t.section\t.rodata.str1.1,\"aMS\",@progbits,1";
ReadOnlySection = ".rodata";
FourByteConstantSection = ".rodata.cst";
EightByteConstantSection = ".rodata.cst";
SixteenByteConstantSection = ".rodata.cst";
CStringSection = ".rodata.str";
PrivateGlobalPrefix = ".L";
WeakRefDirective = "\t.weak\t";
SetDirective = "\t.set\t";
@ -520,6 +520,16 @@ X86ELFTargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Flags = SectionFlags::setEntitySize(Flags, Size);
}
// FIXME: This is hacky and will be removed when switching from std::string
// sections into 'general' ones
// Mark section as named, when needed (so, we we will need .section directive
// to switch into it).
if (Flags & (SectionFlags::Mergeable ||
SectionFlags::TLS ||
SectionFlags::Linkonce))
Flags |= SectionFlags::Named;
return Flags;
}
@ -645,6 +655,23 @@ X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
}
}
unsigned
X86COFFTargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
const char* name) const {
unsigned Flags =
TargetAsmInfo::SectionFlagsForGlobal(GV,
GV->getSection().c_str());
// Mark section as named, when needed (so, we we will need .section directive
// to switch into it).
if (Flags & (SectionFlags::Mergeable ||
SectionFlags::TLS ||
SectionFlags::Linkonce))
Flags |= SectionFlags::Named;
return Flags;
}
std::string X86COFFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
std::string Flags = ",\"";

View File

@ -63,6 +63,8 @@ namespace llvm {
explicit X86COFFTargetAsmInfo(const X86TargetMachine &TM);
virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
bool Global) const;
virtual unsigned SectionFlagsForGlobal(const GlobalValue *GV,
const char* name) const;
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind kind) const;
virtual std::string PrintSectionFlags(unsigned flags) const;