[lld] r332059 - COFF: Allow ICF on vtable sections.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu May 10 16:31:58 PDT 2018


Author: pcc
Date: Thu May 10 16:31:58 2018
New Revision: 332059

URL: http://llvm.org/viewvc/llvm-project?rev=332059&view=rev
Log:
COFF: Allow ICF on vtable sections.

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

Added:
    lld/trunk/test/COFF/icf-vtables.s
Modified:
    lld/trunk/COFF/ICF.cpp

Modified: lld/trunk/COFF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=332059&r1=332058&r2=332059&view=diff
==============================================================================
--- lld/trunk/COFF/ICF.cpp (original)
+++ lld/trunk/COFF/ICF.cpp Thu May 10 16:31:58 2018
@@ -77,9 +77,10 @@ uint32_t ICF::getHash(SectionChunk *C) {
 // 2017) says that /opt:icf folds both functions and read-only data.
 // Despite that, the MSVC linker folds only functions. We found
 // a few instances of programs that are not safe for data merging.
-// Therefore, we merge only functions just like the MSVC tool. However, we merge
-// identical .xdata sections, because the address of unwind information is
-// insignificant to the user program and the Visual C++ linker does this.
+// Therefore, we merge only functions just like the MSVC tool. However, we also
+// merge read-only sections in a couple of cases where the address of the
+// 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 elegible.
   bool Writable = C->getOutputCharacteristics() & llvm::COFF::IMAGE_SCN_MEM_WRITE;
@@ -90,8 +91,12 @@ bool ICF::isEligible(SectionChunk *C) {
   if (C->getOutputCharacteristics() & llvm::COFF::IMAGE_SCN_MEM_EXECUTE)
     return true;
 
-  // .xdata unwind info sections are eligble.
-  return C->getSectionName().split('$').first == ".xdata";
+  // .xdata unwind info sections are eligible.
+  if (C->getSectionName().split('$').first == ".xdata")
+    return true;
+
+  // So are vtables.
+  return C->Sym && C->Sym->getName().startswith("??_7");
 }
 
 // Split an equivalence class into smaller classes.

Added: lld/trunk/test/COFF/icf-vtables.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/icf-vtables.s?rev=332059&view=auto
==============================================================================
--- lld/trunk/test/COFF/icf-vtables.s (added)
+++ lld/trunk/test/COFF/icf-vtables.s Thu May 10 16:31:58 2018
@@ -0,0 +1,28 @@
+# REQUIRES: x86
+# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s
+# RUN: lld-link %t.obj /out:%t.exe /entry:main /subsystem:console
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+.globl main
+main:
+# CHECK-NEXT: 140001000 00200040 01000000 01200040 01000000
+.8byte "??_"
+.8byte "??_7"
+# CHECK-NEXT: 140001010 01200040 01000000
+.8byte "??_7a"
+
+.section .rdata,"dr",discard,"??_"
+.globl "??_"
+"??_":
+.byte 42
+
+.section .rdata,"dr",discard,"??_7"
+.globl "??_7"
+"??_7":
+.byte 42
+
+.section .rdata,"dr",discard,"??_7a"
+.globl "??_7a"
+"??_7a":
+.byte 42




More information about the llvm-commits mailing list