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]

[PATCH] m68k/BFD: Fix segfault with non-elf32-m68k output


Hi,

 This change:

2010-02-03  Nick Clifton  <nickc@redhat.com>

	* elf-bfd.h (emum elf_object_id): Rename to elf_target_id.  Add
	entries for other architectures.
	(struct elf_link_hash_table): Add hash_table_id field.
	(elf_hash_table_id): New accessor macro.
	* elflink.c (_bfd_elf_link_hash_table_init): Add target_id
	parameter.
	* elf-m10300.c (elf32_mn10300_hash_table): Check table id before
	returning cast pointer.
	(elf32_mn10300_link_hash_table_create): Identify new table as
	containing MN10300 extensions.
	(mn10300_elf_relax_section): Check pointer returned by
	elf32_mn10300_hash_table.
	[...]
	* elf32-m68k.c: Likewise, except using M68K extensions.

broke m68k LD testsuite like this:

[...]
Executing on host: sh -c {m68k-elf-ld   -o tmpdir/sr1 --traditional-format -G 0--defsym __stack_chk_fail=0 -Ttext 0x1000 tmpdir/sr1.o tmpdir/sr2.o 2>&1}  /dev/null ld.tmp (timeout = 300)
m68k-elf-ld: warning: cannot find entry symbol _start; defaulting to 00001000
m68k-elf-ld: warning: cannot find entry symbol _start; defaulting to 00001000
m68k-elf-ld   -o tmpdir/sr2.sr --traditional-format -G 0 --defsym __stack_chk_fail=0 -Ttext 0x1000 --oformat srec tmpdir/sr1.o tmpdir/sr2.o
Executing on host: sh -c {m68k-elf-ld   -o tmpdir/sr2.sr --traditional-format -G 0 --defsym __stack_chk_fail=0 -Ttext 0x1000 --oformat srec tmpdir/sr1.o tmpdir/sr2.o 2>&1}  /dev/null ld.tmp (timeout = 300)
sh: line 1:  4669 Segmentation fault      m68k-elf-ld -o tmpdir/sr2.sr --traditional-format -G 0 --defsym __stack_chk_fail=0 -Ttext 0x1000 --oformat srec tmpdir/sr1.o tmpdir/sr2.o 2>&1
sh: line 1:  4669 Segmentation fault      m68k-elf-ld -o tmpdir/sr2.sr --traditional-format -G 0 --defsym __stack_chk_fail=0 -Ttext 0x1000 --oformat srec tmpdir/sr1.o tmpdir/sr2.o 2>&1
FAIL: S-records
[...]
FAIL: S-records with constructors

The reason is the output BFD is srec and therefore when 
bfd_elf_m68k_set_target_options() is called for it the new implementation 
of elf_m68k_hash_table() returns NULL.  Given that it makes no sense to 
set target-specific options for a generic target like this the proper fix 
I believe is just to return doing nothing, having checked that the 
arguments are valid as for the usual case.

 This change removes the failures and has passed regression testing for 
m68k-elf.  OK to apply?

2010-08-17  Maciej W. Rozycki  <macro@codesourcery.com>

	bfd/
	* elf32-m68k.c (bfd_elf_m68k_set_target_options): Don't set GOT
	options unless an m68k hash table has been found.

  Maciej

binutils-fsf-2.20.51-20100817-bfd-m68k-target-options-0.patch
Index: bfd/elf32-m68k.c
===================================================================
--- bfd/elf32-m68k.c	(revision 296366)
+++ bfd/elf32-m68k.c	(working copy)
@@ -4745,34 +4745,44 @@ void
 bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling)
 {
   struct elf_m68k_link_hash_table *htab;
-
-  htab = elf_m68k_hash_table (info);
+  bfd_boolean use_neg_got_offsets_p;
+  bfd_boolean allow_multigot_p;
+  bfd_boolean local_gp_p;
 
   switch (got_handling)
     {
     case 0:
       /* --got=single.  */
-      htab->local_gp_p = FALSE;
-      htab->use_neg_got_offsets_p = FALSE;
-      htab->allow_multigot_p = FALSE;
+      local_gp_p = FALSE;
+      use_neg_got_offsets_p = FALSE;
+      allow_multigot_p = FALSE;
       break;
 
     case 1:
       /* --got=negative.  */
-      htab->local_gp_p = TRUE;
-      htab->use_neg_got_offsets_p = TRUE;
-      htab->allow_multigot_p = FALSE;
+      local_gp_p = TRUE;
+      use_neg_got_offsets_p = TRUE;
+      allow_multigot_p = FALSE;
       break;
 
     case 2:
       /* --got=multigot.  */
-      htab->local_gp_p = TRUE;
-      htab->use_neg_got_offsets_p = TRUE;
-      htab->allow_multigot_p = TRUE;
+      local_gp_p = TRUE;
+      use_neg_got_offsets_p = TRUE;
+      allow_multigot_p = TRUE;
       break;
 
     default:
       BFD_ASSERT (FALSE);
+      return;
+    }
+
+  htab = elf_m68k_hash_table (info);
+  if (htab != NULL)
+    {
+      htab->local_gp_p = local_gp_p;
+      htab->use_neg_got_offsets_p = use_neg_got_offsets_p;
+      htab->allow_multigot_p = allow_multigot_p;
     }
 }
 


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