ld: Add --enable-textrel-check=[no|yes|warning|error]

Message ID 20200525135726.622657-1-hjl.tools@gmail.com
State New
Headers show
Series
  • ld: Add --enable-textrel-check=[no|yes|warning|error]
Related show

Commit Message

Add a configure option, --enable-textrel-check=[no|yes|warning|error],
to decide what ELF linker should do by default with DT_TEXTREL in an
executable or shared library.

This patch depends on

https://sourceware.org/pipermail/binutils/2020-May/111250.html

OK for master?

H.J.
---
	PR ld/20824
	* NEWS: Mention --enable-textrel-check=[no|yes|warning|error].
	* configure.ac: Add --enable-textrel-check=[no|yes|warning|error].
	(DEFAULT_LD_TEXTREL_CHECK): New AC_DEFINE_UNQUOTED.
	(DEFAULT_LD_TEXTREL_CHECK_WARNING): Likewise.
	* ldmain.c (main): Initialize link_info.textrel_check to
	DEFAULT_LD_TEXTREL_CHECK.
	* lexsup.c (ld_options): Check DEFAULT_LD_TEXTREL_CHECK_WARNING.
	* config.in: Regenerated.
	* configure: Likewise.
---
 ld/NEWS         |  4 ++++
 ld/config.in    |  6 ++++++
 ld/configure    | 41 +++++++++++++++++++++++++++++++++++++++--
 ld/configure.ac | 28 ++++++++++++++++++++++++++++
 ld/ldmain.c     |  1 +
 ld/lexsup.c     |  7 ++++++-
 6 files changed, 84 insertions(+), 3 deletions(-)

-- 
2.26.2

Comments

On Mon, May 25, 2020 at 6:57 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>

> Add a configure option, --enable-textrel-check=[no|yes|warning|error],

> to decide what ELF linker should do by default with DT_TEXTREL in an

> executable or shared library.

>

> This patch depends on

>

> https://sourceware.org/pipermail/binutils/2020-May/111250.html

>

> OK for master?

>

> H.J.

> ---

>         PR ld/20824

>         * NEWS: Mention --enable-textrel-check=[no|yes|warning|error].

>         * configure.ac: Add --enable-textrel-check=[no|yes|warning|error].

>         (DEFAULT_LD_TEXTREL_CHECK): New AC_DEFINE_UNQUOTED.

>         (DEFAULT_LD_TEXTREL_CHECK_WARNING): Likewise.

>         * ldmain.c (main): Initialize link_info.textrel_check to

>         DEFAULT_LD_TEXTREL_CHECK.

>         * lexsup.c (ld_options): Check DEFAULT_LD_TEXTREL_CHECK_WARNING.

>         * config.in: Regenerated.

>         * configure: Likewise.

> ---

>  ld/NEWS         |  4 ++++

>  ld/config.in    |  6 ++++++

>  ld/configure    | 41 +++++++++++++++++++++++++++++++++++++++--

>  ld/configure.ac | 28 ++++++++++++++++++++++++++++

>  ld/ldmain.c     |  1 +

>  ld/lexsup.c     |  7 ++++++-

>  6 files changed, 84 insertions(+), 3 deletions(-)

>

> diff --git a/ld/NEWS b/ld/NEWS

> index 0aaa13d487..5dd912447e 100644

> --- a/ld/NEWS

> +++ b/ld/NEWS

> @@ -1,5 +1,9 @@

>  -*- text -*-

>

> +* Add a configure option, --enable-textrel-check=[no|yes|warning|error],

> +  to decide what ELF linker should do by default with DT_TEXTREL in an

> +  executable or shared library.

> +

>  * Add a command-line option for ELF linker, --warn-textrel, to warn that

>    DT_TEXTREL is set in a position-independent executable or shared object.

>

> diff --git a/ld/config.in b/ld/config.in

> index d93c9b0830..8cadcba60f 100644

> --- a/ld/config.in

> +++ b/ld/config.in

> @@ -16,6 +16,12 @@

>  /* Define if you want compressed debug sections by default. */

>  #undef DEFAULT_FLAG_COMPRESS_DEBUG

>

> +/* The default method for DT_TEXTREL check in ELF linker. */

> +#undef DEFAULT_LD_TEXTREL_CHECK

> +

> +/* Define to 1 if DT_TEXTREL check is warning in ELF linker by default. */

> +#undef DEFAULT_LD_TEXTREL_CHECK_WARNING

> +

>  /* 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 e1dbc95747..f766419d3f 100755

> --- a/ld/configure

> +++ b/ld/configure

> @@ -831,6 +831,7 @@ enable_got

>  enable_compressed_debug_sections

>  enable_new_dtags

>  enable_relro

> +enable_textrel_check

>  enable_separate_code

>  enable_default_hash_style

>  enable_werror

> @@ -1498,6 +1499,8 @@ Optional Features:

>                            compress debug sections by default]

>    --enable-new-dtags      set DT_RUNPATH instead of DT_RPATH by default]

>    --enable-relro          enable -z relro in ELF linker by default

> +  --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-default-hash-style={sysv,gnu,both}

>                            use this default hash style

> @@ -12032,7 +12035,7 @@ else

>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2

>    lt_status=$lt_dlunknown

>    cat > conftest.$ac_ext <<_LT_EOF

> -#line 12035 "configure"

> +#line 12038 "configure"

>  #include "confdefs.h"

>

>  #if HAVE_DLFCN_H

> @@ -12138,7 +12141,7 @@ else

>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2

>    lt_status=$lt_dlunknown

>    cat > conftest.$ac_ext <<_LT_EOF

> -#line 12141 "configure"

> +#line 12144 "configure"

>  #include "confdefs.h"

>

>  #if HAVE_DLFCN_H

> @@ -15876,6 +15879,16 @@ if test "${enable_relro+set}" = set; then :

>  esac

>  fi

>

> +# Decide if DT_TEXTREL check should be enabled in ELF linker.

> +ac_default_ld_textrel_check=unset

> +# Check whether --enable-textrel-check was given.

> +if test "${enable_textrel_check+set}" = set; then :

> +  enableval=$enable_textrel_check; ac_default_ld_textrel_check=$enableval

> +else

> +  ac_default_ld_textrel_check=no

> +fi

> +

> +

>  # Decide if -z separate-code should be enabled in ELF linker by default.

>  ac_default_ld_z_separate_code=unset

>  # Check whether --enable-separate-code was given.

> @@ -17618,6 +17631,30 @@ cat >>confdefs.h <<_ACEOF

>  _ACEOF

>

>

> +ac_default_ld_textrel_check_warning=0

> +case "${ac_default_ld_textrel_check}" in

> +  unset|no)

> +    ac_default_ld_textrel_check=textrel_check_none

> +    ;;

> +  yes|warning)

> +    ac_default_ld_textrel_check=textrel_check_warning

> +    ac_default_ld_textrel_check_warning=1

> +    ;;

> +  error)

> +    ac_default_ld_textrel_check=textrel_check_error

> +    ;;

> +esac

> +

> +cat >>confdefs.h <<_ACEOF

> +#define DEFAULT_LD_TEXTREL_CHECK $ac_default_ld_textrel_check

> +_ACEOF

> +

> +

> +cat >>confdefs.h <<_ACEOF

> +#define DEFAULT_LD_TEXTREL_CHECK_WARNING $ac_default_ld_textrel_check_warning

> +_ACEOF

> +

> +

>  if test "${ac_default_ld_z_separate_code}" = unset; then

>    ac_default_ld_z_separate_code=0

>  fi

> diff --git a/ld/configure.ac b/ld/configure.ac

> index b5e849d84a..5d3757d20b 100644

> --- a/ld/configure.ac

> +++ b/ld/configure.ac

> @@ -176,6 +176,14 @@ AC_ARG_ENABLE(relro,

>    no)  ac_default_ld_z_relro=0 ;;

>  esac])dnl

>

> +# Decide if DT_TEXTREL check should be enabled in ELF linker.

> +ac_default_ld_textrel_check=unset

> +AC_ARG_ENABLE([textrel-check],

> +             AC_HELP_STRING([--enable-textrel-check=@<:@yes|no|warning|error@:>@],

> +                            [enable DT_TEXTREL check in ELF linker]),

> +             [ac_default_ld_textrel_check=$enableval],

> +             [ac_default_ld_textrel_check=no])

> +

>  # Decide if -z separate-code should be enabled in ELF linker by default.

>  ac_default_ld_z_separate_code=unset

>  AC_ARG_ENABLE(separate-code,

> @@ -447,6 +455,26 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_RELRO,

>    $ac_default_ld_z_relro,

>    [Define to 1 if you want to enable -z relro in ELF linker by default.])

>

> +ac_default_ld_textrel_check_warning=0

> +case "${ac_default_ld_textrel_check}" in

> +  unset|no)

> +    ac_default_ld_textrel_check=textrel_check_none

> +    ;;

> +  yes|warning)

> +    ac_default_ld_textrel_check=textrel_check_warning

> +    ac_default_ld_textrel_check_warning=1

> +    ;;

> +  error)

> +    ac_default_ld_textrel_check=textrel_check_error

> +    ;;

> +esac

> +AC_DEFINE_UNQUOTED(DEFAULT_LD_TEXTREL_CHECK,

> +  $ac_default_ld_textrel_check,

> +  [The default method for DT_TEXTREL check in ELF linker.])

> +AC_DEFINE_UNQUOTED(DEFAULT_LD_TEXTREL_CHECK_WARNING,

> +  $ac_default_ld_textrel_check_warning,

> +  [Define to 1 if DT_TEXTREL check is warning in ELF linker by default.])

> +

>  if test "${ac_default_ld_z_separate_code}" = unset; then

>    ac_default_ld_z_separate_code=0

>  fi

> diff --git a/ld/ldmain.c b/ld/ldmain.c

> index 3499e7c784..e2c559ea3e 100644

> --- a/ld/ldmain.c

> +++ b/ld/ldmain.c

> @@ -286,6 +286,7 @@ main (int argc, char **argv)

>    link_info.combreloc = TRUE;

>    link_info.strip_discarded = TRUE;

>    link_info.prohibit_multiple_definition_absolute = FALSE;

> +  link_info.textrel_check = DEFAULT_LD_TEXTREL_CHECK;

>    link_info.emit_hash = DEFAULT_EMIT_SYSV_HASH;

>    link_info.emit_gnu_hash = DEFAULT_EMIT_GNU_HASH;

>    link_info.callbacks = &link_callbacks;

> diff --git a/ld/lexsup.c b/ld/lexsup.c

> index 3733a7c893..fbe200ffae 100644

> --- a/ld/lexsup.c

> +++ b/ld/lexsup.c

> @@ -517,7 +517,12 @@ static const struct ld_option ld_options[] =

>      '\0', NULL, N_("Warn if start of section changes due to alignment"),

>      TWO_DASHES },

>    { {"warn-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},

> -    '\0', NULL, N_("Warn if outpout has DT_TEXTREL"),

> +    '\0', NULL,

> +#if DEFAULT_LD_TEXTREL_CHECK_WARNING

> +    N_("Warn if outpout has DT_TEXTREL (default)"),

> +#else

> +    N_("Warn if outpout has DT_TEXTREL"),

> +#endif

>      TWO_DASHES },

>    { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},

>      '\0', NULL, NULL, NO_HELP },

> --

> 2.26.2

>


Hi, Nick, Alan,

Now, --warn-textrel has been added to master branch.  I'd like to check
it this patch.  Is it OK?

Thanks.

-- 
H.J.
Hi H.J.

>>         PR ld/20824

>>         * NEWS: Mention --enable-textrel-check=[no|yes|warning|error].

>>         * configure.ac: Add --enable-textrel-check=[no|yes|warning|error].

>>         (DEFAULT_LD_TEXTREL_CHECK): New AC_DEFINE_UNQUOTED.

>>         (DEFAULT_LD_TEXTREL_CHECK_WARNING): Likewise.

>>         * ldmain.c (main): Initialize link_info.textrel_check to

>>         DEFAULT_LD_TEXTREL_CHECK.

>>         * lexsup.c (ld_options): Check DEFAULT_LD_TEXTREL_CHECK_WARNING.

>>         * config.in: Regenerated.

>>         * configure: Likewise.


 
> Now, --warn-textrel has been added to master branch.  I'd like to check

> it this patch.  Is it OK?


Approved - please apply.

Cheers
  Nick

Patch

diff --git a/ld/NEWS b/ld/NEWS
index 0aaa13d487..5dd912447e 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,9 @@ 
 -*- text -*-
 
+* Add a configure option, --enable-textrel-check=[no|yes|warning|error],
+  to decide what ELF linker should do by default with DT_TEXTREL in an
+  executable or shared library.
+
 * Add a command-line option for ELF linker, --warn-textrel, to warn that
   DT_TEXTREL is set in a position-independent executable or shared object.
 
diff --git a/ld/config.in b/ld/config.in
index d93c9b0830..8cadcba60f 100644
--- a/ld/config.in
+++ b/ld/config.in
@@ -16,6 +16,12 @@ 
 /* Define if you want compressed debug sections by default. */
 #undef DEFAULT_FLAG_COMPRESS_DEBUG
 
+/* The default method for DT_TEXTREL check in ELF linker. */
+#undef DEFAULT_LD_TEXTREL_CHECK
+
+/* Define to 1 if DT_TEXTREL check is warning in ELF linker by default. */
+#undef DEFAULT_LD_TEXTREL_CHECK_WARNING
+
 /* 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 e1dbc95747..f766419d3f 100755
--- a/ld/configure
+++ b/ld/configure
@@ -831,6 +831,7 @@  enable_got
 enable_compressed_debug_sections
 enable_new_dtags
 enable_relro
+enable_textrel_check
 enable_separate_code
 enable_default_hash_style
 enable_werror
@@ -1498,6 +1499,8 @@  Optional Features:
                           compress debug sections by default]
   --enable-new-dtags      set DT_RUNPATH instead of DT_RPATH by default]
   --enable-relro          enable -z relro in ELF linker by default
+  --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-default-hash-style={sysv,gnu,both}
                           use this default hash style
@@ -12032,7 +12035,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12035 "configure"
+#line 12038 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12138,7 +12141,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12141 "configure"
+#line 12144 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15876,6 +15879,16 @@  if test "${enable_relro+set}" = set; then :
 esac
 fi
 
+# Decide if DT_TEXTREL check should be enabled in ELF linker.
+ac_default_ld_textrel_check=unset
+# Check whether --enable-textrel-check was given.
+if test "${enable_textrel_check+set}" = set; then :
+  enableval=$enable_textrel_check; ac_default_ld_textrel_check=$enableval
+else
+  ac_default_ld_textrel_check=no
+fi
+
+
 # Decide if -z separate-code should be enabled in ELF linker by default.
 ac_default_ld_z_separate_code=unset
 # Check whether --enable-separate-code was given.
@@ -17618,6 +17631,30 @@  cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+ac_default_ld_textrel_check_warning=0
+case "${ac_default_ld_textrel_check}" in
+  unset|no)
+    ac_default_ld_textrel_check=textrel_check_none
+    ;;
+  yes|warning)
+    ac_default_ld_textrel_check=textrel_check_warning
+    ac_default_ld_textrel_check_warning=1
+    ;;
+  error)
+    ac_default_ld_textrel_check=textrel_check_error
+    ;;
+esac
+
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_LD_TEXTREL_CHECK $ac_default_ld_textrel_check
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_LD_TEXTREL_CHECK_WARNING $ac_default_ld_textrel_check_warning
+_ACEOF
+
+
 if test "${ac_default_ld_z_separate_code}" = unset; then
   ac_default_ld_z_separate_code=0
 fi
diff --git a/ld/configure.ac b/ld/configure.ac
index b5e849d84a..5d3757d20b 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -176,6 +176,14 @@  AC_ARG_ENABLE(relro,
   no)  ac_default_ld_z_relro=0 ;;
 esac])dnl
 
+# Decide if DT_TEXTREL check should be enabled in ELF linker.
+ac_default_ld_textrel_check=unset
+AC_ARG_ENABLE([textrel-check],
+	      AC_HELP_STRING([--enable-textrel-check=@<:@yes|no|warning|error@:>@],
+			     [enable DT_TEXTREL check in ELF linker]),
+	      [ac_default_ld_textrel_check=$enableval],
+	      [ac_default_ld_textrel_check=no])
+
 # Decide if -z separate-code should be enabled in ELF linker by default.
 ac_default_ld_z_separate_code=unset
 AC_ARG_ENABLE(separate-code,
@@ -447,6 +455,26 @@  AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_RELRO,
   $ac_default_ld_z_relro,
   [Define to 1 if you want to enable -z relro in ELF linker by default.])
 
+ac_default_ld_textrel_check_warning=0
+case "${ac_default_ld_textrel_check}" in
+  unset|no)
+    ac_default_ld_textrel_check=textrel_check_none
+    ;;
+  yes|warning)
+    ac_default_ld_textrel_check=textrel_check_warning
+    ac_default_ld_textrel_check_warning=1
+    ;;
+  error)
+    ac_default_ld_textrel_check=textrel_check_error
+    ;;
+esac
+AC_DEFINE_UNQUOTED(DEFAULT_LD_TEXTREL_CHECK,
+  $ac_default_ld_textrel_check,
+  [The default method for DT_TEXTREL check in ELF linker.])
+AC_DEFINE_UNQUOTED(DEFAULT_LD_TEXTREL_CHECK_WARNING,
+  $ac_default_ld_textrel_check_warning,
+  [Define to 1 if DT_TEXTREL check is warning in ELF linker by default.])
+
 if test "${ac_default_ld_z_separate_code}" = unset; then
   ac_default_ld_z_separate_code=0
 fi
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 3499e7c784..e2c559ea3e 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -286,6 +286,7 @@  main (int argc, char **argv)
   link_info.combreloc = TRUE;
   link_info.strip_discarded = TRUE;
   link_info.prohibit_multiple_definition_absolute = FALSE;
+  link_info.textrel_check = DEFAULT_LD_TEXTREL_CHECK;
   link_info.emit_hash = DEFAULT_EMIT_SYSV_HASH;
   link_info.emit_gnu_hash = DEFAULT_EMIT_GNU_HASH;
   link_info.callbacks = &link_callbacks;
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 3733a7c893..fbe200ffae 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -517,7 +517,12 @@  static const struct ld_option ld_options[] =
     '\0', NULL, N_("Warn if start of section changes due to alignment"),
     TWO_DASHES },
   { {"warn-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
-    '\0', NULL, N_("Warn if outpout has DT_TEXTREL"),
+    '\0', NULL,
+#if DEFAULT_LD_TEXTREL_CHECK_WARNING
+    N_("Warn if outpout has DT_TEXTREL (default)"),
+#else
+    N_("Warn if outpout has DT_TEXTREL"),
+#endif
     TWO_DASHES },
   { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
     '\0', NULL, NULL, NO_HELP },