When linking two object files, one with a definition of symbol FOO and one with a definition of symbol FOO in a section marked with SHF_EXCLUDE then GNU ld complains about 'multiple definitions of 'FOO''. GOLD handles this situation just fine. t1.s: .text .section .text.startup,"ax",@progbits .p2align 4,,15 .globl main .type main, @function main: t2.s: .text .section .text.startup,"axe",@progbits .p2align 4,,15 .globl main .type main, @function main: (ignore assembler warnings about bogus section attributes) > ld t1.o t2.o -o a.out t2.o: In function `main': (.text.startup+0x0): multiple definition of `main' t1.o:(.text.startup+0x0): first defined here > gold t1.o t2.o -o a.out
This works: diff --git a/ld/ldmain.c b/ld/ldmain.c index e7a8dff..294c5b9 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -959,6 +959,11 @@ multiple_definition (struct bfd_link_info *info, && bfd_is_abs_section (nsec->output_section))) return; + /* Ignore a redefinition from excluded section. */ + if ((osec->flags & SEC_EXCLUDE) != 0 + || (nsec->flags & SEC_EXCLUDE) != 0) + return; + name = h->root.string; if (nbfd == NULL) {
This is better: index e7a8dff..052b276 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -959,6 +959,19 @@ multiple_definition (struct bfd_link_info *info, && bfd_is_abs_section (nsec->output_section))) return; + /* Ignore a redefinition from excluded section. */ + if (!bfd_link_relocatable (&link_info) + && ((osec->flags & SEC_EXCLUDE) != 0 + || (nsec->flags & SEC_EXCLUDE) != 0)) + { + if ((osec->flags & SEC_EXCLUDE) != 0) + { + h->u.def.section = nsec; + h->u.def.value = nval; + } + return; + } + name = h->root.string; if (nbfd == NULL) {
My gut feeling is that it would be better to deal with this as we do with other sections that are discarded early in the link. --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -2294,6 +2294,12 @@ section_already_linked (bfd *abfd, asection *sec, void *data) return; } + /* Deal with SHF_EXCLUDE ELF sections. */ + if (!bfd_link_relocatable (&link_info) + && (abfd->flags & BFD_PLUGIN) == 0 + && (sec->flags & (SEC_GROUP | SEC_KEEP | SEC_EXCLUDE)) == SEC_EXCLUDE) + sec->output_section = bfd_abs_section_ptr; + if (!(abfd->flags & DYNAMIC)) bfd_section_already_linked (abfd, sec, &link_info); }
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2e84f9c1b5770b803b739bcd157d7a457c22b56f commit 2e84f9c1b5770b803b739bcd157d7a457c22b56f Author: Alan Modra <amodra@gmail.com> Date: Fri Aug 26 22:01:15 2016 +0930 Ignore symbols defined in SHF_EXCLUDE sections PR 20513 * ldlang.c (section_already_linked): Deal with SHF_EXCLUDE sections.
Fixed
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=652a8f4f57243c41e71da06b6d0fe27540f3cbba commit 652a8f4f57243c41e71da06b6d0fe27540f3cbba Author: H.J. Lu <hjl.tools@gmail.com> Date: Thu Sep 1 12:01:00 2016 -0700 Add tests for PR ld/20513 PR ld/20513 * testsuite/ld-elf/pr20513a.d: New file. * testsuite/ld-elf/pr20513a.s: Likewise. * testsuite/ld-elf/pr20513b.d: Likewise. * testsuite/ld-elf/pr20513b.s: Likewise. * testsuite/ld-elf/pr20513c.d: Likewise. * testsuite/ld-elf/pr20513d.d: Likewise. * testsuite/ld-elf/pr20513e.d: Likewise. * testsuite/ld-elf/pr20513f.d: Likewise.
Hi H.J. > Add tests for PR ld/20513 > > PR ld/20513 > * testsuite/ld-elf/pr20513c.d: Likewise. > * testsuite/ld-elf/pr20513d.d: Likewise. These new tests are producing multiple regressions in the linker testsuite for lots of targets. For example: Checking Binutils in: arceb-elf ... done LD REGRESSION: ld-elf/pr20513c LD REGRESSION: ld-elf/pr20513d Affected targets are: arceb-elf, avr-elf, cr16-elf, cris-elf, crisv32-elf, crx-elf, d10v-elf, d30v-elf, dlx-elf, fr30-elf, frv-elf, ft32-elf, h8300-elf, h8300-rtems, i860-stardent-elf, ip2k-elf, iq2000-elf, lm32-rtems4.10, m32c-elf, m32r-elf, m68hc11-elf, mcore-elf, mep-elf, microblaze-elf, mn10200-elf, moxie-elf, msp430-elf, mt-elf, nds32le-elf, or1k-elf, pj-elf, rl78-elf, rx-elf, spu-elf, tic6x-elf, v850-elf, visium-elf, xgate-elf, xstormy16-elf Most of the failures are due to the targets not supporting shared libraries, but the dlx-elf target has extra problems that need to be investigated. Please could you fix these regressions ? Cheers Nick