Bug 2539 - avr-as generates wrong opcode for call/jmp with lables
Summary: avr-as generates wrong opcode for call/jmp with lables
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.17
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-12 20:54 UTC by Raphael Mack
Modified: 2006-04-13 09:15 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu (Gentoo 3.4.5)
Target: avr
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raphael Mack 2006-04-12 20:54:28 UTC
If I compile

------
.arch	atmega128
.text
.org	0x0
	jmp main
.org	0x46
.global	main
.type	main, @function
main:
	nop
	jmp main
------
with
avr-as -g -D -o t.elf -mmcu=atmega128 t.S
I get
------
 avr-objdump -D t.elf

t.elf:     file format elf32-avr

Disassembly of section .text:

00000000 <main-0x46>:
   0:   0c 94 00 00     jmp     0       ; 0x0 <main-0x46>
        ...

00000046 <main>:
  46:   00 00           nop
  48:   0c 94 00 00     jmp     0       ; 0x0 <main-0x46>
------

which should be a "jmp 0x46". When I use rjmp/rcall it works fine.
Comment 1 Nick Clifton 2006-04-13 09:15:38 UTC
Hi Mack,

  This is not a bug, but a feature.  The AVR assembler has chosen to use a reloc
with the JMP instruction, so the actual address is not resolved until link time.
 If you disassemble the object file with -Dr instead of -D you will see:

  00000000 <main-0x46>:
   0:   0c 94 00 00     jmp     0       ; 0x0 <main-0x46>
                        0: R_AVR_CALL   .text+0x46
  
etc.  The reason for this is that the JMP instruction takes an absolute address
as its operand, and this address cannot be known until the linker has assigned a
location to the .text section.

The RJMP and RCALL instructions on the other hand take PC-relative operands, so
their values can be computed by the assembler at assembly time.  Hence these two
instructions do not generate relocs.

Cheers
  Nick