This is an archive of the discontinued LLVM Phabricator instance.

[lld][ELF] Support relocation R_AVR_LDS_STS_16 on AVRTiny devices
ClosedPublic

Authored by benshi001 on Dec 11 2022, 7:52 PM.

Details

Summary

The relocation 'R_AVR_LDS_STS_16' is introduced for the compact
16-bit 'LDS/STS' instructions on AVRTiny devices.

Diff Detail

Event Timeline

benshi001 created this revision.Dec 11 2022, 7:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2022, 7:52 PM
benshi001 requested review of this revision.Dec 11 2022, 7:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2022, 7:52 PM
benshi001 added inline comments.Dec 11 2022, 8:02 PM
lld/ELF/Arch/AVR.cpp
175

The assembler won't emit R_AVR_LDS_STS_16 for AVRTiny devices. And this check is hard to be tested in the unit tests.

lld/test/ELF/avr-reloc.s
84

lds/sts are 32-bit instructions on non avrtiny devices.

lld/test/ELF/avrtiny-reloc.s
3

The reasons why I create a new avrtiny-reloc.s, other than add my tests into the existing avr-reloc.s, are

  1. Some instructions in avr-reloc.s are not supported on avrtiny devices, and the assembler will emit errors.
  2. AVRTiny devices have their special relocations which will not be emitted on ordinary avr devices.
59

lds/sts are 16-bit instructions on avrtiny devices, while they are 32-bit on ordinary avr devices.

This comment was removed by benshi001.

Here is the compact LDS/STS instruction's binary format.

aykevl added inline comments.Dec 26 2022, 3:43 PM
lld/test/ELF/avr-reloc.s
84

Why does the comment say R_AVR_LDS_STS_16 for atmega328p? (Sounds like a copy/paste error)

benshi001 updated this revision to Diff 485330.Dec 26 2022, 6:37 PM
benshi001 marked an inline comment as done.Dec 26 2022, 6:40 PM
benshi001 added inline comments.
lld/test/ELF/avr-reloc.s
84

Thanks. I have corrected them. llvm emits relocation R_AVR_16 for lds/sts on AVR while R_AVR_LDS_STS_16 on AVRTiny.

benshi001 marked an inline comment as done.Dec 26 2022, 6:42 PM
aykevl accepted this revision.Dec 30 2022, 11:27 AM
This revision is now accepted and ready to land.Dec 30 2022, 11:27 AM

@MaskRay Any comments on this patch ?

MaskRay requested changes to this revision.Dec 30 2022, 6:36 PM
This revision now requires changes to proceed.Dec 30 2022, 6:36 PM
MaskRay added inline comments.Dec 30 2022, 6:41 PM
lld/ELF/Arch/AVR.cpp
175

calcEFlags is costly. I don't think any other arch has such an eflags based relocation check. Is it really necessary?

I suggest that you remove it, at the very least, there is no trailing dot in all lld/ELF diagnostics.

lld/test/ELF/avrtiny-reloc.s
1

avr-tiny*

Can avr-reloc.s be augmented to test -mcpu=attiny10?

benshi001 updated this revision to Diff 485756.Dec 31 2022, 2:13 AM
benshi001 marked 2 inline comments as done.Dec 31 2022, 2:16 AM
benshi001 added inline comments.
lld/ELF/Arch/AVR.cpp
175

Thanks. I have removed this unnecessary check.

lld/test/ELF/avr-reloc.s
53

Currently the disassembler can correctly decode those instructions.

lld/test/ELF/avrtiny-reloc.s
1

I would like to do that, but it is impossible. Since avr-reloc.s contains instructions which are invalid on AVRTiny, the assembler will report errors, so I have to create a seperate file for AVRTiny.

benshi001 marked 2 inline comments as done.Dec 31 2022, 2:17 AM
benshi001 updated this revision to Diff 485758.Dec 31 2022, 2:22 AM
benshi001 edited the summary of this revision. (Show Details)
benshi001 added inline comments.Dec 31 2022, 2:36 AM
lld/test/ELF/avrtiny-reloc.s
1

Actually avrtiny is not a subset of avr, though their common part is quite large, they each have own specific stuff (instruction mnemonics, instruction formats, instruction encodings, relocations, etc.).

MaskRay added inline comments.Dec 31 2022, 12:29 PM
lld/test/ELF/avrtiny-reloc.s
3

You can use --defsym as used by llvm/test/MC/ELF/relocation-alias.s

benshi001 updated this revision to Diff 485792.Dec 31 2022, 6:40 PM
benshi001 marked an inline comment as done.
benshi001 added inline comments.
lld/test/ELF/avrtiny-reloc.s
3

Thanks. I have used --defsym=tiny=1 to distinguish avr and avrtiny instructions.

benshi001 marked an inline comment as done.Dec 31 2022, 6:41 PM
MaskRay added inline comments.Dec 31 2022, 11:35 PM
lld/test/ELF/avr-reloc.s
6

The prevailing style in this directory is to place | on the previous line

49

TINY

Remove . from the subject.

benshi001 retitled this revision from [lld][ELF] Support relocation R_AVR_LDS_STS_16 on AVRTiny devices. to [lld][ELF] Support relocation R_AVR_LDS_STS_16 on AVRTiny devices.
benshi001 marked 2 inline comments as done.

Thanks.

MaskRay accepted this revision.Jan 1 2023, 12:22 AM

Thanks!

This revision is now accepted and ready to land.Jan 1 2023, 12:22 AM