Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ ELF/InputFiles.h @@ -65,8 +65,13 @@ ArchiveKind, BitcodeKind, BinaryKind, + SyntheticKind, }; + InputFile(Kind K, MemoryBufferRef M); + + static InputFile *createSyntheticFile(StringRef Name); + Kind kind() const { return FileKind; } bool isElf() const { @@ -120,7 +125,6 @@ static bool IsInGroup; protected: - InputFile(Kind K, MemoryBufferRef M); std::vector Sections; std::vector Symbols; Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -55,6 +55,10 @@ ++NextGroupId; } +InputFile *InputFile::createSyntheticFile(StringRef Name) { + return make(SyntheticKind, MemoryBufferRef("", Name)); +} + Optional elf::readFile(StringRef Path) { // The --chroot option changes our virtual root directory. // This is useful when you are dealing with files created by --reproduce. Index: ELF/LTO.cpp =================================================================== --- ELF/LTO.cpp +++ ELF/LTO.cpp @@ -163,11 +163,9 @@ R.FinalDefinitionInLinkageUnit = (IsExecutable || Sym->Visibility != STV_DEFAULT) && DR && // Skip absolute symbols from ELF objects, otherwise PC-rel relocations - // will be generated by for them, triggering linker errors. - // 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())); + // will be generated by for them, triggering linker errors. Symbol + // section is always null for bitcode symbols, hence the check. + !(DR->Section == nullptr && !isa(Sym->File)); if (R.Prevailing) undefine(Sym); Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -184,8 +184,9 @@ // 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, InputFile::createSyntheticFile(Cmd->Location), + Cmd->Name, STB_GLOBAL, Visibility, STT_NOTYPE, + SymValue, 0, Sec); Cmd->Sym = cast(Sym); } @@ -201,8 +202,9 @@ 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, InputFile::createSyntheticFile(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 @@ -267,10 +267,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 // RUN: ld.lld -o /dev/null %t1.so %t2.o %t3.o %t.a -gc-sections -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 Index: test/ELF/linkerscript/symbol-ordering-file2.s =================================================================== --- test/ELF/linkerscript/symbol-ordering-file2.s +++ test/ELF/linkerscript/symbol-ordering-file2.s @@ -7,10 +7,11 @@ # RUN: echo "SECTIONS { bar = 1; }" > %t.script # RUN: ld.lld --symbol-ordering-file %t.ord %t.o --script %t.script \ # RUN: -o %t.out 2>&1 | FileCheck %s -# CHECK: warning: : unable to order absolute symbol: bar +# CHECK: warning: {{.*}}.script:1: unable to order absolute symbol: bar ## Check we do not crash when trying to order --defsym symbol. # RUN: echo "bar" > %t.ord # RUN: ld.lld --symbol-ordering-file %t.ord %t.o -defsym=bar=1 \ -# RUN: -o %t.out 2>&1 | FileCheck %s +# RUN: -o %t.out 2>&1 | FileCheck %s --check-prefix=DEFSYM +# DEFSYM: warning: -defsym: unable to order absolute symbol: bar Index: test/ELF/linkerscript/trace.s =================================================================== --- test/ELF/linkerscript/trace.s +++ test/ELF/linkerscript/trace.s @@ -0,0 +1,6 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o + +# RUN: echo "SECTIONS { bar = 1; }" > %t.script +# RUN: ld.lld %t.o --script %t.script -trace-symbol bar -o %t.out 2>&1 | FileCheck %s +# CHECK: {{.*}}.script:1: definition of bar