Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/userguide/documentation/linker_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,11 @@ A version script is a sequence of *version nodes*. Each node has an optional
name and contains `global:` and/or `local:` blocks. Each block lists symbol
patterns terminated by `;`.

:::{note}
It is an error for a ``local:`` block to appear before a ``global:`` block in
the same version node.
:::

```
/* Anonymous (unnamed) version node. */
{
Expand Down
4 changes: 4 additions & 0 deletions lib/ScriptParser/ScriptParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,10 @@ void ScriptParser::readVersionSymbols(VersionScriptNode &VSN) {
continue;
}
if (Tok == "global:" || (Tok == "global" && consume(":"))) {
if (VSN.getLocalBlock()) {
setError("global scope must appear before local scope", Tok);
return;
}
VSN.switchToGlobal();
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#---GlobalAfterLocal.test------------ SharedLib,VersionScript ----------------#
#BEGIN_COMMENT
# This test verifies that version-script diagnostics point at a global block
# that appears after a local block.
#END_COMMENT
#START_TEST
RUN: %clang %clangopts -o %t1.o -c %p/Inputs/1.c -fPIC
RUN: %not %link %linkopts -o %t1.so %t1.o -shared \
RUN: --version-script %p/Inputs/vs.t 2>&1 \
RUN: | %filecheck %s --strict-whitespace --match-full-lines
#END_TEST

CHECK:Error: {{.*}}vs.t:4:3: global scope must appear before local scope{{.*}}
CHECK-NEXT:>>> global:
CHECK-NEXT:>>> ^
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int foo() { return 0; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
V1 {
local:
*;
global:
foo;
};
Loading