Bug 13503 - [avr] Support RELOCs to represent a byte
Summary: [avr] Support RELOCs to represent a byte
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-15 16:14 UTC by Georg-Johann Lay
Modified: 2012-09-11 17:01 UTC (History)
4 users (show)

See Also:
Host:
Target: avr
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Georg-Johann Lay 2011-12-15 16:14:56 UTC
Suppose the following C code from avr-gcc 4.7:

extern const __pgmx char foo;
const __pgmx void * pointer = &foo;

Notice that __pgmx is not a macro but a new built-in keyword for a named address space that can hold 24-bit pointers.

The code from above tries to assembler the address of foo.
However, there is *no* way to do that in binutils because the recprective RELOCs like hh8 are not allowed in places they are needed:

.global	pointer
	.data
	.type	pointer, @object
	.size	pointer, 3
pointer:
	.word	foo
	.warning	"assembling 24-bit address needs binutils extension for hh8(foo)"
	.byte	0	 ;  hh8(foo)

avr-gcc emits a "0" to work around that but the code of not correct as the high part of the address will always be 0.
Comment 1 Georg-Johann Lay 2011-12-15 16:19:21 UTC
See also respective extensions to avr-gcc:

http://gcc.gnu.org/PR49868
http://gcc.gnu.org/PR50931
Comment 2 Georg-Johann Lay 2012-01-29 17:58:26 UTC
(In reply to comment #0)
> Suppose the following C code from avr-gcc 4.7:
> 
> extern const __pgmx char foo;
> const __pgmx void * pointer = &foo;

Please notice that the address spaces have been renamed recently and the name for the 3-byte address is __memx now.

Thus, if you want to see the missing feature in code compiled from C, the C source now must read:

extern const __memx char foo;
const __memx void *pointer = &foo;

The generated assembler code will be the same, of course, and the feature as described above to support

    .byte    hh8(foo)

is still missing.
Comment 3 Georg-Johann Lay 2012-03-04 13:39:16 UTC
(In reply to comment #1)
> See also respective extensions to avr-gcc:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50931
Comment 4 Georg-Johann Lay 2012-03-04 13:41:53 UTC
(In reply to comment #1)
> See also respective extensions to avr-gcc:

Finally, the right link to the avr-gcc named address space support, including 24-bit pointers:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49868
Comment 5 Sourceware Commits 2012-05-11 12:59:28 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2012-05-11 12:59:24

Modified files:
	gas            : ChangeLog 
	gas/config     : tc-avr.c 
	bfd            : ChangeLog bfd-in2.h elf32-avr.c libbfd.h 
	                 reloc.c 
	include/elf    : ChangeLog avr.h 

Log message:
	PR 13503
	* reloc.c: Add new ENUM for BFD_RELOC_AVR_8_LO,
	BFD_RELOC_AVR_8_HI, BFD_RELOC_AVR_8_HHI.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenrate.
	* elf32-avr.c (elf_avr_howto_table): Add entries for
	R_AVR_8_LO8, R_AVR_8_HI8, R_AVR_8_HHI8.
	(avr_reloc_map): Add RELOC mappings for R_AVR_8_LO8, R_AVR_8_HI8,
	R_AVR_8_HHI8.
	
	* config/tc-avr.c (exp_mod_pm): Remove variable.
	(exp_mod_data_t): New typedef.
	(pexp_mod_data, exp_mod_data): New variables.
	(avr_parse_cons_expression): Scan through exp_mod_data[] to find
	data expression modifiers "pm", "gs", "lo8", hi8", "hhi8", "hh8"
	and set pexp_mod_data accordingly to be used in avr_cons_fix_new.
	(avr_cons_fix_new): Handle new data expression modifiers shipped
	in pexp_mod_data.
	(md_apply_fix): Handle BFD_RELOC_AVR_8_LO, BFD_RELOC_AVR_8_HI,
	BFD_RELOC_AVR_8_HHI.
	
	* elf/avr.h (RELOC_NUMBERS): Add values for R_AVR_8_LO8,
	R_AVR_8_HI8, R_AVR_8_HHI8.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4727&r2=1.4728
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-avr.c.diff?cvsroot=src&r1=1.80&r2=1.81
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5679&r2=1.5680
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/bfd-in2.h.diff?cvsroot=src&r1=1.568&r2=1.569
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-avr.c.diff?cvsroot=src&r1=1.55&r2=1.56
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/libbfd.h.diff?cvsroot=src&r1=1.273&r2=1.274
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/reloc.c.diff?cvsroot=src&r1=1.228&r2=1.229
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/elf/ChangeLog.diff?cvsroot=src&r1=1.440&r2=1.441
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/elf/avr.h.diff?cvsroot=src&r1=1.12&r2=1.13
Comment 6 Nick Clifton 2012-05-11 13:00:48 UTC
Patch applied.
Comment 7 Sourceware Commits 2012-05-16 14:52:22 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2012-05-16 14:52:16

Modified files:
	gas            : ChangeLog 
	gas/config     : tc-avr.c 
	include/elf    : ChangeLog avr.h 
	bfd            : ChangeLog bfd-in2.h elf32-avr.c libbfd.h 
	                 reloc.c 

Log message:
	PR 13503
	* reloc.c: Rename BFD_RELOC_AVR_8_HHI to BFD_RELOC_AVR_8_HLO.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenrate.
	* elf32-avr.c (elf_avr_howto_table): Rename R_AVR_8_HHI8 to
	R_AVR_8_HLO8.
	(avr_reloc_map): Ditto.
	
	* config/tc-avr.c (avr_cons_fix_new): Rename R_AVR_8_HHI8 to
	R_AVR_8_HLO8.
	(exp_mod_data) Ditto. And replace "hhi8" with "hlo8".
	(md_apply_fix): Rename BFD_RELOC_AVR_8_HHI to BFD_RELOC_AVR_8_HLO.
	
	* avr.h (RELOC_NUMBERS): Rename R_AVR_8_HHI8 to R_AVR_8_HLO8.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4735&r2=1.4736
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-avr.c.diff?cvsroot=src&r1=1.81&r2=1.82
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/elf/ChangeLog.diff?cvsroot=src&r1=1.443&r2=1.444
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/elf/avr.h.diff?cvsroot=src&r1=1.13&r2=1.14
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5687&r2=1.5688
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/bfd-in2.h.diff?cvsroot=src&r1=1.572&r2=1.573
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-avr.c.diff?cvsroot=src&r1=1.56&r2=1.57
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/libbfd.h.diff?cvsroot=src&r1=1.276&r2=1.277
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/reloc.c.diff?cvsroot=src&r1=1.231&r2=1.232
Comment 8 Sourceware Commits 2012-06-11 14:26:48 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2012-06-11 14:26:41

Modified files:
	gas            : ChangeLog 
	gas/config     : tc-avr.c 

Log message:
	PR 13503
	* config/tc-avr.c (exp_mod): Fix typo introduced in 1.82
	from 2012-05-16.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4751&r2=1.4752
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-avr.c.diff?cvsroot=src&r1=1.82&r2=1.83
Comment 9 Sourceware Commits 2012-09-11 17:01:11 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	denisc@sourceware.org	2012-09-11 17:01:00

Modified files:
	gas            : ChangeLog 
	gas/config     : tc-avr.h 

Log message:
	PR gas/13503
	* config/tc-avr.h (TC_VALIDATE_FIX): Skip: BFD_RELOC_AVR_8_LO,
	BFD_RELOC_AVR_8_HI, BFD_RELOC_AVR_8_HLO.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4826&r2=1.4827
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-avr.h.diff?cvsroot=src&r1=1.18&r2=1.19