Always create dynamic sections for -E/--dynamic-list
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 18 Feb 2016 11:13:19 +0000 (03:13 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 18 Feb 2016 11:13:51 +0000 (03:13 -0800)
In embedded environments, including boot loaders, the non-PIC executable
needs to export its symbols to modules loaded in the future.  We should
always create dynamic sections for -E/--dynamic-list.

bfd/

PR ld/19617
* elflink.c (elf_link_add_object_symbols): Always create dynamic
sections for -E/--dynamic-list.

ld/

PR ld/19617
* testsuite/ld-elf/pr19617.s: New file.
* testsuite/ld-elf/pr19617a.d: Likewise.
* testsuite/ld-elf/pr19617b.d: Likewise.
* testsuite/ld-elf/pr19617c.d: Likewise.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-elf/pr19617.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr19617a.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr19617b.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr19617c.d [new file with mode: 0644]

index b5e5788ca6f1da08dea79405338db84ec58fc639..1c9e201e76ec478fdabef1daafbf1c358790e909 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-18  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/19617
+       * elflink.c (elf_link_add_object_symbols): Always create dynamic
+       sections for -E/--dynamic-list.
+
 2016-02-17  H.J. Lu  <hongjiu.lu@intel.com>
 
        * elf64-x86-64.c (elf_backend_omit_section_dynsym): New.  Defined
index ac03ce5003adea4a8fef6481e638c02a7d85d177..c7672edf8ab58197a1d10e3c54ef58f2c20e8d0d 100644 (file)
@@ -3598,11 +3598,14 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
       /* If we are creating a shared library, create all the dynamic
         sections immediately.  We need to attach them to something,
         so we attach them to this BFD, provided it is the right
-        format and is not from ld --just-symbols.  FIXME: If there
+        format and is not from ld --just-symbols.  Always create the
+        dynamic sections for -E/--dynamic-list.  FIXME: If there
         are no input BFD's of the same format as the output, we can't
         make a shared library.  */
       if (!just_syms
-         && bfd_link_pic (info)
+         && (bfd_link_pic (info)
+             || info->export_dynamic
+             || info->dynamic)
          && is_elf_hash_table (htab)
          && info->output_bfd->xvec == abfd->xvec
          && !htab->dynamic_sections_created)
index badac3733eee3d195fc11e88e08026bbf280bed0..923f77903092fc739faa8a99c2bbab7de652f873 100644 (file)
@@ -1,3 +1,11 @@
+2016-02-18  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/19617
+       * testsuite/ld-elf/pr19617.s: New file.
+       * testsuite/ld-elf/pr19617a.d: Likewise.
+       * testsuite/ld-elf/pr19617b.d: Likewise.
+       * testsuite/ld-elf/pr19617c.d: Likewise.
+
 2016-02-18  Nick Clifton  <nickc@redhat.com>
 
        * Makefile.am (CXX_FOR_TARGET): Check for the presence of an
diff --git a/ld/testsuite/ld-elf/pr19617.s b/ld/testsuite/ld-elf/pr19617.s
new file mode 100644 (file)
index 0000000..0acb8f5
--- /dev/null
@@ -0,0 +1,19 @@
+       .data
+       .global bar
+bar:
+       .type bar,"object"
+       .long 0
+       .text
+       .type start,"function"
+       .global start
+start:
+       .type _start,"function"
+       .global _start
+_start:
+       .type __start,"function"
+       .global __start
+__start:
+       .type main,"function"
+       .global main
+main:
+       .long 0
diff --git a/ld/testsuite/ld-elf/pr19617a.d b/ld/testsuite/ld-elf/pr19617a.d
new file mode 100644 (file)
index 0000000..c8ebef0
--- /dev/null
@@ -0,0 +1,12 @@
+#source: pr19617.s
+#ld: -E
+#readelf : --dyn-syms --wide
+
+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 +FUNC +GLOBAL +DEFAULT +[0-9]+ +start
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +bar
+#pass
diff --git a/ld/testsuite/ld-elf/pr19617b.d b/ld/testsuite/ld-elf/pr19617b.d
new file mode 100644 (file)
index 0000000..87bdffd
--- /dev/null
@@ -0,0 +1,10 @@
+#source: pr19617.s
+#ld: --dynamic-list-data
+#readelf : --dyn-syms --wide
+
+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 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +bar
+#pass
diff --git a/ld/testsuite/ld-elf/pr19617c.d b/ld/testsuite/ld-elf/pr19617c.d
new file mode 100644 (file)
index 0000000..1c758d8
--- /dev/null
@@ -0,0 +1,8 @@
+#source: pr19617.s
+#ld: --dynamic-list-data
+#readelf : --dyn-syms --wide
+
+#failif
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +FUNC +GLOBAL +DEFAULT +[0-9]+ +start
+#...