COFF::COMDATType Type);
bool ParseSectionName(StringRef &SectionName);
- bool ParseSectionFlags(StringRef FlagsString, unsigned* Flags);
+ bool ParseSectionFlags(StringRef SectionName, StringRef FlagsString,
+ unsigned *Flags);
void Initialize(MCAsmParser &Parser) override {
// Call the base implementation.
return SectionKind::getData();
}
-bool COFFAsmParser::ParseSectionFlags(StringRef FlagsString, unsigned* Flags) {
+bool COFFAsmParser::ParseSectionFlags(StringRef SectionName,
+ StringRef FlagsString, unsigned *Flags) {
enum {
- None = 0,
- Alloc = 1 << 0,
- Code = 1 << 1,
- Load = 1 << 2,
- InitData = 1 << 3,
- Shared = 1 << 4,
- NoLoad = 1 << 5,
- NoRead = 1 << 6,
- NoWrite = 1 << 7
+ None = 0,
+ Alloc = 1 << 0,
+ Code = 1 << 1,
+ Load = 1 << 2,
+ InitData = 1 << 3,
+ Shared = 1 << 4,
+ NoLoad = 1 << 5,
+ NoRead = 1 << 6,
+ NoWrite = 1 << 7,
+ Discardable = 1 << 8,
};
bool ReadOnlyRemoved = false;
SecFlags &= ~Load;
break;
+ case 'D': // discardable
+ SecFlags |= Discardable;
+ break;
+
case 'r': // read-only
ReadOnlyRemoved = false;
SecFlags |= NoWrite;
*Flags |= COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
if (SecFlags & NoLoad)
*Flags |= COFF::IMAGE_SCN_LNK_REMOVE;
+ if ((SecFlags & Discardable) ||
+ MCSectionCOFF::isImplicitlyDiscardable(SectionName))
+ *Flags |= COFF::IMAGE_SCN_MEM_DISCARDABLE;
if ((SecFlags & NoRead) == 0)
*Flags |= COFF::IMAGE_SCN_MEM_READ;
if ((SecFlags & NoWrite) == 0)
// a: Ignored.
// b: BSS section (uninitialized data)
// d: data section (initialized data)
-// n: Discardable section
+// n: "noload" section (removed by linker)
+// D: Discardable section
// r: Readable section
// s: Shared section
// w: Writable section
StringRef FlagsStr = getTok().getStringContents();
Lex();
- if (ParseSectionFlags(FlagsStr, &Flags))
+ if (ParseSectionFlags(SectionName, FlagsStr, &Flags))
return true;
}
.section s_a,"a"; .long 1
.section s_b,"b"; .long 1
.section s_d,"d"; .long 1
+.section s_D,"D"; .long 1
.section s_n,"n"; .long 1
.section s_r,"r"; .long 1
.section s_s,"s"; .long 1
// CHECK-NEXT: ]
// CHECK: }
// CHECK: Section {
+// CHECK: Name: s_D
+// CHECK: Characteristics [
+// CHECK-NEXT: IMAGE_SCN_ALIGN_1BYTES
+// CHECK-NEXT: IMAGE_SCN_MEM_DISCARDABLE
+// CHECK-NEXT: IMAGE_SCN_MEM_READ
+// CHECK-NEXT: IMAGE_SCN_MEM_WRITE
+// CHECK-NEXT: ]
+// CHECK: }
+// CHECK: Section {
// CHECK: Name: s_n
// CHECK: Characteristics [
// CHECK-NEXT: IMAGE_SCN_ALIGN_1BYTES
// CHECK-NEXT: ]
// CHECK: }
+// Sections starting with ".debug" are implicitly discardable. This is
+// compatible with gas.
+.section .debug_asdf,"dr"; .long 1
+// CHECK: Section {
+// CHECK: Name: .debug_asdf
+// CHECK: Characteristics [
+// CHECK-NEXT: IMAGE_SCN_ALIGN_1BYTES
+// CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
+// CHECK-NEXT: IMAGE_SCN_MEM_DISCARDABLE
+// CHECK-NEXT: IMAGE_SCN_MEM_READ
+// CHECK-NEXT: ]
+// CHECK: }
+
+
// CHECK: ]