From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by sourceware.org (Postfix) with ESMTPS id B46553857BA4 for ; Mon, 8 Jan 2024 15:24:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B46553857BA4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B46553857BA4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704727482; cv=none; b=lpNx0Lh6+BcJQScRqMSsXwSXB5X7xpm+fiDLzjv+62b7goCR7VC7sQBL3grazblREfCnu22UPB4VFPbK8jQUEysx3e/JDopdF72AhYmc1UDSq/f5EZ0zwYkeASCAObM4pRQuw0+zShi9FmlcoOfbYxpvrTgSuxzQSQJsFp/JPws= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704727482; c=relaxed/simple; bh=qhm3YQGU5Kz00XUIaqeEgn3dEQCyT2wGuprJcvJ+MY0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=WeUlQYksmUH2o3mvQhRwmE8JooiVhVb9rBhF8luF1dyUViamzpQ1kYVO7AP5r8SH4pOK5eI5Co6n9Tjg0/7TQffht7IIiicRvGkiS2LyAtpCeyx7DPAy6tzxXxpHxCZeetfB1NMExihrIRKGBn2Vck1cKzuQs6haYO/UT5UUsr0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-dbe78430946so1109163276.0 for ; Mon, 08 Jan 2024 07:24:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704727480; x=1705332280; darn=sourceware.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=O2Z+YMlQgsrLewyRfMjcwXqJhxkEVLxmZoAgA1ZLNEY=; b=klzHX2MVAoGabu9QO4ky+iyPx54Th6U4PyJt6fqTYP5f2VyO3P/W/iwupUsqPib7Ku +vHDH6LQ58+a/PtWAYkEN+P7nPfbj42Py/+otjlAOa+UV+07zot08nTRhXqB3PjCViyQ Xo5kpQJnvkk03gsxzDrfhZlxKFWs3s8rDlnnSWOsJy65OOmrmHFbaA/BsQLbX0o7HFkG OWfXPCEST4Eo8gGljzXk9ZWXwnRJJDOuvUdKzp89F2YS1sSxcr9+HALmr9astzmeTeED p7YQzv/V14WuLKmLS2mQWCT3mzgnFd3nWWxwWRUHB3RJC1Wvc+TQq/2GGF4MDjKhfjCG rHEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704727480; x=1705332280; h=content-transfer-encoding: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=O2Z+YMlQgsrLewyRfMjcwXqJhxkEVLxmZoAgA1ZLNEY=; b=X8rtrz3Um31kZdpavREavBJ6sZn0RRF6fkjnsDWaeTmDn95csICh6+IlE24G7qHmdV y6PDWorJD5OkLP/JBTYXUh2E013UuwJQg56wNPvm3j86B6IzfWlocZAqXJToIF9UZnAH cKnSNtEmuTi+bClxxTj3CTYRskVo7bC/kJMaoQM8gscwlavkYg04sVU+GNMmMXPhrAPd AEMOTLMgarC9od4K8i0qyCIEB/jGoPzPkaoEohAlTYQK2vSRuU5uFmXd8lGkgjdMLIZq Vmt6yXTqFlqFm/qlbr0Nhmq+BWp2ZuuNQ5FKmtUh+yPVljw95vv7BktpsPINVh/BInPW PyqQ== X-Gm-Message-State: AOJu0Yx6WP0IwSB/+vcsRVQ3BvKS/WNaK4cg7H72GJ+dlIHUcUsC/YOO cISFvsew8RaFikmU/N27I0XhckDh0BERWrzc3fMASorQ X-Google-Smtp-Source: AGHT+IHC+DIefzZRd9FEeAjyjrrMJU7PER7MXguQ9A7KBItMlZewowkJfDi5VC7ttEArocD8yWpon8bRy+9++U1iSK0= X-Received: by 2002:a25:6946:0:b0:dbe:d59a:20b2 with SMTP id e67-20020a256946000000b00dbed59a20b2mr1507792ybc.52.1704727479528; Mon, 08 Jan 2024 07:24:39 -0800 (PST) MIME-Version: 1.0 References: <20240106221001.1754844-1-hjl.tools@gmail.com> <20240106221001.1754844-3-hjl.tools@gmail.com> In-Reply-To: <20240106221001.1754844-3-hjl.tools@gmail.com> From: "H.J. Lu" Date: Mon, 8 Jan 2024 07:24:03 -0800 Message-ID: Subject: Re: [PATCH v2 2/2] ld: Add --enable-mark-plt configure option To: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3021.2 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,T_SCC_BODY_TEXT_LINE 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 Sat, Jan 6, 2024 at 2:10=E2=80=AFPM H.J. Lu wrote: > > Add --enable-mark-plt linker configure option to mark PLT entries with > DT_X86_64_PLT, DT_X86_64_PLTSZ and DT_X86_64_PLTENT dynamic tags by > default. > > * NEWS: Mention -z mark-plt/-z nomark-plt and --enable-mark-plt. > * config.in: Regenerated. > * configure: Likewise. > * configure.ac: Add --enable-mark-plt. > (DEFAULT_LD_Z_MARK_PLT): New AC_DEFINE_UNQUOTED. > * emulparams/x86-64-plt.sh (PARSE_AND_LIST_OPTIONS_X86_64_PLT): > Support DEFAULT_LD_Z_MARK_PLT. > * emultempl/elf-x86.em (elf_x86_64_before_parse): New function. > (LDEMUL_BEFORE_PARSE): New. Set to elf_x86_64_before_parse for > x86-64 targets. > --- > ld/NEWS | 5 +++++ > ld/config.in | 4 ++++ > ld/configure | 26 ++++++++++++++++++++++++-- > ld/configure.ac | 17 +++++++++++++++++ > ld/emulparams/x86-64-plt.sh | 7 ++++++- > ld/emultempl/elf-x86.em | 17 +++++++++++++++++ > 6 files changed, 73 insertions(+), 3 deletions(-) > > diff --git a/ld/NEWS b/ld/NEWS > index a2c0b7fbcfe..cedd0d72d1b 100644 > --- a/ld/NEWS > +++ b/ld/NEWS > @@ -1,5 +1,10 @@ > -*- text -*- > > +* Add -z mark-plt/-z nomark-plt options to x86-64 ELF linker to mark PLT > + entries with DT_X86_64_PLT, DT_X86_64_PLTSZ and DT_X86_64_PLTENT dynam= ic > + tags. Also added --enable-mark-plt configure option to mark PLT entri= es > + by default. > + > * Support Intel APX relocations. > > * On RISC-V, add ld target option --[no-]check-uleb128. Should rebuild = the > diff --git a/ld/config.in b/ld/config.in > index 86d90d53752..52d62f06ff0 100644 > --- a/ld/config.in > +++ b/ld/config.in > @@ -45,6 +45,10 @@ > default. */ > #undef DEFAULT_LD_WARN_RWX_SEGMENTS > > +/* Define to 1 if you want to enable -z mark-plt in ELF x86-64 linker by > + default. */ > +#undef DEFAULT_LD_Z_MARK_PLT > + > /* Define to 1 if you want to enable -z relro in ELF linker by default. = */ > #undef DEFAULT_LD_Z_RELRO > > diff --git a/ld/configure b/ld/configure > index 07eb669d906..b7f29ca68b7 100755 > --- a/ld/configure > +++ b/ld/configure > @@ -852,6 +852,7 @@ enable_new_dtags > enable_relro > enable_textrel_check > enable_separate_code > +enable_mark_plt > enable_warn_execstack > enable_error_execstack > enable_warn_rwx_segments > @@ -1546,6 +1547,7 @@ Optional Features: > --enable-textrel-check=3D[yes|no|warning|error] > enable DT_TEXTREL check in ELF linker > --enable-separate-code enable -z separate-code in ELF linker by defau= lt > + --enable-mark-plt enable -z mark-plt in ELF x86-64 linker by def= ault > --enable-warn-execstack enable warnings when creating an executable st= ack > --enable-error-execstack > turn executable stack warnings into errors > @@ -11681,7 +11683,7 @@ else > lt_dlunknown=3D0; lt_dlno_uscore=3D1; lt_dlneed_uscore=3D2 > lt_status=3D$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 11684 "configure" > +#line 11686 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -11787,7 +11789,7 @@ else > lt_dlunknown=3D0; lt_dlno_uscore=3D1; lt_dlneed_uscore=3D2 > lt_status=3D$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 11790 "configure" > +#line 11792 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -15682,6 +15684,17 @@ esac > fi > > > +# Decide if -z mark-plt should be enabled in ELF x86-64 linker by defaul= t. > +ac_default_ld_z_mark_plt=3Dunset > +# Check whether --enable-mark-plt was given. > +if test "${enable_mark_plt+set}" =3D set; then : > + enableval=3D$enable_mark_plt; case "${enableval}" in > + yes) ac_default_ld_z_mark_plt=3D1 ;; > + no) ac_default_ld_z_mark_plt=3D0 ;; > +esac > +fi > + > + > > # By default warn when an executable stack is created due to object file= s > # requesting such, not when the user specifies -z execstack. > @@ -19365,6 +19378,15 @@ cat >>confdefs.h <<_ACEOF > _ACEOF > > > +if test "${ac_default_ld_z_mark_plt}" =3D unset; then > + ac_default_ld_z_mark_plt=3D0 > +fi > + > +cat >>confdefs.h <<_ACEOF > +#define DEFAULT_LD_Z_MARK_PLT $ac_default_ld_z_mark_plt > +_ACEOF > + > + > > > cat >>confdefs.h <<_ACEOF > diff --git a/ld/configure.ac b/ld/configure.ac > index b46f415fe9b..4a11787ae71 100644 > --- a/ld/configure.ac > +++ b/ld/configure.ac > @@ -213,6 +213,16 @@ AC_ARG_ENABLE(separate-code, > no) ac_default_ld_z_separate_code=3D0 ;; > esac]) > > +# Decide if -z mark-plt should be enabled in ELF x86-64 linker by defaul= t. > +ac_default_ld_z_mark_plt=3Dunset > +AC_ARG_ENABLE(mark-plt, > + AS_HELP_STRING([--enable-mark-plt], > + [enable -z mark-plt in ELF x86-64 linker by default]), > +[case "${enableval}" in > + yes) ac_default_ld_z_mark_plt=3D1 ;; > + no) ac_default_ld_z_mark_plt=3D0 ;; > +esac]) > + > > # By default warn when an executable stack is created due to object file= s > # requesting such, not when the user specifies -z execstack. > @@ -562,6 +572,13 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_SEPARATE_CODE, > $ac_default_ld_z_separate_code, > [Define to 1 if you want to enable -z separate-code in ELF linker by d= efault.]) > > +if test "${ac_default_ld_z_mark_plt}" =3D unset; then > + ac_default_ld_z_mark_plt=3D0 > +fi > +AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_MARK_PLT, > + $ac_default_ld_z_mark_plt, > + [Define to 1 if you want to enable -z mark-plt in ELF x86-64 linker by= default.]) > + > > AC_DEFINE_UNQUOTED(DEFAULT_LD_WARN_EXECSTACK, > $ac_default_ld_warn_execstack, > diff --git a/ld/emulparams/x86-64-plt.sh b/ld/emulparams/x86-64-plt.sh > index 92732401dc7..d1a5c65937f 100644 > --- a/ld/emulparams/x86-64-plt.sh > +++ b/ld/emulparams/x86-64-plt.sh > @@ -1,5 +1,10 @@ > PARSE_AND_LIST_OPTIONS_X86_64_PLT=3D' > - fprintf (file, _("\ > + if (DEFAULT_LD_Z_MARK_PLT !=3D 0) > + fprintf (file, _("\ > + -z mark-plt Mark PLT with dynamic tags (default)\n\ > + -z nomark-plt Do not mark PLT with dynamic tags\n")); > + else > + fprintf (file, _("\ > -z mark-plt Mark PLT with dynamic tags\n\ > -z nomark-plt Do not mark PLT with dynamic tags (default= )\n")); > ' > diff --git a/ld/emultempl/elf-x86.em b/ld/emultempl/elf-x86.em > index 0ccad72ab9a..a6eda14253f 100644 > --- a/ld/emultempl/elf-x86.em > +++ b/ld/emultempl/elf-x86.em > @@ -56,3 +56,20 @@ EOF > > LDEMUL_BEFORE_PARSE=3Delf_x86_before_parse > fi > + > +case x${OUTPUT_FORMAT} in > + x*x86-64*) > +fragment < + > +static void > +elf_x86_64_before_parse (void) > +{ > + params.mark_plt =3D DEFAULT_LD_Z_MARK_PLT; > + > + elf_x86_before_parse (); > +} > +EOF > + > + LDEMUL_BEFORE_PARSE=3Delf_x86_64_before_parse > + ;; > +esac > -- > 2.43.0 > Any comments? Thanks. --=20 H.J.