Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ ELF/InputFiles.h @@ -65,6 +65,7 @@ ArchiveKind, BitcodeKind, BinaryKind, + SyntheticKind, }; Kind kind() const { return FileKind; } @@ -339,6 +340,13 @@ void parse(); }; +class SyntheticFile : public InputFile { +public: + explicit SyntheticFile(StringRef Name) + : InputFile(SyntheticKind, {"", Name}) {} + static bool classof(const InputFile *F) { return F->kind() == SyntheticKind; } +}; + InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "", uint64_t OffsetInArchive = 0); InputFile *createSharedFile(MemoryBufferRef MB, StringRef DefaultSoName); Index: ELF/LTO.cpp =================================================================== --- ELF/LTO.cpp +++ ELF/LTO.cpp @@ -162,7 +162,8 @@ // Symbol section is always null for bitcode symbols, hence the check // for isElf(). Skip linker script defined symbols as well: they have // no File defined. - !(DR->Section == nullptr && (!Sym->File || Sym->File->isElf())); + !(DR->Section == nullptr && + (isa(Sym->File) || Sym->File->isElf())); if (R.Prevailing) undefine(Sym); Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -184,8 +184,8 @@ // write expressions like this: `alignment = 16; . = ALIGN(., alignment)`. uint64_t SymValue = Value.Sec ? 0 : Value.getValue(); - replaceSymbol(Sym, nullptr, Cmd->Name, STB_GLOBAL, Visibility, - STT_NOTYPE, SymValue, 0, Sec); + replaceSymbol(Sym, make(Cmd->Location), Cmd->Name, + STB_GLOBAL, Visibility, STT_NOTYPE, SymValue, 0, Sec); Cmd->Sym = cast(Sym); } @@ -201,8 +201,8 @@ std::tie(Sym, std::ignore) = Symtab->insert(Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false, /*File*/ nullptr); - replaceSymbol(Sym, nullptr, Cmd->Name, STB_GLOBAL, Visibility, - STT_NOTYPE, 0, 0, nullptr); + replaceSymbol(Sym, make(Cmd->Location), Cmd->Name, + STB_GLOBAL, Visibility, STT_NOTYPE, 0, 0, nullptr); Cmd->Sym = cast(Sym); Cmd->Provide = false; } Index: ELF/MapFile.cpp =================================================================== --- ELF/MapFile.cpp +++ ELF/MapFile.cpp @@ -264,7 +264,7 @@ // Print out a header. outs() << "Cross Reference Table\n\n"; - print("Symbol", "File"); + print("Symbol", "Location"); // Print out a table. for (auto KV : Map) { Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -264,10 +264,11 @@ } void ScriptParser::readDefsym(StringRef Name) { + std::string Loc = getCurrentLocation(); Expr E = readExpr(); if (!atEOF()) setError("EOF expected, but got " + next()); - SymbolAssignment *Cmd = make(Name, E, getCurrentLocation()); + SymbolAssignment *Cmd = make(Name, E, Loc); Script->SectionCommands.push_back(Cmd); } Index: test/ELF/cref.s =================================================================== --- test/ELF/cref.s +++ test/ELF/cref.s @@ -9,7 +9,7 @@ // RUN: ld.lld -shared -o %t1.so %t1.o -gc-sections // RUN: ld.lld -o /dev/null %t1.so %t2.o %t3.o %t.a -cref | FileCheck -strict-whitespace %s -// CHECK: Symbol File +// CHECK: Symbol Location // CHECK-NEXT: bar {{.*}}2.o // CHECK-NEXT: {{.*}}3.o // CHECK-NEXT: foo {{.*}}1.so Index: test/ELF/just-symbols-cref.s =================================================================== --- test/ELF/just-symbols-cref.s +++ test/ELF/just-symbols-cref.s @@ -5,7 +5,7 @@ # RUN: ld.lld -just-symbols=%t1.exe -o %t2.exe -cref | FileCheck %s -# CHECK: Symbol File +# CHECK: Symbol Location # CHECK-NEXT: bar {{.*exe}} # CHECK-NEXT: foo {{.*exe}} Index: test/ELF/linkerscript/cref.s =================================================================== --- test/ELF/linkerscript/cref.s +++ test/ELF/linkerscript/cref.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { foo = 1; }" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o -cref -defsym=bar=2 | FileCheck %s + +# CHECK: Symbol Location +# CHECK-NEXT: bar -defsym +# CHECK-NEXT: {{.*}}.o +# CHECK-NEXT: foo {{.*}}.script:1 +# CHECK-NEXT: {{.*}}.o + +.global foo, bar +.quad foo +.quad bar Index: test/ELF/linkerscript/relocation-relative-absolute.s =================================================================== --- test/ELF/linkerscript/relocation-relative-absolute.s +++ test/ELF/linkerscript/relocation-relative-absolute.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { answer = 1; }" > %t.script +# RUN: not ld.lld -o %t --script %t.script %t.o -pie 2>&1 | FileCheck %s + +# CHECK: error: relocation R_X86_64_PLT32 cannot refer to absolute symbol: answer +# CHECK-NEXT: >>> defined in {{.*}}script:1 +# CHECK-NEXT: >>> referenced by {{.*}}o:(.text+0x1) + +.globl _start +_start: + +call answer@PLT