From patchwork Tue Dec 6 21:44:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 30519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3064374wrr; Tue, 6 Dec 2022 13:46:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf5CE2JOnKLSuqheAFh39gSTNHhQi87lNTTZdWcY6q3WMRFPInKErsXLDXw2KhGEBhIYw+nV X-Received: by 2002:a17:906:a212:b0:7b2:804f:a31c with SMTP id r18-20020a170906a21200b007b2804fa31cmr57846124ejy.523.1670363170140; Tue, 06 Dec 2022 13:46:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670363170; cv=none; d=google.com; s=arc-20160816; b=xDQH7aWK+m6B6rkQOYADOs5AoGQV69LOZYM0J9fArUe5DoJ2QCQ6GiF+tq0qCLjP0F W5gtOm02BqTchg1HuYQTvPZFS3h4+fJlX1rn8/gW2Jws75ARgbA7DHu5WkUtvBTef714 e6txt0Wusa72OsQmKilSvIMw1LAPm0Q6hDI2eUOwRSPBa7rROiXmPisBeqZ5LFfJ7vGc FZZiByc7sCgtn6lcOE6xS4gaBnQ2bP+NlxKnxcGuRvXMbwonjKAf+fW8Qac+YqETPdOk FqNs8OAWi62yrISdbZlNvw8tzAVjhmOE+9yYU21fquFXPzpeoNIlqSjGhUrbhmTdOKN1 /qYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=NNFN8aiCbFt0C1cgsHzHt2MEct7QK4DROauIqLVutjQ=; b=BmFT06RL0ax9O5D8HglgTIhlq6NmaKu/SPXbvfq/uPtVo9D6z8ge1ItfPAeK78WZC2 TjJeHQ6nAtaHb/8Lfs73HawLGCq7aA9ZXDzwPAjnv//jClsLnAah9yIXTS46kuhbuHcg 8ip6pCqWtEMvZqwvGLEzRlJQebf1Wt3+5iHcV0lPiGeA2tcskyWXz0fneeiJ9wrUb7Ud gRNYNzDoYwplUjrVqPLt7IOuq4fIpVMT1K11nyXIzS6raADKuaTF/ZPQy0Rn/gHNRnyZ Gd5vbqOxIOud+Mz84ZO/6eh2Jtqm5iSwuI6RXl8Qkrj+yF9R/NeSPBI4mOOygwbCGKPZ G9kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=mfW+hT6W; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bc3-20020a056402204300b0046b2327d140si2488233edb.334.2022.12.06.13.46.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 13:46:10 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=mfW+hT6W; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CFA7D382D3D5 for ; Tue, 6 Dec 2022 21:45:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFA7D382D3D5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670363112; bh=NNFN8aiCbFt0C1cgsHzHt2MEct7QK4DROauIqLVutjQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mfW+hT6WJysm1UPjRhyQH8ATbw0U2gAp6mXQ9erPbM2gQDDcf92UT8ANMGBee2+GP HVXtwec9Ld9FZYxbpPv+veKJ3fKTXoXCiS4FCygdpZ+0MUDhdUZCDw0bB7Utm4zpq5 O1Y7nq9bSNZP9fOs8obfNKGKsCljy1+e+NqUsIG8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id BFF233839D01 for ; Tue, 6 Dec 2022 21:44:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BFF233839D01 Received: by mail-pl1-x635.google.com with SMTP id w23so15228530ply.12 for ; Tue, 06 Dec 2022 13:44:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NNFN8aiCbFt0C1cgsHzHt2MEct7QK4DROauIqLVutjQ=; b=NUG3SlsaQuN42a6s3TfcXko+HggwbH9PMa7XAb2jwzjbGMjBF0gMpkoOoBNa0VpR/B tKMPLi1Vln2IwWn8+1WalC31z8tsPoBDnl/DdsiFZXw0NklJpqnA4gR8GIQWZrXqEGEt wC1y9MW772wJWCMWuF6Y7lhZOJ+PYrL7XON2VGHSjbQuqfhAMFPawepKVmkCY4pm8cRx LxSdlO5fXDfPBMSw+8xLDXyfxJetG/SIPMZYbtMBCeRrYJTNklLI28m+8lKEi0hrKdCF qZbvjO/pUvtZFKxP6u2Jj5fx/2ABM5uvn/iy6c0NgoBskqlXnbjbi9FiTVtO4Iyiq1Nn pcJg== X-Gm-Message-State: ANoB5pnRrDUxu36OE+oavQ3Bmixgz0ZNAVYeAOHPpyZAN18lyx/MTqhx 9ukH+ODHI6gR80vAPnFiXuYxQrbAqj8= X-Received: by 2002:a17:902:f689:b0:189:8002:19a0 with SMTP id l9-20020a170902f68900b00189800219a0mr436760plg.29.1670363086408; Tue, 06 Dec 2022 13:44:46 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.30.207]) by smtp.gmail.com with ESMTPSA id l17-20020a17090b079100b00218a4795b0dsm11213122pjz.34.2022.12.06.13.44.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 13:44:46 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 8907A7401BC for ; Tue, 6 Dec 2022 13:44:44 -0800 (PST) To: binutils@sourceware.org Subject: [PATCH] gold: Remove BND from 64-bit x86-64 IBT PLT Date: Tue, 6 Dec 2022 13:44:44 -0800 Message-Id: <20221206214444.799449-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3024.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Binutils" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751502731495983661?= X-GMAIL-MSGID: =?utf-8?q?1751502731495983661?= Since MPX support has been removed from x86-64 psABI, remove BND from 64-bit IBT PLT by using 32-bit IBT PLT. PR gold/29851 * x86_64.cc (Output_data_plt_x86_64_ibt<32>::first_plt_entry): Renamed to ... (Output_data_plt_x86_64_ibt::first_plt_entry): This. (Output_data_plt_x86_64_ibt<64>::first_plt_entry): Removed. (Output_data_plt_x86_64_ibt::do_fill_first_plt_entry): Drop the size == 32 check. (Output_data_plt_x86_64_ibt<32>::plt_entry): Renamed to ... (Output_data_plt_x86_64_ibt::plt_entry): This. (Output_data_plt_x86_64_ibt<64>::plt_entry): Removed. (Output_data_plt_x86_64_ibt<32>::aplt_entry): Renamed to ... (Output_data_plt_x86_64_ibt::aplt_entry): This. (Output_data_plt_x86_64_ibt<64>::aplt_entry): Removed. (Output_data_plt_x86_64_ibt::do_fill_plt_entry): Drop the size == 32 check. (Output_data_plt_x86_64_ibt::fill_aplt_entry): Likewise. --- gold/x86_64.cc | 57 ++++++++------------------------------------------ 1 file changed, 9 insertions(+), 48 deletions(-) diff --git a/gold/x86_64.cc b/gold/x86_64.cc index 86b232a5e2d..83684b90fcf 100644 --- a/gold/x86_64.cc +++ b/gold/x86_64.cc @@ -2328,12 +2328,10 @@ Output_data_plt_x86_64_ibt::set_final_data_size() // The first entry in the IBT PLT. -template<> +template const unsigned char -Output_data_plt_x86_64_ibt<32>::first_plt_entry[plt_entry_size] = +Output_data_plt_x86_64_ibt::first_plt_entry[plt_entry_size] = { - // MPX isn't supported for x32, so we don't need the BND prefix. - // From AMD64 ABI Draft 0.98, page 76 0xff, 0x35, // pushq contents of memory address 0, 0, 0, 0, // replaced with address of .got + 8 0xff, 0x25, // jmp indirect @@ -2341,18 +2339,6 @@ Output_data_plt_x86_64_ibt<32>::first_plt_entry[plt_entry_size] = 0x90, 0x90, 0x90, 0x90 // noop (x4) }; -template<> -const unsigned char -Output_data_plt_x86_64_ibt<64>::first_plt_entry[plt_entry_size] = -{ - // Use the BND prefix so that IBT is compatible with MPX. - 0xff, 0x35, // pushq contents of memory address - 0, 0, 0, 0, // replaced with address of .got + 8 - 0xf2, 0xff, 0x25, // bnd jmp indirect - 0, 0, 0, 0, // replaced with address of .got + 16 - 0x0f, 0x1f, 0x00 // nop -}; - template void Output_data_plt_x86_64_ibt::do_fill_first_plt_entry( @@ -2362,7 +2348,7 @@ Output_data_plt_x86_64_ibt::do_fill_first_plt_entry( { // Offsets to the addresses needing relocation. const unsigned int roff1 = 2; - const unsigned int roff2 = (size == 32) ? 8 : 9; + const unsigned int roff2 = 8; memcpy(pov, first_plt_entry, plt_entry_size); // We do a jmp relative to the PC at the end of this instruction. @@ -2376,9 +2362,9 @@ Output_data_plt_x86_64_ibt::do_fill_first_plt_entry( // Subsequent entries in the IBT PLT. -template<> +template const unsigned char -Output_data_plt_x86_64_ibt<32>::plt_entry[plt_entry_size] = +Output_data_plt_x86_64_ibt::plt_entry[plt_entry_size] = { // From AMD64 ABI Draft 1.0-rc1, Chapter 13. 0xf3, 0x0f, 0x1e, 0xfa, // endbr64 @@ -2389,24 +2375,11 @@ Output_data_plt_x86_64_ibt<32>::plt_entry[plt_entry_size] = 0x90, 0x90 // nop }; -template<> -const unsigned char -Output_data_plt_x86_64_ibt<64>::plt_entry[plt_entry_size] = -{ - // From AMD64 ABI Draft 1.0-rc1, Chapter 13. - 0xf3, 0x0f, 0x1e, 0xfa, // endbr64 - 0x68, // pushq immediate - 0, 0, 0, 0, // replaced with offset into relocation table - 0xf2, 0xe9, // bnd jmpq relative - 0, 0, 0, 0, // replaced with offset to start of .plt - 0x90 // nop -}; - // Entries in the IBT Additional PLT. -template<> +template const unsigned char -Output_data_plt_x86_64_ibt<32>::aplt_entry[aplt_entry_size] = +Output_data_plt_x86_64_ibt::aplt_entry[aplt_entry_size] = { // From AMD64 ABI Draft 1.0-rc1, Chapter 13. 0xf3, 0x0f, 0x1e, 0xfa, // endbr64 @@ -2416,18 +2389,6 @@ Output_data_plt_x86_64_ibt<32>::aplt_entry[aplt_entry_size] = 0x90, 0x90 // nop }; -template<> -const unsigned char -Output_data_plt_x86_64_ibt<64>::aplt_entry[aplt_entry_size] = -{ - // From AMD64 ABI Draft 1.0-rc1, Chapter 13. - 0xf3, 0x0f, 0x1e, 0xfa, // endbr64 - 0xf2, 0xff, 0x25, // bnd jmpq indirect - 0, 0, 0, 0, // replaced with address of symbol in .got - 0x0f, 0x1f, 0x04, 0x00, // nop - 0x90, // nop -}; - template unsigned int Output_data_plt_x86_64_ibt::do_fill_plt_entry( @@ -2440,7 +2401,7 @@ Output_data_plt_x86_64_ibt::do_fill_plt_entry( { // Offsets to the addresses needing relocation. const unsigned int roff1 = 5; - const unsigned int roff2 = (size == 32) ? 10 : 11; + const unsigned int roff2 = 10; memcpy(pov, plt_entry, plt_entry_size); elfcpp::Swap_unaligned<32, false>::writeval(pov + roff1, plt_index); @@ -2459,7 +2420,7 @@ Output_data_plt_x86_64_ibt::fill_aplt_entry( unsigned int plt_index) { // Offset to the address needing relocation. - const unsigned int roff = (size == 32) ? 6 : 7; + const unsigned int roff = 6; // Check PC-relative offset overflow in PLT entry. uint64_t plt_got_pcrel_offset = (got_address + got_offset