1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

ELF: Add support for the exclude section bit for gas compat.

llvm-svn: 190769
This commit is contained in:
Benjamin Kramer 2013-09-15 19:53:20 +00:00
parent 29e93ff017
commit e8d495c088
6 changed files with 38 additions and 9 deletions

View File

@ -1196,6 +1196,9 @@ enum {
// This section holds Thread-Local Storage.
SHF_TLS = 0x400U,
// This section is excluded from the final executable or shared library.
SHF_EXCLUDE = 0x80000000U,
// Start of target-specific flags.
/// XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped

View File

@ -279,14 +279,17 @@ static SectionKind computeSectionKind(unsigned Flags) {
return SectionKind::getDataRel();
}
static int parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
int flags = 0;
static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
unsigned flags = 0;
for (unsigned i = 0; i < flagsStr.size(); i++) {
switch (flagsStr[i]) {
case 'a':
flags |= ELF::SHF_ALLOC;
break;
case 'e':
flags |= ELF::SHF_EXCLUDE;
break;
case 'x':
flags |= ELF::SHF_EXECINSTR;
break;
@ -315,7 +318,7 @@ static int parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
*UseLastGroup = true;
break;
default:
return -1;
return -1U;
}
}
@ -381,8 +384,8 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush) {
StringRef FlagsStr = getTok().getStringContents();
Lex();
int extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup);
if (extraFlags < 0)
unsigned extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup);
if (extraFlags == -1U)
return TokError("unknown flag");
Flags |= extraFlags;

View File

@ -75,6 +75,8 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
OS << ",#execinstr";
if (Flags & ELF::SHF_WRITE)
OS << ",#write";
if (Flags & ELF::SHF_EXCLUDE)
OS << ",#exclude";
if (Flags & ELF::SHF_TLS)
OS << ",#tls";
OS << '\n';
@ -84,6 +86,8 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
OS << ",\"";
if (Flags & ELF::SHF_ALLOC)
OS << 'a';
if (Flags & ELF::SHF_EXCLUDE)
OS << 'e';
if (Flags & ELF::SHF_EXECINSTR)
OS << 'x';
if (Flags & ELF::SHF_GROUP)

View File

@ -266,6 +266,7 @@ void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
#define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
BCase(SHF_WRITE)
BCase(SHF_ALLOC)
BCase(SHF_EXCLUDE)
BCase(SHF_EXECINSTR)
BCase(SHF_MERGE)
BCase(SHF_STRINGS)

View File

@ -8,9 +8,9 @@
.section -.note.GNU,"",@progbits
// CHECK: Name: .note.GNU-stack (56)
// CHECK: Name: .note.GNU-stack2 (143)
// CHECK: Name: .note.GNU- (160)
// CHECK: Name: -.note.GNU (132)
// CHECK: Name: .note.GNU-stack2 (153)
// CHECK: Name: .note.GNU- (170)
// CHECK: Name: -.note.GNU (142)
// Test that the defaults are used
@ -120,11 +120,28 @@ bar:
// CHECK-NEXT: EntrySize: 0
// CHECK-NEXT: }
.section .excluded,"e",@progbits
// CHECK: Section {
// CHECK: Name: .excluded (92)
// CHECK-NEXT: Type: SHT_PROGBITS (0x1)
// CHECK-NEXT: Flags [ (0x80000000)
// CHECK-NEXT: SHF_EXCLUDE (0x80000000)
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset: 0x50
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 0
// CHECK-NEXT: AddressAlignment: 1
// CHECK-NEXT: EntrySize: 0
// CHECK-NEXT: }
// Test that we handle the strings like gas
.section bar-"foo"
.section "foo"
// CHECK: Section {
// CHECK: Name: bar-"foo" (171)
// CHECK: Name: bar-"foo" (181)
// CHECK: Section {
// CHECK: Name: foo (52)

View File

@ -377,6 +377,7 @@ static const char *getElfSectionType(unsigned Arch, unsigned Type) {
static const EnumEntry<unsigned> ElfSectionFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, SHF_WRITE ),
LLVM_READOBJ_ENUM_ENT(ELF, SHF_ALLOC ),
LLVM_READOBJ_ENUM_ENT(ELF, SHF_EXCLUDE ),
LLVM_READOBJ_ENUM_ENT(ELF, SHF_EXECINSTR ),
LLVM_READOBJ_ENUM_ENT(ELF, SHF_MERGE ),
LLVM_READOBJ_ENUM_ENT(ELF, SHF_STRINGS ),