[RFC,v4,6/6] Implement and document -z unique / -z nounique handling in gold

Message ID ea8dbf661f292a00bcd6aac07c063d96c51b0f2e.1594308458.git.vivek@collabora.com
State New
Headers show
Series
  • binutils patches for DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE
Related show

Commit Message

Alan Modra via Binutils July 9, 2020, 3:29 p.m.
---
 gold/layout.cc | 6 ++++++
 gold/options.h | 3 +++
 2 files changed, 9 insertions(+)

-- 
2.11.0

Comments

Alan Modra via Binutils July 9, 2020, 5:12 p.m. | #1
>  gold/layout.cc | 6 ++++++

>  gold/options.h | 3 +++

>  2 files changed, 9 insertions(+)

>

> diff --git a/gold/layout.cc b/gold/layout.cc

> index 13e533aaf2..9c4fc0d22d 100644

> --- a/gold/layout.cc

> +++ b/gold/layout.cc

> @@ -5358,6 +5358,12 @@ Layout::finish_dynamic_section(const Input_objects* input_objects,

>      flags |= elfcpp::DF_1_PIE;

>    if (flags != 0)

>      odyn->add_constant(elfcpp::DT_FLAGS_1, flags);

> +

> +  flags = 0;

> +  if (parameters->options().unique())

> +    flags |= elfcpp::DF_GNU_1_UNIQUE;

> +  if (flags != 0)

> +    odyn->add_constant(elfcpp::DT_GNU_FLAGS_1, flags);

>  }

>

>  // Set the size of the _DYNAMIC symbol table to be the size of the

> diff --git a/gold/options.h b/gold/options.h

> index 3c8d25a662..8902b94a84 100644

> --- a/gold/options.h

> +++ b/gold/options.h

> @@ -1463,6 +1463,9 @@ class General_options

>    DEFINE_bool(interpose, options::DASH_Z, '\0', false,

>               N_("Mark object to interpose all DSOs but executable"),

>               NULL);

> +  DEFINE_bool(unique, options::DASH_Z, '\0', false,

> +              N_("Mark DSO to be loaded at most once, and only in the main namespace"),

> +              N_("Do not mark the DSO as one to be loaded only in the main namespace"));

>    DEFINE_bool_alias(lazy, now, options::DASH_Z, '\0',

>                     N_("Mark object for lazy runtime binding"),

>                     NULL, true);


This is OK, with an appropriate ChangeLog entry.

Thanks!

-cary

Patch

diff --git a/gold/layout.cc b/gold/layout.cc
index 13e533aaf2..9c4fc0d22d 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -5358,6 +5358,12 @@  Layout::finish_dynamic_section(const Input_objects* input_objects,
     flags |= elfcpp::DF_1_PIE;
   if (flags != 0)
     odyn->add_constant(elfcpp::DT_FLAGS_1, flags);
+
+  flags = 0;
+  if (parameters->options().unique())
+    flags |= elfcpp::DF_GNU_1_UNIQUE;
+  if (flags != 0)
+    odyn->add_constant(elfcpp::DT_GNU_FLAGS_1, flags);
 }
 
 // Set the size of the _DYNAMIC symbol table to be the size of the
diff --git a/gold/options.h b/gold/options.h
index 3c8d25a662..8902b94a84 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -1463,6 +1463,9 @@  class General_options
   DEFINE_bool(interpose, options::DASH_Z, '\0', false,
 	      N_("Mark object to interpose all DSOs but executable"),
 	      NULL);
+  DEFINE_bool(unique, options::DASH_Z, '\0', false,
+              N_("Mark DSO to be loaded at most once, and only in the main namespace"),
+              N_("Do not mark the DSO as one to be loaded only in the main namespace"));
   DEFINE_bool_alias(lazy, now, options::DASH_Z, '\0',
 		    N_("Mark object for lazy runtime binding"),
 		    NULL, true);