PATCH: Implement ELF linker -z global option

H.J. Lu hongjiu.lu@intel.com
Tue Nov 20 16:48:00 GMT 2012


Hi,

This path implements ELF linker -z global option to set

#define DF_1_GLOBAL	0x00000002	/* Set RTLD_GLOBAL for this object.  */

OK to install?

Thanks.


H.J.
---
ld/

2012-11-16  H.J. Lu  <hongjiu.lu@intel.com>

	* ld.texinfo: Document "-z global".

	* emultempl/elf32.em (gld${EMULATION_NAME}_handle_option): Support
	"-z global".
	(gld${EMULATION_NAME}_list_options): Likewise.

ld/testsuite/

2012-11-16  H.J. Lu  <hongjiu.lu@intel.com>

	* ld-elf/global1.d: New file.

diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 9e263a9..acb01e5 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -2300,6 +2300,8 @@ fragment <<EOF
 EOF
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
 fragment <<EOF
+      else if (strcmp (optarg, "global") == 0)
+	link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
       else if (strcmp (optarg, "initfirst") == 0)
 	link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
       else if (strcmp (optarg, "interpose") == 0)
@@ -2419,6 +2421,9 @@ EOF
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
 fragment <<EOF
   fprintf (file, _("\
+  -z global                   Make symbols in DSO available for subsequently\n\
+                               loaded objects\n"));
+  fprintf (file, _("\
   -z initfirst                Mark DSO to be initialized first at runtime\n"));
   fprintf (file, _("\
   -z interpose                Mark object to interpose all DSOs but executable\n"));
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 4a8118f..7670e96 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -1024,6 +1024,11 @@ shared libraries are still allowed.
 @item execstack
 Marks the object as requiring executable stack.
 
+@item global
+This option is only meaningful when building a shared object.  It makes
+the symbols defined by this shared object available for symbol resolution
+of subsequently loaded libraries.
+
 @item initfirst
 This option is only meaningful when building a shared object.
 It marks the object so that its runtime initialization will occur
diff --git a/ld/testsuite/ld-elf/global1.d b/ld/testsuite/ld-elf/global1.d
new file mode 100644
index 0000000..eae7f0d
--- /dev/null
+++ b/ld/testsuite/ld-elf/global1.d
@@ -0,0 +1,8 @@
+#source: start.s
+#ld: -shared -z global
+#readelf: -d
+#target: *-*-linux* *-*-gnu*
+
+#...
+ 0x0*6ffffffb \(FLAGS_1\) *Flags: GLOBAL
+#pass



More information about the Binutils mailing list