This is the mail archive of the binutils@sourceware.org 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]

Adjust the "objcopy --extract-symbol" test and fix mmix


Alan, are you ok with the following testsuite patch?

If not, I'll just xfail that test for mmix-knuth-mmixware;
--extract-symbols is not of much use anyway for this target (and
IMHO other non-vxworks targets). The effect of the option is
still true to the documentation, which says nothing about symbols
having to retain their type, if you want to weasel it.
Anyone thinking bad of this action should really explore the
usefulness of the --extract-symbols option for themselves.

(I'm using switch instead of "if" to make it easier for other
targets to adjust the expected nm output, if needed.)

Works for native i686-linux, cris-elf and mmix-knuth-mmixware.

ld/testsuite:
	* ld-scripts/script.exp (extract_symbol_test): Allow nm output of
	"objcopy --extract-symbols" result to differ from original in
	general and in particular on mmix-knuth-mmixware.

diff --git a/ld/testsuite/ld-scripts/script.exp b/ld/testsuite/ld-scripts/script.exp
index b5f175f..e735bda 100644
--- a/ld/testsuite/ld-scripts/script.exp
+++ b/ld/testsuite/ld-scripts/script.exp
@@ -111,6 +111,7 @@ proc extract_symbol_test { testfile testname } {
     global objcopy
     global nm
     global size
+    global target_triplet

     set copyfile tmpdir/extract
     set args "--extract-symbol $testfile $copyfile"
@@ -121,8 +122,22 @@ proc extract_symbol_test { testfile testname } {
     }

     set orig_syms [run_host_cmd $nm $testfile]
+    set syms_massaged $orig_syms
+    switch -regexp $target_triplet {
+	^mmix-knuth-mmixware$ {
+	    # Without section sizes (stripped together with the
+	    # contents for this target), we can't deduce the symbol
+	    # types.  Artificially tracking the symbol types is
+	    # considered not worthwhile as there's no known use-case
+	    # for --extract-symbols for this target.  The option is
+	    # supported just enough to emit the same symbol values,
+	    # but absolute symbol types are expected.
+	    regsub -all " \[TD\] " $syms_massaged " A " syms_massaged
+	}
+    }
+
     set extract_syms [run_host_cmd $nm $copyfile]
-    if ![string equal $orig_syms $extract_syms] {
+    if ![string equal $syms_massaged $extract_syms] {
 	fail $testname
 	return
     }

With that ok, I can commit the following to make the boo-boo go away.
(I already had this done only to notice symbols did not retain their
artificially deduced type and that the test still failed!)

On Sun, 18 Oct 2015, Hans-Peter Nilsson wrote:
> I guess I'll just have to hack mmo.c to not do
> the start-address = Main check if there's no section contents,
> using that hook.

(I couldn't use the hook; there's an earlier consistency check
in particular for "nm" reading the file.)

bfd:
	* mmo.c (struct mmo_data_struct): New members
	symbol_consistency_override_calculated and ignore_symbol_consistency.
	(mmo_section_has_contents, mmo_ignore_symbol_consistency): New
	functions.
	(mmo_create_symbol): Check with mmo_ignore_symbol_consistency if to
	report an error for unexpected value of Main.
	(mmo_write_symbols_and_terminator): Similar.

diff --git a/bfd/mmo.c b/bfd/mmo.c
index 484a370..f92fd10 100644
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -330,6 +330,14 @@ struct mmo_data_struct

     /* We also need a buffer to hold the bytes we count reading or writing.  */
     bfd_byte buf[4];
+
+    /* Whether we've calculated symbol consistency requirement yet.  We do this
+       when-needed, which must be at some time after all section
+       contents is known.  */
+    bfd_boolean symbol_consistency_override_calculated;
+
+    /* Whether to consistency-check symbol values, in particular "Main".  */
+    bfd_boolean ignore_symbol_consistency;
   };

 typedef struct mmo_data_struct tdata_type;
@@ -586,6 +594,34 @@ mmo_mkobject (bfd *abfd)
 }

 static bfd_boolean
+mmo_section_has_contents (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *p ATTRIBUTE_UNUSED)
+{
+  /* The point is to match what --extract-symbols does (well, negated).  */
+  return bfd_get_section_size (sec) != 0;
+}
+
+/* Find out whether we should omit symbol consistency checks for this
+   bfd and cache the value.
+
+   This function must only be called when all section contents is
+   known.  However, calculating symbol consistency at the time the
+   private BFD data is initialized is too late for some uses.  */
+
+static bfd_boolean
+mmo_ignore_symbol_consistency (bfd *abfd)
+{
+  if (!abfd->tdata.mmo_data->symbol_consistency_override_calculated)
+    {
+      abfd->tdata.mmo_data->ignore_symbol_consistency =
+	bfd_sections_find_if (abfd, mmo_section_has_contents, NULL) == NULL;
+
+      abfd->tdata.mmo_data->symbol_consistency_override_calculated = TRUE;
+    }
+
+  return abfd->tdata.mmo_data->ignore_symbol_consistency;
+}
+
+static bfd_boolean
 mmo_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
 {
   if (bfd_get_flavour (ibfd) != bfd_target_mmo_flavour
@@ -1208,7 +1244,8 @@ mmo_create_symbol (bfd *abfd, const char *symname, bfd_vma addr, enum
      object.  For written objects, we do it while setting the symbol
      table.  */
   if (strcmp (symname, MMIX_START_SYMBOL_NAME) == 0
-      && bfd_get_start_address (abfd) != addr)
+      && bfd_get_start_address (abfd) != addr
+      && !mmo_ignore_symbol_consistency (abfd))
     {
       (*_bfd_error_handler)
 	(_("%s: invalid mmo file: initialization value for $255 is not `Main'\n"),
@@ -2900,13 +2937,14 @@ mmo_write_symbols_and_terminator (bfd *abfd)
 	  = (mainsym->value
 	     + mainsym->section->output_section->vma
 	     + mainsym->section->output_offset);
-	  memcpy (table + 1, orig_table, i * sizeof (asymbol *));
+	memcpy (table + 1, orig_table, i * sizeof (asymbol *));
 	table[0] = mainsym;

 	/* Check that the value assigned to :Main is the same as the entry
 	   address.  The default linker script asserts this.  This is as
 	   good a place as any to check this consistency. */
-	if (mainvalue != bfd_get_start_address (abfd))
+	if (mainvalue != bfd_get_start_address (abfd)
+	    && !mmo_ignore_symbol_consistency (abfd))
 	  {
 	    /* Arbitrary buffer to hold the printable representation of a
 	       vma.  */

brgds, H-P


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