[PATCH] D50498: [LLD][ELF] - Fix crash when using empty --defsym.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 9 02:12:13 PDT 2018


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

We have a crash issue when handling the empty -defsym.

For parsing this option we are using ScriptParser class which is used
generally for reading the linker script. For empty defsym case, we
pass the empty memory buffer and crash in the place removed in https://reviews.llvm.org/rL336436.

But reverting of the above patch would not help here (we would still crash but a bit later). And
even after fixing the crash we would report something like
"lld.exe: error: -defsym:1: unexpected EOF"
It is probably not the appropriate message because mentions EOF.

I think the issue should be handled on a higher level like this patch does.
So we do not want to pass the empty memory buffer first of all I believe.


https://reviews.llvm.org/D50498

Files:
  ELF/Driver.cpp
  test/ELF/defsym.s


Index: test/ELF/defsym.s
===================================================================
--- test/ELF/defsym.s
+++ test/ELF/defsym.s
@@ -68,8 +68,12 @@
 # EXPR-NEXT:   Section: Absolute
 # EXPR-NEXT: }
 
-# RUN: not ld.lld -o %t %t.o --defsym=foo2=und 2>&1 | FileCheck %s -check-prefix=ERR
-# ERR: error: -defsym:1: symbol not found: und
+# RUN: not ld.lld -o %t %t.o --defsym=foo2=und 2>&1 | FileCheck %s -check-prefix=ERR1
+# ERR1: error: -defsym:1: symbol not found: und
+
+# RUN: not ld.lld -o %t %t.o --defsym= 2>&1 | FileCheck %s -check-prefix=ERR2
+# RUN: not ld.lld -o %t %t.o --defsym=foo 2>&1 | FileCheck %s -check-prefix=ERR2
+# ERR2: error: -defsym: syntax error
 
 .globl foo1
  foo1 = 0x123
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -1026,7 +1026,10 @@
       StringRef From;
       StringRef To;
       std::tie(From, To) = StringRef(Arg->getValue()).split('=');
-      readDefsym(From, MemoryBufferRef(To, "-defsym"));
+      if (From.empty() || To.empty())
+        error("-defsym: syntax error");
+      else
+        readDefsym(From, MemoryBufferRef(To, "-defsym"));
       break;
     }
     case OPT_script:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50498.159881.patch
Type: text/x-patch
Size: 1222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180809/8229d558/attachment.bin>


More information about the llvm-commits mailing list