[MC][COFF] Add COFF section flag "Info"
authorchenglin.bi <chenglin.bi@linaro.org>
Wed, 19 Oct 2022 02:32:32 +0000 (10:32 +0800)
committerchenglin.bi <chenglin.bi@linaro.org>
Wed, 19 Oct 2022 02:32:58 +0000 (10:32 +0800)
For now, we have not parse section flag `Info` in asm file. When we emit a section with info flag to asm, then compile asm to obj we will lose the Info flag for the section.
The motivation of this change is ARM64EC's hybmp$x section. If we lose the Info flag MSVC link will report a warning:
`warning LNK4078: multiple '.hybmp' sections found with different attributes`

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D136125

llvm/lib/MC/MCParser/COFFAsmParser.cpp
llvm/lib/MC/MCSectionCOFF.cpp
llvm/test/CodeGen/ARM/global-merge-dllexport.ll
llvm/test/MC/COFF/linker-options.ll
llvm/test/MC/COFF/section.s

index b78595f..ea123f4 100644 (file)
@@ -159,16 +159,17 @@ static SectionKind computeSectionKind(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,
+    Info = 1 << 9,
   };
 
   bool ReadOnlyRemoved = false;
@@ -238,6 +239,10 @@ bool COFFAsmParser::ParseSectionFlags(StringRef SectionName,
       SecFlags |= NoRead | NoWrite;
       break;
 
+    case 'i': // info
+      SecFlags |= Info;
+      break;
+
     default:
       return TokError("unknown flag");
     }
@@ -265,6 +270,8 @@ bool COFFAsmParser::ParseSectionFlags(StringRef SectionName,
     *Flags |= COFF::IMAGE_SCN_MEM_WRITE;
   if (SecFlags & Shared)
     *Flags |= COFF::IMAGE_SCN_MEM_SHARED;
+  if (SecFlags & Info)
+    *Flags |= COFF::IMAGE_SCN_LNK_INFO;
 
   return false;
 }
index f7ca037..02979c9 100644 (file)
@@ -63,6 +63,8 @@ void MCSectionCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
   if ((getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
       !isImplicitlyDiscardable(getName()))
     OS << 'D';
+  if (getCharacteristics() & COFF::IMAGE_SCN_LNK_INFO)
+    OS << 'i';
   OS << '"';
 
   if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
index 98d7525..8d027f2 100644 (file)
@@ -13,7 +13,7 @@ define void @f1(i32 %a1, i32 %a2) {
 }
 
 ; CHECK: .lcomm .L_MergedGlobals,8,4
-; CHECK: .section .drectve,"yn"
+; CHECK: .section .drectve,"yni"
 ; CHECK: .ascii " /EXPORT:y,DATA"
 ; CHECK: .globl x
 ; CHECK: .set x, .L_MergedGlobals
index 24ac84d..2672356 100644 (file)
@@ -10,7 +10,7 @@ define dllexport void @foo() {
   ret void
 }
 
-; CHECK: .section        .drectve,"yn"
+; CHECK: .section        .drectve,"yni"
 ; CHECK: .ascii   " /DEFAULTLIB:msvcrt.lib"
 ; CHECK: .ascii   " /DEFAULTLIB:msvcrt.lib"
 ; CHECK: .ascii   " /DEFAULTLIB:secur32.lib"
index 05203c8..05a9155 100644 (file)
@@ -37,6 +37,7 @@
 .section s_w,"w"; .long 1
 .section s_x,"x"; .long 1
 .section s_y,"y"; .long 1
+.section s_i,"i"; .long 1
 
 // CHECK:        Section {
 // CHECK:          Name: s
 // CHECK-NEXT:       IMAGE_SCN_ALIGN_1BYTES
 // CHECK-NEXT:     ]
 // CHECK:        }
+// CHECK:        Section {
+// CHECK:          Name: s_i
+// CHECK:          Characteristics [
+// CHECK-NEXT:       IMAGE_SCN_ALIGN_1BYTES
+// CHECK-NEXT:       IMAGE_SCN_LNK_INFO
+// CHECK-NEXT:       IMAGE_SCN_MEM_READ
+// CHECK-NEXT:       IMAGE_SCN_MEM_WRITE
+// CHECK-NEXT:     ]
+// CHECK:        }
 
 // w makes read-only to readable
 .section s_rw,"rw"; .long 1