Index: ELF/SymbolListFile.cpp =================================================================== --- ELF/SymbolListFile.cpp +++ ELF/SymbolListFile.cpp @@ -78,23 +78,34 @@ }; void VersionScriptParser::run() { - expect("{"); - if (peek() == "global:") { - next(); - while (!Error) { - Config->VersionScriptGlobals.push_back(next()); - expect(";"); - if (peek() == "local:") - break; + size_t Id = 0; + bool HasAnonymousTag = false; + while (!atEOF() && !Error) { + if (peek() == "{") + HasAnonymousTag = true; + else + next(); + if (Id > 0 && HasAnonymousTag) + setError("anonymous version tag cannot be " + "combined with other version tag"); + + expect("{"); + if (peek() == "global:") { + next(); + while (!Error) { + Config->VersionScriptGlobals.push_back(next()); + expect(";"); + if (peek() == "local:") + break; + } } + expect("local:"); + expect("*"); + expect(";"); + expect("}"); + expect(";"); + ++Id; } - expect("local:"); - expect("*"); - expect(";"); - expect("}"); - expect(";"); - if (!atEOF()) - setError("expected EOF"); } void elf::parseVersionScript(MemoryBufferRef MB) { Index: test/ELF/version-script.s =================================================================== --- test/ELF/version-script.s +++ test/ELF/version-script.s @@ -17,6 +17,28 @@ # RUN: ld.lld --version-script %t.script --dynamic-list %t.list %t.o %t2.so -o %t # RUN: llvm-readobj -dyn-symbols %t | FileCheck --check-prefix=EXE %s +# RUN: echo "VERSION_1.0{ \ +# RUN: global: foo1; \ +# RUN: local: *; }; \ +# RUN: VERSION_2.0{ \ +# RUN: global: foo3; \ +# RUN: 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=DSO %s + +# RUN: echo "VERSION_1.0{ \ +# RUN: global: foo1; \ +# RUN: local: *; }; \ +# RUN: { \ +# RUN: global: foo3; \ +# RUN: local: *; }; " > %t5.script +# RUN: not ld.lld --version-script %t5.script -shared %t.o %t2.so -o %t5.so 2>&1 | \ +# RUN: FileCheck -check-prefix=ERR %s +# ERR: anonymous version tag cannot be combined with other version tag + +# RUN: ld.lld --version-script %t.script --dynamic-list %t.list %t.o %t2.so -o %t2 +# RUN: llvm-readobj %t2 > /dev/null + # DSO: DynamicSymbols [ # DSO-NEXT: Symbol { # DSO-NEXT: Name: @ (0)