[llvm] 7a718e1 - [MC] Use COMDAT for LSDA only if IR comdat type is any

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 21 14:41:58 PDT 2021


Author: Petr Hosek
Date: 2021-04-21T14:41:39-07:00
New Revision: 7a718e16302314352227188fc82f757468a75e0b

URL: https://github.com/llvm/llvm-project/commit/7a718e16302314352227188fc82f757468a75e0b
DIFF: https://github.com/llvm/llvm-project/commit/7a718e16302314352227188fc82f757468a75e0b.diff

LOG: [MC] Use COMDAT for LSDA only if IR comdat type is any

This fixed issue introduced in 16af97393346ad636298605930a8b503a55eb40a
and 796feb61637c407aefcc0d462f24a1cc41f350d8.

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

Added: 
    

Modified: 
    llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
    llvm/test/CodeGen/X86/gcc_except_table-multi.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 0c8a92180969..6fed2ee12524 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -890,9 +890,11 @@ MCSection *TargetLoweringObjectFileELF::getSectionForLSDA(
   unsigned Flags = LSDA->getFlags();
   const MCSymbolELF *LinkedToSym = nullptr;
   StringRef Group;
+  bool IsComdat = false;
   if (const Comdat *C = getELFComdat(&F)) {
     Flags |= ELF::SHF_GROUP;
     Group = C->getName();
+    IsComdat = C->getSelectionKind() == Comdat::Any;
   }
   // Use SHF_LINK_ORDER to facilitate --gc-sections if we can use GNU ld>=2.36
   // or LLD, which support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER.
@@ -908,7 +910,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForLSDA(
   return getContext().getELFSection(
       (TM.getUniqueSectionNames() ? LSDA->getName() + "." + F.getName()
                                   : LSDA->getName()),
-      LSDA->getType(), Flags, 0, Group, F.hasComdat(), MCSection::NonUniqueID,
+      LSDA->getType(), Flags, 0, Group, IsComdat, MCSection::NonUniqueID,
       LinkedToSym);
 }
 

diff  --git a/llvm/test/CodeGen/X86/gcc_except_table-multi.ll b/llvm/test/CodeGen/X86/gcc_except_table-multi.ll
index c1bd86e3d9b4..962050f7a6e6 100644
--- a/llvm/test/CodeGen/X86/gcc_except_table-multi.ll
+++ b/llvm/test/CodeGen/X86/gcc_except_table-multi.ll
@@ -53,6 +53,28 @@ eh.resume:
   resume { i8*, i32 } %0
 }
 
+;; If the function is in a comdat group with noduplicates kind, the generated
+;; .gcc_except_table should is lowered to a zero-flag ELF section group.
+$zero = comdat noduplicates
+define i32 @zero() uwtable comdat personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+; CHECK-LABEL:       zero:
+; 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_NOUNIQUE-NEXT: .section .gcc_except_table,"aG", at progbits,zero{{$}}
+; NOUNIQUE-NEXT:     .section .gcc_except_table,"aG", at progbits,zero{{$}}
+entry:
+  invoke void @ext() to label %try.cont unwind label %lpad
+lpad:
+  %0 = landingpad { i8*, i32 } catch i8* bitcast (i8** @_ZTIi to i8*)
+  br label %eh.resume
+try.cont:
+  ret i32 0
+eh.resume:
+  resume { i8*, i32 } %0
+}
+
 declare void @ext()
 
 declare i32 @__gxx_personality_v0(...)


        


More information about the llvm-commits mailing list