From bf89386a862ace008f0152bca8bddf996d3993c8 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 18 Feb 2016 03:13:19 -0800 Subject: [PATCH] Always create dynamic sections for -E/--dynamic-list 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 | 6 ++++++ bfd/elflink.c | 7 +++++-- ld/ChangeLog | 8 ++++++++ ld/testsuite/ld-elf/pr19617.s | 19 +++++++++++++++++++ ld/testsuite/ld-elf/pr19617a.d | 12 ++++++++++++ ld/testsuite/ld-elf/pr19617b.d | 10 ++++++++++ ld/testsuite/ld-elf/pr19617c.d | 8 ++++++++ 7 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-elf/pr19617.s create mode 100644 ld/testsuite/ld-elf/pr19617a.d create mode 100644 ld/testsuite/ld-elf/pr19617b.d create mode 100644 ld/testsuite/ld-elf/pr19617c.d diff --git a/bfd/ChangeLog b/bfd/ChangeLog index b5e5788ca6f..1c9e201e76e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2016-02-18 H.J. Lu + + PR ld/19617 + * elflink.c (elf_link_add_object_symbols): Always create dynamic + sections for -E/--dynamic-list. + 2016-02-17 H.J. Lu * elf64-x86-64.c (elf_backend_omit_section_dynsym): New. Defined diff --git a/bfd/elflink.c b/bfd/elflink.c index ac03ce5003a..c7672edf8ab 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -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) diff --git a/ld/ChangeLog b/ld/ChangeLog index badac3733ee..923f7790309 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,11 @@ +2016-02-18 H.J. Lu + + 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 * 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 index 00000000000..0acb8f5db22 --- /dev/null +++ b/ld/testsuite/ld-elf/pr19617.s @@ -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 index 00000000000..c8ebef06d08 --- /dev/null +++ b/ld/testsuite/ld-elf/pr19617a.d @@ -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 index 00000000000..87bdffd5fd4 --- /dev/null +++ b/ld/testsuite/ld-elf/pr19617b.d @@ -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 index 00000000000..1c758d8f6c3 --- /dev/null +++ b/ld/testsuite/ld-elf/pr19617c.d @@ -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 +#... -- 2.30.2