unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE
@ 2020-03-30 17:42 Vivek Das Mohapatra via Libc-alpha
  2020-03-30 17:42 ` [RFC][PATCH 1/6] Define a new DT_FLAGS_1 flag DF_1_UNIQUE for ld, readelf et al Vivek Das Mohapatra via Libc-alpha
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Vivek Das Mohapatra via Libc-alpha @ 2020-03-30 17:42 UTC (permalink / raw)
  To: vivek, libc-alpha

This patch series is in support of the glibc RTLD_SHARED work
discussed in https://sourceware.org/bugzilla/show_bug.cgi?id=22745.

It adds a DT_FLAGS_1 value DF_1_UNIQUE which is intended to mark
libraries which should implicitly be opened as if RTLD_SHARED
had been passed to dlmopen when the target namespace is not
LM_ID_BASE.

This patch series adds support for DF_1_UNIQUE to ld, gold, and
readelf (and documents it in the help text and so forth).

Vivek Das Mohapatra (6):
  Define a new DT_FLAGS_1 flag DF_1_UNIQUE for ld, readelf et al
  Handle DF_1_UNIQUE in ld
  Document DF_1_UNIQUE in the man page and ld help output
  Handle DF_1_UNIQUE in readelf
  Define DT_FLAGS_1 flag DF_1_UNIQUE for gold
  Implement and document DF_1_UNIQUE handling in gold

 binutils/readelf.c   | 5 +++++
 elfcpp/elfcpp.h      | 4 +++-
 gold/layout.cc       | 2 ++
 gold/options.h       | 3 +++
 include/elf/common.h | 1 +
 ld/emultempl/elf.em  | 2 ++
 ld/ld.texi           | 7 +++++++
 ld/lexsup.c          | 2 ++
 8 files changed, 25 insertions(+), 1 deletion(-)

-- 
2.11.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [RFC][PATCH 1/6] Define a new DT_FLAGS_1 flag DF_1_UNIQUE for ld, readelf et al
  2020-03-30 17:42 [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Vivek Das Mohapatra via Libc-alpha
@ 2020-03-30 17:42 ` Vivek Das Mohapatra via Libc-alpha
  2020-03-30 17:42 ` [RFC][PATCH 2/6] Handle DF_1_UNIQUE in ld Vivek Das Mohapatra via Libc-alpha
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Vivek Das Mohapatra via Libc-alpha @ 2020-03-30 17:42 UTC (permalink / raw)
  To: vivek, libc-alpha

---
 include/elf/common.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/elf/common.h b/include/elf/common.h
index 6741c34a00..afea0973b9 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -1095,6 +1095,7 @@
 #define	DF_1_KMOD	0x10000000
 #define	DF_1_WEAKFILTER	0x20000000
 #define	DF_1_NOCOMMON	0x40000000
+#define	DF_1_UNIQUE	0x80000000
 
 /* Flag values for the DT_FLAGS entry.	*/
 #define DF_ORIGIN	(1 << 0)
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC][PATCH 2/6] Handle DF_1_UNIQUE in ld
  2020-03-30 17:42 [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Vivek Das Mohapatra via Libc-alpha
  2020-03-30 17:42 ` [RFC][PATCH 1/6] Define a new DT_FLAGS_1 flag DF_1_UNIQUE for ld, readelf et al Vivek Das Mohapatra via Libc-alpha
@ 2020-03-30 17:42 ` Vivek Das Mohapatra via Libc-alpha
  2020-03-30 17:42 ` [RFC][PATCH 3/6] Document DF_1_UNIQUE in the man page and ld help output Vivek Das Mohapatra via Libc-alpha
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Vivek Das Mohapatra via Libc-alpha @ 2020-03-30 17:42 UTC (permalink / raw)
  To: vivek, libc-alpha

---
 ld/emultempl/elf.em | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index bb7e537530..3d63917313 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -787,6 +787,8 @@ fragment <<EOF
 	  link_info.flags |= (bfd_vma) DF_ORIGIN;
 	  link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
 	}
+      else if (strcmp (optarg, "unique") == 0)
+        link_info.flags_1 |= (bfd_vma) DF_1_UNIQUE;
       else if (strcmp (optarg, "combreloc") == 0)
 	link_info.combreloc = TRUE;
       else if (strcmp (optarg, "nocombreloc") == 0)
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC][PATCH 3/6] Document DF_1_UNIQUE in the man page and ld help output
  2020-03-30 17:42 [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Vivek Das Mohapatra via Libc-alpha
  2020-03-30 17:42 ` [RFC][PATCH 1/6] Define a new DT_FLAGS_1 flag DF_1_UNIQUE for ld, readelf et al Vivek Das Mohapatra via Libc-alpha
  2020-03-30 17:42 ` [RFC][PATCH 2/6] Handle DF_1_UNIQUE in ld Vivek Das Mohapatra via Libc-alpha
@ 2020-03-30 17:42 ` Vivek Das Mohapatra via Libc-alpha
  2020-03-30 17:42 ` [RFC][PATCH 4/6] Handle DF_1_UNIQUE in readelf Vivek Das Mohapatra via Libc-alpha
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Vivek Das Mohapatra via Libc-alpha @ 2020-03-30 17:42 UTC (permalink / raw)
  To: vivek, libc-alpha

---
 ld/ld.texi  | 7 +++++++
 ld/lexsup.c | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/ld/ld.texi b/ld/ld.texi
index 9f562935be..af7dfcbb41 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1271,6 +1271,13 @@ Specify that the dynamic loader should modify its symbol search order
 so that symbols in this shared library interpose all other shared
 libraries not so marked.
 
+@item unique
+When generating a shared library or other dynamically loadable ELF object
+mark it as one that should only ever be loaded once, and only in the main
+namespace (when using @code{dlmopen}). This is primarily used to mark
+fundamental libraries such as libc, libpthread et al which cannot function
+correctly unless they are the sole instances of themselves.
+
 @item lazy
 When generating an executable or shared library, mark it to tell the
 dynamic linker to defer function call resolution to the point when
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 2597e2d630..3876b922f4 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -1806,6 +1806,8 @@ elf_shlib_list_options (FILE *file)
   fprintf (file, _("\
   -z interpose                Mark object to interpose all DSOs but executable\n"));
   fprintf (file, _("\
+  -z unique                   Mark DSO to be loaded at most once, and only in the main namespace\n"));
+  fprintf (file, _("\
   -z lazy                     Mark object lazy runtime binding (default)\n"));
   fprintf (file, _("\
   -z loadfltr                 Mark object requiring immediate process\n"));
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC][PATCH 4/6] Handle DF_1_UNIQUE in readelf
  2020-03-30 17:42 [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Vivek Das Mohapatra via Libc-alpha
                   ` (2 preceding siblings ...)
  2020-03-30 17:42 ` [RFC][PATCH 3/6] Document DF_1_UNIQUE in the man page and ld help output Vivek Das Mohapatra via Libc-alpha
@ 2020-03-30 17:42 ` Vivek Das Mohapatra via Libc-alpha
  2020-03-30 17:42 ` [RFC][PATCH 5/6] Define DT_FLAGS_1 flag DF_1_UNIQUE for gold Vivek Das Mohapatra via Libc-alpha
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Vivek Das Mohapatra via Libc-alpha @ 2020-03-30 17:42 UTC (permalink / raw)
  To: vivek, libc-alpha

---
 binutils/readelf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index eb41e10dae..ed1d757623 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -10349,6 +10349,11 @@ process_dynamic_section (Filedata * filedata)
 		      printf (" NOCOMMON");
 		      val ^= DF_1_NOCOMMON;
 		    }
+                  if (val & DF_1_UNIQUE)
+                    {
+                      printf (" UNIQUE");
+                      val ^= DF_1_UNIQUE;
+                    }
 		  if (val != 0)
 		    printf (" %lx", val);
 		  puts ("");
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC][PATCH 5/6] Define DT_FLAGS_1 flag DF_1_UNIQUE for gold
  2020-03-30 17:42 [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Vivek Das Mohapatra via Libc-alpha
                   ` (3 preceding siblings ...)
  2020-03-30 17:42 ` [RFC][PATCH 4/6] Handle DF_1_UNIQUE in readelf Vivek Das Mohapatra via Libc-alpha
@ 2020-03-30 17:42 ` Vivek Das Mohapatra via Libc-alpha
  2020-03-30 17:42 ` [RFC][PATCH 6/6] Implement and document DF_1_UNIQUE handling in gold Vivek Das Mohapatra via Libc-alpha
  2020-03-30 18:06 ` [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Florian Weimer
  6 siblings, 0 replies; 11+ messages in thread
From: Vivek Das Mohapatra via Libc-alpha @ 2020-03-30 17:42 UTC (permalink / raw)
  To: vivek, libc-alpha

---
 elfcpp/elfcpp.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h
index 339faadaf3..7740fbe202 100644
--- a/elfcpp/elfcpp.h
+++ b/elfcpp/elfcpp.h
@@ -897,6 +897,7 @@ enum DF
 };
 
 // Flags found in the DT_FLAGS_1 dynamic element.
+// See also: include/elf/common.h
 
 enum DF_1
 {
@@ -913,7 +914,8 @@ enum DF_1
   DF_1_INTERPOSE = 0x400,
   DF_1_NODEFLIB = 0x800,
   DF_1_NODUMP = 0x1000,
-  DF_1_CONLFAT = 0x2000
+  DF_1_CONLFAT = 0x2000,
+  DF_1_UNIQUE = 0x80000000
 };
 
 // Version numbers which appear in the vd_version field of a Verdef
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC][PATCH 6/6] Implement and document DF_1_UNIQUE handling in gold
  2020-03-30 17:42 [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Vivek Das Mohapatra via Libc-alpha
                   ` (4 preceding siblings ...)
  2020-03-30 17:42 ` [RFC][PATCH 5/6] Define DT_FLAGS_1 flag DF_1_UNIQUE for gold Vivek Das Mohapatra via Libc-alpha
@ 2020-03-30 17:42 ` Vivek Das Mohapatra via Libc-alpha
  2020-03-30 18:06 ` [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Florian Weimer
  6 siblings, 0 replies; 11+ messages in thread
From: Vivek Das Mohapatra via Libc-alpha @ 2020-03-30 17:42 UTC (permalink / raw)
  To: vivek, libc-alpha

---
 gold/layout.cc | 2 ++
 gold/options.h | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/gold/layout.cc b/gold/layout.cc
index be437f3900..d97ac57afc 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -5351,6 +5351,8 @@ Layout::finish_dynamic_section(const Input_objects* input_objects,
     flags |= elfcpp::DF_1_NOW;
   if (parameters->options().Bgroup())
     flags |= elfcpp::DF_1_GROUP;
+  if (parameters->options().unique())
+    flags |= elfcpp::DF_1_UNIQUE;
   if (flags != 0)
     odyn->add_constant(elfcpp::DT_FLAGS_1, flags);
 }
diff --git a/gold/options.h b/gold/options.h
index b2059d984c..de151642c7 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -1459,6 +1459,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"),
+              NULL);
   DEFINE_bool_alias(lazy, now, options::DASH_Z, '\0',
 		    N_("Mark object for lazy runtime binding"),
 		    NULL, true);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE
  2020-03-30 17:42 [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Vivek Das Mohapatra via Libc-alpha
                   ` (5 preceding siblings ...)
  2020-03-30 17:42 ` [RFC][PATCH 6/6] Implement and document DF_1_UNIQUE handling in gold Vivek Das Mohapatra via Libc-alpha
@ 2020-03-30 18:06 ` Florian Weimer
  2020-03-31 12:11   ` Vivek Das Mohapatra via Libc-alpha
  6 siblings, 1 reply; 11+ messages in thread
From: Florian Weimer @ 2020-03-30 18:06 UTC (permalink / raw)
  To: Vivek Das Mohapatra via Libc-alpha; +Cc: vivek

* Vivek Das Mohapatra via Libc-alpha:

> This patch series is in support of the glibc RTLD_SHARED work
> discussed in https://sourceware.org/bugzilla/show_bug.cgi?id=22745.
>
> It adds a DT_FLAGS_1 value DF_1_UNIQUE which is intended to mark
> libraries which should implicitly be opened as if RTLD_SHARED
> had been passed to dlmopen when the target namespace is not
> LM_ID_BASE.
>
> This patch series adds support for DF_1_UNIQUE to ld, gold, and
> readelf (and documents it in the help text and so forth).

I think you should repost this series to the binutils list.

It would perhaps be less controversial to add a new dynamic tag in the
GNU range for this, rather than a global flag value (in the space
shared with other operating systems).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE
  2020-03-30 18:06 ` [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Florian Weimer
@ 2020-03-31 12:11   ` Vivek Das Mohapatra via Libc-alpha
  2020-05-29 14:00     ` Vivek Das Mohapatra via Libc-alpha
  0 siblings, 1 reply; 11+ messages in thread
From: Vivek Das Mohapatra via Libc-alpha @ 2020-03-31 12:11 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Vivek Das Mohapatra via Libc-alpha, vivek

> It would perhaps be less controversial to add a new dynamic tag in the
> GNU range for this, rather than a global flag value (in the space
> shared with other operating systems).

Ok, I'll do that. Thanks. Other than that, do you see any problems with
the implementation or documentation?




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE
  2020-03-31 12:11   ` Vivek Das Mohapatra via Libc-alpha
@ 2020-05-29 14:00     ` Vivek Das Mohapatra via Libc-alpha
  2020-05-29 16:13       ` Florian Weimer via Libc-alpha
  0 siblings, 1 reply; 11+ messages in thread
From: Vivek Das Mohapatra via Libc-alpha @ 2020-05-29 14:00 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Vivek Das Mohapatra via Libc-alpha, vivek

On Tue, 31 Mar 2020, Vivek Das Mohapatra via Libc-alpha wrote:

>> It would perhaps be less controversial to add a new dynamic tag in the
>> GNU range for this, rather than a global flag value (in the space
>> shared with other operating systems).
>
> Ok, I'll do that. Thanks. Other than that, do you see any problems with
> the implementation or documentation?

Finally got back round to this bit - could you tell me what the GNU range
is exactly? Did you mean put it in DT_FLAGS instead? or inbetween DT_LOOS
and DT_HIOS? Or something else?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE
  2020-05-29 14:00     ` Vivek Das Mohapatra via Libc-alpha
@ 2020-05-29 16:13       ` Florian Weimer via Libc-alpha
  0 siblings, 0 replies; 11+ messages in thread
From: Florian Weimer via Libc-alpha @ 2020-05-29 16:13 UTC (permalink / raw)
  To: Vivek Das Mohapatra via Libc-alpha; +Cc: vivek

* Vivek Das Mohapatra via Libc-alpha:

> On Tue, 31 Mar 2020, Vivek Das Mohapatra via Libc-alpha wrote:
>
>>> It would perhaps be less controversial to add a new dynamic tag in the
>>> GNU range for this, rather than a global flag value (in the space
>>> shared with other operating systems).
>>
>> Ok, I'll do that. Thanks. Other than that, do you see any problems with
>> the implementation or documentation?
>
> Finally got back round to this bit - could you tell me what the GNU range
> is exactly? Did you mean put it in DT_FLAGS instead? or inbetween DT_LOOS
> and DT_HIOS? Or something else?

Yes, I expect a constant value somewhere around DT_GNU_PRELINKED or
DT_GNU_HASH, depending on exact semantics.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-05-29 16:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 17:42 [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Vivek Das Mohapatra via Libc-alpha
2020-03-30 17:42 ` [RFC][PATCH 1/6] Define a new DT_FLAGS_1 flag DF_1_UNIQUE for ld, readelf et al Vivek Das Mohapatra via Libc-alpha
2020-03-30 17:42 ` [RFC][PATCH 2/6] Handle DF_1_UNIQUE in ld Vivek Das Mohapatra via Libc-alpha
2020-03-30 17:42 ` [RFC][PATCH 3/6] Document DF_1_UNIQUE in the man page and ld help output Vivek Das Mohapatra via Libc-alpha
2020-03-30 17:42 ` [RFC][PATCH 4/6] Handle DF_1_UNIQUE in readelf Vivek Das Mohapatra via Libc-alpha
2020-03-30 17:42 ` [RFC][PATCH 5/6] Define DT_FLAGS_1 flag DF_1_UNIQUE for gold Vivek Das Mohapatra via Libc-alpha
2020-03-30 17:42 ` [RFC][PATCH 6/6] Implement and document DF_1_UNIQUE handling in gold Vivek Das Mohapatra via Libc-alpha
2020-03-30 18:06 ` [RFC][PATCH 0/6] binutils patches to add DT_FLAGS_1 / DF_1_UNIQUE Florian Weimer
2020-03-31 12:11   ` Vivek Das Mohapatra via Libc-alpha
2020-05-29 14:00     ` Vivek Das Mohapatra via Libc-alpha
2020-05-29 16:13       ` Florian Weimer via Libc-alpha

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).