Skip to content

Commit

Permalink
[MC][COFF] Add COFF section flag "Info"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bcl5980 committed Oct 19, 2022
1 parent 771aee9 commit b18293e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
25 changes: 16 additions & 9 deletions llvm/lib/MC/MCParser/COFFAsmParser.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -238,6 +239,10 @@ bool COFFAsmParser::ParseSectionFlags(StringRef SectionName,
SecFlags |= NoRead | NoWrite;
break;

case 'i': // info
SecFlags |= Info;
break;

default:
return TokError("unknown flag");
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/MC/MCSectionCOFF.cpp
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/global-merge-dllexport.ll
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/COFF/linker-options.ll
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions llvm/test/MC/COFF/section.s
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b18293e

Please sign in to comment.