<div dir="auto"><div>Does this accept "{ global: local; }"?</div><div dir="auto"><br><div dir="auto">Peter</div><br><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">On Feb 3, 2017 5:35 AM, "Rafael Espindola via llvm-commits" <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Fri Feb 3 07:24:01 2017<br>
New Revision: 294006<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=294006&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=294006&view=rev</a><br>
Log:<br>
Handle numbers followed by ":" in linker scripts.<br>
<br>
This is a fix for Bugzilla 31813.<br>
<br>
The problem is that the tokenizer does not create a separate token for<br>
":" unless there's white space before it. Changed it to always create<br>
a token for ":" and reworked some logic that relied on ":" being<br>
attached to some tokens like "global:" and "local:".<br>
<br>
Modified:<br>
lld/trunk/ELF/LinkerScript.cpp<br>
lld/trunk/ELF/ScriptParser.cpp<br>
lld/trunk/test/ELF/<wbr>linkerscript/numbers.s<br>
lld/trunk/test/ELF/version-<wbr>script.s<br>
<br>
Modified: lld/trunk/ELF/LinkerScript.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=294006&r1=294005&r2=294006&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>LinkerScript.cpp?rev=294006&<wbr>r1=294005&r2=294006&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/LinkerScript.cpp (original)<br>
+++ lld/trunk/ELF/LinkerScript.cpp Fri Feb 3 07:24:01 2017<br>
@@ -1938,17 +1938,20 @@ unsigned ScriptParser::readPhdrType() {<br>
void ScriptParser::<wbr>readAnonymousDeclaration() {<br>
// Read global symbols first. "global:" is default, so if there's<br>
// no label, we assume global symbols.<br>
- if (consume("global:") || peek() != "local:")<br>
+ if (peek() != "local") {<br>
+ if (consume("global"))<br>
+ expect(":");<br>
Config->VersionScriptGlobals = readSymbols();<br>
-<br>
+ }<br>
readLocals();<br>
expect("}");<br>
expect(";");<br>
}<br>
<br>
void ScriptParser::readLocals() {<br>
- if (!consume("local:"))<br>
+ if (!consume("local"))<br>
return;<br>
+ expect(":");<br>
std::vector<SymbolVersion> Locals = readSymbols();<br>
for (SymbolVersion V : Locals) {<br>
if (V.Name == "*") {<br>
@@ -1967,9 +1970,11 @@ void ScriptParser::<wbr>readVersionDeclaratio<br>
Config->VersionDefinitions.<wbr>push_back({VerStr, VersionId});<br>
<br>
// Read global symbols.<br>
- if (consume("global:") || peek() != "local:")<br>
+ if (peek() != "local") {<br>
+ if (consume("global"))<br>
+ expect(":");<br>
Config->VersionDefinitions.<wbr>back().Globals = readSymbols();<br>
-<br>
+ }<br>
readLocals();<br>
expect("}");<br>
<br>
@@ -1993,7 +1998,7 @@ std::vector<SymbolVersion> ScriptParser:<br>
continue;<br>
}<br>
<br>
- if (peek() == "}" || peek() == "local:" || Error)<br>
+ if (peek() == "}" || peek() == "local" || Error)<br>
break;<br>
StringRef Tok = next();<br>
Ret.push_back({unquote(Tok), false, hasWildcard(Tok)});<br>
<br>
Modified: lld/trunk/ELF/ScriptParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=294006&r1=294005&r2=294006&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>ScriptParser.cpp?rev=294006&<wbr>r1=294005&r2=294006&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/ScriptParser.cpp (original)<br>
+++ lld/trunk/ELF/ScriptParser.cpp Fri Feb 3 07:24:01 2017<br>
@@ -104,7 +104,7 @@ void ScriptParserBase::tokenize(<wbr>MemoryBu<br>
// so that you can write "file-name.cpp" as one bare token, for example.<br>
size_t Pos = S.find_first_not_of(<br>
"<wbr>ABCDEFGHIJKLMNOPQRSTUVWXYZabcd<wbr>efghijklmnopqrstuvwxyz"<br>
- "0123456789_.$/\\~=+[]*?-:!<>^<wbr>");<br>
+ "0123456789_.$/\\~=+[]*?-!<>^"<wbr>);<br>
<br>
// A character that cannot start a word (which is usually a<br>
// punctuation) forms a single character token.<br>
<br>
Modified: lld/trunk/test/ELF/<wbr>linkerscript/numbers.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/numbers.s?rev=294006&r1=294005&r2=294006&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/ELF/<wbr>linkerscript/numbers.s?rev=<wbr>294006&r1=294005&r2=294006&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/test/ELF/<wbr>linkerscript/numbers.s (original)<br>
+++ lld/trunk/test/ELF/<wbr>linkerscript/numbers.s Fri Feb 3 07:24:01 2017<br>
@@ -49,6 +49,20 @@<br>
# RUN: FileCheck --check-prefix=ERR3 %s<br>
# ERR3: malformed number: 0x11m<br>
<br>
+## Make sure that numbers can be followed by a ":" with and without a space,<br>
+## e.g. "0x100 :" or "0x100:"<br>
+# RUN: echo "SECTIONS { \<br>
+# RUN: .hex1 0x400 : { *(.hex.1) } \<br>
+# RUN: .hex2 0x500:{ *(.hex.2) } \<br>
+# RUN: }" > %t5.script<br>
+# RUN: ld.lld %t --script %t5.script -o %t6<br>
+# RUN: llvm-objdump -section-headers %t6 | FileCheck -check-prefix=SECADDR %s<br>
+# SECADDR: Sections:<br>
+# SECADDR-NEXT: Idx Name Size Address<br>
+# SECADDR-NEXT: 0 00000000 0000000000000000<br>
+# SECADDR-NEXT: 1 .hex1 00000008 0000000000000400<br>
+# SECADDR-NEXT: 2 .hex2 00000008 0000000000000500<br>
+<br>
.globl _start<br>
_start:<br>
nop<br>
<br>
Modified: lld/trunk/test/ELF/version-<wbr>script.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/version-script.s?rev=294006&r1=294005&r2=294006&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/ELF/<wbr>version-script.s?rev=294006&<wbr>r1=294005&r2=294006&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/test/ELF/version-<wbr>script.s (original)<br>
+++ lld/trunk/test/ELF/version-<wbr>script.s Fri Feb 3 07:24:01 2017<br>
@@ -14,7 +14,8 @@<br>
# RUN: ld.lld --version-script %t3.script -shared %t.o %t2.so -o %t3.so<br>
# RUN: llvm-readobj -dyn-symbols %t3.so | FileCheck --check-prefix=DSO2 %s<br>
<br>
-# RUN: echo "VERSION_1.0 { global: foo1; local: *; };" > %t4.script<br>
+## Also check that both "global:" and "global :" forms are accepted<br>
+# RUN: echo "VERSION_1.0 { global : foo1; local : *; };" > %t4.script<br>
# RUN: echo "VERSION_2.0 { global: foo3; local: *; };" >> %t4.script<br>
# RUN: ld.lld --version-script %t4.script -shared %t.o %t2.so -o %t4.so<br>
# RUN: llvm-readobj -dyn-symbols %t4.so | FileCheck --check-prefix=VERDSO %s<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div></div>