[PATCH] D51376: ELF: Don't examine values of linker script symbols during ICF.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 28 12:43:46 PDT 2018


pcc created this revision.
pcc added reviewers: ruiu, grimar.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.

These symbols are declared early with the same value, so they otherwise
appear identical to ICF.


Repository:
  rL LLVM

https://reviews.llvm.org/D51376

Files:
  lld/ELF/ICF.cpp
  lld/ELF/LinkerScript.cpp
  lld/ELF/Symbols.h
  lld/test/ELF/linkerscript/Inputs/icf.script
  lld/test/ELF/linkerscript/icf.s


Index: lld/test/ELF/linkerscript/icf.s
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/icf.s
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o %S/Inputs/icf.script -o %t --icf=all --print-icf-sections | count 0
+
+.section .text.foo,"ax", at progbits
+jmp foo
+
+.section .text.bar,"ax", at progbits
+jmp bar
Index: lld/test/ELF/linkerscript/Inputs/icf.script
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/Inputs/icf.script
@@ -0,0 +1,2 @@
+foo = 1;
+bar = 2;
Index: lld/ELF/Symbols.h
===================================================================
--- lld/ELF/Symbols.h
+++ lld/ELF/Symbols.h
@@ -115,6 +115,9 @@
   // True if this symbol is specified by --trace-symbol option.
   unsigned Traced : 1;
 
+  // True if this symbol is defined by a linker script.
+  unsigned ScriptDefined : 1;
+
   bool includeInDynsym() const;
   uint8_t computeBinding() const;
   bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; }
@@ -157,9 +160,10 @@
   Symbol(Kind K, InputFile *File, StringRefZ Name, uint8_t Binding,
          uint8_t StOther, uint8_t Type)
       : File(File), NameData(Name.Data), NameSize(Name.Size), Binding(Binding),
-        Type(Type), StOther(StOther), SymbolKind(K), NeedsPltAddr(false),
-        IsInIplt(false), IsInIgot(false), IsPreemptible(false),
-        Used(!Config->GcSections), NeedsTocRestore(false) {}
+        Type(Type), StOther(StOther), SymbolKind(K), ScriptDefined(false),
+        NeedsPltAddr(false), IsInIplt(false), IsInIgot(false),
+        IsPreemptible(false), Used(!Config->GcSections),
+        NeedsTocRestore(false) {}
 
 public:
   // True the symbol should point to its PLT entry.
@@ -371,6 +375,7 @@
   S->ExportDynamic = Sym.ExportDynamic;
   S->CanInline = Sym.CanInline;
   S->Traced = Sym.Traced;
+  S->ScriptDefined = Sym.ScriptDefined;
 
   // Print out a log message if --trace-symbol was specified.
   // This is for debugging.
Index: lld/ELF/LinkerScript.cpp
===================================================================
--- lld/ELF/LinkerScript.cpp
+++ lld/ELF/LinkerScript.cpp
@@ -209,6 +209,7 @@
                          STT_NOTYPE, 0, 0, nullptr);
   Cmd->Sym = cast<Defined>(Sym);
   Cmd->Provide = false;
+  Sym->ScriptDefined = true;
 }
 
 // This method is used to handle INSERT AFTER statement. Here we rebuild
Index: lld/ELF/ICF.cpp
===================================================================
--- lld/ELF/ICF.cpp
+++ lld/ELF/ICF.cpp
@@ -252,7 +252,7 @@
 
     auto *DA = dyn_cast<Defined>(&SA);
     auto *DB = dyn_cast<Defined>(&SB);
-    if (!DA || !DB)
+    if (!DA || !DB || DA->ScriptDefined || DB->ScriptDefined)
       return false;
 
     // Relocations referring to absolute symbols are constant-equal if their


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51376.162935.patch
Type: text/x-patch
Size: 2912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180828/24390d5b/attachment.bin>


More information about the llvm-commits mailing list