This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, binutils] Fix implib test failures


The tests added for the ELF import library feature (commit 
76359541825cf36ecd14ab6b5974ee56e1c59eff) fail on most targets for various 

(1) use of non generic .bss directive
(2) varying number of spaces in output between targets
(3) restriction on where a section can start due to default linker scripts
(4) code for the feature segfault when dealing with local symbols
(5) assert failure in swap_out_syms when ELF output section cannot be found

This patch aims at fixing all these issues by:

(a) using equivalent .section target independent directive instead of .bss 
(fixes (1))
(b) making regex matching more flexible and not setting a specific .data start 
address (fixes (2) and (3))
(c) skipping local symbols when filtering symbols to output in import library 
(fixes (4))
(d) errorring out instead of using an assert when ELF output section cannot be 
found (fixes (5)).

Many thanks to Alan Modra and Nick Clifton for spotting the issues and 
providing with fixes.

ChangeLog entries are as follow:

*** bfd/ChangeLog ***

2016-07-18  Nick Clifton  <>

        * elf.c (_bfd_elf_filter_global_symbols): Skip local symbols.
        (swap_out_syms): Error out when not finding ELF output section instead
        of asserting we find one.
        * elflink.c (elf_output_implib): Call bfd_set_error before displaying
        error message.

*** ld/ChangeLog ***

2016-07-18  Alan Modra  <>
            Thomas Preud'homme  <>

        * testsuite/ld-elf/elf.exp: Xfail targets using 
        _bfd_generic_final_link instead of bfd_elf_final_link when running
        import library tests.
        (Generate import library): Stop setting .data section start address.
        * testsuite/ld-elf/implib.s: Remove first .bss directive and replace
        second one with equivalent .section directive.
        * testsuite/ld-elf/implib.rd: Escape dot in filename, stop testing
        addresses of symbols and be more flexible on the number of spaces in

The changes have been tested on arm-none-eabi, i386-linux-gnu, x86_64-linux-
gnu, avr-elf, bfin-elf, mipstx39-elf and d30v-elf. They pass successfully on 
all these targets except on d30v-elf where they xfail as expected (target does 
not use bfd_elf_final_link).

Is this ok for trunk?

Best regards,

diff --git a/bfd/elf.c b/bfd/elf.c
index ebcf40a92578b588c19312b1e4e521fff8ddad14..2d5f69c5f4392cf4dec73edd4e95a5260d2db239 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3893,9 +3893,10 @@ _bfd_elf_filter_global_symbols (bfd *abfd, struct bfd_link_info *info,
       h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, FALSE);
+      if (h == NULL)
+	continue;
       if (h->type != bfd_link_hash_defined && h->type != bfd_link_hash_defweak)
       if (h->linker_def || h->ldscript_def)
@@ -7641,7 +7642,9 @@ error_return:
 		     section of a symbol to be a section that is
 		     actually in the output file.  */
 		  sec2 = bfd_get_section_by_name (abfd, sec->name);
-		  if (sec2 == NULL)
+		  if (sec2 != NULL)
+		    shndx = _bfd_elf_section_from_bfd_section (abfd, sec2);
+		  if (shndx == SHN_BAD)
 		      _bfd_error_handler (_("\
 Unable to find equivalent output section for symbol '%s' from section '%s'"),
@@ -7650,9 +7653,6 @@ Unable to find equivalent output section for symbol '%s' from section '%s'"),
 		      bfd_set_error (bfd_error_invalid_operation);
 		      goto error_return;
-		  shndx = _bfd_elf_section_from_bfd_section (abfd, sec2);
-		  BFD_ASSERT (shndx != SHN_BAD);
diff --git a/bfd/elflink.c b/bfd/elflink.c
index a994b839f9c152b276912ee0b596eda822bd2acc..5bc57408e47056d8c393f7247ab6312927c598cc 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -11091,6 +11091,7 @@ elf_output_implib (bfd *abfd, struct bfd_link_info *info)
     symcount = _bfd_elf_filter_global_symbols (abfd, info, sympp, symcount);
   if (symcount == 0)
+      bfd_set_error (bfd_error_no_symbols);
       (*_bfd_error_handler) (_("%B: no symbol found for import library"),
       goto free_sym_buf;
diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp
index 832f313c5b4f290a37df83d5e5dfcd4c3e624cb0..1b8d203ce6e84ade5472d7a0f9bacbf05156f0b2 100644
--- a/ld/testsuite/ld-elf/elf.exp
+++ b/ld/testsuite/ld-elf/elf.exp
@@ -136,6 +136,10 @@ foreach t $test_list {
     run_dump_test [file rootname $t]
+# These targets use bfd_elf_final_link rather than bfd_generic_final_link
+# and thus do not have support for ELF import library
+setup_xfail "am33lin-*-*" "d30v-*-*" "dlx-*-*" "i960-*-*" "m68hc1x-*-*"
+setup_xfail "m88k-*-*" "pj-*-*" "score7-*-*" "sh64-*-*" "vxworks-*-*"
 # Check that the --out-implib option work correctly.
 run_ld_link_tests {
     {"Generate empty import library"
@@ -145,7 +149,7 @@ run_ld_link_tests {
      {{ld empty-implib.out}}
     {"Generate import library"
-     "-Tdata=0x1000 --out-implib=tmpdir/implib.lib" ""
+     "--out-implib=tmpdir/implib.lib" ""
      {{readelf {-s tmpdir/implib.lib} implib.rd}}
diff --git a/ld/testsuite/ld-elf/empty-implib.out b/ld/testsuite/ld-elf/empty-implib.out
index b123064df3f6f429c59fe204d57e57ed76a8d5be..cc6a9f47726c93be36b33e1b5252684b65573c84 100644
--- a/ld/testsuite/ld-elf/empty-implib.out
+++ b/ld/testsuite/ld-elf/empty-implib.out
@@ -1,2 +1,3 @@
 .*: .*: no symbol found for import library
 .*: .*: failed to generate import library
diff --git a/ld/testsuite/ld-elf/implib.rd b/ld/testsuite/ld-elf/implib.rd
index 9f854a59bd26054a8fdb49f6dbaac4120b2c7ef1..41ee435ec5d14f283a3aaca97355a956e097a97f 100644
--- a/ld/testsuite/ld-elf/implib.rd
+++ b/ld/testsuite/ld-elf/implib.rd
@@ -1,10 +1,10 @@
-File: tmpdir/implib.lib
+File: tmpdir/implib\.lib
 Symbol table '.symtab' contains 3 entries:
-   Num:    Value +Size Type    Bind   Vis      Ndx Name
-     0: [0-9a-f]+     0 NOTYPE  LOCAL  DEFAULT  UND 
-     1: 0+100[0-3]     1 OBJECT  GLOBAL DEFAULT  ABS exported1
-     2: 0+100[0-3]     1 OBJECT  GLOBAL DEFAULT  ABS exported2
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: [0-9a-f]+ +0 NOTYPE +LOCAL +DEFAULT +UND 
+ +1: [0-9a-f]+ +1 OBJECT +GLOBAL DEFAULT +ABS exported1
+ +2: [0-9a-f]+ +1 OBJECT +GLOBAL DEFAULT +ABS exported2
 File: tmpdir/implib
diff --git a/ld/testsuite/ld-elf/implib.s b/ld/testsuite/ld-elf/implib.s
index a86a940c138d7dd65e42c609adbe594c579061ac..e4d527b22939163f796b73109ee63680bd030aed 100644
--- a/ld/testsuite/ld-elf/implib.s
+++ b/ld/testsuite/ld-elf/implib.s
@@ -1,5 +1,4 @@
 .ifndef NO_GLOBAL
-	.bss
 	.comm	exported1,1
@@ -10,7 +9,7 @@ exported2:
 	.byte	21
-	.bss
+	.section ".bss", "aw", %nobits
 	.space	1
 	.size	not_exported1, 1

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]