From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 6C312384E7A3 for ; Mon, 12 Dec 2022 20:35:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6C312384E7A3 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-oi1-x22a.google.com with SMTP id n205so12382641oib.1 for ; Mon, 12 Dec 2022 12:35:34 -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=8Df8MWQMIXuL5rkxenletbLbm6r4+En+G1s3XaUYgI0=; b=MdS1zYbQV1hid5LBjHSV9+RuXR67oTYRkNmsrRCHP+/N8LHu5Aopb6Nh/lRiQfqK3c 6OJqSDUWreOE1GrsQTBUzfXqdBCq7YPAv4zJbD5QqZQopkQiOwFpQRPUMMHWlwrCsBE7 S9Ok/NI7wJLVIDGTCzKTS6eYh64Uuwwy8wfbmj4vI0zaOVpX/AhWhZ4UIE6AMq245//r Bh6OtnNi8VUD4SOpXfjcyf/7pRXyzTyph1WOvBwIbWcBHzFWrQRDbmOKVr79zFCT3EOL E7t3Z3bAPBN4HWJZkRRMWk4U1q3CCLcsyIAhTewIapFXMCDp/i/blq1+PIS+xWBCq+Gp J0Iw== 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=8Df8MWQMIXuL5rkxenletbLbm6r4+En+G1s3XaUYgI0=; b=q4nwV0JnLdxmWYCT+UShifleZojP+eP/cikwTvd/WNP5RGfe7iFzZ1TtsmcrEZZsVD SGiGAjFnIQjEvpqT9VnsZChtS/9rljmtd+wZ/mgxiItQbbRj+a4FrMc/xFD3f60bh9Ks ZsmzMDDO0ick4Phq10r8SaaOMl93plHUeR7P4K/CGcC9bfIhflo6hzHvY3htUgpbSesG fT9KxTjTQPYN5mHfhuVNi0o0wwjIM+zwJLXrHP6B7IGBzFEZwcuDJRbzv+hv2ZGH8+Ug hjf/b4lPy0XT6yj/xSWiV+TecrKHbBoa9mPdLibroN/fOMBqwsrbcDok95Pp/f/Sj2Et Yowg== X-Gm-Message-State: ANoB5pmtRVQF8y/35GweJulI/9U3UYuMIfYMzlXXDql4NT9o8sDkDBPP D03xq1Bmo3KuX8YRtnXk81tAjFRc1dehP97utNAV+4Ng X-Google-Smtp-Source: AA0mqf60GM+iQOkdMSWwYTzHE39/qFW8VFzTMGMyj9DnGhHP3ZeVVC0pZ8DV8NSC5FkKbJ13jWKC9xfg+S7Lu/1jMGE= X-Received: by 2002:a05:6808:351:b0:359:d97b:3f6f with SMTP id j17-20020a056808035100b00359d97b3f6fmr20503oie.298.1670877333417; Mon, 12 Dec 2022 12:35:33 -0800 (PST) MIME-Version: 1.0 References: <20221206214444.799449-1-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Mon, 12 Dec 2022 12:34:57 -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=-3022.9 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 Thu, Dec 8, 2022 at 8:12 AM H.J. Lu wrote: > > 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. I am checking it in today. -- H.J.