Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -1919,17 +1919,20 @@ 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 Locals = readSymbols(); for (SymbolVersion V : Locals) { if (V.Name == "*") { @@ -1948,9 +1951,11 @@ 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("}"); @@ -1974,7 +1979,7 @@ continue; } - if (peek() == "}" || peek() == "local:" || Error) + if (peek() == "}" || peek() == "local" || Error) break; StringRef Tok = next(); Ret.push_back({unquote(Tok), false, hasWildcard(Tok)}); Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -104,7 +104,7 @@ // 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. Index: test/ELF/linkerscript/numbers.s =================================================================== --- test/ELF/linkerscript/numbers.s +++ test/ELF/linkerscript/numbers.s @@ -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 Index: test/ELF/version-script.s =================================================================== --- test/ELF/version-script.s +++ test/ELF/version-script.s @@ -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