Allow new just-symbols test to run on XCOFF and PE

Alan Modra amodra@gmail.com
Tue Jul 28 04:05:43 GMT 2020


On Tue, Jul 28, 2020 at 09:02:19AM +0930, Alan Modra wrote:
> On Mon, Jul 27, 2020 at 03:15:05PM +0100, Maciej W. Rozycki wrote:
> > On Mon, 27 Jul 2020, Alan Modra via Binutils wrote:
> > 
> > > 	* testsuite/ld-misc/just-symbols.exp: Run for x86_64 PE too.
> > > 	Set LDFLAGS for PE and XCOFF.
> > > 	* testsuite/ld-misc/just-symbols.ld: Accept XCOFF mapped .data.
> > > 
> > > diff --git a/ld/testsuite/ld-misc/just-symbols-1.dd b/ld/testsuite/ld-misc/just-symbols-1.dd
> > > index 8908a235ae..9502566ac9 100644
> > > --- a/ld/testsuite/ld-misc/just-symbols-1.dd
> > > +++ b/ld/testsuite/ld-misc/just-symbols-1.dd
> > > @@ -1,5 +1,3 @@
> > > -.*: +file format .*
> > > -
> > > -Contents of section \.data:
> > > +#...
> > >   [0-9a-f]+ (?:(:?12000000|00120000|00000012) 0{8}|0{8} 00000012) 0{8} 0{8} .*
> > >  #pass
> > 
> >  This breaks one purpose of the test case, that is ensuring that data from 
> > the input `.data' section coming from just-symbols-1.o is first in the 
> > output `.data' section; that is that `--just-symbols' actually works as 
> > intended and does not pull contents from just-symbols-0.o/just-symbols-0. 
> > 
> >  Sorry not to have been clear about it in the change description of commit 
> > 97c79e2174fb ("PR ld/26288: Allow the use of `--just-symbols' with ET_EXEC 
> > input").
> > 
> >  Would you be able to update your change to keep that purpose?  What's 
> > there with the affected targets that causes extra data to be present 
> > ahead?
> 
> It's not extra data but rather that some aout formats don't even have
> a .data section.
> 
> ~/build/gas/i386-msdos/ld$ ../binutils/objdump -s tmpdir/just-symbols-1obj 
> 
> tmpdir/just-symbols-1obj:     file format msdos
> 
> Contents of section .text:
>  0000 12000000 00000000 00000000 00000000  ................
> 
> I'll reinstate the "file format" and "Contents of section" lines but
> match any named section.

That failed on another aout target, ns32k, where the linker always
gives a a non-empty .text section.  So I'm reverting the
just-symbols-1.dd change and applying the following.  The lang_check
change fixes msp430-elf bfd_merge_private_bfd_data errors.

	* ldlang.c (lang_check): Don't complain about relocs or merge
	attributes from --just-symbols input.
	* testsuite/ld-misc/just-symbols.exp: Just dump .data section.
	Don't run test on a number of targets.

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 6943adfdc3..1dd17ffff2 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -7001,8 +7001,9 @@ lang_check (void)
 	 input format may not have equivalent representations in
 	 the output format (and besides BFD does not translate
 	 relocs for other link purposes than a final link).  */
-      if ((bfd_link_relocatable (&link_info)
-	   || link_info.emitrelocations)
+      if (!file->flags.just_syms
+	  && (bfd_link_relocatable (&link_info)
+	      || link_info.emitrelocations)
 	  && (compatible == NULL
 	      || (bfd_get_flavour (input_bfd)
 		  != bfd_get_flavour (link_info.output_bfd)))
@@ -7026,8 +7027,9 @@ lang_check (void)
 
       /* If the input bfd has no contents, it shouldn't set the
 	 private data of the output bfd.  */
-      else if ((input_bfd->flags & DYNAMIC) != 0
-	       || bfd_count_sections (input_bfd) != 0)
+      else if (!file->flags.just_syms
+	       && ((input_bfd->flags & DYNAMIC) != 0
+		   || bfd_count_sections (input_bfd) != 0))
 	{
 	  bfd_error_handler_type pfn = NULL;
 
diff --git a/ld/testsuite/ld-misc/just-symbols.exp b/ld/testsuite/ld-misc/just-symbols.exp
index 59c725d0d2..e3c012f0f6 100644
--- a/ld/testsuite/ld-misc/just-symbols.exp
+++ b/ld/testsuite/ld-misc/just-symbols.exp
@@ -20,7 +20,13 @@
 #
 
 # SH/PE targets complain about zero VMA.
-if { [istarget sh-*-pe] } {
+# i386-msdos doesn't have .data
+# tic30-coff has a weird 32-bit reloc that divides sym value by four
+# alpha-dec-vms wants a bunch of libs to link
+if { [istarget sh-*-pe]
+     || [istarget *-*-msdos]
+     || [istarget *c30-*-*]
+     || [istarget alpha-*-vms] } {
     return
 }
 
@@ -49,13 +55,13 @@ run_ld_link_tests [list \
      "$LDFLAGS -e 0 -T just-symbols.ld --just-symbols=tmpdir/just-symbols-0.o" "" \
      "" \
      {just-symbols-1.s} \
-     {{objdump -s just-symbols-1.dd}} \
+     {{objdump {-s -j .data} just-symbols-1.dd}} \
      "just-symbols-1obj"] \
     [list "Executable with --just-symbols test" \
      "$LDFLAGS -e 0 -T just-symbols.ld --just-symbols=tmpdir/just-symbols-0" "" \
      "" \
      {just-symbols-1.s} \
-     {{objdump -s just-symbols-1.dd}} \
+     {{objdump {-s -j .data} just-symbols-1.dd}} \
      "just-symbols-1exe"] \
 ]
 

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list