Implements the missing relocation types for AVR target.
The results have been cross-checked with binutils.
Original patch by LemonBoy. Some changes by me.
Differential D78741
[LLD][ELF][AVR] Implement the missing relocation types aykevl on Apr 23 2020, 11:57 AM. Authored by
Details Implements the missing relocation types for AVR target. Original patch by LemonBoy. Some changes by me.
Diff Detail
Event TimelineComment Actions
Yes - there is no document I have been able to find either. As you note, the best we can do is compile and dump the sources under AVR-GCC and see that the expectations match up. This patch is really good, the test coverage is nice too (TIL --defsym=). I will have a deeper review of the specific relocation bitwise expressions for correctness this week.
Comment Actions I've checked over all of the relocation logic, cross referenced with both the AVR ISA manual and the AVR LLVM fixture implementations in AVRAsmBackend.cpp - everything looks consistent to me. Nice patch! I think there are a few missing check[U]Int calls (I've left couple comments comments) but other than that, everything looks good from an AVR perspective.
Comment Actions I won't have time to update this diff in the near future so feel free to add the value range checks in a follow-up commit/patch. Comment Actions I actually wrote a patch very similar to this one (but not implementing as many relocations). It's here: https://gist.github.com/aykevl/ce3c04e1175d9602c9dfaf0cf91298ba It's heavily documented. Feel free to use it however you wish. I have an inline comment for what I suspect is a bug in this patch.
Comment Actions I have attached a patch that addresses review comments:
With these changes, I can successfully link at least some TinyGo compiled programs. @LemonBoy from your previous comment it looks like you don't intend to work on this further, is that correct? If so, are you okay with me taking over this patch, thus uploading this new patch for example?
Comment Actions
Yeah go for it, let's land this patchset. Comment Actions @MaskRay thanks! I wasn't aware of that option. Changes I made:
Comment Actions Thanks for the review! This should address all comments. -Ttext=0 was indeed unnecessary (tests still pass) so I've removed it.
Comment Actions
I've confirmed that # is not a valid comment char in the original AVR assembler. See: http://ww1.microchip.com/downloads/en/devicedoc/40001917a.pdf#page=12 (section 4.3). I don't know why # at the start of a line works as a comment, perhaps these lines are removed by llvm-lit? Comment Actions Thanks for the update. All look good to me now. MCParser supports # in the line beginning. 6.12 of the document you linked says "Unsurprisingly, this directive does exactly nothing. The only reason it exists is that it is required by the ANSI C standard" but I think that is not true. GCC/clang will report error: invalid preprocessing directive |
The comment I wrote on my patch is the following:
I'm not sure when it would trigger, perhaps with debug info. Did you test that?
Also, what does the MEMORY part of your linker script look like? For me it looks like this:
In other words, code and data are 0x800000 apart (in the ELF file). This is also the convention followed by the avr-gcc toolchain.