llvm.org GIT mirror llvm / 766f253
ELF: Add support for the exclude section bit for gas compat. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190769 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 7 years ago
6 changed file(s) with 38 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
11951195 // This section holds Thread-Local Storage.
11961196 SHF_TLS = 0x400U,
11971197
1198 // This section is excluded from the final executable or shared library.
1199 SHF_EXCLUDE = 0x80000000U,
1200
11981201 // Start of target-specific flags.
11991202
12001203 /// XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped
278278 return SectionKind::getDataRel();
279279 }
280280
281 static int parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
282 int flags = 0;
281 static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
282 unsigned flags = 0;
283283
284284 for (unsigned i = 0; i < flagsStr.size(); i++) {
285285 switch (flagsStr[i]) {
286286 case 'a':
287287 flags |= ELF::SHF_ALLOC;
288288 break;
289 case 'e':
290 flags |= ELF::SHF_EXCLUDE;
291 break;
289292 case 'x':
290293 flags |= ELF::SHF_EXECINSTR;
291294 break;
314317 *UseLastGroup = true;
315318 break;
316319 default:
317 return -1;
320 return -1U;
318321 }
319322 }
320323
380383 StringRef FlagsStr = getTok().getStringContents();
381384 Lex();
382385
383 int extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup);
384 if (extraFlags < 0)
386 unsigned extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup);
387 if (extraFlags == -1U)
385388 return TokError("unknown flag");
386389 Flags |= extraFlags;
387390
7474 OS << ",#execinstr";
7575 if (Flags & ELF::SHF_WRITE)
7676 OS << ",#write";
77 if (Flags & ELF::SHF_EXCLUDE)
78 OS << ",#exclude";
7779 if (Flags & ELF::SHF_TLS)
7880 OS << ",#tls";
7981 OS << '\n';
8385 OS << ",\"";
8486 if (Flags & ELF::SHF_ALLOC)
8587 OS << 'a';
88 if (Flags & ELF::SHF_EXCLUDE)
89 OS << 'e';
8690 if (Flags & ELF::SHF_EXECINSTR)
8791 OS << 'x';
8892 if (Flags & ELF::SHF_GROUP)
265265 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
266266 BCase(SHF_WRITE)
267267 BCase(SHF_ALLOC)
268 BCase(SHF_EXCLUDE)
268269 BCase(SHF_EXECINSTR)
269270 BCase(SHF_MERGE)
270271 BCase(SHF_STRINGS)
77 .section -.note.GNU,"",@progbits
88
99 // CHECK: Name: .note.GNU-stack (56)
10 // CHECK: Name: .note.GNU-stack2 (143)
11 // CHECK: Name: .note.GNU- (160)
12 // CHECK: Name: -.note.GNU (132)
10 // CHECK: Name: .note.GNU-stack2 (153)
11 // CHECK: Name: .note.GNU- (170)
12 // CHECK: Name: -.note.GNU (142)
1313
1414 // Test that the defaults are used
1515
119119 // CHECK-NEXT: EntrySize: 0
120120 // CHECK-NEXT: }
121121
122 .section .excluded,"e",@progbits
123
124 // CHECK: Section {
125 // CHECK: Name: .excluded (92)
126 // CHECK-NEXT: Type: SHT_PROGBITS (0x1)
127 // CHECK-NEXT: Flags [ (0x80000000)
128 // CHECK-NEXT: SHF_EXCLUDE (0x80000000)
129 // CHECK-NEXT: ]
130 // CHECK-NEXT: Address: 0x0
131 // CHECK-NEXT: Offset: 0x50
132 // CHECK-NEXT: Size: 0
133 // CHECK-NEXT: Link: 0
134 // CHECK-NEXT: Info: 0
135 // CHECK-NEXT: AddressAlignment: 1
136 // CHECK-NEXT: EntrySize: 0
137 // CHECK-NEXT: }
138
122139 // Test that we handle the strings like gas
123140 .section bar-"foo"
124141 .section "foo"
125142
126143 // CHECK: Section {
127 // CHECK: Name: bar-"foo" (171)
144 // CHECK: Name: bar-"foo" (181)
128145 // CHECK: Section {
129146 // CHECK: Name: foo (52)
376376 static const EnumEntry ElfSectionFlags[] = {
377377 LLVM_READOBJ_ENUM_ENT(ELF, SHF_WRITE ),
378378 LLVM_READOBJ_ENUM_ENT(ELF, SHF_ALLOC ),
379 LLVM_READOBJ_ENUM_ENT(ELF, SHF_EXCLUDE ),
379380 LLVM_READOBJ_ENUM_ENT(ELF, SHF_EXECINSTR ),
380381 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MERGE ),
381382 LLVM_READOBJ_ENUM_ENT(ELF, SHF_STRINGS ),