Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -42,6 +42,7 @@ llvm::StringRef Sysroot; std::string RPath; std::vector SearchPaths; + std::vector Undefined; bool AllowMultipleDefinition; bool AsNeeded = false; bool Bsymbolic; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -189,6 +189,9 @@ } } + for (auto *Arg : Args.filtered(OPT_undefined)) + Config->Undefined.push_back(Arg->getValue()); + if (Files.empty()) error("no input files."); } @@ -225,8 +228,8 @@ for (std::unique_ptr &F : Files) Symtab.addFile(std::move(F)); - for (auto *Arg : Args.filtered(OPT_undefined)) - Symtab.addUndefinedOpt(Arg->getValue()); + for (auto &U : Config->Undefined) + Symtab.addUndefinedOpt(U); if (Config->OutputFile.empty()) Config->OutputFile = "a.out"; Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -43,6 +43,7 @@ void readAsNeeded(); void readEntry(); + void readExtern(); void readGroup(); void readInclude(); void readOutput(); @@ -63,6 +64,8 @@ continue; if (Tok == "ENTRY") { readEntry(); + } else if (Tok == "EXTERN") { + readExtern(); } else if (Tok == "GROUP" || Tok == "INPUT") { readGroup(); } else if (Tok == "INCLUDE") { @@ -181,6 +184,16 @@ expect(")"); } +void LinkerScript::readExtern() { + expect("("); + for (;;) { + StringRef Tok = next(); + if (Tok == ")") + return; + Config->Undefined.push_back(Tok); + } +} + void LinkerScript::readGroup() { expect("("); for (;;) { Index: test/elf2/linkerscript.s =================================================================== --- test/elf2/linkerscript.s +++ test/elf2/linkerscript.s @@ -6,6 +6,10 @@ # RUN: rm -f %t.dir/libxyz.a # RUN: llvm-ar rcs %t.dir/libxyz.a %t2.o +# RUN: echo "EXTERN( undef undef2 )" > %t.script +# RUN: ld.lld2 %t -o %t2 %t.script +# RUN: llvm-readobj %t2 > /dev/null + # RUN: echo "GROUP(" %t ")" > %t.script # RUN: ld.lld2 -o %t2 %t.script # RUN: llvm-readobj %t2 > /dev/null