From owner-svn-src-head@freebsd.org Wed Mar 18 20:28:28 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 51EB726BDD8; Wed, 18 Mar 2020 20:28:28 +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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48jM7H5nGvz3NHS; Wed, 18 Mar 2020 20:28:27 +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 9E9F427797; Wed, 18 Mar 2020 20:28:27 +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 02IKSRcN087850; Wed, 18 Mar 2020 20:28:27 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 02IKSQGH087844; Wed, 18 Mar 2020 20:28:26 GMT (envelope-from dim@FreeBSD.org) Message-Id: <202003182028.02IKSQGH087844@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Wed, 18 Mar 2020 20:28:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359084 - in head/contrib/llvm-project/lld/ELF: . Arch X-SVN-Group: head X-SVN-Commit-Author: dim X-SVN-Commit-Paths: in head/contrib/llvm-project/lld/ELF: . Arch X-SVN-Commit-Revision: 359084 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Mar 2020 20:28:28 -0000 Author: dim Date: Wed Mar 18 20:28:26 2020 New Revision: 359084 URL: https://svnweb.freebsd.org/changeset/base/359084 Log: Merge commit 00925aadb from llvm git (by Fangrui Song): [ELF][PPC32] Fix canonical PLTs when the order does not match the PLT order Reviewed By: Bdragon28 Differential Revision: https://reviews.llvm.org/D75394 This is needed to fix miscompiled canonical PLTs on ppc32/lld10. Requested by: bdragon MFC after: 6 weeks X-MFC-With: 358851 Differential Revision: https://reviews.freebsd.org/D24109 Modified: head/contrib/llvm-project/lld/ELF/Arch/PPC.cpp head/contrib/llvm-project/lld/ELF/Relocations.cpp head/contrib/llvm-project/lld/ELF/SyntheticSections.cpp head/contrib/llvm-project/lld/ELF/SyntheticSections.h head/contrib/llvm-project/lld/ELF/Writer.cpp Modified: head/contrib/llvm-project/lld/ELF/Arch/PPC.cpp ============================================================================== --- head/contrib/llvm-project/lld/ELF/Arch/PPC.cpp Wed Mar 18 20:12:46 2020 (r359083) +++ head/contrib/llvm-project/lld/ELF/Arch/PPC.cpp Wed Mar 18 20:28:26 2020 (r359084) @@ -71,12 +71,11 @@ void writePPC32GlinkSection(uint8_t *buf, size_t numEn // non-GOT-non-PLT relocations referencing external functions for -fpie/-fPIE. uint32_t glink = in.plt->getVA(); // VA of .glink if (!config->isPic) { - for (const Symbol *sym : in.plt->entries) - if (sym->needsPltAddr) { - writePPC32PltCallStub(buf, sym->getGotPltVA(), nullptr, 0); - buf += 16; - glink += 16; - } + for (const Symbol *sym : cast(in.plt)->canonical_plts) { + writePPC32PltCallStub(buf, sym->getGotPltVA(), nullptr, 0); + buf += 16; + glink += 16; + } } // On PPC Secure PLT ABI, bl foo@plt jumps to a call stub, which loads an Modified: head/contrib/llvm-project/lld/ELF/Relocations.cpp ============================================================================== --- head/contrib/llvm-project/lld/ELF/Relocations.cpp Wed Mar 18 20:12:46 2020 (r359083) +++ head/contrib/llvm-project/lld/ELF/Relocations.cpp Wed Mar 18 20:28:26 2020 (r359084) @@ -1206,6 +1206,7 @@ static void processRelocAux(InputSectionBase &sec, Rel // PPC32 canonical PLT entries are at the beginning of .glink cast(sym).value = in.plt->headerSize; in.plt->headerSize += 16; + cast(in.plt)->canonical_plts.push_back(&sym); } } sym.needsPltAddr = true; Modified: head/contrib/llvm-project/lld/ELF/SyntheticSections.cpp ============================================================================== --- head/contrib/llvm-project/lld/ELF/SyntheticSections.cpp Wed Mar 18 20:12:46 2020 (r359083) +++ head/contrib/llvm-project/lld/ELF/SyntheticSections.cpp Wed Mar 18 20:28:26 2020 (r359084) @@ -2446,12 +2446,9 @@ PltSection::PltSection() : SyntheticSection(SHF_ALLOC | SHF_EXECINSTR, SHT_PROGBITS, 16, ".plt"), headerSize(target->pltHeaderSize) { // On PowerPC, this section contains lazy symbol resolvers. - if (config->emachine == EM_PPC || config->emachine == EM_PPC64) { + if (config->emachine == EM_PPC64) { name = ".glink"; alignment = 4; - // PLTresolve is at the end. - if (config->emachine == EM_PPC) - footerSize = 64; } // On x86 when IBT is enabled, this section contains the second PLT (lazy @@ -2467,11 +2464,6 @@ PltSection::PltSection() } void PltSection::writeTo(uint8_t *buf) { - if (config->emachine == EM_PPC) { - writePPC32GlinkSection(buf, entries.size()); - return; - } - // At beginning of PLT, we have code to call the dynamic // linker to resolve dynsyms at runtime. Write such code. target->writePltHeader(buf); @@ -2489,7 +2481,7 @@ void PltSection::addEntry(Symbol &sym) { } size_t PltSection::getSize() const { - return headerSize + entries.size() * target->pltEntrySize + footerSize; + return headerSize + entries.size() * target->pltEntrySize; } bool PltSection::isNeeded() const { @@ -2541,6 +2533,19 @@ void IpltSection::addSymbols() { target->addPltSymbols(*this, off); off += target->pltEntrySize; } +} + +PPC32GlinkSection::PPC32GlinkSection() { + name = ".glink"; + alignment = 4; +} + +void PPC32GlinkSection::writeTo(uint8_t *buf) { + writePPC32GlinkSection(buf, entries.size()); +} + +size_t PPC32GlinkSection::getSize() const { + return headerSize + entries.size() * target->pltEntrySize + footerSize; } // This is an x86-only extra PLT section and used only when a security Modified: head/contrib/llvm-project/lld/ELF/SyntheticSections.h ============================================================================== --- head/contrib/llvm-project/lld/ELF/SyntheticSections.h Wed Mar 18 20:12:46 2020 (r359083) +++ head/contrib/llvm-project/lld/ELF/SyntheticSections.h Wed Mar 18 20:28:26 2020 (r359084) @@ -684,7 +684,6 @@ class PltSection : public SyntheticSection { (public) size_t getNumEntries() const { return entries.size(); } size_t headerSize; - size_t footerSize = 0; std::vector entries; }; @@ -703,6 +702,16 @@ class IpltSection final : public SyntheticSection { (p bool isNeeded() const override { return !entries.empty(); } void addSymbols(); void addEntry(Symbol &sym); +}; + +class PPC32GlinkSection : public PltSection { +public: + PPC32GlinkSection(); + void writeTo(uint8_t *buf) override; + size_t getSize() const override; + + std::vector canonical_plts; + static constexpr size_t footerSize = 64; }; // This is x86-only. Modified: head/contrib/llvm-project/lld/ELF/Writer.cpp ============================================================================== --- head/contrib/llvm-project/lld/ELF/Writer.cpp Wed Mar 18 20:12:46 2020 (r359083) +++ head/contrib/llvm-project/lld/ELF/Writer.cpp Wed Mar 18 20:28:26 2020 (r359084) @@ -521,7 +521,8 @@ template void createSyntheticSections() { add(in.ibtPlt); } - in.plt = make(); + in.plt = config->emachine == EM_PPC ? make() + : make(); add(in.plt); in.iplt = make(); add(in.iplt);