From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by sourceware.org (Postfix) with ESMTPS id 4933F38CCDFC for ; Thu, 8 Dec 2022 16:13:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4933F38CCDFC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-1433ef3b61fso2325578fac.10 for ; Thu, 08 Dec 2022 08:13:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=YVMSSBCiOJwmnwrFfAYYUEKh1PMgvQXvV5qOSlfjnkw=; b=AYD0OmgRJ4tgHrgJeJHelpPPQHnZ8gZjJr5PBXiPyfD+xpkvA2OjcLuiKbvspqtodD T31Fv65SMbW3+VI1LSST9A0n/1zcY5cRbmMoRimrZRBhM3/2VeVBe/yyxAVPGh/cMYB9 Gax8jtpRZzmzj+MqXRd2UAMYPuC46fQXbPzebFDLRZCDEk/QTLhhkOIuHL/zTO3hsoua cZ5IxHuY9ifWp3UBnOS/i4uHvL62b0P2sG6Ob7fPhX+fZXkY/q7QsC58fC4yiX2nPfld MTL8lKcAeyXKaR5j9xby+BzYm102PvcYGNkM2iUTscQ8svyupL4d69GRwBUhXr65o+cJ J4qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YVMSSBCiOJwmnwrFfAYYUEKh1PMgvQXvV5qOSlfjnkw=; b=Ir1uuzLeQGZWhqPyhVqUfMaekYylvMZNmrTVGCo4yc4nQMaALN0CH80Y0YV0PU90cq y2kMs9xe72zMl21q7eoygHP4Z8FxCd+nzj5UyuKW5Cxf4f8PN2FGQW8s2HDiaXcgbjf1 osfZcmgZL5MkCCbq6UuaXRa3lAu624eJ5c9YhD1sz2TGJIU0zoE6GV9aLwtexVeRIuZL fNiMZyvdr+uwzyCc+bf3by8an0+71yk4dGjIuEX3Qcsr8IiJN/EBZxv/+EdT3N3eJrC2 MNEM/RUdNGRYqXWEdJFn3/TM0Ecr+wUVvhBkRAjaDZbd1cxOb+vB+1yaSViWtZbZ1rOk 87cQ== X-Gm-Message-State: ANoB5pmCtUUr1GVsm7AklG3OOLgp3thGb3MdVdxyRXz8cSetAE3rg11k N6kbfu+/4h29a0a7yDTMCjYl2fCba2KQAotiL4ZquiSy X-Google-Smtp-Source: AA0mqf5ykzFoH/nIeOZiZZhjNLsqoDUm3dKDC1Ycnvywm0liyc4lk7uvQDHwzJwXp3thkynsAFYjs8gVvfCrNBTWKKs= X-Received: by 2002:a05:6870:cb45:b0:13b:8bb8:5c5b with SMTP id oz5-20020a056870cb4500b0013b8bb85c5bmr49603526oab.298.1670516006171; Thu, 08 Dec 2022 08:13:26 -0800 (PST) MIME-Version: 1.0 References: <20221206214444.799449-1-hjl.tools@gmail.com> In-Reply-To: <20221206214444.799449-1-hjl.tools@gmail.com> From: "H.J. Lu" Date: Thu, 8 Dec 2022 08:12:50 -0800 Message-ID: Subject: Re: [PATCH] gold: Remove BND from 64-bit x86-64 IBT PLT To: binutils@sourceware.org, Cary Coutant Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3021.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,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 List-Id: On Tue, Dec 6, 2022 at 1:44 PM H.J. Lu wrote: > > 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 > -- > 2.38.1 > Hi Cary, Is it OK for gold? Thanks. -- H.J.