[binutils-gdb] ld/x86: Remove hidden _edata, __bss_start, and _end

H.J.Lu hjl@sourceware.org
Fri Jun 8 19:43:00 GMT 2018


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ecf99cc09236316db27fd8ffaedca864f81ea081

commit ecf99cc09236316db27fd8ffaedca864f81ea081
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Jun 8 12:41:31 2018 -0700

    ld/x86: Remove hidden _edata, __bss_start, and _end
    
    There is no need to put hidden _edata, __bss_start, and _end in dynamic
    symbol table in shared libraries.
    
    bfd/
    
    	PR ld/23161
    	* elfxx-x86.c (elf_x86_hide_linker_defined): New function.
    	(_bfd_x86_elf_link_check_relocs): Use it to hide hidden
    	__bss_start, _end and _edata in shared libraries.
    
    ld/
    
    	PR ld/23161
    	* testsuite/ld-elf/pr23161d.rd: Remove local _edata, __bss_start,
    	and _end from dynamic symbol table.

Diff:
---
 bfd/ChangeLog                   |  7 +++++++
 bfd/elfxx-x86.c                 | 29 +++++++++++++++++++++++++++++
 ld/ChangeLog                    |  6 ++++++
 ld/testsuite/ld-elf/pr23161c.rd |  8 +-------
 4 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index c7e28b8..a0ea93e 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2018-06-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/23161
+	* elfxx-x86.c (elf_x86_hide_linker_defined): New function.
+	(_bfd_x86_elf_link_check_relocs): Use it to hide hidden
+	__bss_start, _end and _edata in shared libraries.
+
 2018-06-07  Alan Modra  <amodra@gmail.com>
 
 	* elf32-tic6x.c (elf32_tic6x_check_relocs): Reference
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 3a7573f..827bb6c 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -876,6 +876,27 @@ elf_x86_linker_defined (struct bfd_link_info *info, const char *name)
     }
 }
 
+/* Hide a linker-defined symbol, NAME, with hidden visibility.  */
+
+static void
+elf_x86_hide_linker_defined (struct bfd_link_info *info,
+			     const char *name)
+{
+  struct elf_link_hash_entry *h;
+
+  h = elf_link_hash_lookup (elf_hash_table (info), name,
+			    FALSE, FALSE, FALSE);
+  if (h == NULL)
+    return;
+
+  while (h->root.type == bfd_link_hash_indirect)
+    h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+  if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
+      || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
+    _bfd_elf_link_hash_hide_symbol (info, h, TRUE);
+}
+
 bfd_boolean
 _bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
 {
@@ -916,6 +937,14 @@ _bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
 	      elf_x86_linker_defined (info, "_end");
 	      elf_x86_linker_defined (info, "_edata");
 	    }
+	  else
+	    {
+	      /* Hide hidden __bss_start, _end and _edata in shared
+		 libraries.  */
+	      elf_x86_hide_linker_defined (info, "__bss_start");
+	      elf_x86_hide_linker_defined (info, "_end");
+	      elf_x86_hide_linker_defined (info, "_edata");
+	    }
 	}
     }
 
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 0dcfcbb..efdd6d7 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,4 +1,10 @@
 2018-06-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/23161
+	* testsuite/ld-elf/pr23161d.rd: Remove local _edata, __bss_start,
+	and _end from dynamic symbol table.
+
+2018-06-08  H.J. Lu  <hongjiu.lu@intel.com>
 	    Alan Modra  <amodra@gmail.com>
 
 	PR ld/23161
diff --git a/ld/testsuite/ld-elf/pr23161c.rd b/ld/testsuite/ld-elf/pr23161c.rd
index 904f126..be99655 100644
--- a/ld/testsuite/ld-elf/pr23161c.rd
+++ b/ld/testsuite/ld-elf/pr23161c.rd
@@ -3,10 +3,4 @@ There are no relocations in this file.
 Symbol table '\.dynsym' contains [0-9]+ entries:
  +Num: +Value +Size Type +Bind +Vis +Ndx Name
  +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
-#...
- +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +LOCAL +DEFAULT +[0-9]+ +__bss_start
-#...
- +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +LOCAL +DEFAULT +[0-9]+ +_edata
-#...
- +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +LOCAL +DEFAULT +[0-9]+ +_end
-#...
+ +1: +[a-f0-9]+ +[0-9]+ +FUNC +GLOBAL +DEFAULT +[0-9]+ +foo



More information about the Binutils-cvs mailing list