[lld] r294006 - Handle numbers followed by ":" in linker scripts.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 3 05:40:39 PST 2017


Sorry, forgot to add to the commit message:

Patch by Dmitry Mikulin!

Rafael Espindola via llvm-commits <llvm-commits at lists.llvm.org> writes:

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


More information about the llvm-commits mailing list