[PATCH] D45440: [ELF] - Do not crash when trying to order --defsym/linker script symbols.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 9 07:06:08 PDT 2018


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

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


https://reviews.llvm.org/D45440

Files:
  ELF/Writer.cpp
  test/ELF/linkerscript/symbol-ordering-file2.s


Index: test/ELF/linkerscript/symbol-ordering-file2.s
===================================================================
--- test/ELF/linkerscript/symbol-ordering-file2.s
+++ test/ELF/linkerscript/symbol-ordering-file2.s
@@ -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
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1057,16 +1057,16 @@
       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());
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45440.141639.patch
Type: text/x-patch
Size: 1757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180409/06a9bdaa/attachment.bin>


More information about the llvm-commits mailing list