[PATCH] D101512: [CodeGen] don't emit addrsig symbol if it's used only by metadata

Zequan Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 28 21:42:25 PDT 2021


zequanwu created this revision.
zequanwu added reviewers: pcc, rnk.
Herald added subscribers: pengfei, hiraditya.
zequanwu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Value only used by metadata can be removed from .addrsig table.
This solves the undefined symbol error when enabling addrsig table on COFF LTO.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101512

Files:
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/test/CodeGen/X86/addrsig.ll


Index: llvm/test/CodeGen/X86/addrsig.ll
===================================================================
--- llvm/test/CodeGen/X86/addrsig.ll
+++ llvm/test/CodeGen/X86/addrsig.ll
@@ -19,9 +19,13 @@
   %a2 = bitcast i32* @a2 to i8*
   %i1 = bitcast void()* @i1 to i8*
   %i2 = bitcast void()* @i2 to i8*
+  call void @llvm.dbg.value(metadata i8* bitcast (void()* @metadata_f to i8*), metadata !5, metadata !DIExpression()), !dbg !7
   unreachable
 }
 
+; CHECK-NOT: .addrsig_sym metadata_f
+declare void @metadata_f()
+
 ; CHECK-NOT: .addrsig_sym f2
 define internal void @f2() local_unnamed_addr {
   unreachable
@@ -55,3 +59,17 @@
 @i1 = ifunc void(), void()* @f1
 ; CHECK-NOT: .addrsig_sym i2
 @i2 = internal local_unnamed_addr ifunc void(), void()* @f2
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
+!1 = !DIFile(filename: "a", directory: "")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)
+!4 = !DILocation(line: 0, scope: !3)
+!5 = !DILocalVariable(scope: !6)
+!6 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)
+!7 = !DILocation(line: 0, scope: !6, inlinedAt: !4)
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1847,11 +1847,20 @@
   if (TM.Options.EmitAddrsig) {
     // Emit address-significance attributes for all globals.
     OutStreamer->emitAddrsig();
-    for (const GlobalValue &GV : M.global_values())
+    for (const GlobalValue &GV : M.global_values()) {
+      if (!GV.use_empty()) {
+        unsigned MetadataCount = 0;
+        for (auto U = GV.user_begin(), E = GV.user_end(); U != E; ++U)
+          if (U->isUsedByMetadata())
+            ++MetadataCount;
+        if (MetadataCount == GV.getNumUses())
+          continue;
+      }
       if (!GV.use_empty() && !GV.isThreadLocal() &&
           !GV.hasDLLImportStorageClass() && !GV.getName().startswith("llvm.") &&
           !GV.hasAtLeastLocalUnnamedAddr())
         OutStreamer->emitAddrsigSym(getSymbol(&GV));
+    }
   }
 
   // Emit symbol partition specifications (ELF only).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101512.341401.patch
Type: text/x-patch
Size: 2497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210429/b922aa1a/attachment.bin>


More information about the llvm-commits mailing list