[llvm] b18293e - [MC][COFF] Add COFF section flag "Info"
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 18 19:33:06 PDT 2022
Author: chenglin.bi
Date: 2022-10-19T10:32:58+08:00
New Revision: b18293edc39f216339c64dccc6c9abf9eb1aab11
URL: https://github.com/llvm/llvm-project/commit/b18293edc39f216339c64dccc6c9abf9eb1aab11
DIFF: https://github.com/llvm/llvm-project/commit/b18293edc39f216339c64dccc6c9abf9eb1aab11.diff
LOG: [MC][COFF] Add COFF section flag "Info"
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
Added:
Modified:
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
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/COFFAsmParser.cpp b/llvm/lib/MC/MCParser/COFFAsmParser.cpp
index b78595f5bab48..ea123f43536f7 100644
--- a/llvm/lib/MC/MCParser/COFFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/COFFAsmParser.cpp
@@ -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;
}
diff --git a/llvm/lib/MC/MCSectionCOFF.cpp b/llvm/lib/MC/MCSectionCOFF.cpp
index f7ca0375544a0..02979c966ca79 100644
--- a/llvm/lib/MC/MCSectionCOFF.cpp
+++ b/llvm/lib/MC/MCSectionCOFF.cpp
@@ -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) {
diff --git a/llvm/test/CodeGen/ARM/global-merge-dllexport.ll b/llvm/test/CodeGen/ARM/global-merge-dllexport.ll
index 98d75250a3038..8d027f290a0e2 100644
--- a/llvm/test/CodeGen/ARM/global-merge-dllexport.ll
+++ b/llvm/test/CodeGen/ARM/global-merge-dllexport.ll
@@ -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
diff --git a/llvm/test/MC/COFF/linker-options.ll b/llvm/test/MC/COFF/linker-options.ll
index 24ac84da1e2df..26723560d74d4 100644
--- a/llvm/test/MC/COFF/linker-options.ll
+++ b/llvm/test/MC/COFF/linker-options.ll
@@ -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"
diff --git a/llvm/test/MC/COFF/section.s b/llvm/test/MC/COFF/section.s
index 05203c883f174..05a915535ae31 100644
--- a/llvm/test/MC/COFF/section.s
+++ b/llvm/test/MC/COFF/section.s
@@ -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
@@ -143,6 +144,15 @@
// 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
More information about the llvm-commits
mailing list