mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-28 15:33:16 +00:00
Add hacky way to distinguish named and named sections. This will be generalized in the future.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53311 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5248670096
commit
b20015b621
@ -53,6 +53,7 @@ namespace llvm {
|
|||||||
TLS = 1 << 5, ///< Section contains thread-local data
|
TLS = 1 << 5, ///< Section contains thread-local data
|
||||||
Debug = 1 << 6, ///< Section contains debug data
|
Debug = 1 << 6, ///< Section contains debug data
|
||||||
Linkonce = 1 << 7, ///< Section is linkonce
|
Linkonce = 1 << 7, ///< Section is linkonce
|
||||||
|
Named = 1 << 8, ///< Section is named
|
||||||
// Some gap for future flags
|
// Some gap for future flags
|
||||||
EntitySize = 0xFF << 24 ///< Entity size for mergeable sections
|
EntitySize = 0xFF << 24 ///< Entity size for mergeable sections
|
||||||
};
|
};
|
||||||
|
@ -193,36 +193,36 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
|
|||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
|
TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
|
||||||
const char* name) const {
|
const char* Name) const {
|
||||||
unsigned flags = SectionFlags::None;
|
unsigned Flags = SectionFlags::None;
|
||||||
|
|
||||||
// Decode flags from global itself.
|
// Decode flags from global itself.
|
||||||
if (GV) {
|
if (GV) {
|
||||||
SectionKind::Kind kind = SectionKindForGlobal(GV);
|
SectionKind::Kind Kind = SectionKindForGlobal(GV);
|
||||||
switch (kind) {
|
switch (Kind) {
|
||||||
case SectionKind::Text:
|
case SectionKind::Text:
|
||||||
flags |= SectionFlags::Code;
|
Flags |= SectionFlags::Code;
|
||||||
break;
|
break;
|
||||||
case SectionKind::ThreadData:
|
case SectionKind::ThreadData:
|
||||||
flags |= SectionFlags::TLS;
|
Flags |= SectionFlags::TLS;
|
||||||
// FALLS THROUGH
|
// FALLS THROUGH
|
||||||
case SectionKind::Data:
|
case SectionKind::Data:
|
||||||
flags |= SectionFlags::Writeable;
|
Flags |= SectionFlags::Writeable;
|
||||||
break;
|
break;
|
||||||
case SectionKind::ThreadBSS:
|
case SectionKind::ThreadBSS:
|
||||||
flags |= SectionFlags::TLS;
|
Flags |= SectionFlags::TLS;
|
||||||
// FALLS THROUGH
|
// FALLS THROUGH
|
||||||
case SectionKind::BSS:
|
case SectionKind::BSS:
|
||||||
flags |= SectionFlags::BSS;
|
Flags |= SectionFlags::BSS;
|
||||||
break;
|
break;
|
||||||
case SectionKind::ROData:
|
case SectionKind::ROData:
|
||||||
// No additional flags here
|
// No additional flags here
|
||||||
break;
|
break;
|
||||||
case SectionKind::RODataMergeStr:
|
case SectionKind::RODataMergeStr:
|
||||||
flags |= SectionFlags::Strings;
|
Flags |= SectionFlags::Strings;
|
||||||
// FALLS THROUGH
|
// FALLS THROUGH
|
||||||
case SectionKind::RODataMergeConst:
|
case SectionKind::RODataMergeConst:
|
||||||
flags |= SectionFlags::Mergeable;
|
Flags |= SectionFlags::Mergeable;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0 && "Unexpected section kind!");
|
assert(0 && "Unexpected section kind!");
|
||||||
@ -231,35 +231,35 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
|
|||||||
if (GV->hasLinkOnceLinkage() ||
|
if (GV->hasLinkOnceLinkage() ||
|
||||||
GV->hasWeakLinkage() ||
|
GV->hasWeakLinkage() ||
|
||||||
GV->hasCommonLinkage())
|
GV->hasCommonLinkage())
|
||||||
flags |= SectionFlags::Linkonce;
|
Flags |= SectionFlags::Linkonce;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add flags from sections, if any.
|
// Add flags from sections, if any.
|
||||||
if (name) {
|
if (Name) {
|
||||||
// Some lame default implementation
|
Flags |= SectionFlags::Named;
|
||||||
if (strcmp(name, ".bss") == 0 ||
|
|
||||||
strncmp(name, ".bss.", 5) == 0 ||
|
// Some lame default implementation based on some magic section names.
|
||||||
strncmp(name, ".gnu.linkonce.b.", 16) == 0 ||
|
if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
|
||||||
strncmp(name, ".llvm.linkonce.b.", 17) == 0)
|
strncmp(Name, ".llvm.linkonce.b.", 17) == 0)
|
||||||
flags |= SectionFlags::BSS;
|
Flags |= SectionFlags::BSS;
|
||||||
else if (strcmp(name, ".tdata") == 0 ||
|
else if (strcmp(Name, ".tdata") == 0 ||
|
||||||
strncmp(name, ".tdata.", 7) == 0 ||
|
strncmp(Name, ".tdata.", 7) == 0 ||
|
||||||
strncmp(name, ".gnu.linkonce.td.", 17) == 0 ||
|
strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
|
||||||
strncmp(name, ".llvm.linkonce.td.", 18) == 0)
|
strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
|
||||||
flags |= SectionFlags::TLS;
|
Flags |= SectionFlags::TLS;
|
||||||
else if (strcmp(name, ".tbss") == 0 ||
|
else if (strcmp(Name, ".tbss") == 0 ||
|
||||||
strncmp(name, ".tbss.", 6) == 0 ||
|
strncmp(Name, ".tbss.", 6) == 0 ||
|
||||||
strncmp(name, ".gnu.linkonce.tb.", 17) == 0 ||
|
strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
|
||||||
strncmp(name, ".llvm.linkonce.tb.", 18) == 0)
|
strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
|
||||||
flags |= SectionFlags::BSS | SectionFlags::TLS;
|
Flags |= SectionFlags::BSS | SectionFlags::TLS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags;
|
return Flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
|
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;
|
std::string Name;
|
||||||
|
|
||||||
@ -275,28 +275,33 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
|
|||||||
Name = SelectSectionForGlobal(GV);
|
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;
|
return Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lame default implementation. Calculate the section name for global.
|
// Lame default implementation. Calculate the section name for global.
|
||||||
std::string
|
std::string
|
||||||
TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
|
TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
|
||||||
SectionKind::Kind kind = SectionKindForGlobal(GV);
|
SectionKind::Kind Kind = SectionKindForGlobal(GV);
|
||||||
|
|
||||||
if (GV->hasLinkOnceLinkage() ||
|
if (GV->hasLinkOnceLinkage() ||
|
||||||
GV->hasWeakLinkage() ||
|
GV->hasWeakLinkage() ||
|
||||||
GV->hasCommonLinkage())
|
GV->hasCommonLinkage())
|
||||||
return UniqueSectionForGlobal(GV, kind);
|
return UniqueSectionForGlobal(GV, Kind);
|
||||||
else {
|
else {
|
||||||
if (kind == SectionKind::Text)
|
if (Kind == SectionKind::Text)
|
||||||
return getTextSection();
|
return getTextSection();
|
||||||
else if (kind == SectionKind::BSS && getBSSSection())
|
else if (Kind == SectionKind::BSS && getBSSSection())
|
||||||
return getBSSSection();
|
return getBSSSection();
|
||||||
else if (getReadOnlySection() &&
|
else if (getReadOnlySection() &&
|
||||||
(kind == SectionKind::ROData ||
|
(Kind == SectionKind::ROData ||
|
||||||
kind == SectionKind::RODataMergeConst ||
|
Kind == SectionKind::RODataMergeConst ||
|
||||||
kind == SectionKind::RODataMergeStr))
|
Kind == SectionKind::RODataMergeStr))
|
||||||
return getReadOnlySection();
|
return getReadOnlySection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,8 +310,8 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
|
|||||||
|
|
||||||
std::string
|
std::string
|
||||||
TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
|
TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
|
||||||
SectionKind::Kind kind) const {
|
SectionKind::Kind Kind) const {
|
||||||
switch (kind) {
|
switch (Kind) {
|
||||||
case SectionKind::Text:
|
case SectionKind::Text:
|
||||||
return ".gnu.linkonce.t." + GV->getName();
|
return ".gnu.linkonce.t." + GV->getName();
|
||||||
case SectionKind::Data:
|
case SectionKind::Data:
|
||||||
|
@ -335,11 +335,11 @@ X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
|
|||||||
X86TargetAsmInfo(TM) {
|
X86TargetAsmInfo(TM) {
|
||||||
bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
|
bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
|
||||||
|
|
||||||
ReadOnlySection = "\t.section\t.rodata";
|
ReadOnlySection = ".rodata";
|
||||||
FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
|
FourByteConstantSection = ".rodata.cst";
|
||||||
EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
|
EightByteConstantSection = ".rodata.cst";
|
||||||
SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
|
SixteenByteConstantSection = ".rodata.cst";
|
||||||
CStringSection = "\t.section\t.rodata.str1.1,\"aMS\",@progbits,1";
|
CStringSection = ".rodata.str";
|
||||||
PrivateGlobalPrefix = ".L";
|
PrivateGlobalPrefix = ".L";
|
||||||
WeakRefDirective = "\t.weak\t";
|
WeakRefDirective = "\t.weak\t";
|
||||||
SetDirective = "\t.set\t";
|
SetDirective = "\t.set\t";
|
||||||
@ -520,6 +520,16 @@ X86ELFTargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
|
|||||||
Flags = SectionFlags::setEntitySize(Flags, Size);
|
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;
|
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 X86COFFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
|
||||||
std::string Flags = ",\"";
|
std::string Flags = ",\"";
|
||||||
|
|
||||||
|
@ -63,6 +63,8 @@ namespace llvm {
|
|||||||
explicit X86COFFTargetAsmInfo(const X86TargetMachine &TM);
|
explicit X86COFFTargetAsmInfo(const X86TargetMachine &TM);
|
||||||
virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
|
virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
|
||||||
bool Global) const;
|
bool Global) const;
|
||||||
|
virtual unsigned SectionFlagsForGlobal(const GlobalValue *GV,
|
||||||
|
const char* name) const;
|
||||||
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
|
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
|
||||||
SectionKind::Kind kind) const;
|
SectionKind::Kind kind) const;
|
||||||
virtual std::string PrintSectionFlags(unsigned flags) const;
|
virtual std::string PrintSectionFlags(unsigned flags) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user