Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -528,10 +528,15 @@ } template void LinkerScript::addScriptedSymbols() { - for (const std::unique_ptr &Base : Opt.Commands) - if (auto *Cmd = dyn_cast(Base.get())) - if (Cmd->Name != "." && Symtab::X->find(Cmd->Name) == nullptr) - Symtab::X->addAbsolute(Cmd->Name, STV_DEFAULT); + for (const std::unique_ptr &Base : Opt.Commands) { + if (auto *Cmd = dyn_cast(Base.get())) { + if (Cmd->Name != ".") { + SymbolBody *B = Symtab::X->find(Cmd->Name); + if (B == nullptr || B->isUndefined()) + Symtab::X->addAbsolute(Cmd->Name, STV_DEFAULT); + } + } + } } template bool LinkerScript::hasPhdrsCommands() { Index: test/ELF/linkerscript-undef.s =================================================================== --- /dev/null +++ test/ELF/linkerscript-undef.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "SECTIONS { patatino = 0x1234; }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck %s +# CHECK: 0000000000001234 *ABS* 00000000 patatino + +.global _start +_start: + call patatino