From owner-svn-src-vendor@freebsd.org Sat Dec 16 14:46:40 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 9B8CEE8494A; Sat, 16 Dec 2017 14:46:40 +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 5AC6C66D8C; Sat, 16 Dec 2017 14:46:40 +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 vBGEkd9w032680; Sat, 16 Dec 2017 14:46:39 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBGEkc5t032673; Sat, 16 Dec 2017 14:46:38 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201712161446.vBGEkc5t032673@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Sat, 16 Dec 2017 14:46:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r326905 - in vendor/lld/dist: lib/ReaderWriter/MachO test/mach-o X-SVN-Group: vendor X-SVN-Commit-Author: dim X-SVN-Commit-Paths: in vendor/lld/dist: lib/ReaderWriter/MachO test/mach-o X-SVN-Commit-Revision: 326905 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, 16 Dec 2017 14:46:40 -0000 Author: dim Date: Sat Dec 16 14:46:38 2017 New Revision: 326905 URL: https://svnweb.freebsd.org/changeset/base/326905 Log: Vendor import of lld 5.0.1 release r320880: https://llvm.org/svn/llvm-project/lld/tags/RELEASE_501/final@320880 Modified: vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler.h vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_arm.cpp vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_x86.cpp vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp vendor/lld/dist/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp vendor/lld/dist/test/mach-o/lazy-bind-x86_64.yaml Modified: vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler.h ============================================================================== --- vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler.h Sat Dec 16 14:46:24 2017 (r326904) +++ vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler.h Sat Dec 16 14:46:38 2017 (r326905) @@ -112,6 +112,10 @@ class ArchHandler { (public) /// info in final executables. virtual bool isLazyPointer(const Reference &); + /// Reference from an __stub_helper entry to the required offset of the + /// lazy bind commands. + virtual Reference::KindValue lazyImmediateLocationKind() = 0; + /// Returns true if the specified relocation is paired to the next relocation. virtual bool isPairedReloc(const normalized::Relocation &) = 0; Modified: vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_arm.cpp ============================================================================== --- vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_arm.cpp Sat Dec 16 14:46:24 2017 (r326904) +++ vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_arm.cpp Sat Dec 16 14:46:38 2017 (r326905) @@ -67,6 +67,10 @@ class ArchHandler_arm : public ArchHandler { (public) return invalid; } + Reference::KindValue lazyImmediateLocationKind() override { + return lazyImmediateLocation; + } + Reference::KindValue pointerKind() override { return invalid; } Modified: vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp ============================================================================== --- vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp Sat Dec 16 14:46:24 2017 (r326904) +++ vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp Sat Dec 16 14:46:38 2017 (r326905) @@ -127,6 +127,10 @@ class ArchHandler_arm64 : public ArchHandler { (public return pointer64; } + Reference::KindValue lazyImmediateLocationKind() override { + return lazyImmediateLocation; + } + uint32_t dwarfCompactUnwindType() override { return 0x03000000; } Modified: vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_x86.cpp ============================================================================== --- vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_x86.cpp Sat Dec 16 14:46:24 2017 (r326904) +++ vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_x86.cpp Sat Dec 16 14:46:38 2017 (r326905) @@ -70,6 +70,10 @@ class ArchHandler_x86 : public ArchHandler { (public) return delta32; } + Reference::KindValue lazyImmediateLocationKind() override { + return lazyImmediateLocation; + } + Reference::KindValue unwindRefToEhFrameKind() override { return invalid; } Modified: vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp ============================================================================== --- vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp Sat Dec 16 14:46:24 2017 (r326904) +++ vendor/lld/dist/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp Sat Dec 16 14:46:38 2017 (r326905) @@ -116,6 +116,10 @@ class ArchHandler_x86_64 : public ArchHandler { (publi return unwindFDEToFunction; } + Reference::KindValue lazyImmediateLocationKind() override { + return lazyImmediateLocation; + } + Reference::KindValue unwindRefToEhFrameKind() override { return unwindInfoToEhFrame; } Modified: vendor/lld/dist/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp ============================================================================== --- vendor/lld/dist/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Sat Dec 16 14:46:24 2017 (r326904) +++ vendor/lld/dist/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Sat Dec 16 14:46:38 2017 (r326905) @@ -172,6 +172,8 @@ class Util { (private) SymbolScope &symbolScope); void appendSection(SectionInfo *si, NormalizedFile &file); uint32_t sectionIndexForAtom(const Atom *atom); + void fixLazyReferenceImm(const DefinedAtom *atom, uint32_t offset, + NormalizedFile &file); typedef llvm::DenseMap AtomToIndex; struct AtomAndIndex { const Atom *atom; uint32_t index; SymbolScope scope; }; @@ -1423,6 +1425,8 @@ void Util::addRebaseAndBindingInfo(const lld::File &at uint8_t segmentIndex; uint64_t segmentStartAddr; + uint32_t offsetInBindInfo = 0; + for (SectionInfo *sect : _sectionInfos) { segIndexForSection(sect, segmentIndex, segmentStartAddr); for (const AtomInfo &info : sect->atomsAndOffsets) { @@ -1467,6 +1471,59 @@ void Util::addRebaseAndBindingInfo(const lld::File &at bind.symbolName = targ->name(); bind.addend = ref->addend(); nFile.lazyBindingInfo.push_back(bind); + + // Now that we know the segmentOffset and the ordinal attribute, + // we can fix the helper's code + + fixLazyReferenceImm(atom, offsetInBindInfo, nFile); + + // 5 bytes for opcodes + variable sizes (target name + \0 and offset + // encode's size) + offsetInBindInfo += + 6 + targ->name().size() + llvm::getULEB128Size(bind.segOffset); + if (bind.ordinal > BIND_IMMEDIATE_MASK) + offsetInBindInfo += llvm::getULEB128Size(bind.ordinal); + } + } + } + } +} + +void Util::fixLazyReferenceImm(const DefinedAtom *atom, uint32_t offset, + NormalizedFile &file) { + for (const auto &ref : *atom) { + const DefinedAtom *da = dyn_cast(ref->target()); + if (da == nullptr) + return; + + const Reference *helperRef = nullptr; + for (const Reference *hr : *da) { + if (hr->kindValue() == _archHandler.lazyImmediateLocationKind()) { + helperRef = hr; + break; + } + } + if (helperRef == nullptr) + continue; + + // TODO: maybe get the fixed atom content from _archHandler ? + for (SectionInfo *sectInfo : _sectionInfos) { + for (const AtomInfo &atomInfo : sectInfo->atomsAndOffsets) { + if (atomInfo.atom == helperRef->target()) { + auto sectionContent = + file.sections[sectInfo->normalizedSectionIndex].content; + uint8_t *rawb = + file.ownedAllocations.Allocate(sectionContent.size()); + llvm::MutableArrayRef newContent{rawb, + sectionContent.size()}; + std::copy(sectionContent.begin(), sectionContent.end(), + newContent.begin()); + llvm::support::ulittle32_t *loc = + reinterpret_cast( + &newContent[atomInfo.offsetInSection + + helperRef->offsetInAtom()]); + *loc = offset; + file.sections[sectInfo->normalizedSectionIndex].content = newContent; } } } Modified: vendor/lld/dist/test/mach-o/lazy-bind-x86_64.yaml ============================================================================== --- vendor/lld/dist/test/mach-o/lazy-bind-x86_64.yaml Sat Dec 16 14:46:24 2017 (r326904) +++ vendor/lld/dist/test/mach-o/lazy-bind-x86_64.yaml Sat Dec 16 14:46:38 2017 (r326905) @@ -80,8 +80,8 @@ undefined-symbols: # CHECK-HELPERS:Disassembly of section __TEXT,__stub_helper: # CHECK-HELPERS: 68 00 00 00 00 pushq $0 -# CHECK-HELPERS: 68 10 00 00 00 pushq $16 -# CHECK-HELPERS: 68 20 00 00 00 pushq $32 +# CHECK-HELPERS: 68 0b 00 00 00 pushq $11 +# CHECK-HELPERS: 68 16 00 00 00 pushq $22 # Make sure the stub helper is correctly aligned # CHECK-DYLIBS: sectname __stub_helper