From: "H.J. Lu" <hjl.tools@gmail.com>
To: binutils@sourceware.org
Subject: Re: [PATCH v2 2/2] ld: Add --enable-mark-plt configure option
Date: Mon, 8 Jan 2024 07:24:03 -0800 [thread overview]
Message-ID: <CAMe9rOpZ9Lj83kdq514mTxcRsR0owaHNGR0ivwEzgCZzMDCcnw@mail.gmail.com> (raw)
In-Reply-To: <20240106221001.1754844-3-hjl.tools@gmail.com>
On Sat, Jan 6, 2024 at 2:10 PM H.J. Lu <hjl.tools@gmail.com> 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 dynamic
> + tags. Also added --enable-mark-plt configure option to mark PLT entries
> + 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=[yes|no|warning|error]
> enable DT_TEXTREL check in ELF linker
> --enable-separate-code enable -z separate-code in ELF linker by default
> + --enable-mark-plt enable -z mark-plt in ELF x86-64 linker by default
> --enable-warn-execstack enable warnings when creating an executable stack
> --enable-error-execstack
> turn executable stack warnings into errors
> @@ -11681,7 +11683,7 @@ else
> lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> lt_status=$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=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> lt_status=$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 default.
> +ac_default_ld_z_mark_plt=unset
> +# Check whether --enable-mark-plt was given.
> +if test "${enable_mark_plt+set}" = set; then :
> + enableval=$enable_mark_plt; case "${enableval}" in
> + yes) ac_default_ld_z_mark_plt=1 ;;
> + no) ac_default_ld_z_mark_plt=0 ;;
> +esac
> +fi
> +
> +
>
> # By default warn when an executable stack is created due to object files
> # 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}" = unset; then
> + ac_default_ld_z_mark_plt=0
> +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=0 ;;
> esac])
>
> +# Decide if -z mark-plt should be enabled in ELF x86-64 linker by default.
> +ac_default_ld_z_mark_plt=unset
> +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=1 ;;
> + no) ac_default_ld_z_mark_plt=0 ;;
> +esac])
> +
>
> # By default warn when an executable stack is created due to object files
> # 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 default.])
>
> +if test "${ac_default_ld_z_mark_plt}" = unset; then
> + ac_default_ld_z_mark_plt=0
> +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='
> - fprintf (file, _("\
> + if (DEFAULT_LD_Z_MARK_PLT != 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=elf_x86_before_parse
> fi
> +
> +case x${OUTPUT_FORMAT} in
> + x*x86-64*)
> +fragment <<EOF
> +
> +static void
> +elf_x86_64_before_parse (void)
> +{
> + params.mark_plt = DEFAULT_LD_Z_MARK_PLT;
> +
> + elf_x86_before_parse ();
> +}
> +EOF
> +
> + LDEMUL_BEFORE_PARSE=elf_x86_64_before_parse
> + ;;
> +esac
> --
> 2.43.0
>
Any comments?
Thanks.
--
H.J.
next prev parent reply other threads:[~2024-01-08 15:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-06 22:09 [PATCH v2 0/2] Improve -z mark-plt H.J. Lu
2024-01-06 22:10 ` [PATCH v2 1/2] elf: Add elf_backend_add_glibc_version_dependency H.J. Lu
2024-01-08 15:22 ` H.J. Lu
2024-01-09 13:45 ` H.J. Lu
2024-01-06 22:10 ` [PATCH v2 2/2] ld: Add --enable-mark-plt configure option H.J. Lu
2024-01-08 15:24 ` H.J. Lu [this message]
2024-01-09 13:46 ` H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMe9rOpZ9Lj83kdq514mTxcRsR0owaHNGR0ivwEzgCZzMDCcnw@mail.gmail.com \
--to=hjl.tools@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).