Bug 3874 - linker crashes with -m avr2 --oformat ihex
Summary: linker crashes with -m avr2 --oformat ihex
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-15 22:16 UTC by Juergen Weigert
Modified: 2007-01-24 20:24 UTC (History)
3 users (show)

See Also:
Host:
Target: cross-avr-binutils
Build:
Last reconfirmed:


Attachments
avr_test.o (422 bytes, application/octet-stream)
2007-01-15 22:20 UTC, Juergen Weigert
Details
Add definition of elf_backend_omit_section_dynsym to elf32-avr.c (357 bytes, patch)
2007-01-19 12:23 UTC, Nick Clifton
Details | Diff
Check for avr formated hash tables before using them in avr code. (1.66 KB, patch)
2007-01-24 18:00 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Juergen Weigert 2007-01-15 22:16:15 UTC
Using any simple test program, do this on a 32bit host (64bit hosts tend not to 
crash reliably here)

$ avr-gcc -mmcu=attiny2313 avr_test.c -c
$ avr-ld -m avr2 -o avr_test.hex /opt/cross/avr/lib/crttn2313.o --oformat ihex 
avr_test.o
BFD 2.17.50.0.8 20061201 internal error, aborting at ../../bfd/linker.c line 
2397 in set_symbol_from_hash

I tracked that back to one specific patch added in August 2006:
cvs -d :pserver:anoncvs@sourceware.org:/cvs/src co -D '2006-10-17 15:41' 
binutils
- is good
cvs -d :pserver:anoncvs@sourceware.org:/cvs/src co -D '2006-10-17 15:42' 
binutils
- crashes.

The Changelog of the patch has this:
diff -u -r1.3635 -r1.3636
--- bfd/ChangeLog       16 Oct 2006 17:21:44 -0000      1.3635
+++ bfd/ChangeLog       17 Oct 2006 13:41:46 -0000      1.3636
@@ -1,3 +1,55 @@
+2006-10-17  Alan Modra  <amodra@bigpond.net.au>
+
+       * elf-bfd.h (struct elf_link_hash_table): Reorder.  Add
+       text_index_section and data_index_section.
+       (struct elf_backend_data): Add elf_backend_init_index_section.
+       (_bfd_elf_init_1_index_section): Declare.
+       (_bfd_elf_init_2_index_sections): Declare.
+       * elfxx-target.h (elf_backend_init_index_section): Define.
+       (elfNN_bed): Init new field.
+       * elflink.c (_bfd_elf_link_omit_section_dynsym): Keep first tls
+       section and text_index_section plus data_index_section.
+       (_bfd_elf_link_renumber_dynsyms): Clear dynindx on omitted sections.
+       (_bfd_elf_init_1_index_section): New function.
+       (_bfd_elf_init_2_index_sections): New function.
+       (bfd_elf_size_dynsym_hash_dynstr): Call elf_backend_init_index_section.
+       (elf_link_input_bfd): When emitting relocs, use text_index_section
+       and data_index_section for removed sections.
+       * elf-m10300.c (elf_backend_omit_section_dynsym): Define.
+       * elf32-i386.c: Likewise.
+       * elf32-m32r.c: Likewise.
+       * elf32-sh.c: Likewise.
...
elf32-avr.c is not in the list. Can someone please help extending this patch 
to cover also avr targets?

Thanks,
        Jw.
Comment 1 Juergen Weigert 2007-01-15 22:20:50 UTC
Created attachment 1501 [details]
avr_test.o

main object to test
Comment 2 Nick Clifton 2007-01-19 12:23:50 UTC
Created attachment 1509 [details]
Add definition of elf_backend_omit_section_dynsym to elf32-avr.c
Comment 3 Nick Clifton 2007-01-19 12:26:04 UTC
Hi Juergen,

  I do not have access to the /opt/cross/avr/lib/crttn2313.o object file, so I
am not able to reproduce this bug.  But adding the necessary line to elf32-avr.c
looks fairly straightforward, so please could you try out the attached patch and
let me know if it works for you ?

Cheers
  Nick
Comment 4 Juergen Weigert 2007-01-22 18:43:10 UTC
Sorry for the crttn2313.o, it is not necessary to reproduce.
Using the attached avr_test.o, 
$ avr-ld -m avr2 -o avr_test.hex --oformat ihex avr_test.o
also crashes the linker.

Nick, I am sorry to say this, but your patch (definition of 
elf_backend_omit_section_dynsym) does not cure the crash.
(anyway, thanks for providing the definition.)
Comment 5 Nick Clifton 2007-01-24 18:00:36 UTC
Created attachment 1520 [details]
Check for avr formated hash tables before using them in avr code.
Comment 6 Nick Clifton 2007-01-24 18:03:27 UTC
Hi Juergen,

  OK, I found a 32-bit host and reproduced the problem.  It turns out to be
memory corruption in the AVR code due to the use of the linker's --oformat
command line option.  This selects a non-AVR aware output format, which
internally means that a different kind of hash table is used.  The AVR code was
always assuming that its special, extended hash tables were being used, and so
it was corruptong memory.

  Please could you try out the uploaded patch which should fix this problem.

Cheers
  Nick
Comment 7 Juergen Weigert 2007-01-24 20:24:05 UTC
Works!
And I am really happy, this turned out to be only avr-related.
Thanks you!