[PATCH] D57987: lld: unquote possibly quoted `EXTERN("symbol")` entry in linker script
Lucian Adrian Grijincu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 8 16:39:52 PST 2019
luciang created this revision.
luciang added a reviewer: ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
`gold` accepts quoted strings:
name=gold/yyscript.y
252┊ file_cmd:
253┊ EXTERN '(' extern_name_list ')'
312┊ /* A list of external undefined symbols. We put the lexer into
313┊ expression mode so that commas separate names; this is what the GNU
314┊ linker does. */
315┊
316┊ extern_name_list:
317┊ { script_push_lex_into_expression_mode(closure); }
318┊ extern_name_list_body
319┊ { script_pop_lex_mode(closure); }
320┊ ;
321┊
322┊ extern_name_list_body:
323┊ string
324┊ { script_add_extern(closure, $1.value, $1.length); }
325┊ | extern_name_list_body string
326┊ { script_add_extern(closure, $2.value, $2.length); }
327┊ | extern_name_list_body ',' string
328┊ { script_add_extern(closure, $3.value, $3.length); }
329┊ ;
330┊
1123┊ /* A string can be either a STRING or a QUOTED_STRING. Almost all the
1124┊ time we don't care, and we use this rule. */
1125┊ string:
1126┊ STRING
1127┊ { $$ = $1; }
1128┊ | QUOTED_STRING
1129┊ { $$ = $1; }
1130┊ ;
`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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D57987
Files:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/linkerscript.s
Index: lld/test/ELF/linkerscript/linkerscript.s
===================================================================
--- lld/test/ELF/linkerscript/linkerscript.s
+++ lld/test/ELF/linkerscript/linkerscript.s
@@ -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
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -329,7 +329,7 @@
void ScriptParser::readExtern() {
expect("(");
while (!errorCount() && !consume(")"))
- Config->Undefined.push_back(next());
+ Config->Undefined.push_back(unquote(next()));
}
void ScriptParser::readGroup() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57987.186075.patch
Type: text/x-patch
Size: 934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190209/4471cf90/attachment.bin>
More information about the llvm-commits
mailing list