[lld] r329678 - [ELF] - Do not crash when trying to order --defsym/linker script symbols.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 10 02:44:44 PDT 2018


Author: grimar
Date: Tue Apr 10 02:44:44 2018
New Revision: 329678

URL: http://llvm.org/viewvc/llvm-project?rev=329678&view=rev
Log:
[ELF] - Do not crash when trying to order --defsym/linker script symbols.

Currently, we crash because File is null for
such symbols.

Differential revision: https://reviews.llvm.org/D45440

Added:
    lld/trunk/test/ELF/linkerscript/symbol-ordering-file2.s
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=329678&r1=329677&r2=329678&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Apr 10 02:44:44 2018
@@ -1057,16 +1057,16 @@ static DenseMap<const InputSectionBase *
       auto *D = dyn_cast<Defined>(&Sym);
       InputFile *File = Sym.File;
       if (Sym.isUndefined())
-        warn(File->getName() +
+        warn(toString(File) +
              ": unable to order undefined symbol: " + Sym.getName());
       else if (Sym.isShared())
-        warn(File->getName() +
+        warn(toString(File) +
              ": unable to order shared symbol: " + Sym.getName());
       else if (D && !D->Section)
-        warn(File->getName() +
+        warn(toString(File) +
              ": unable to order absolute symbol: " + Sym.getName());
       else if (D && !D->Section->Live)
-        warn(File->getName() +
+        warn(toString(File) +
              ": unable to order discarded symbol: " + Sym.getName());
     }
 

Added: lld/trunk/test/ELF/linkerscript/symbol-ordering-file2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/symbol-ordering-file2.s?rev=329678&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/symbol-ordering-file2.s (added)
+++ lld/trunk/test/ELF/linkerscript/symbol-ordering-file2.s Tue Apr 10 02:44:44 2018
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+
+## Check we do not crash when trying to order linker script symbol.
+
+# RUN: echo "bar" > %t.ord
+# RUN: echo "SECTIONS { bar = 1; }" > %t.script
+# RUN: ld.lld --symbol-ordering-file %t.ord %t.o --script %t.script \
+# RUN:   -o %t.out 2>&1 | FileCheck %s
+# CHECK: warning: <internal>: unable to order absolute symbol: bar
+
+## Check we do not crash when trying to order --defsym symbol.
+
+# RUN: echo "bar" > %t.ord
+# RUN: ld.lld --symbol-ordering-file %t.ord %t.o -defsym=bar=1 \
+# RUN:   -o %t.out 2>&1 | FileCheck %s




More information about the llvm-commits mailing list