[PATCH] D97436: [lld-link] Fix addrsig symbols merging in ICF.

Zequan Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 20:15:41 PST 2021


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

Addrsig symbols inside executable sections will be merged during ICF, this patch
fixes it.

This causes 13 tests failed in lld-link, because lld-link mark all symbols as
address-sigfinicant if the address-sigfinicant table doesn't exist. There is no
command line argument to control this behavior. In ld.lld, this can be
controlled by `-icf=all` to disable it. A workaround could be to simply add an
empty `.addrsig` section to those failing tests. I am worried that adding a flag
argument similar to ld.lld to control this will not align with the flag commands
of MSVC Linker.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97436

Files:
  lld/COFF/ICF.cpp
  lld/test/COFF/icf-safe.s


Index: lld/test/COFF/icf-safe.s
===================================================================
--- lld/test/COFF/icf-safe.s
+++ lld/test/COFF/icf-safe.s
@@ -2,11 +2,13 @@
 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-win32 %s -o %t1.obj
 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-win32 %S/Inputs/icf-safe.s -o %t2.obj
 # RUN: lld-link /dll /noentry /out:%t.dll /verbose /opt:noref,icf %t1.obj %t2.obj 2>&1 | FileCheck %s
-# RUN: lld-link /dll /noentry /out:%t.dll /verbose /opt:noref,icf /export:g3 /export:g4 %t1.obj %t2.obj 2>&1 | FileCheck --check-prefix=EXPORT %s
+# RUN: lld-link /dll /noentry /out:%t.dll /verbose /opt:noref,icf /export:g3 /export:g4 /export:f3 /export:f4 %t1.obj %t2.obj 2>&1 | FileCheck --check-prefix=EXPORT %s
 
 # CHECK-NOT: Selected
 # CHECK: Selected g3
 # CHECK-NEXT:   Removed g4
+# CHECK: Selected f3
+# CHECK-NEXT:   Removed f4
 # CHECK-NOT: Removed
 # CHECK-NOT: Selected
 
@@ -32,6 +34,28 @@
 g4:
 .byte 2
 
+.section .text,"xr",one_only,f1
+.globl f1
+f1:
+ nop
+
+.section .text,"xr",one_only,f2
+.globl f2
+f2:
+ nop
+
+.section .text,"xr",one_only,f3
+.globl f3
+f3:
+ nop
+
+.section .text,"xr",one_only,f4
+.globl f4
+f4:
+ nop
+
 .addrsig
 .addrsig_sym g1
 .addrsig_sym g2
+.addrsig_sym f1
+.addrsig_sym f2
\ No newline at end of file
Index: lld/COFF/ICF.cpp
===================================================================
--- lld/COFF/ICF.cpp
+++ lld/COFF/ICF.cpp
@@ -76,9 +76,10 @@
 // section is insignificant to the user program and the behaviour matches that
 // of the Visual C++ linker.
 bool ICF::isEligible(SectionChunk *c) {
-  // Non-comdat chunks, dead chunks, and writable chunks are not eligible.
+  // Non-comdat chunks, dead chunks, writable chunks and chunks in the
+  // address-significance table are not eligible.
   bool writable = c->getOutputCharacteristics() & llvm::COFF::IMAGE_SCN_MEM_WRITE;
-  if (!c->isCOMDAT() || !c->live || writable)
+  if (!c->isCOMDAT() || !c->live || writable || c->keepUnique)
     return false;
 
   // Code sections are eligible.
@@ -94,8 +95,8 @@
   if (c->sym && c->sym->getName().startswith("??_7"))
     return true;
 
-  // Anything else not in an address-significance table is eligible.
-  return !c->keepUnique;
+  // Anything else is eligible.
+  return true;
 }
 
 // Split an equivalence class into smaller classes.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97436.326272.patch
Type: text/x-patch
Size: 2339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210225/75a62791/attachment.bin>


More information about the llvm-commits mailing list