From owner-svn-src-vendor@freebsd.org Sat Jan 6 21:36:53 2018 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 06DDFDF36AA; Sat, 6 Jan 2018 21:36:52 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C33E081528; Sat, 6 Jan 2018 21:36:50 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E055517F2B; Sat, 6 Jan 2018 21:36:49 +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 w06LanuN067601; Sat, 6 Jan 2018 21:36:49 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w06LamLw067590; Sat, 6 Jan 2018 21:36:48 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201801062136.w06LamLw067590@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Sat, 6 Jan 2018 21:36:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r327647 - in vendor/lld/dist-release_60: ELF docs test/ELF test/ELF/Inputs test/ELF/linkerscript X-SVN-Group: vendor X-SVN-Commit-Author: dim X-SVN-Commit-Paths: in vendor/lld/dist-release_60: ELF docs test/ELF test/ELF/Inputs test/ELF/linkerscript X-SVN-Commit-Revision: 327647 X-SVN-Commit-Repository: base 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.25 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: Sat, 06 Jan 2018 21:36:53 -0000 Author: dim Date: Sat Jan 6 21:36:48 2018 New Revision: 327647 URL: https://svnweb.freebsd.org/changeset/base/327647 Log: Vendor import of lld release_60 branch r321788: https://llvm.org/svn/llvm-project/lld/branches/release_60@321788 Added: vendor/lld/dist-release_60/test/ELF/Inputs/shlib-undefined-ref.s (contents, props changed) vendor/lld/dist-release_60/test/ELF/gnu-ifunc-dyntags.s (contents, props changed) vendor/lld/dist-release_60/test/ELF/linkerscript/nobits-offset.s (contents, props changed) vendor/lld/dist-release_60/test/ELF/relocation-size-err.s (contents, props changed) vendor/lld/dist-release_60/test/ELF/shlib-undefined-shared.s (contents, props changed) vendor/lld/dist-release_60/test/ELF/weak-undef-rw.s (contents, props changed) Modified: vendor/lld/dist-release_60/ELF/Driver.cpp vendor/lld/dist-release_60/ELF/Relocations.cpp vendor/lld/dist-release_60/ELF/SyntheticSections.cpp vendor/lld/dist-release_60/ELF/Writer.cpp vendor/lld/dist-release_60/docs/ReleaseNotes.rst Modified: vendor/lld/dist-release_60/ELF/Driver.cpp ============================================================================== --- vendor/lld/dist-release_60/ELF/Driver.cpp Sat Jan 6 21:36:38 2018 (r327646) +++ vendor/lld/dist-release_60/ELF/Driver.cpp Sat Jan 6 21:36:48 2018 (r327647) @@ -1043,7 +1043,8 @@ template void LinkerDriver::link(opt::Inp return; // Handle undefined symbols in DSOs. - Symtab->scanShlibUndefined(); + if (!Config->Shared) + Symtab->scanShlibUndefined(); // Handle the -exclude-libs option. if (Args.hasArg(OPT_exclude_libs)) Modified: vendor/lld/dist-release_60/ELF/Relocations.cpp ============================================================================== --- vendor/lld/dist-release_60/ELF/Relocations.cpp Sat Jan 6 21:36:38 2018 (r327646) +++ vendor/lld/dist-release_60/ELF/Relocations.cpp Sat Jan 6 21:36:48 2018 (r327647) @@ -367,7 +367,7 @@ static bool isRelExpr(RelExpr Expr) { static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym, InputSectionBase &S, uint64_t RelOff) { // These expressions always compute a constant - if (isRelExprOneOfPic) return true; + // The size of a non preemptible symbol is a constant. + if (E == R_SIZE) + return true; + // For the target and the relocation, we want to know if they are // absolute or relative. bool AbsVal = isAbsoluteValue(Sym); @@ -592,6 +596,12 @@ static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, R if (IsConstant) return Expr; + // We can create any dynamic relocation supported by the dynamic linker if a + // section is writable or we are passed -z notext. + bool CanWrite = (S.Flags & SHF_WRITE) || !Config->ZText; + if (CanWrite && Target->isPicRel(Type)) + return Expr; + // If the relocation is to a weak undef, and we are producing // executable, give up on it and produce a non preemptible 0. if (!Config->Shared && Sym.isUndefWeak()) { @@ -599,12 +609,6 @@ static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, R IsConstant = true; return Expr; } - - // We can create any dynamic relocation supported by the dynamic linker if a - // section is writable or we are passed -z notext. - bool CanWrite = (S.Flags & SHF_WRITE) || !Config->ZText; - if (CanWrite && Target->isPicRel(Type)) - return Expr; // If we got here we know that this relocation would require the dynamic // linker to write a value to read only memory or use an unsupported Modified: vendor/lld/dist-release_60/ELF/SyntheticSections.cpp ============================================================================== --- vendor/lld/dist-release_60/ELF/SyntheticSections.cpp Sat Jan 6 21:36:38 2018 (r327646) +++ vendor/lld/dist-release_60/ELF/SyntheticSections.cpp Sat Jan 6 21:36:48 2018 (r327647) @@ -1064,7 +1064,7 @@ template void DynamicSection::final addInt(DT_DEBUG, 0); this->Link = InX::DynStrTab->getParent()->SectionIndex; - if (InX::RelaDyn->getParent() && !InX::RelaDyn->empty()) { + if (!InX::RelaDyn->empty()) { addInSec(InX::RelaDyn->DynamicTag, InX::RelaDyn); addSize(InX::RelaDyn->SizeDynamicTag, InX::RelaDyn->getParent()); @@ -1081,7 +1081,13 @@ template void DynamicSection::final addInt(IsRela ? DT_RELACOUNT : DT_RELCOUNT, NumRelativeRels); } } - if (InX::RelaPlt->getParent() && !InX::RelaPlt->empty()) { + // .rel[a].plt section usually consists of two parts, containing plt and + // iplt relocations. It is possible to have only iplt relocations in the + // output. In that case RelaPlt is empty and have zero offset, the same offset + // as RelaIplt have. And we still want to emit proper dynamic tags for that + // case, so here we always use RelaPlt as marker for the begining of + // .rel[a].plt section. + if (InX::RelaPlt->getParent()->Live) { addInSec(DT_JMPREL, InX::RelaPlt); addSize(DT_PLTRELSZ, InX::RelaPlt->getParent()); switch (Config->EMachine) { Modified: vendor/lld/dist-release_60/ELF/Writer.cpp ============================================================================== --- vendor/lld/dist-release_60/ELF/Writer.cpp Sat Jan 6 21:36:38 2018 (r327646) +++ vendor/lld/dist-release_60/ELF/Writer.cpp Sat Jan 6 21:36:48 2018 (r327647) @@ -1767,30 +1767,36 @@ template void Writer::fixSectionAli // virtual address (modulo the page size) so that the loader can load // executables without any address adjustment. static uint64_t getFileAlignment(uint64_t Off, OutputSection *Cmd) { - // If the section is not in a PT_LOAD, we just have to align it. - if (!Cmd->PtLoad) - return alignTo(Off, Cmd->Alignment); - - OutputSection *First = Cmd->PtLoad->FirstSec; + OutputSection *First = Cmd->PtLoad ? Cmd->PtLoad->FirstSec : nullptr; // The first section in a PT_LOAD has to have congruent offset and address // module the page size. if (Cmd == First) return alignTo(Off, std::max(Cmd->Alignment, Config->MaxPageSize), Cmd->Addr); + // For SHT_NOBITS we don't want the alignment of the section to impact the + // offset of the sections that follow. Since nothing seems to care about the + // sh_offset of the SHT_NOBITS section itself, just ignore it. + if (Cmd->Type == SHT_NOBITS) + return Off; + + // If the section is not in a PT_LOAD, we just have to align it. + if (!Cmd->PtLoad) + return alignTo(Off, Cmd->Alignment); + // If two sections share the same PT_LOAD the file offset is calculated // using this formula: Off2 = Off1 + (VA2 - VA1). return First->Offset + Cmd->Addr - First->Addr; } static uint64_t setOffset(OutputSection *Cmd, uint64_t Off) { - if (Cmd->Type == SHT_NOBITS) { - Cmd->Offset = Off; - return Off; - } - Off = getFileAlignment(Off, Cmd); Cmd->Offset = Off; + + // For SHT_NOBITS we should not count the size. + if (Cmd->Type == SHT_NOBITS) + return Off; + return Off + Cmd->Size; } Modified: vendor/lld/dist-release_60/docs/ReleaseNotes.rst ============================================================================== --- vendor/lld/dist-release_60/docs/ReleaseNotes.rst Sat Jan 6 21:36:38 2018 (r327646) +++ vendor/lld/dist-release_60/docs/ReleaseNotes.rst Sat Jan 6 21:36:48 2018 (r327647) @@ -29,7 +29,13 @@ ELF Improvements COFF Improvements ----------------- -* Item 1. +* A GNU ld style frontend for the COFF linker has been added for MinGW. + In MinGW environments, the linker is invoked with GNU ld style parameters; + which LLD previously only supported when used as an ELF linker. When + a PE/COFF target is chosen, those parameters are rewritten into the + lld-link style parameters and the COFF linker is invoked instead. + +* Initial support for the ARM64 architecture has been added. MachO Improvements ------------------ Added: vendor/lld/dist-release_60/test/ELF/Inputs/shlib-undefined-ref.s ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lld/dist-release_60/test/ELF/Inputs/shlib-undefined-ref.s Sat Jan 6 21:36:48 2018 (r327647) @@ -0,0 +1,4 @@ +.globl f +f: + call should_not_be_exported@PLT + ret Added: vendor/lld/dist-release_60/test/ELF/gnu-ifunc-dyntags.s ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lld/dist-release_60/test/ELF/gnu-ifunc-dyntags.s Sat Jan 6 21:36:48 2018 (r327647) @@ -0,0 +1,41 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld -pie %t.o -o %tout +# RUN: llvm-objdump -section-headers %tout | FileCheck %s +# RUN: llvm-readobj -dynamic-table -r %tout | FileCheck %s --check-prefix=TAGS + +## Check we produce DT_PLTREL/DT_JMPREL/DT_PLTGOT and DT_PLTRELSZ tags +## when there are no other relocations except R_*_IRELATIVE. + +# CHECK: Name Size Address +# CHECK: .rela.plt 00000030 0000000000000210 +# CHECK: .got.plt 00000010 0000000000002000 + +# TAGS: Relocations [ +# TAGS-NEXT: Section {{.*}} .rela.plt { +# TAGS-NEXT: R_X86_64_IRELATIVE +# TAGS-NEXT: R_X86_64_IRELATIVE +# TAGS-NEXT: } +# TAGS-NEXT: ] + +# TAGS: Tag Type Name/Value +# TAGS: 0x0000000000000017 JMPREL 0x210 +# TAGS: 0x0000000000000002 PLTRELSZ 48 +# TAGS: 0x0000000000000003 PLTGOT 0x2000 +# TAGS: 0x0000000000000014 PLTREL RELA + +.text +.type foo STT_GNU_IFUNC +.globl foo +foo: + ret + +.type bar STT_GNU_IFUNC +.globl bar +bar: + ret + +.globl _start +_start: + call foo + call bar Added: vendor/lld/dist-release_60/test/ELF/linkerscript/nobits-offset.s ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lld/dist-release_60/test/ELF/linkerscript/nobits-offset.s Sat Jan 6 21:36:48 2018 (r327647) @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { \ +# RUN: .sec1 (NOLOAD) : { . += 1; } \ +# RUN: .text : { *(.text) } \ +# RUN: };" > %t.script +# RUN: ld.lld %t.o -T %t.script -o %t +# RUN: llvm-readelf --sections %t | FileCheck %s + +# We used to misalign section offsets if the first section in a +# PT_LOAD was SHT_NOBITS. + +# CHECK: [ 2] .text PROGBITS 0000000000000010 001010 000010 00 AX 0 0 16 + +.global _start +_start: + nop +.p2align 4 Added: vendor/lld/dist-release_60/test/ELF/relocation-size-err.s ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lld/dist-release_60/test/ELF/relocation-size-err.s Sat Jan 6 21:36:48 2018 (r327647) @@ -0,0 +1,12 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s + +// CHECK: error: can't create dynamic relocation R_X86_64_SIZE64 against symbol: foo in readonly segment; recompile object files with -fPIC + + .global foo +foo: + .quad 42 + .size foo, 8 + + .quad foo@SIZE Added: vendor/lld/dist-release_60/test/ELF/shlib-undefined-shared.s ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lld/dist-release_60/test/ELF/shlib-undefined-shared.s Sat Jan 6 21:36:48 2018 (r327647) @@ -0,0 +1,15 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t1.o %S/Inputs/shlib-undefined-ref.s +# RUN: ld.lld -shared -o %t1.so %t1.o + +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t2.o %s +# RUN: echo "{ local: *; };" > %t.script +# RUN: ld.lld -shared -version-script %t.script -o %t2.so %t2.o %t1.so +# RUN: llvm-nm -g %t2.so | FileCheck -allow-empty %s + +# CHECK-NOT: should_not_be_exported + +.globl should_not_be_exported +should_not_be_exported: + ret Added: vendor/lld/dist-release_60/test/ELF/weak-undef-rw.s ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lld/dist-release_60/test/ELF/weak-undef-rw.s Sat Jan 6 21:36:48 2018 (r327647) @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t --export-dynamic +# RUN: llvm-readobj -r %t | FileCheck %s + +# CHECK: R_X86_64_64 foobar 0x0 + + .global _start +_start: + .data + .weak foobar + .quad foobar