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

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 20 23:54:04 PDT 2021


phosek updated this revision to Diff 339113.
Herald added a subscriber: pengfei.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100909/new/

https://reviews.llvm.org/D100909

Files:
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/test/CodeGen/X86/elf-group-gcc_except_table.ll


Index: llvm/test/CodeGen/X86/elf-group-gcc_except_table.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/elf-group-gcc_except_table.ll
@@ -0,0 +1,27 @@
+; Checks that the generated .gcc_except_table for function in comdat with
+; noduplicates kind is lowered to a zero-flag ELF section group.
+; RUN: llc < %s -mtriple=x86_64-unknown-linux | FileCheck %s
+
+; CHECK-LABEL:       group:
+; CHECK:             .cfi_endproc
+; CHECK-NEXT:        .section .gcc_except_table.group,"aG", at progbits,group{{$}}
+
+ at _ZTIi = external constant i8*
+
+$group = comdat noduplicates
+
+define i32 @group() uwtable comdat personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+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(...)
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -890,9 +890,11 @@
   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 @@
   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);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100909.339113.patch
Type: text/x-patch
Size: 2097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210421/21fd0e0f/attachment.bin>


More information about the llvm-commits mailing list