I want to interleave data and code, and maintain a linked list of it, in the .text section. The problem I'm having is that the assmebler does not seem to align assembler instructions by itself, and if I align the code part manually my list generation pointer arithmetic fails.
.text .set here, . ; remember start of definition .byte 4 ; size of data .ascii "fool" ; data ;.balign 2, 0 ; <-- part 1 of my woes .global fool ; code definition .type fool, @function fool: ret .byte (. - here) ; <-- part 2 of my woes
The way the example is shown the assembler generates fool at an odd adress, which the AVR doesn't like at all (can't call it, can't jump to it, ...). Other than that the assembler generates the layout I am aiming for.
If I uncomment the alignment then the link pointer generation (last line) fails with:
$ /usr/local/avr-4.2.2/bin/avr-gcc -mmcu=atmega8 -Os -nostartfiles -o y x.S
x.S: Assembler messages:
x.S:11: Error: illegal relocation size: 1
Using a .word instead of .byte fixes the problem but wastes a byte (the result is guaranteed < 256).
I could manually pad but I would rather understand why it works without alignment and doesn't with it. Can somebody tell me where I'm going wrong and how I would do this correctly?