[llvm] [MC,ELF] .section: unconditionally print section flag 'G' after 'o' (PR #77422)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 00:12:08 PST 2024


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/77422

- [MC] Parse SHF_LINK_ORDER argument before section group name
- [MC,ELF] .section: unconditionally print section flag 'G' after 'o'


>From 43e4b1e8fda3fd3f38479bb6e9d3cbc4c32945aa Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Mon, 8 Jan 2024 19:27:13 -0800
Subject: [PATCH 1/2] [MC] Parse SHF_LINK_ORDER argument before section group
 name

When both SHF_LINK_ORDER | SHF_GROUP flags are set, GNU assembler from
2.35 onwards (https://sourceware.org/PR25381
https://sourceware.org/binutils/docs/as/Section.html) parses the
SHF_LINK_ORDER argument before section group name, different from us.

This is unfortunate, but does not matter because the `.section` flag `o`
is a niche feature only used by compiler instrumentations, not adopted
by hand-written assembly, and using both flags is extremely rare. Let's
just match GNU assembler. There is another benefit: we now support
zero-flag section group with the SHF_LINK_ORDER flag, while previously
there isn't a syntax.

While here, print 'G' after 'o' to be clear that the 'G' argument is
parsed after the 'o' argument. To make the diff smaller, we don't print
'G' after 'w' in the absence of 'o' for now.
---
 llvm/lib/MC/MCParser/ELFAsmParser.cpp         |  6 +++---
 llvm/lib/MC/MCSectionELF.cpp                  | 20 +++++++++++--------
 .../AArch64/patchable-function-entry.ll       |  4 ++--
 .../LoongArch/patchable-function-entry.ll     |  2 +-
 llvm/test/CodeGen/Mips/xray-section-group.ll  |  2 +-
 .../CodeGen/RISCV/patchable-function-entry.ll |  2 +-
 ...lock-sections-labels-functions-sections.ll |  2 +-
 .../CodeGen/X86/gcc_except_table-multi.ll     |  4 ++--
 .../CodeGen/X86/patchable-function-entry.ll   |  4 ++--
 .../stack-size-section-function-sections.ll   |  4 ++--
 llvm/test/CodeGen/X86/stack-size-section.ll   |  2 +-
 llvm/test/CodeGen/X86/xray-section-group.ll   |  2 +-
 llvm/test/MC/ELF/section-combine.s            |  6 +++---
 llvm/test/MC/ELF/section.s                    | 16 +++++++++++++++
 14 files changed, 48 insertions(+), 28 deletions(-)

diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index 93e1d2f44b8c56..d4c4bcb8564889 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -616,12 +616,12 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
     if (Mergeable)
       if (parseMergeSize(Size))
         return true;
-    if (Group)
-      if (parseGroup(GroupName, IsComdat))
-        return true;
     if (Flags & ELF::SHF_LINK_ORDER)
       if (parseLinkedToSym(LinkedToSym))
         return true;
+    if (Group)
+      if (parseGroup(GroupName, IsComdat))
+        return true;
     if (maybeParseUniqueID(UniqueID))
       return true;
   }
diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp
index 95fdf33522076e..1e1b5edb94d761 100644
--- a/llvm/lib/MC/MCSectionELF.cpp
+++ b/llvm/lib/MC/MCSectionELF.cpp
@@ -90,7 +90,9 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
     OS << 'e';
   if (Flags & ELF::SHF_EXECINSTR)
     OS << 'x';
-  if (Flags & ELF::SHF_GROUP)
+  // TODO: Always print G after o to be clear that the 'G' argument is parsed
+  // after the 'o' argument.
+  if ((Flags & ELF::SHF_GROUP) && !(Flags & ELF::SHF_LINK_ORDER))
     OS << 'G';
   if (Flags & ELF::SHF_WRITE)
     OS << 'w';
@@ -102,6 +104,8 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
     OS << 'T';
   if (Flags & ELF::SHF_LINK_ORDER)
     OS << 'o';
+  if ((Flags & ELF::SHF_GROUP) && (Flags & ELF::SHF_LINK_ORDER))
+    OS << 'G';
   if (Flags & ELF::SHF_GNU_RETAIN)
     OS << 'R';
 
@@ -183,13 +187,6 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
     OS << "," << EntrySize;
   }
 
-  if (Flags & ELF::SHF_GROUP) {
-    OS << ",";
-    printName(OS, Group.getPointer()->getName());
-    if (isComdat())
-      OS << ",comdat";
-  }
-
   if (Flags & ELF::SHF_LINK_ORDER) {
     OS << ",";
     if (LinkedToSym)
@@ -198,6 +195,13 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
       OS << '0';
   }
 
+  if (Flags & ELF::SHF_GROUP) {
+    OS << ",";
+    printName(OS, Group.getPointer()->getName());
+    if (isComdat())
+      OS << ",comdat";
+  }
+
   if (isUnique())
     OS << ",unique," << UniqueID;
 
diff --git a/llvm/test/CodeGen/AArch64/patchable-function-entry.ll b/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
index 5750c1f601bdef..89a2e2bf4abbcf 100644
--- a/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
@@ -48,7 +48,7 @@ define void @f3() "patchable-function-entry"="3" comdat {
 ; CHECK-NEXT: .Lfunc_begin3:
 ; CHECK-COUNT-3: nop
 ; CHECK-NEXT:  ret
-; CHECK:       .section __patchable_function_entries,"aGwo", at progbits,f3,comdat,f3{{$}}
+; CHECK:       .section __patchable_function_entries,"awoG", at progbits,f3,f3,comdat{{$}}
 ; CHECK-NEXT:  .p2align 3
 ; CHECK-NEXT:  .xword .Lfunc_begin3
   ret void
@@ -60,7 +60,7 @@ define void @f5() "patchable-function-entry"="5" comdat {
 ; CHECK-NEXT: .Lfunc_begin4:
 ; CHECK-COUNT-5: nop
 ; CHECK-NEXT:  sub sp, sp, #16
-; CHECK:       .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5{{$}}
+; CHECK:       .section __patchable_function_entries,"awoG", at progbits,f5,f5,comdat{{$}}
 ; CHECK:       .p2align 3
 ; CHECK-NEXT:  .xword .Lfunc_begin4
   %frame = alloca i8, i32 16
diff --git a/llvm/test/CodeGen/LoongArch/patchable-function-entry.ll b/llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
index aaa3fda1ae7769..2e390d1e2c33af 100644
--- a/llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
@@ -31,7 +31,7 @@ define void @f5() "patchable-function-entry"="5" comdat {
 ; CHECK-NEXT:    .Lfunc_begin2:
 ; CHECK-COUNT-5:   nop
 ; CHECK-NEXT:      ret
-; CHECK:         .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5{{$}}
+; CHECK:         .section __patchable_function_entries,"awoG", at progbits,f5,f5,comdat{{$}}
 ; LA32:          .p2align 2
 ; LA32-NEXT:     .word .Lfunc_begin2
 ; LA64:          .p2align 3
diff --git a/llvm/test/CodeGen/Mips/xray-section-group.ll b/llvm/test/CodeGen/Mips/xray-section-group.ll
index 5a208217092dd7..e9cd045d4411e1 100644
--- a/llvm/test/CodeGen/Mips/xray-section-group.ll
+++ b/llvm/test/CodeGen/Mips/xray-section-group.ll
@@ -24,7 +24,7 @@ $bar = comdat any
 define i32 @bar() nounwind noinline uwtable "function-instrument"="xray-always" comdat($bar) {
 ; CHECK: .section .text.bar,"axG", at progbits,bar,comdat
   ret i32 1
-; CHECK: .section xray_instr_map,"aGo", at progbits,bar,comdat,bar{{$}}
+; CHECK: .section xray_instr_map,"aoG", at progbits,bar,bar,comdat{{$}}
 }
 
 ; CHECK-OBJ: Section {
diff --git a/llvm/test/CodeGen/RISCV/patchable-function-entry.ll b/llvm/test/CodeGen/RISCV/patchable-function-entry.ll
index 2804fdfc1ac9c5..4eeb1bf3138580 100644
--- a/llvm/test/CodeGen/RISCV/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/RISCV/patchable-function-entry.ll
@@ -37,7 +37,7 @@ define void @f5() "patchable-function-entry"="5" comdat {
 ; NORVC-NEXT:    jalr zero, 0(ra)
 ; RVC-COUNT-5:   c.nop
 ; RVC-NEXT:      c.jr ra
-; CHECK:       .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5{{$}}
+; CHECK:       .section __patchable_function_entries,"awoG", at progbits,f5,f5,comdat{{$}}
 ; RV32:        .p2align 2
 ; RV32-NEXT:   .word .Lfunc_begin2
 ; RV64:        .p2align 3
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll b/llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
index b8217bbc00760f..3be3ab70f8a693 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
@@ -35,7 +35,7 @@ define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
 ; CHECK:		.section .text._Z4fooTIiET_v,"axG", at progbits,_Z4fooTIiET_v,comdat
 ; CHECK-LABEL:	_Z4fooTIiET_v:
 ; CHECK-NEXT:	[[FOOCOMDAT_BEGIN:.Lfunc_begin[0-9]+]]:
-; CHECK:		.section .llvm_bb_addr_map,"Go", at llvm_bb_addr_map,_Z4fooTIiET_v,comdat,.text._Z4fooTIiET_v{{$}}
+; CHECK:		.section .llvm_bb_addr_map,"oG", at llvm_bb_addr_map,.text._Z4fooTIiET_v,_Z4fooTIiET_v,comdat{{$}}
 ; CHECK-NEXT:		.byte 2				# version
 ; CHECK-NEXT:		.byte 0				# feature
 ; CHECK-NEXT:		.quad [[FOOCOMDAT_BEGIN]]	# function address
diff --git a/llvm/test/CodeGen/X86/gcc_except_table-multi.ll b/llvm/test/CodeGen/X86/gcc_except_table-multi.ll
index 8da3ebfed2bdd7..1eb902ae90795d 100644
--- a/llvm/test/CodeGen/X86/gcc_except_table-multi.ll
+++ b/llvm/test/CodeGen/X86/gcc_except_table-multi.ll
@@ -17,7 +17,7 @@ define i32 @group() uwtable comdat personality ptr @__gxx_personality_v0 {
 ; CHECK:             .cfi_endproc
 ; NORMAL-NEXT:       .section .gcc_except_table.group,"aG", at progbits,group,comdat{{$}}
 ; SEP_BFD-NEXT:      .section .gcc_except_table.group,"aG", at progbits,group,comdat{{$}}
-; SEP-NEXT:          .section .gcc_except_table.group,"aGo", at progbits,group,comdat,group{{$}}
+; SEP-NEXT:          .section .gcc_except_table.group,"aoG", at progbits,group,group,comdat{{$}}
 ; SEP_NOUNIQUE-NEXT: .section .gcc_except_table,"aG", at progbits,group,comdat{{$}}
 ; NOUNIQUE-NEXT:     .section .gcc_except_table,"aG", at progbits,group,comdat{{$}}
 entry:
@@ -61,7 +61,7 @@ define i32 @zero() uwtable comdat personality ptr @__gxx_personality_v0 {
 ; CHECK:             .cfi_endproc
 ; NORMAL-NEXT:       .section .gcc_except_table.zero,"aG", at progbits,zero{{$}}
 ; SEP_BFD-NEXT:      .section .gcc_except_table.zero,"aG", at progbits,zero{{$}}
-; SEP-NEXT:          .section .gcc_except_table.zero,"aGo", at progbits,zero,zero{{$}}
+; SEP-NEXT:          .section .gcc_except_table.zero,"aoG", at progbits,zero,zero{{$}}
 ; SEP_NOUNIQUE-NEXT: .section .gcc_except_table,"aG", at progbits,zero{{$}}
 ; NOUNIQUE-NEXT:     .section .gcc_except_table,"aG", at progbits,zero{{$}}
 entry:
diff --git a/llvm/test/CodeGen/X86/patchable-function-entry.ll b/llvm/test/CodeGen/X86/patchable-function-entry.ll
index 124f5c57c74b5a..8c37f545108015 100644
--- a/llvm/test/CodeGen/X86/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/X86/patchable-function-entry.ll
@@ -50,7 +50,7 @@ define void @f3() "patchable-function-entry"="3" comdat {
 ; 32-NEXT:     nop
 ; 64:          nopl (%rax)
 ; CHECK:       ret
-; CHECK:       .section __patchable_function_entries,"aGwo", at progbits,f3,comdat,f3{{$}}
+; CHECK:       .section __patchable_function_entries,"awoG", at progbits,f3,f3,comdat{{$}}
 ; 32:          .p2align 2
 ; 32-NEXT:     .long .Lfunc_begin3
 ; 64:          .p2align 3
@@ -66,7 +66,7 @@ define void @f5() "patchable-function-entry"="5" comdat {
 ; 32-NEXT:     nop
 ; 64:          nopl 8(%rax,%rax)
 ; CHECK-NEXT:  ret
-; CHECK:       .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5{{$}}
+; CHECK:       .section __patchable_function_entries,"awoG", at progbits,f5,f5,comdat{{$}}
 ; 32:          .p2align 2
 ; 32-NEXT:     .long .Lfunc_begin4
 ; 64:          .p2align 3
diff --git a/llvm/test/CodeGen/X86/stack-size-section-function-sections.ll b/llvm/test/CodeGen/X86/stack-size-section-function-sections.ll
index 92f312bd1185ce..b9606c081a90e0 100644
--- a/llvm/test/CodeGen/X86/stack-size-section-function-sections.ll
+++ b/llvm/test/CodeGen/X86/stack-size-section-function-sections.ll
@@ -15,9 +15,9 @@
 
 ; Check we add .stack_size section to a COMDAT group with the corresponding .text section if such a COMDAT exists.
 ; UNIQ:   .section        .text._Z4fooTIiET_v,"axG", at progbits,_Z4fooTIiET_v,comdat{{$}}
-; UNIQ:   .section        .stack_sizes,"Go", at progbits,_Z4fooTIiET_v,comdat,.text._Z4fooTIiET_v{{$}}
+; UNIQ:   .section        .stack_sizes,"oG", at progbits,.text._Z4fooTIiET_v,_Z4fooTIiET_v,comdat{{$}}
 ; NOUNIQ: .section        .text,"axG", at progbits,_Z4fooTIiET_v,comdat,unique,3
-; NOUNIQ: .section        .stack_sizes,"Go", at progbits,_Z4fooTIiET_v,comdat,.text,unique,3
+; NOUNIQ: .section        .stack_sizes,"oG", at progbits,.text,_Z4fooTIiET_v,comdat,unique,3
 
 $_Z4fooTIiET_v = comdat any
 
diff --git a/llvm/test/CodeGen/X86/stack-size-section.ll b/llvm/test/CodeGen/X86/stack-size-section.ll
index 3652ee845a7f34..866acbe140147e 100644
--- a/llvm/test/CodeGen/X86/stack-size-section.ll
+++ b/llvm/test/CodeGen/X86/stack-size-section.ll
@@ -29,7 +29,7 @@ define void @func2() #0 {
 
 ; Check that we still put .stack_sizes into the corresponding COMDAT group if any.
 ; CHECK: .section .text._Z4fooTIiET_v,"axG", at progbits,_Z4fooTIiET_v,comdat
-; GROUPS: .section .stack_sizes,"Go", at progbits,_Z4fooTIiET_v,comdat,.text._Z4fooTIiET_v{{$}}
+; GROUPS: .section .stack_sizes,"oG", at progbits,.text._Z4fooTIiET_v,_Z4fooTIiET_v,comdat{{$}}
 ; NOGROUPS: .section .stack_sizes,"", at progbits
 $_Z4fooTIiET_v = comdat any
 define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
diff --git a/llvm/test/CodeGen/X86/xray-section-group.ll b/llvm/test/CodeGen/X86/xray-section-group.ll
index c05520adf89972..1f2855b089d22e 100644
--- a/llvm/test/CodeGen/X86/xray-section-group.ll
+++ b/llvm/test/CodeGen/X86/xray-section-group.ll
@@ -12,7 +12,7 @@ $bar = comdat any
 define i32 @bar() nounwind noinline uwtable "function-instrument"="xray-always" comdat($bar) {
 ; CHECK: .section .text.bar,"axG", at progbits,bar,comdat
   ret i32 1
-; CHECK: .section xray_instr_map,"aGo", at progbits,bar,comdat,bar{{$}}
+; CHECK: .section xray_instr_map,"aoG", at progbits,bar,bar,comdat{{$}}
 }
 
 ; CHECK-OBJ:      section xray_instr_map:
diff --git a/llvm/test/MC/ELF/section-combine.s b/llvm/test/MC/ELF/section-combine.s
index b68eaa3a05afaa..a6da8581a056e0 100644
--- a/llvm/test/MC/ELF/section-combine.s
+++ b/llvm/test/MC/ELF/section-combine.s
@@ -39,10 +39,10 @@ bar:
 .section .foo,"o", at progbits,bar,unique,1
 .byte 5
 
-.section .foo,"Go", at progbits,comdat0,comdat,bar,unique,1
+.section .foo,"Go", at progbits,bar,comdat0,comdat,unique,1
 .byte 6
 
-.section .foo,"Go", at progbits,comdat1,comdat,bar,unique,1
+.section .foo,"Go", at progbits,bar,comdat1,comdat,unique,1
 .byte 7
-.section .foo,"Go", at progbits,comdat1,comdat,bar,unique,1
+.section .foo,"oG", at progbits,bar,comdat1,comdat,unique,1
 .byte 8
diff --git a/llvm/test/MC/ELF/section.s b/llvm/test/MC/ELF/section.s
index 8c625256a2761d..e4e6f4bccb8a41 100644
--- a/llvm/test/MC/ELF/section.s
+++ b/llvm/test/MC/ELF/section.s
@@ -166,9 +166,11 @@ bar:
 .section .shf_metadata1,"ao", at progbits,.Lshf_metadata_target2_1
 .section .shf_metadata2,"ao", at progbits,.Lshf_metadata_target2_2
 .section .shf_metadata3,"ao", at progbits,.shf_metadata_target1
+.section .linkorder_group_zero,"aoG", at progbits,.shf_metadata_target1,foo
 // ASM: .section .shf_metadata1,"ao", at progbits,.Lshf_metadata_target2_1
 // ASM: .section .shf_metadata2,"ao", at progbits,.Lshf_metadata_target2_2
 // ASM: .section .shf_metadata3,"ao", at progbits,.shf_metadata_target1
+// ASM: .section .linkorder_group_zero,"aoG", at progbits,.shf_metadata_target1,foo{{$}}
 
 // CHECK:      Section {
 // CHECK:        Index: 22
@@ -221,6 +223,20 @@ bar:
 // CHECK-NEXT:   Link:    22
 // CHECK-NEXT:   Info:    0
 
+// CHECK:      Section {
+// CHECK:        Name: .linkorder_group_zero
+// CHECK-NEXT:   Type: SHT_PROGBITS
+// CHECK-NEXT:   Flags [
+// CHECK-NEXT:     SHF_ALLOC
+// CHECK-NEXT:     SHF_GROUP
+// CHECK-NEXT:     SHF_LINK_ORDER
+// CHECK-NEXT:   ]
+// CHECK-NEXT:   Address:
+// CHECK-NEXT:   Offset:
+// CHECK-NEXT:   Size:
+// CHECK-NEXT:   Link:    22
+// CHECK-NEXT:   Info:    0
+
 .section	.text.foo
 // CHECK:        Section {
 // CHECK:          Name: .text.foo

>From ab675a9994594f8655057b662ee554c30d07ffa6 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Mon, 8 Jan 2024 23:59:03 -0800
Subject: [PATCH 2/2] [MC,ELF] .section: unconditionally print section flag 'G'
 after 'o'

* Placing 'G' before 'M' (SHF_MERGE) can be misleading as the sh_entsize
  argument goes before the section group name (if a reader doesn't know
  that the order of extra arguments is not affected by the order of flags.
* 'a', 'w', and 'x' indicate basic permission-related flags. Separating
  them with 'G' is kinda ugly.

Simplify code and move 'G' after 'o'. The new output is more similar to
GCC.
---
 llvm/lib/MC/MCSectionELF.cpp                   |  6 +-----
 llvm/test/CodeGen/Mips/ehframe-indirect.ll     |  2 +-
 llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll   |  4 ++--
 llvm/test/CodeGen/SPARC/constructor.ll         |  4 ++--
 llvm/test/CodeGen/X86/constructor.ll           | 12 ++++++------
 llvm/test/CodeGen/X86/elf-comdat.ll            |  2 +-
 llvm/test/CodeGen/X86/elf-comdat2.ll           |  2 +-
 llvm/test/CodeGen/X86/elf-group.ll             |  2 +-
 .../CodeGen/X86/explicit-section-mergeable.ll  | 18 +++++++++---------
 .../test/CodeGen/X86/global-sections-comdat.ll |  6 +++---
 .../DebugInfo/SystemZ/eh_frame_personality.ll  |  2 +-
 .../DebugInfo/SystemZ/eh_frame_personality.s   |  2 +-
 .../JITLink/x86-64/ELF_ehframe_basic.s         |  2 +-
 ...hframe_large_static_personality_encodings.s |  2 +-
 llvm/test/MC/ELF/alias-to-local.s              |  2 +-
 llvm/test/MC/ELF/relocation.s                  |  2 +-
 llvm/test/tools/llvm-symbolizer/frame.s        |  2 +-
 17 files changed, 34 insertions(+), 38 deletions(-)

diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp
index 1e1b5edb94d761..b1efb839ba75f6 100644
--- a/llvm/lib/MC/MCSectionELF.cpp
+++ b/llvm/lib/MC/MCSectionELF.cpp
@@ -90,10 +90,6 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
     OS << 'e';
   if (Flags & ELF::SHF_EXECINSTR)
     OS << 'x';
-  // TODO: Always print G after o to be clear that the 'G' argument is parsed
-  // after the 'o' argument.
-  if ((Flags & ELF::SHF_GROUP) && !(Flags & ELF::SHF_LINK_ORDER))
-    OS << 'G';
   if (Flags & ELF::SHF_WRITE)
     OS << 'w';
   if (Flags & ELF::SHF_MERGE)
@@ -104,7 +100,7 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
     OS << 'T';
   if (Flags & ELF::SHF_LINK_ORDER)
     OS << 'o';
-  if ((Flags & ELF::SHF_GROUP) && (Flags & ELF::SHF_LINK_ORDER))
+  if (Flags & ELF::SHF_GROUP)
     OS << 'G';
   if (Flags & ELF::SHF_GNU_RETAIN)
     OS << 'R';
diff --git a/llvm/test/CodeGen/Mips/ehframe-indirect.ll b/llvm/test/CodeGen/Mips/ehframe-indirect.ll
index b3f4b48329d7bc..e36fa2f9ce423d 100644
--- a/llvm/test/CodeGen/Mips/ehframe-indirect.ll
+++ b/llvm/test/CodeGen/Mips/ehframe-indirect.ll
@@ -62,7 +62,7 @@ declare void @foo()
 ; N64: .8byte _ZTISt9exception
 ; ALL: .hidden DW.ref.__gxx_personality_v0
 ; ALL: .weak DW.ref.__gxx_personality_v0
-; ALL: .section .data.DW.ref.__gxx_personality_v0,"aGw", at progbits,DW.ref.__gxx_personality_v0,comdat
+; ALL: .section .data.DW.ref.__gxx_personality_v0,"awG", at progbits,DW.ref.__gxx_personality_v0,comdat
 ; O32: .p2align 2
 ; N32: .p2align 2
 ; N64: .p2align 3
diff --git a/llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll b/llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll
index 45aeb73b1a6ba9..025a5ad787fbe0 100644
--- a/llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll
+++ b/llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll
@@ -49,9 +49,9 @@ entry:
 ; LARGE-SECUREPLT:   addi 30, 30, .LTOC-.L0$pb at l
 ; LARGE-SECUREPLT:   bl call_foo at PLT+32768
 
-; LARGE:      .section .bss.bar1,"aGw", at nobits,bar1,comdat
+; LARGE:      .section .bss.bar1,"awG", at nobits,bar1,comdat
 ; LARGE:      bar1:
-; LARGE:      .section .bss.bar2,"aGw", at nobits,bar1,comdat
+; LARGE:      .section .bss.bar2,"awG", at nobits,bar1,comdat
 ; LARGE:      bar2:
 ; LARGE:      .section .got2,"aw", at progbits
 ; LARGE-NEXT: .p2align 2
diff --git a/llvm/test/CodeGen/SPARC/constructor.ll b/llvm/test/CodeGen/SPARC/constructor.ll
index e69ad26d09279a..dea152dd0f0892 100644
--- a/llvm/test/CodeGen/SPARC/constructor.ll
+++ b/llvm/test/CodeGen/SPARC/constructor.ll
@@ -17,11 +17,11 @@ entry:
 ; CTOR:      .section      .ctors,"aw"
 ; CTOR-NEXT: .p2align      2
 ; CTOR-NEXT: .word  f
-; CTOR-NEXT: .section      .ctors.65520,"aGw"
+; CTOR-NEXT: .section      .ctors.65520,"awG", at progbits,v,comdat{{$}}
 ; CTOR-NEXT: .p2align      2
 ; CTOR-NEXT: .word  g
 
-; INIT-ARRAY:    .section  .init_array.15,"aGw"
+; INIT-ARRAY:    .section  .init_array.15,"awG", at init_array,v,comdat{{$}}
 ; INIT-ARRAY-NEXT: .p2align  2
 ; INIT-ARRAY-NEXT: .word g
 ; INIT-ARRAY-NEXT: .section  .init_array,"aw"
diff --git a/llvm/test/CodeGen/X86/constructor.ll b/llvm/test/CodeGen/X86/constructor.ll
index 0fea69b5a7bcb5..3133979b32f837 100644
--- a/llvm/test/CodeGen/X86/constructor.ll
+++ b/llvm/test/CodeGen/X86/constructor.ll
@@ -43,17 +43,17 @@ entry:
 ; CTOR-NEXT:	.quad	j
 ; CTOR-NEXT:	.quad	i
 ; CTOR-NEXT:	.quad	f
-; CTOR-NEXT:	.section	.ctors.09980,"aGw", at progbits,v,comdat
+; CTOR-NEXT:	.section	.ctors.09980,"awG", at progbits,v,comdat
 ; CTOR-NEXT:	.p2align	3
 ; CTOR-NEXT:	.quad	h
-; CTOR-NEXT:	.section	.ctors.65520,"aGw", at progbits,v,comdat
+; CTOR-NEXT:	.section	.ctors.65520,"awG", at progbits,v,comdat
 ; CTOR-NEXT:	.p2align	3
 ; CTOR-NEXT:	.quad	g
 
-; INIT-ARRAY:		.section	.init_array.15,"aGw", at init_array,v,comdat
+; INIT-ARRAY:		.section	.init_array.15,"awG", at init_array,v,comdat
 ; INIT-ARRAY-NEXT:	.p2align	3
 ; INIT-ARRAY-NEXT:	.quad	g
-; INIT-ARRAY-NEXT:	.section	.init_array.55555,"aGw", at init_array,v,comdat
+; INIT-ARRAY-NEXT:	.section	.init_array.55555,"awG", at init_array,v,comdat
 ; INIT-ARRAY-NEXT:	.p2align	3
 ; INIT-ARRAY-NEXT:	.quad	h
 ; INIT-ARRAY-NEXT:	.section	.init_array,"aw", at init_array
@@ -62,10 +62,10 @@ entry:
 ; INIT-ARRAY-NEXT:	.quad	i
 ; INIT-ARRAY-NEXT:	.quad	j
 
-; NACL:		.section	.init_array.15,"aGw", at init_array,v,comdat
+; NACL:		.section	.init_array.15,"awG", at init_array,v,comdat
 ; NACL-NEXT:	.p2align	2
 ; NACL-NEXT:	.long	g
-; NACL-NEXT:	.section	.init_array.55555,"aGw", at init_array,v,comdat
+; NACL-NEXT:	.section	.init_array.55555,"awG", at init_array,v,comdat
 ; NACL-NEXT:	.p2align	2
 ; NACL-NEXT:	.long	h
 ; NACL-NEXT:	.section	.init_array,"aw", at init_array
diff --git a/llvm/test/CodeGen/X86/elf-comdat.ll b/llvm/test/CodeGen/X86/elf-comdat.ll
index 35d8d6f2d2af9b..10770dd07409d0 100644
--- a/llvm/test/CodeGen/X86/elf-comdat.ll
+++ b/llvm/test/CodeGen/X86/elf-comdat.ll
@@ -7,5 +7,5 @@ define void @f() comdat($f) {
 }
 ; CHECK: .section        .text.f,"axG", at progbits,f,comdat
 ; CHECK: .globl  f
-; CHECK: .section        .bss.v,"aGw", at nobits,f,comdat
+; CHECK: .section        .bss.v,"awG", at nobits,f,comdat
 ; CHECK: .globl  v
diff --git a/llvm/test/CodeGen/X86/elf-comdat2.ll b/llvm/test/CodeGen/X86/elf-comdat2.ll
index 786cec78cc30f7..3e43c43b7d7419 100644
--- a/llvm/test/CodeGen/X86/elf-comdat2.ll
+++ b/llvm/test/CodeGen/X86/elf-comdat2.ll
@@ -5,7 +5,7 @@ $foo = comdat any
 @foo = global i32 42
 
 ; CHECK:      .type   bar, at object
-; CHECK-NEXT: .section        .data.bar,"aGw", at progbits,foo,comdat
+; CHECK-NEXT: .section        .data.bar,"awG", at progbits,foo,comdat
 ; CHECK-NEXT: .globl  bar
 ; CHECK:      .type   foo, at object
 ; CHECK-NEXT: .data
diff --git a/llvm/test/CodeGen/X86/elf-group.ll b/llvm/test/CodeGen/X86/elf-group.ll
index 3aaef0fa49da13..a69ba491be0ffb 100644
--- a/llvm/test/CodeGen/X86/elf-group.ll
+++ b/llvm/test/CodeGen/X86/elf-group.ll
@@ -4,7 +4,7 @@
 
 ; CHECK: .section .text.f1,"axG", at progbits,f1{{$}}
 ; CHECK: .section .text.f2,"axG", at progbits,f1{{$}}
-; CHECK: .section .bss.g1,"aGw", at nobits,f1{{$}}
+; CHECK: .section .bss.g1,"awG", at nobits,f1{{$}}
 
 $f1 = comdat nodeduplicate
 
diff --git a/llvm/test/CodeGen/X86/explicit-section-mergeable.ll b/llvm/test/CodeGen/X86/explicit-section-mergeable.ll
index 0a3a60474e1ed9..09995919d95594 100644
--- a/llvm/test/CodeGen/X86/explicit-section-mergeable.ll
+++ b/llvm/test/CodeGen/X86/explicit-section-mergeable.ll
@@ -139,9 +139,9 @@
 !4 = !{ptr @implicit_rodata_cst4}
 
 ;; Test implicit section assignment for globals in distinct comdat groups.
-; CHECK: .section .rodata.cst4,"aGM", at progbits,4,f,comdat,unique,[[#U+7]]
+; CHECK: .section .rodata.cst4,"aMG", at progbits,4,f,comdat,unique,[[#U+7]]
 ; CHECK: implicit_rodata_cst4_comdat:
-; CHECK: .section .rodata.cst8,"aGM", at progbits,8,g,comdat,unique,[[#U+8]]
+; CHECK: .section .rodata.cst8,"aMG", at progbits,8,g,comdat,unique,[[#U+8]]
 ; CHECK: implicit_rodata_cst8_comdat:
 
 ;; Check that globals in distinct comdat groups that are explicitly assigned
@@ -153,11 +153,11 @@
 ;; are incorrect.
 ; CHECK: .section .explicit_comdat_distinct,"aM", at progbits,4,unique,[[#U+9]]
 ; CHECK: explicit_comdat_distinct_supply_uid:
-; CHECK: .section .explicit_comdat_distinct,"aGM", at progbits,4,f,comdat,unique,[[#U+10]]
+; CHECK: .section .explicit_comdat_distinct,"aMG", at progbits,4,f,comdat,unique,[[#U+10]]
 ; CHECK: explicit_comdat_distinct1:
-; CHECK: .section .explicit_comdat_distinct,"aGM", at progbits,4,g,comdat,unique,[[#U+10]]
+; CHECK: .section .explicit_comdat_distinct,"aMG", at progbits,4,g,comdat,unique,[[#U+10]]
 ; CHECK: explicit_comdat_distinct2:
-; CHECK: .section .explicit_comdat_distinct,"aGM", at progbits,8,h,comdat,unique,[[#U+11]]
+; CHECK: .section .explicit_comdat_distinct,"aMG", at progbits,8,h,comdat,unique,[[#U+11]]
 ; CHECK: explicit_comdat_distinct3:
 
 $f = comdat any
@@ -173,9 +173,9 @@ $h = comdat any
 @explicit_comdat_distinct3 = unnamed_addr constant [2 x i32] [i32 1, i32 1], section ".explicit_comdat_distinct", comdat($h)
 
 ;; Test implicit section assignment for globals in the same comdat group.
-; CHECK: .section .rodata.cst4,"aGM", at progbits,4,i,comdat,unique,[[#U+12]]
+; CHECK: .section .rodata.cst4,"aMG", at progbits,4,i,comdat,unique,[[#U+12]]
 ; CHECK: implicit_rodata_cst4_same_comdat:
-; CHECK: .section .rodata.cst8,"aGM", at progbits,8,i,comdat,unique,[[#U+13]]
+; CHECK: .section .rodata.cst8,"aMG", at progbits,8,i,comdat,unique,[[#U+13]]
 ; CHECK: implicit_rodata_cst8_same_comdat:
 
 ;; Check that globals in the same comdat group that are explicitly assigned
@@ -187,10 +187,10 @@ $h = comdat any
 ;; are incorrect.
 ; CHECK: .section .explicit_comdat_same,"aM", at progbits,4,unique,[[#U+14]]
 ; CHECK: explicit_comdat_same_supply_uid:
-; CHECK: .section .explicit_comdat_same,"aGM", at progbits,4,i,comdat,unique,[[#U+15]]
+; CHECK: .section .explicit_comdat_same,"aMG", at progbits,4,i,comdat,unique,[[#U+15]]
 ; CHECK: explicit_comdat_same1:
 ; CHECK: explicit_comdat_same2:
-; CHECK: .section .explicit_comdat_same,"aGM", at progbits,8,i,comdat,unique,[[#U+16]]
+; CHECK: .section .explicit_comdat_same,"aMG", at progbits,8,i,comdat,unique,[[#U+16]]
 ; CHECK: explicit_comdat_same3:
 
 $i = comdat any
diff --git a/llvm/test/CodeGen/X86/global-sections-comdat.ll b/llvm/test/CodeGen/X86/global-sections-comdat.ll
index 730050dda5f30e..7b793815f238db 100644
--- a/llvm/test/CodeGen/X86/global-sections-comdat.ll
+++ b/llvm/test/CodeGen/X86/global-sections-comdat.ll
@@ -41,6 +41,6 @@ bb5:
 $G16 = comdat any
 @G16 = unnamed_addr constant i32 42, comdat
 
-; LINUX: .section	.rodata.cst4.G16,"aGM", at progbits,4,G16,comdat
-; LINUX-SECTIONS: .section	.rodata.cst4.G16,"aGM", at progbits,4,G16,comdat
-; LINUX-SECTIONS-SHORT: .section	.rodata.cst4,"aGM", at progbits,4,G16,comdat
+; LINUX: .section	.rodata.cst4.G16,"aMG", at progbits,4,G16,comdat
+; LINUX-SECTIONS: .section	.rodata.cst4.G16,"aMG", at progbits,4,G16,comdat
+; LINUX-SECTIONS-SHORT: .section	.rodata.cst4,"aMG", at progbits,4,G16,comdat
diff --git a/llvm/test/DebugInfo/SystemZ/eh_frame_personality.ll b/llvm/test/DebugInfo/SystemZ/eh_frame_personality.ll
index e1c656c4b3eb7d..002da2f0e7f2e2 100644
--- a/llvm/test/DebugInfo/SystemZ/eh_frame_personality.ll
+++ b/llvm/test/DebugInfo/SystemZ/eh_frame_personality.ll
@@ -39,7 +39,7 @@ clean:
 ; CHECK-REF: .cfi_lsda 27, .Lexception0
 ; CHECK-REF: .hidden	DW.ref.__gxx_personality_v0
 ; CHECK-REF: .weak	DW.ref.__gxx_personality_v0
-; CHECK-REF: .section	.data.DW.ref.__gxx_personality_v0,"aGw", at progbits,DW.ref.__gxx_personality_v0,comdat
+; CHECK-REF: .section	.data.DW.ref.__gxx_personality_v0,"awG", at progbits,DW.ref.__gxx_personality_v0,comdat
 ; CHECK-REF-NEXT: .p2align	3
 ; CHECK-REF-NEXT: .type	DW.ref.__gxx_personality_v0, at object
 ; CHECK-REF-NEXT: .size	DW.ref.__gxx_personality_v0, 8
diff --git a/llvm/test/DebugInfo/SystemZ/eh_frame_personality.s b/llvm/test/DebugInfo/SystemZ/eh_frame_personality.s
index c452951941a16c..0c99361b4acf1d 100644
--- a/llvm/test/DebugInfo/SystemZ/eh_frame_personality.s
+++ b/llvm/test/DebugInfo/SystemZ/eh_frame_personality.s
@@ -25,7 +25,7 @@ foo:                                    # @foo
 
 	.hidden	DW.ref.__gxx_personality_v0
 	.weak	DW.ref.__gxx_personality_v0
-	.section	.data.DW.ref.__gxx_personality_v0,"aGw", at progbits,DW.ref.__gxx_personality_v0,comdat
+	.section	.data.DW.ref.__gxx_personality_v0,"awG", at progbits,DW.ref.__gxx_personality_v0,comdat
 	.align	8
 	.type	DW.ref.__gxx_personality_v0, at object
 	.size	DW.ref.__gxx_personality_v0, 8
diff --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_ehframe_basic.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_ehframe_basic.s
index 1b3ff16ea1495f..c01ced5d0523b4 100644
--- a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_ehframe_basic.s
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_ehframe_basic.s
@@ -106,7 +106,7 @@ GCC_except_table1:
 	.quad	_ZTIi
 	.hidden	DW.ref.__gxx_personality_v0
 	.weak	DW.ref.__gxx_personality_v0
-	.section	.data.DW.ref.__gxx_personality_v0,"aGw", at progbits,DW.ref.__gxx_personality_v0,comdat
+	.section	.data.DW.ref.__gxx_personality_v0,"awG", at progbits,DW.ref.__gxx_personality_v0,comdat
 	.p2align	3
 	.type	DW.ref.__gxx_personality_v0, at object
 	.size	DW.ref.__gxx_personality_v0, 8
diff --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_ehframe_large_static_personality_encodings.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_ehframe_large_static_personality_encodings.s
index 02538442d9d9ec..64990b5d38f079 100644
--- a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_ehframe_large_static_personality_encodings.s
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_ehframe_large_static_personality_encodings.s
@@ -190,7 +190,7 @@ GCC_except_table1:
 	.hidden	DW.ref.__gxx_personality_v0
 	.weak	DW.ref.__gxx_personality_v0
 
-	.section	.data.DW.ref.__gxx_personality_v0,"aGw", at progbits,DW.ref.__gxx_personality_v0,comdat
+	.section	.data.DW.ref.__gxx_personality_v0,"awG", at progbits,DW.ref.__gxx_personality_v0,comdat
 	.p2align	3
 	.type	DW.ref.__gxx_personality_v0, at object
 	.size	DW.ref.__gxx_personality_v0, 8
diff --git a/llvm/test/MC/ELF/alias-to-local.s b/llvm/test/MC/ELF/alias-to-local.s
index 5b6ac058c1e81c..beff230a8db30d 100644
--- a/llvm/test/MC/ELF/alias-to-local.s
+++ b/llvm/test/MC/ELF/alias-to-local.s
@@ -10,7 +10,7 @@ foo:
 	movl	$zed, %eax
 
 
-	.section	.data.bar,"aGw", at progbits,zed,comdat
+	.section	.data.bar,"awG", at progbits,zed,comdat
 bar:
 	.byte	42
 
diff --git a/llvm/test/MC/ELF/relocation.s b/llvm/test/MC/ELF/relocation.s
index 797e31f529b3db..80b671aa2c859e 100644
--- a/llvm/test/MC/ELF/relocation.s
+++ b/llvm/test/MC/ELF/relocation.s
@@ -4,7 +4,7 @@
 // Test that we produce the correct relocation.
 
 
-        .section	.pr23272,"aGw", at progbits,pr23272,comdat
+        .section	.pr23272,"awG", at progbits,pr23272,comdat
 	.globl pr23272
 pr23272:
 pr23272_2:
diff --git a/llvm/test/tools/llvm-symbolizer/frame.s b/llvm/test/tools/llvm-symbolizer/frame.s
index 28cbd493182e0d..741132ad32d752 100644
--- a/llvm/test/tools/llvm-symbolizer/frame.s
+++ b/llvm/test/tools/llvm-symbolizer/frame.s
@@ -203,7 +203,7 @@ hwasan.module_ctor:                     // @hwasan.module_ctor
 	.size	hwasan.module_ctor, .Lfunc_end1-hwasan.module_ctor
 	.cfi_endproc
                                         // -- End function
-	.section	.init_array.0,"aGw", at init_array,hwasan.module_ctor,comdat
+	.section	.init_array.0,"awG", at init_array,hwasan.module_ctor,comdat
 	.p2align	3
 	.xword	hwasan.module_ctor
 	.section	.debug_str,"MS", at progbits,1



More information about the llvm-commits mailing list