[PATCH] D37615: [AVR] implement the relocation of LDI and other Instructions for LLD
Leslie Zhai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 11 02:13:49 PDT 2017
xiangzhai updated this revision to Diff 114546.
xiangzhai retitled this revision from "[AVR] implement the relocation of LDI for LLD" to "[AVR] implement the relocation of LDI and other Instructions for LLD".
xiangzhai added a comment.
Dear Rui,
> I believe you want to learn/investigate more about ELF/AVR to write code for an ELF/AVR linker.
Yes 先生 :) and I read ld.bfd's elf32-avr.c <https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf32-avr.c;h=830da288f3cd3e6a070b5ced908ca05d6b11e4b0;hb=HEAD#l1013> `avr_final_link_relocate`, then re-implement the relocation of LDI and other Instructions for LLD, tested by `make check-lld` and compared with avr-ld, the result is same:
$ avr-gcc -mmcu=atmega328p -o basic-avr.o -c basic-avr.s
$ avr-readelf -r basic-avr.o
Relocation section '.rela.text' at offset 0xe4 contains 10 entries:
Offset Info Type Sym.Value Sym. Name + Addend
00000000 00000106 R_AVR_LO8_LDI 00000000 .text + 12
00000002 00000107 R_AVR_HI8_LDI 00000000 .text + 16
00000004 00000108 R_AVR_HH8_LDI 00000000 .text + 12
00000006 00000113 R_AVR_LDI 00000000 .text + 12
00000008 00000102 R_AVR_7_PCREL 00000000 .text + e
0000000a 00000103 R_AVR_13_PCREL 00000000 .text + e
0000000c 00000115 R_AVR_6_ADIW 00000000 .text + 16
0000000e 00000112 R_AVR_CALL 00000000 .text + e
00000012 00000112 R_AVR_CALL 00000000 .text + 12
00000016 00000112 R_AVR_CALL 00000000 .text + 16
relocated by avr-ld:
$ avr-ld -o basic-avr basic-avr.o -Ttext=0
$ avr-objdump -d basic-avr
basic-avr: file format elf32-avr
Disassembly of section .text:
00000000 <__ctors_end>:
0: 12 e1 ldi r17, 0x12 ; 18
2: 20 e0 ldi r18, 0x00 ; 0
4: 30 e0 ldi r19, 0x00 ; 0
6: 42 e1 ldi r20, 0x12 ; 18
8: 11 f4 brne .+4 ; 0xe <next>
a: 01 c0 rjmp .+2 ; 0xe <next>
c: 46 96 adiw r24, 0x16 ; 22
0000000e <next>:
e: 0c 94 07 00 jmp 0xe ; 0xe <next>
00000012 <foo>:
12: 0c 94 09 00 jmp 0x12 ; 0x12 <foo>
00000016 <bar>:
16: 0c 94 0b 00 jmp 0x16 ; 0x16 <bar>
compared with LLD, the result is same:
$ llvm/build/bin/ld.lld -o basic-avr-lld basic-avr.o -Ttext=0
$ avr-objdump -d basic-avr-lld
basic-avr-lld: file format elf32-avr
Disassembly of section .text:
00000000 <main>:
0: 12 e1 ldi r17, 0x12 ; 18
2: 20 e0 ldi r18, 0x00 ; 0
4: 30 e0 ldi r19, 0x00 ; 0
6: 42 e1 ldi r20, 0x12 ; 18
8: 11 f4 brne .+4 ; 0xe <next>
a: 01 c0 rjmp .+2 ; 0xe <next>
c: 46 96 adiw r24, 0x16 ; 22
0000000e <next>:
e: 0c 94 07 00 jmp 0xe ; 0xe <next>
00000012 <foo>:
12: 0c 94 09 00 jmp 0x12 ; 0x12 <foo>
00000016 <bar>:
16: 0c 94 0b 00 jmp 0x16 ; 0x16 <bar>
先生 please review my patch, thanks a lot!
Regards,
Leslie Zhai
Repository:
rL LLVM
https://reviews.llvm.org/D37615
Files:
ELF/Arch/AVR.cpp
test/ELF/basic-avr.s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37615.114546.patch
Type: text/x-patch
Size: 5650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170911/ac3f3bde/attachment.bin>
More information about the llvm-commits
mailing list