[lld] r340998 - ELF: Don't examine values of linker script symbols during ICF.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 29 16:43:38 PDT 2018


Author: pcc
Date: Wed Aug 29 16:43:38 2018
New Revision: 340998

URL: http://llvm.org/viewvc/llvm-project?rev=340998&view=rev
Log:
ELF: Don't examine values of linker script symbols during ICF.

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

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

Added:
    lld/trunk/test/ELF/linkerscript/icf.s
Modified:
    lld/trunk/ELF/ICF.cpp
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/Symbols.h

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=340998&r1=340997&r2=340998&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Wed Aug 29 16:43:38 2018
@@ -252,7 +252,10 @@ bool ICF<ELFT>::constantEq(const InputSe
 
     auto *DA = dyn_cast<Defined>(&SA);
     auto *DB = dyn_cast<Defined>(&SB);
-    if (!DA || !DB)
+
+    // Placeholder symbols generated by linker scripts look the same now but
+    // may have different values later.
+    if (!DA || !DB || DA->ScriptDefined || DB->ScriptDefined)
       return false;
 
     // Relocations referring to absolute symbols are constant-equal if their

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=340998&r1=340997&r2=340998&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Aug 29 16:43:38 2018
@@ -209,6 +209,7 @@ static void declareSymbol(SymbolAssignme
                          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

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=340998&r1=340997&r2=340998&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Aug 29 16:43:38 2018
@@ -164,7 +164,8 @@ protected:
       : 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) {}
+        Used(!Config->GcSections), NeedsTocRestore(false),
+        ScriptDefined(false) {}
 
 public:
   // True the symbol should point to its PLT entry.
@@ -187,6 +188,9 @@ public:
   // PPC64 toc pointer.
   unsigned NeedsTocRestore : 1;
 
+  // True if this symbol is defined by a linker script.
+  unsigned ScriptDefined : 1;
+
   // The Type field may also have this value. It means that we have not yet seen
   // a non-Lazy symbol with this name, so we don't know what its type is. The
   // Type field is normally set to this value for Lazy symbols unless we saw a
@@ -376,6 +380,7 @@ void replaceSymbol(Symbol *S, ArgT &&...
   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.

Added: lld/trunk/test/ELF/linkerscript/icf.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/icf.s?rev=340998&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/icf.s (added)
+++ lld/trunk/test/ELF/linkerscript/icf.s Wed Aug 29 16:43:38 2018
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+
+# RUN: echo "foo = 1; bar = 2;" > %t.script
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o %t.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




More information about the llvm-commits mailing list