From owner-svn-src-vendor@freebsd.org Tue May 30 17:38:07 2017 Return-Path: Delivered-To: svn-src-vendor@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2B956B94BC6; Tue, 30 May 2017 17:38:07 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D75CC717FC; Tue, 30 May 2017 17:38:06 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4UHc5PU046072; Tue, 30 May 2017 17:38:05 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4UHc4Hl046059; Tue, 30 May 2017 17:38:04 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201705301738.v4UHc4Hl046059@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Tue, 30 May 2017 17:38:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r319238 - in vendor/lld/dist: ELF test/ELF/linkerscript X-SVN-Group: vendor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-vendor@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the vendor work area tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 May 2017 17:38:07 -0000 Author: dim Date: Tue May 30 17:38:04 2017 New Revision: 319238 URL: https://svnweb.freebsd.org/changeset/base/319238 Log: Vendor import of lld trunk r304222: https://llvm.org/svn/llvm-project/lld/trunk@304222 Added: vendor/lld/dist/test/ELF/linkerscript/bss-fill.s (contents, props changed) Modified: vendor/lld/dist/ELF/LinkerScript.cpp vendor/lld/dist/ELF/LinkerScript.h vendor/lld/dist/ELF/MapFile.cpp vendor/lld/dist/ELF/MapFile.h vendor/lld/dist/ELF/OutputSections.cpp vendor/lld/dist/ELF/ScriptParser.cpp vendor/lld/dist/ELF/Writer.cpp vendor/lld/dist/test/ELF/linkerscript/align.s vendor/lld/dist/test/ELF/linkerscript/merge-sections.s vendor/lld/dist/test/ELF/linkerscript/symbol-reserved.s Modified: vendor/lld/dist/ELF/LinkerScript.cpp ============================================================================== --- vendor/lld/dist/ELF/LinkerScript.cpp Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/ELF/LinkerScript.cpp Tue May 30 17:38:04 2017 (r319238) @@ -52,11 +52,12 @@ LinkerScript *elf::Script; uint64_t ExprValue::getValue() const { if (Sec) { if (Sec->getOutputSection()) - return Sec->getOffset(Val) + Sec->getOutputSection()->Addr; + return alignTo(Sec->getOffset(Val) + Sec->getOutputSection()->Addr, + Alignment); error("unable to evaluate expression: input section " + Sec->Name + " has no output section assigned"); } - return Val; + return alignTo(Val, Alignment); } uint64_t ExprValue::getSecAddr() const { @@ -143,7 +144,7 @@ void LinkerScript::assignSymbol(SymbolAssignment *Cmd, } else { Sym->Section = V.Sec; if (Sym->Section->Flags & SHF_ALLOC) - Sym->Value = V.Val; + Sym->Value = alignTo(V.Val, V.Alignment); else Sym->Value = V.getValue(); } @@ -290,6 +291,9 @@ LinkerScript::computeInputSections(const InputSectionD size_t SizeBefore = Ret.size(); for (InputSectionBase *Sec : InputSections) { + if (!isa(Sec)) + continue; + if (Sec->Assigned) continue; @@ -1075,6 +1079,9 @@ template void OutputSectionCommand::write Sec->CompressedData.size()); return; } + + if (Sec->Type == SHT_NOBITS) + return; // Write leading padding. ArrayRef Sections = Sec->Sections; Modified: vendor/lld/dist/ELF/LinkerScript.h ============================================================================== --- vendor/lld/dist/ELF/LinkerScript.h Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/ELF/LinkerScript.h Tue May 30 17:38:04 2017 (r319238) @@ -41,7 +41,12 @@ struct ExprValue { SectionBase *Sec; uint64_t Val; bool ForceAbsolute; + uint64_t Alignment = 1; + ExprValue(SectionBase *Sec, bool ForceAbsolute, uint64_t Val, + uint64_t Alignment) + : Sec(Sec), Val(Val), ForceAbsolute(ForceAbsolute), Alignment(Alignment) { + } ExprValue(SectionBase *Sec, bool ForceAbsolute, uint64_t Val) : Sec(Sec), Val(Val), ForceAbsolute(ForceAbsolute) {} ExprValue(SectionBase *Sec, uint64_t Val) : ExprValue(Sec, false, Val) {} Modified: vendor/lld/dist/ELF/MapFile.cpp ============================================================================== --- vendor/lld/dist/ELF/MapFile.cpp Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/ELF/MapFile.cpp Tue May 30 17:38:04 2017 (r319238) @@ -100,7 +100,7 @@ getSymbolStrings(ArrayRef Syms) { } template -void elf::writeMapFile(llvm::ArrayRef Script) { +void elf::writeMapFile(llvm::ArrayRef Script) { if (Config->MapFile.empty()) return; @@ -123,10 +123,7 @@ void elf::writeMapFile(llvm::ArrayRef S << " Align Out In Symbol\n"; // Print out file contents. - for (BaseCommand *Base : Script) { - auto *Cmd = dyn_cast(Base); - if (!Cmd) - continue; + for (OutputSectionCommand *Cmd : Script) { OutputSection *OSec = Cmd->Sec; writeHeader(OS, OSec->Addr, OSec->Size, OSec->Alignment); OS << OSec->Name << '\n'; @@ -147,7 +144,7 @@ void elf::writeMapFile(llvm::ArrayRef S } } -template void elf::writeMapFile(ArrayRef); -template void elf::writeMapFile(ArrayRef); -template void elf::writeMapFile(ArrayRef); -template void elf::writeMapFile(ArrayRef); +template void elf::writeMapFile(ArrayRef); +template void elf::writeMapFile(ArrayRef); +template void elf::writeMapFile(ArrayRef); +template void elf::writeMapFile(ArrayRef); Modified: vendor/lld/dist/ELF/MapFile.h ============================================================================== --- vendor/lld/dist/ELF/MapFile.h Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/ELF/MapFile.h Tue May 30 17:38:04 2017 (r319238) @@ -14,8 +14,9 @@ namespace lld { namespace elf { -struct BaseCommand; -template void writeMapFile(llvm::ArrayRef Script); +struct OutputSectionCommand; +template +void writeMapFile(llvm::ArrayRef Script); } } Modified: vendor/lld/dist/ELF/OutputSections.cpp ============================================================================== --- vendor/lld/dist/ELF/OutputSections.cpp Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/ELF/OutputSections.cpp Tue May 30 17:38:04 2017 (r319238) @@ -117,7 +117,7 @@ template static void finalizeShtGroup(Out // the symbol table. Sec->Link = InX::SymTab->OutSec->SectionIndex; - // sh_link then contain index of an entry in symbol table section which + // sh_info then contain index of an entry in symbol table section which // provides signature of the section group. elf::ObjectFile *Obj = Sec->Sections[0]->getFile(); assert(Config->Relocatable && Sec->Sections.size() == 1); Modified: vendor/lld/dist/ELF/ScriptParser.cpp ============================================================================== --- vendor/lld/dist/ELF/ScriptParser.cpp Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/ELF/ScriptParser.cpp Tue May 30 17:38:04 2017 (r319238) @@ -859,7 +859,11 @@ Expr ScriptParser::readPrimary() { expect(","); Expr E2 = readExpr(); expect(")"); - return [=] { return alignTo(E().getValue(), E2().getValue()); }; + return [=] { + ExprValue V = E(); + V.Alignment = E2().getValue(); + return V; + }; } if (Tok == "ALIGNOF") { StringRef Name = readParenLiteral(); Modified: vendor/lld/dist/ELF/Writer.cpp ============================================================================== --- vendor/lld/dist/ELF/Writer.cpp Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/ELF/Writer.cpp Tue May 30 17:38:04 2017 (r319238) @@ -74,6 +74,7 @@ template class Writer { (private) std::unique_ptr Buffer; std::vector OutputSections; + std::vector OutputSectionCommands; OutputSectionFactory Factory{OutputSections}; void addRelIpltSymbols(); @@ -262,6 +263,10 @@ template void Writer::run() { Script->fabricateDefaultCommands(); } + for (BaseCommand *Base : Script->Opt.Commands) + if (auto *Cmd = dyn_cast(Base)) + OutputSectionCommands.push_back(Cmd); + // If -compressed-debug-sections is specified, we need to compress // .debug_* sections. Do it right now because it changes the size of // output sections. @@ -311,7 +316,7 @@ template void Writer::run() { // Handle -Map option. - writeMapFile(Script->Opt.Commands); + writeMapFile(OutputSectionCommands); if (ErrorCount) return; @@ -1201,8 +1206,6 @@ template void Writer::finalizeSecti if (ErrorCount) return; - // So far we have added sections from input object files. - // This function adds linker-created Out::* sections. addPredefinedSections(); removeUnusedSyntheticSections(OutputSections); @@ -1270,8 +1273,20 @@ template void Writer::addPredefined // ARM ABI requires .ARM.exidx to be terminated by some piece of data. // We have the terminater synthetic section class. Add that at the end. auto *OS = dyn_cast_or_null(findSection(".ARM.exidx")); - if (OS && !OS->Sections.empty() && !Config->Relocatable) - OS->addSection(make()); + if (!OS || OS->Sections.empty() || Config->Relocatable) + return; + + auto *Sentinel = make(); + OS->addSection(Sentinel); + // If there are linker script commands existing at this point then add the + // sentinel to the last of these too. + if (OutputSectionCommand *C = Script->getCmd(OS)) { + auto ISD = std::find_if(C->Commands.rbegin(), C->Commands.rend(), + [](const BaseCommand *Base) { + return isa(Base); + }); + cast(*ISD)->Sections.push_back(Sentinel); + } } // The linker is expected to define SECNAME_start and SECNAME_end @@ -1315,10 +1330,9 @@ void Writer::addStartStopSymbols(OutputSection * template OutputSectionCommand *Writer::findSectionCommand(StringRef Name) { - for (BaseCommand *Base : Script->Opt.Commands) - if (auto *Cmd = dyn_cast(Base)) - if (Cmd->Name == Name) - return Cmd; + for (OutputSectionCommand *Cmd : OutputSectionCommands) + if (Cmd->Name == Name) + return Cmd; return nullptr; } @@ -1713,7 +1727,7 @@ template void Writer::writeHeader() EHdr->e_ehsize = sizeof(Elf_Ehdr); EHdr->e_phnum = Phdrs.size(); EHdr->e_shentsize = sizeof(Elf_Shdr); - EHdr->e_shnum = OutputSections.size() + 1; + EHdr->e_shnum = OutputSectionCommands.size() + 1; EHdr->e_shstrndx = InX::ShStrTab->OutSec->SectionIndex; if (Config->EMachine == EM_ARM) @@ -1745,8 +1759,8 @@ template void Writer::writeHeader() // Write the section header table. Note that the first table entry is null. auto *SHdrs = reinterpret_cast(Buf + EHdr->e_shoff); - for (OutputSection *Sec : OutputSections) - Sec->writeHeaderTo(++SHdrs); + for (OutputSectionCommand *Cmd : OutputSectionCommands) + Cmd->Sec->writeHeaderTo(++SHdrs); } // Open a result file. @@ -1769,10 +1783,7 @@ template void Writer::openFile() { template void Writer::writeSectionsBinary() { uint8_t *Buf = Buffer->getBufferStart(); - for (BaseCommand *Base : Script->Opt.Commands) { - auto *Cmd = dyn_cast(Base); - if (!Cmd) - continue; + for (OutputSectionCommand *Cmd : OutputSectionCommands) { OutputSection *Sec = Cmd->Sec; if (Sec->Flags & SHF_ALLOC) Cmd->writeTo(Buf + Sec->Offset); @@ -1799,19 +1810,13 @@ template void Writer::writeSections // In -r or -emit-relocs mode, write the relocation sections first as in // ELf_Rel targets we might find out that we need to modify the relocated // section while doing it. - for (BaseCommand *Base : Script->Opt.Commands) { - auto *Cmd = dyn_cast(Base); - if (!Cmd) - continue; + for (OutputSectionCommand *Cmd : OutputSectionCommands) { OutputSection *Sec = Cmd->Sec; if (Sec->Type == SHT_REL || Sec->Type == SHT_RELA) Cmd->writeTo(Buf + Sec->Offset); } - for (BaseCommand *Base : Script->Opt.Commands) { - auto *Cmd = dyn_cast(Base); - if (!Cmd) - continue; + for (OutputSectionCommand *Cmd : OutputSectionCommands) { OutputSection *Sec = Cmd->Sec; if (Sec != Out::Opd && Sec != EhFrameHdr && Sec->Type != SHT_REL && Sec->Type != SHT_RELA) Modified: vendor/lld/dist/test/ELF/linkerscript/align.s ============================================================================== --- vendor/lld/dist/test/ELF/linkerscript/align.s Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/test/ELF/linkerscript/align.s Tue May 30 17:38:04 2017 (r319238) @@ -64,7 +64,7 @@ # SYMBOLS-NEXT: 0000000000010000 *ABS* 00000000 __code_base__ # SYMBOLS-NEXT: 0000000000001000 *ABS* 00000000 VAR # SYMBOLS-NEXT: 0000000000011000 .bbb 00000000 __start_bbb -# SYMBOLS-NEXT: 0000000000012000 *ABS* 00000000 __end_bbb +# SYMBOLS-NEXT: 0000000000012000 .bbb 00000000 __end_bbb .global _start _start: Added: vendor/lld/dist/test/ELF/linkerscript/bss-fill.s ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lld/dist/test/ELF/linkerscript/bss-fill.s Tue May 30 17:38:04 2017 (r319238) @@ -0,0 +1,7 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { .bss : { . += 0x10000; *(.bss) } =0xFF };" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o + +.section .bss,"",@nobits +.short 0 Modified: vendor/lld/dist/test/ELF/linkerscript/merge-sections.s ============================================================================== --- vendor/lld/dist/test/ELF/linkerscript/merge-sections.s Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/test/ELF/linkerscript/merge-sections.s Tue May 30 17:38:04 2017 (r319238) @@ -31,6 +31,16 @@ # 0x19E = begin + sizeof(.foo) = 0x190 + 0xE # CHECK-NEXT: Value: 0x19E +# Check that we don't crash with --gc-sections +# RUN: ld.lld --gc-sections -o %t2 --script %t.script %t -shared +# RUN: llvm-readobj -s -t %t2 | FileCheck %s --check-prefix=GC + +# GC: Name: .foo +# GC-NEXT: Type: SHT_PROGBITS +# GC-NEXT: Flags [ +# GC-NEXT: SHF_ALLOC +# GC-NEXT: ] + .section .foo.1a,"aMS",@progbits,1 .asciz "foo" Modified: vendor/lld/dist/test/ELF/linkerscript/symbol-reserved.s ============================================================================== --- vendor/lld/dist/test/ELF/linkerscript/symbol-reserved.s Tue May 30 17:38:02 2017 (r319237) +++ vendor/lld/dist/test/ELF/linkerscript/symbol-reserved.s Tue May 30 17:38:04 2017 (r319238) @@ -11,6 +11,12 @@ # SHARED: 0000000000000005 .dynsym 00000000 .hidden newsym +# RUN: echo "PROVIDE_HIDDEN(newsym = ALIGN(__ehdr_start, CONSTANT(MAXPAGESIZE)) + 5);" > %t.script +# RUN: ld.lld -o %t1 %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=ALIGNED %s + +# ALIGNED: 0000000000200005 .text 00000000 .hidden newsym + .global _start _start: lea newsym(%rip),%rax