From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by sourceware.org (Postfix) with ESMTPS id 3ED473857C41 for ; Tue, 9 Jan 2024 13:46:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3ED473857C41 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 3ED473857C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704808013; cv=none; b=xZ701Vtqv36UuggYyg5/u6lxAbWnrrRtdpATfpTr67lxrSM/KQaD0uSIUnxtq50BjdR4XZvGNJRBEfa35t2OM0Fn0SIMaozEeQbnCBWUiQ1ci8ARePOvyw2EkRUkegXrdWPgR61HOFHV44KqTZ/gPTVTAiykc+iMq5PnwiMvXJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704808013; c=relaxed/simple; bh=TVOJEZMq+1HFUNFobK/67emq1PwmtWJldeOIW61fRsI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=RHM1dwsM6ezwqWJe3PqtMF1apjrDYO/8H7rQf9NxQlEPOfhOE4vyBJl8oae5cqR1z0OmkaMjS08pC8NCW89lVMD3nmiQnAOHmkkMcitDyOYwdDNMe5J6sUTbRKPqt6M2hGWqZy87ixjgohtQ9J6Om7GHNfmHRKyU/mqKzJf4p9c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-5f3da7ba2bfso30128527b3.3 for ; Tue, 09 Jan 2024 05:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704808009; x=1705412809; 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=oN8gfMHd5IC2BJV1svVmLjWxz+1PpyQCDiOoa25AnHg=; b=C/OA4MIZH5wG6TOXBoa/m3ics1PuQ/Drn9mSMtbzDwrLnMjI+SyJ6iuw+PRSjEHKfi fK9iXuIIqAgayfMAv78oVu/p/Qiuu/qfvPAh16mE3ziKMKRPay4R4rEF7U0SdwMzPhkN L0bRKdOjzjMmZFST0yKjH4jHCSXxYHNkR8KM3L2gZJr0COprp+JE45WxlWNCEaCHsFpd Rgmgj0iI1HpAVec5eoKqiffylY73H9qX6n7JB8M4fFa1nEK3bocP4suivUNVwmcMR33g 4q50S6Y3E0BGQIs3F0vInFL62eEtySH1N7A2QbWCDFVxwd5Yjq/KSrRsh0mY1gZ3Tqfi TNlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704808009; x=1705412809; 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=oN8gfMHd5IC2BJV1svVmLjWxz+1PpyQCDiOoa25AnHg=; b=N7ELEstviH4YFmjqu0onneYSIjn+EjRvpMi6uhQXKj+5gyQ+Ew8N/C9nbkIIStrnkM qjUg34Wq2xIL7jSaIfcdyqX6jm5aeOLxmCNSdyfbzWEratpVCaNsQ9vj08MBjLr/BFQQ dLtIp6Ychcpp7d9+NIPszSUZ2n7723YM0QAc5dnnJrIpjo+I9aR0WY1Z4HmG+U7yMKbN faXWCnyovMVm/Mxh8hmmYGKMWuXi1XxlQ1XxWjePXQImvjsZhk5Ip59VjkYtlmcspyvd CLyj7/Ra2TXcuF2X0U9Kk43eVLzbH/fRjVIWGjCniuX1nth6wLgX+D4Kln7z2y+Neu8J 1sog== X-Gm-Message-State: AOJu0YzbqdI7a9ZJbRWuV005Ql6LVJympD/MIvSegfmNAusG63VhIi2W WEyMDv+jbhde62F0s5JZ8Xj3fmWp+PioFel+M01ieBAO5Ls= X-Google-Smtp-Source: AGHT+IHlUQ7IuePIlLSSKa5jCK/0NXyAFpP7g/lLfT/cctyVeMXzFAm9tRQufVcL9M8NIhiua8GqXUrsN8lhVAC9eQw= X-Received: by 2002:a81:9151:0:b0:5d7:1940:f3de with SMTP id i78-20020a819151000000b005d71940f3demr3891631ywg.70.1704808009266; Tue, 09 Jan 2024 05:46:49 -0800 (PST) MIME-Version: 1.0 References: <20240106221001.1754844-1-hjl.tools@gmail.com> <20240106221001.1754844-3-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Tue, 9 Jan 2024 05:46:13 -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.1 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 Mon, Jan 8, 2024 at 7:24=E2=80=AFAM H.J. Lu wrote: > > On Sat, Jan 6, 2024 at 2:10=E2=80=AFPM H.J. Lu wrot= e: > > > > 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 P= LT > > + entries with DT_X86_64_PLT, DT_X86_64_PLTSZ and DT_X86_64_PLTENT dyn= amic > > + tags. Also added --enable-mark-plt configure option to mark PLT ent= ries > > + by default. > > + > > * Support Intel APX relocations. > > > > * On RISC-V, add ld target option --[no-]check-uleb128. Should rebuil= d 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 def= ault > > + --enable-mark-plt enable -z mark-plt in ELF x86-64 linker by d= efault > > --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=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 defa= ult. > > +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 fi= les > > # 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 defa= ult. > > +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 fi= les > > # 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}" =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 (defau= lt)\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. > > -- > H.J. I will check it in later today. --=20 H.J.