This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Drop undefined local symbols from symtab?
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Thu, 19 Feb 2015 04:48:15 -0800
- Subject: Re: Drop undefined local symbols from symtab?
- Authentication-results: sourceware.org; auth=none
- References: <20150218112716 dot GB11515 at bubble dot grove dot modra dot org> <CAMe9rOrmkRVcL=5f22w27K-_McASLHhxwjZ-XyyMfTsbWr32cQ at mail dot gmail dot com> <20150218124846 dot GD11515 at bubble dot grove dot modra dot org> <20150219033916 dot GE11515 at bubble dot grove dot modra dot org>
On Wed, Feb 18, 2015 at 7:39 PM, Alan Modra <amodra@gmail.com> wrote:
> On Wed, Feb 18, 2015 at 11:18:47PM +1030, Alan Modra wrote:
>> On Wed, Feb 18, 2015 at 03:34:43AM -0800, H.J. Lu wrote:
>> > Can you also strip undefined global symbols:
>> >
>> > https://sourceware.org/bugzilla/show_bug.cgi?id=4317
>>
>> Probably. I'll take a look tomorrow. Most likely just a matter of
>> replacing the ELF_ST_BIND test in my elf_link_output_extsym change
>> with a test of !flinfo->info->relocatable. And perhaps arranging to
>> only strip from .symtab if the sym isn't emitted to .dynsym.
>
> I also took out the hack for __ehdr_start.
>
> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
> index 44fc2bb..71f258f 100644
> --- a/bfd/ChangeLog
> +++ b/bfd/ChangeLog
> @@ -1,3 +1,10 @@
> +2015-02-19 Alan Modra <amodra@gmail.com>
> +
> + PR ld/4317
> + * elflink.c (elf_link_input_bfd): Drop undefined local syms.
> + (elf_link_output_extsym): Drop local and global undefined syms.
> + Tidy. Expand comment.
> +
> 2015-02-17 Alan Modra <amodra@gmail.com>
>
> PR ld/17975
> diff --git a/bfd/elflink.c b/bfd/elflink.c
> index 038e43d..0cd85f1 100644
> --- a/bfd/elflink.c
> +++ b/bfd/elflink.c
> @@ -8902,8 +8902,9 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
> a regular file, or that we have been told to strip. However, if
> h->indx is set to -2, the symbol is used by a reloc and we must
> output it. */
> + strip = FALSE;
> if (h->indx == -2)
> - strip = FALSE;
> + ;
> else if ((h->def_dynamic
> || h->ref_dynamic
> || h->root.type == bfd_link_hash_new)
> @@ -8929,12 +8930,11 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
> && h->root.u.undef.abfd != NULL
> && (h->root.u.undef.abfd->flags & BFD_PLUGIN) != 0)
> strip = TRUE;
> - else
> - strip = FALSE;
>
> /* If we're stripping it, and it's not a dynamic symbol, there's
> - nothing else to do unless it is a forced local symbol or a
> - STT_GNU_IFUNC symbol. */
> + nothing else to do. However, if it is a forced local symbol or
> + an ifunc symbol we need to give the backend finish_dynamic_symbol
> + function a chance to make it dynamic. */
> if (strip
> && h->dynindx == -1
> && h->type != STT_GNU_IFUNC
> @@ -9205,9 +9205,18 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
> }
> }
>
> - /* If we're stripping it, then it was just a dynamic symbol, and
> - there's nothing else to do. */
> - if (strip || (input_sec->flags & SEC_EXCLUDE) != 0)
> + /* If the symbol is undefined, and we didn't output it to .dynsym,
> + strip it from .symtab too. Obviously we can't do this for
> + relocatable output or when needed for --emit-relocs. */
> + else if (input_sec == bfd_und_section_ptr
> + && h->indx != -2
> + && !flinfo->info->relocatable)
> + return TRUE;
> + /* Also strip others that we couldn't earlier due to dynamic symbol
> + processing. */
> + if (strip)
> + return TRUE;
> + if ((input_sec->flags & SEC_EXCLUDE) != 0)
> return TRUE;
>
> /* Output a FILE symbol so that following locals are not associated
> @@ -9455,8 +9464,9 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
>
> *ppsection = isec;
>
> - /* Don't output the first, undefined, symbol. */
> - if (ppsection == flinfo->sections)
> + /* Don't output the first, undefined, symbol. In fact, don't
> + output any undefined local symbol. */
> + if (isec == bfd_und_section_ptr)
> continue;
>
> if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
> diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
> index 64f0871..7619bc5 100644
> --- a/ld/testsuite/ChangeLog
> +++ b/ld/testsuite/ChangeLog
> @@ -1,3 +1,14 @@
> +2015-02-19 Alan Modra <amodra@gmail.com>
> +
> + PR ld/4317
> + * ld-aarch64/gc-tls-relocs.d, * ld-cris/locref2.d,
> + * ld-elf/ehdr_start-weak.d, * ld-elf/group1.d,
> + * ld-i386/compressed1.d, * ld-ia64/error1.d, * ld-ia64/error2.d,
> + * ld-ia64/error3.d, * ld-mips-elf/pic-and-nonpic-1.nd,
> + * ld-mmix/undef-3.d, * ld-powerpc/tlsexe.r, * ld-powerpc/tlsexetoc.r,
> + * ld-powerpc/tlsso.r, * ld-powerpc/tlstocso.r,
> + * ld-x86-64/compressed1.d, * ld-x86-64/pie1.d: Update.
> +
I checked in this patch to make sure that PR ld/4317 stays fixed.
Thanks.
--
H.J.
---
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 7619bc5..3eb1c99 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2015-02-19 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/4317
+ * ld-i386/compressed1.d: Use nm/readelf with "failif".
+ * ld-x86-64/compressed1.d: Likewise.
+ * ld-x86-64/pie1.d: Likewise.
+
2015-02-19 Alan Modra <amodra@gmail.com>
PR ld/4317
diff --git a/ld/testsuite/ld-i386/compressed1.d
b/ld/testsuite/ld-i386/compressed1.d
index c17d3c7..e9eeef9 100644
--- a/ld/testsuite/ld-i386/compressed1.d
+++ b/ld/testsuite/ld-i386/compressed1.d
@@ -2,3 +2,9 @@
#as: --32
#ld: -e foo -melf_i386 --noinhibit-exec
#warning: .*/compressed1.c:13: undefined reference to .bar.
+#nm: -n
+
+#failif
+#...
+[ \t]+U bar
+#...
diff --git a/ld/testsuite/ld-x86-64/compressed1.d
b/ld/testsuite/ld-x86-64/compressed1.d
index 9e9d92c..f97c9ad 100644
--- a/ld/testsuite/ld-x86-64/compressed1.d
+++ b/ld/testsuite/ld-x86-64/compressed1.d
@@ -2,3 +2,9 @@
#as: --64
#ld: -e foo -melf_x86_64 --noinhibit-exec
#warning: .*/compressed1.c:13: undefined reference to .bar.
+#nm: -n
+
+#failif
+#...
+[ \t]+U bar
+#...
diff --git a/ld/testsuite/ld-x86-64/pie1.d b/ld/testsuite/ld-x86-64/pie1.d
index 368d153..6373eea 100644
--- a/ld/testsuite/ld-x86-64/pie1.d
+++ b/ld/testsuite/ld-x86-64/pie1.d
@@ -1,4 +1,10 @@
#name: PIE with undefined symbol
#as: --64
#ld: -pie -melf_x86_64 --noinhibit-exec
+#readelf: -s --wide
#warning: \A[^\n]*\.o[^\n]*In function `_start':\n[^\n]*: undefined
reference to `foo'\Z
+
+#failif
+#...
+ +[0-9]+: +[0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +UND foo
+#...