From nobody Sat Dec 25 11:55:39 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 23D6D18F2EF2; Sat, 25 Dec 2021 11:55:43 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JLj7145qsz4lCP; Sat, 25 Dec 2021 11:55:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4BF5516CCC; Sat, 25 Dec 2021 11:55:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BPBtd9U006578; Sat, 25 Dec 2021 11:55:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BPBtdMm006577; Sat, 25 Dec 2021 11:55:39 GMT (envelope-from git) Date: Sat, 25 Dec 2021 11:55:39 GMT Message-Id: <202112251155.1BPBtdMm006577@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 82420cc68852 - stable/12 - Apply upstream lld fix for compressed input sections on BE targets List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 82420cc68852f332874d11b06153589fa7bce502 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640433342; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1ugBvphk98Le8RgdYaM6Vf5zV7785JtNdWXLh3HFgVQ=; b=f8eQkN/wBgQYB6nY3p53uLV3Rt963myjXhFCaz+Cf62akqsyoe21DiVjDvFf9Rr5fs4XSt 5bgHn5XxAHaIh3pvYfNg9pRwTkst/7/viEIpEcJ5wg4KlqW2M3+yPa3aEbOOwRBW5cLad1 JhQOLjcRHoxmoWU8R8QKuTBlGER/JHqn4arqE+lxB7ilB7ooPeXjGyTfhiQSDn8IbibdUk LC6rFE0gJjSlwAZ27wul16Lc5PQ2ABRSi1+EbMgVxZAW5Yz/Rnqmy75qGCWoePHbl4vsrz G/5GnSd9MScDOzVzmLTYuLtHv8ZN/fgAK1ROgZHYwfVLFFcTC35JYJUyasSWqg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640433342; a=rsa-sha256; cv=none; b=V0YIeSTQNLomn1H6ixuU0RGEg2yqI40E4Sd8n3QnZIpBVvuEoLnJNIgGzZisilHt/6LbAz H1eSnm20wbyHleyBl8nb1LAs3P4gI8v/yIP0MG66kuuYJs/42rSr1pj4scG3S8G0zbEaeF H98wj1q4j8sz3LK0mFYTlk9A1Qiv//ozCzFcBkI9+n/yYMS+S/0zeYQrfzzkQWgqq9Yk5J wim2oEqljJR1aQxRP1YqyqizBwWXhva1tMT3j3OptQvPjaj8fR1nEmR+0qBp+U8P1crw7S AETWuW/RkSuZj9IEOyAdt3W+aibe9KKoGi9IAsmVhe6JSpsrNA1qpf5JK+JczA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=82420cc68852f332874d11b06153589fa7bce502 commit 82420cc68852f332874d11b06153589fa7bce502 Author: Dimitry Andric AuthorDate: 2021-08-07 11:14:11 +0000 Commit: Dimitry Andric CommitDate: 2021-12-25 11:51:14 +0000 Apply upstream lld fix for compressed input sections on BE targets Merge commit c6ebc651b6fa from llvm git (by Simon Atanasyan): [LLD] Support compressed input sections on big-endian targets This patch enables compressed input sections on big-endian targets by checking the target endianness and selecting an appropriate `Chdr` structure. Fixes PR51369 Differential Revision: https://reviews.llvm.org/D107635 Reported by: emaste MFC after: 3 days (cherry picked from commit d69d07569ee2404705ff4c4abb45dc0b884eeb35) --- contrib/llvm-project/lld/ELF/InputSection.cpp | 47 ++++++++++++--------------- contrib/llvm-project/lld/ELF/InputSection.h | 1 + 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/contrib/llvm-project/lld/ELF/InputSection.cpp b/contrib/llvm-project/lld/ELF/InputSection.cpp index 6f16fc7abc48..f9cad7f975a7 100644 --- a/contrib/llvm-project/lld/ELF/InputSection.cpp +++ b/contrib/llvm-project/lld/ELF/InputSection.cpp @@ -88,7 +88,22 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags, if (!zlib::isAvailable()) error(toString(file) + ": contains a compressed section, " + "but zlib is not available"); - parseCompressedHeader(); + switch (config->ekind) { + case ELF32LEKind: + parseCompressedHeader(); + break; + case ELF32BEKind: + parseCompressedHeader(); + break; + case ELF64LEKind: + parseCompressedHeader(); + break; + case ELF64BEKind: + parseCompressedHeader(); + break; + default: + llvm_unreachable("unknown ELFT"); + } } } @@ -210,10 +225,7 @@ OutputSection *SectionBase::getOutputSection() { // When a section is compressed, `rawData` consists with a header followed // by zlib-compressed data. This function parses a header to initialize // `uncompressedSize` member and remove the header from `rawData`. -void InputSectionBase::parseCompressedHeader() { - using Chdr64 = typename ELF64LE::Chdr; - using Chdr32 = typename ELF32LE::Chdr; - +template void InputSectionBase::parseCompressedHeader() { // Old-style header if (name.startswith(".zdebug")) { if (!toStringRef(rawData).startswith("ZLIB")) { @@ -239,32 +251,13 @@ void InputSectionBase::parseCompressedHeader() { assert(flags & SHF_COMPRESSED); flags &= ~(uint64_t)SHF_COMPRESSED; - // New-style 64-bit header - if (config->is64) { - if (rawData.size() < sizeof(Chdr64)) { - error(toString(this) + ": corrupted compressed section"); - return; - } - - auto *hdr = reinterpret_cast(rawData.data()); - if (hdr->ch_type != ELFCOMPRESS_ZLIB) { - error(toString(this) + ": unsupported compression type"); - return; - } - - uncompressedSize = hdr->ch_size; - alignment = std::max(hdr->ch_addralign, 1); - rawData = rawData.slice(sizeof(*hdr)); - return; - } - - // New-style 32-bit header - if (rawData.size() < sizeof(Chdr32)) { + // New-style header + if (rawData.size() < sizeof(typename ELFT::Chdr)) { error(toString(this) + ": corrupted compressed section"); return; } - auto *hdr = reinterpret_cast(rawData.data()); + auto *hdr = reinterpret_cast(rawData.data()); if (hdr->ch_type != ELFCOMPRESS_ZLIB) { error(toString(this) + ": unsupported compression type"); return; diff --git a/contrib/llvm-project/lld/ELF/InputSection.h b/contrib/llvm-project/lld/ELF/InputSection.h index 5b91c1c90bd2..c914d0b42155 100644 --- a/contrib/llvm-project/lld/ELF/InputSection.h +++ b/contrib/llvm-project/lld/ELF/InputSection.h @@ -238,6 +238,7 @@ public: } protected: + template void parseCompressedHeader(); void uncompress() const;