Until today the implementation of binutils for the AVR architecture did not support 8-bit relocations. This means that constructs like counted strings: .byte 2f-1f 1: .ascii "blah" 2: were impossible, because GAS would tell me "illegal relocation size: 1". The above example works fine on almost every other supported architecture. The attached patch implements support for BFD_RELOC_8 relocation type in binutils, and for the respective R_AVR_8 relocation type in avr-elf32. Both relocations that are resolved at assembly time as well as link-time applied relocations work. Also attaching a simple testcase which should assemle fine with the patch applied, and will emit two errors without the patch applied.
Created attachment 4609 [details] The patch against binutils 2.18 The patch is against latest stable binutils for AVR, hopefully it should apply without much hassle on later versions.
Created attachment 4610 [details] A simple testcase demonstrating the AVR binutils limitation
Subject: Bug 11297 CVSROOT: /cvs/src Module name: src Changes by: nickc@sourceware.org 2010-02-23 11:38:36 Modified files: bfd : ChangeLog elf32-avr.c gas : ChangeLog gas/config : tc-avr.c include/elf : ChangeLog avr.h Log message: PR 11297: Add support for 8-bit relocations to the AVR toolchain. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4939&r2=1.4940 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/elf32-avr.c.diff?cvsroot=src&r1=1.44&r2=1.45 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4094&r2=1.4095 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/config/tc-avr.c.diff?cvsroot=src&r1=1.71&r2=1.72 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/include/elf/ChangeLog.diff?cvsroot=src&r1=1.390&r2=1.391 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/include/elf/avr.h.diff?cvsroot=src&r1=1.9&r2=1.10
Hi Andrew, Thanks for reporting this problem, and for providing the fix. I have checked your patch into the mainline sources along with these changelog entries. Cheers Nick gas/ChangeLog PR binutils/11297 * config/tc-avr.c (md_apply_fix): Handle BFD_RELOC_8. (avr_cons_fix_new): Handle fixups of a single byte. bfd/ChangeLog PR binutils/11297 * elf32-avr.c (elf_avr_howto_table): Add R_AVR_8. (avr_reloc_map): Map BFD_RELOC_8 to R_AVR_8. include/elf/ChangeLog PR binutils/11297 * avr.h: (R_AVR_8): New relocation number.
A regression happened: this patch was broken by one of later patches. If you try the testcase attached to this ticket, it'll bring the good old error messages: [zap@zap|~]avr-as test.S test.S: Assembler messages: test.S:1: Error: illegal relocation size: 1 test.S:6: Error: illegal relocation size: 1 [zap@zap|~]avr-as --version GNU assembler (GNU Binutils) 2.20
Heck, that's not a binutils regression, it's a fedora package regression: up to Fedora 16 the binutils package was version 2.21, in Fedora 17 it downgraded to 2.20. Sorry for noise :-(