diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -328,8 +328,12 @@ void ScriptParser::readExtern() { expect("("); - while (!errorCount() && !consume(")")) - Config->Undefined.push_back(unquote(next())); + while (!errorCount() && !consume(")")) { + StringRef Name = unquote(next()); + Symtab->addSymbol( + Undefined{nullptr, Name, STB_GLOBAL, STV_DEFAULT, 0}); + Config->Undefined.push_back(Name); + } } void ScriptParser::readGroup() { diff --git a/lld/test/ELF/linkerscript/extern.s b/lld/test/ELF/linkerscript/extern.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/linkerscript/extern.s @@ -0,0 +1,33 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "EXTERN( test )" > %t.script +# RUN: echo "EXTERN( "test" )" >> %t.script +# RUN: echo "EXTERN( "test2" )" >> %t.script +# RUN: ld.lld %t -o %t2 -T %t.script +# RUN: llvm-readobj -t %t2 | FileCheck %s + +.globl _start +_start: + ret + +## Test that the script adds the specified symbols, and that they +## are marked as undefined. + +# CHECK: Symbol { +# CHECK: Name: test (1) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: test2 (6) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: }