This is the mail archive of the 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]

Making gas generate fixups for label differences


  I am adding DIFF relocs for the AVR target to make sure shrinking
  of instructions during linker relaxation doesn't mess up 
  .debug_line information. While I got that working, I have not been
  able to get gas to generate relocs for label difference expressions in 
  the source file. Consider the following piece of code

.section	.text,"ax",@progbits
.global	main
	.type	main, @function
    jmp main
.global	x
	.section .data
	.type	x, @object
	.size	x, 2
	.word	L2 - L1

The assembler evaluates L2 - L1 to 4 bytes and puts the constant 4 into
the data section, but the linker later relaxes jmp to an rjmp (2 bytes instead
of 4) - the difference in the data section becomes incorrect.

$ /scratch/avr/install/bin/avr-objdump -S relax
Disassembly of section .text:

00000000 <main>:
   0:   ff cf           rjmp    .-2         ; 0x0 <main>

   00000002 <L2>:
      2:    08 95           ret

$ /scratch/avr/install/bin/avr-objdump -s relax

      relax:     file format elf32-avr

      Contents of section .data:
       800060 0400                                 ..              
       Contents of section .text:
        0000 ffcf0895                             ....            
        â  ~

I looked at the internals manual, but all the TC_FORCE_RELOC* hooks
appear to kick in much later i.e. there is no fixup for which a
relocation has to be generated in this case - there's just the 
evaluated value.  

What am I missing? How do I force gas to emit a fixup for this case?


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