[PATCH] D32991: [ELF] Initial migration of AVR target

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 17:26:14 PDT 2017


ruiu added a comment.

Leslie,

This patch is work-in-progress for more than a month, and looks like it needs some more time. That is understandable -- it is probably not that easy to land a first patch for a new architecture. So I decided to take a little time to help you. I installed avr-{gcc,objdump,as,ld} using apt-get and read the Wikipedia page of the AVR instruction set (I should have read the official instruction manual, but what's on the Wikipedia page seems correct.)

What I found are:

- `R_AVR_32` is not used nor tested in your patch. You want to simply remove it.
- `.text` segments in AVR ELF outputs should be linked against absolute address zero because AVR is a Harvard-architecture microcontroller on which programs usually reside at address zero. Your output is on the other hand linked against address 0x11000. That's too high for AVR. You want to pass `-Ttext=0` to the linker so that .text sections are linked against 0.
- The AVR ELF seems to use RELA as opposed to REL. That means relocation addends are in relocation tables and not in relocated segments. So you don't need to write `getImplicitAddend()`.
- The relocation is not applied correctly. Operands of JMP or CALL instructions are 22-bit long, and it can only jump to even-numbered addresses (as all instructions are 2 byte long). So, the least significant bit is implicit and always 0. JMP or CALL instructions are in the following form in binary in an object file

  1001 0100 0000 11x0  0000 0000 0000 0000

  and after applying a `R_AVR_CALL` relocation with a 22-bit address `aa aaab cccc cccc cccc cccc` (in binary), the result should look like

  1001 010a aaaa 11xb  cccc cccc cccc cccc

  You can see the instruction encoding here: https://en.wikipedia.org/wiki/Atmel_AVR_instruction_set#Instruction_encoding

I fixed these problems based on your patch. See it here: https://github.com/rui314/llvm-project/commit/880cd5c1c262169dc8bc6b36b5824dd2acfa2132. I confirmed that the output matches with the avr-ld.bfd's output.

Can you update your patch based on mine?


Repository:
  rL LLVM

https://reviews.llvm.org/D32991





More information about the llvm-commits mailing list