[lld] r353756 - lld: unquote possibly quoted `EXTERN("symbol")` entry in linker script.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 11 14:01:33 PST 2019
Author: ruiu
Date: Mon Feb 11 14:01:32 2019
New Revision: 353756
URL: http://llvm.org/viewvc/llvm-project?rev=353756&view=rev
Log:
lld: unquote possibly quoted `EXTERN("symbol")` entry in linker script.
gold accepts quoted strings. binutils requires quoted strings for some
kinds of symbols, e.g.:
it accepts quoted symbols with @ in name:
$ echo 'EXTERN("__libc_start_main@@GLIBC_2.2.5")' > a.script
$ g++ a.script
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
but rejects them if unquoted:
$ echo 'EXTERN(__libc_start_main@@GLIBC_2.2.5)' > a.script
$ g++ a.script
a.script: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
To maintain compatibility with existing linker scripts support quoted
strings in lld as well.
Patch by Lucian Adrian Grijincu.
Differential Revision: https://reviews.llvm.org/D57987
Modified:
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/linkerscript/linkerscript.s
lld/trunk/test/ELF/undefined-opt.s
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=353756&r1=353755&r2=353756&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Mon Feb 11 14:01:32 2019
@@ -329,7 +329,7 @@ void ScriptParser::readEntry() {
void ScriptParser::readExtern() {
expect("(");
while (!errorCount() && !consume(")"))
- Config->Undefined.push_back(next());
+ Config->Undefined.push_back(unquote(next()));
}
void ScriptParser::readGroup() {
Modified: lld/trunk/test/ELF/linkerscript/linkerscript.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript.s?rev=353756&r1=353755&r2=353756&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript.s (original)
+++ lld/trunk/test/ELF/linkerscript/linkerscript.s Mon Feb 11 14:01:32 2019
@@ -3,7 +3,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
# RUN: %p/Inputs/libsearch-st.s -o %t2.o
-# RUN: echo "EXTERN( undef undef2 )" > %t.script
+# RUN: echo "EXTERN( undef undef2 \"undef3\" \"undef4@@other\")" > %t.script
# RUN: ld.lld %t -o %t2 %t.script
# RUN: llvm-readobj %t2 > /dev/null
Modified: lld/trunk/test/ELF/undefined-opt.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/undefined-opt.s?rev=353756&r1=353755&r2=353756&view=diff
==============================================================================
--- lld/trunk/test/ELF/undefined-opt.s (original)
+++ lld/trunk/test/ELF/undefined-opt.s Mon Feb 11 14:01:32 2019
@@ -40,7 +40,7 @@
# TWO-UNDEFINED: Name: zed
# TWO-UNDEFINED: ]
# Now the same logic but linker script is used to set undefines
-# RUN: echo "EXTERN( bar abs )" > %t.script
+# RUN: echo "EXTERN( bar \"abs\" )" > %t.script
# RUN: ld.lld -o %t3 %t.o %tar.a %t.script
# RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TWO-UNDEFINED %s
More information about the llvm-commits
mailing list