This is an archive of the discontinued LLVM Phabricator instance.

[lld][ELF] Support BFD name elf32-avr
ClosedPublic

Authored by benshi001 on May 13 2022, 6:43 AM.

Diff Detail

Event Timeline

benshi001 created this revision.May 13 2022, 6:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 6:43 AM
benshi001 requested review of this revision.May 13 2022, 6:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 6:43 AM
benshi001 added inline comments.May 13 2022, 6:44 AM
lld/test/ELF/linkerscript/avr5.test
15 ↗(On Diff #429226)

This two disassembled lines corresponds to

	sts   abc+1, r25
	sts   abc, r24

in the original assmebly source.

We can see that the address of variable abc is 100, which is correct.

benshi001 added inline comments.May 13 2022, 6:46 AM
lld/test/ELF/linkerscript/avr5.test
11 ↗(On Diff #429226)

I expect to check both section addresses and variable addresses.

benshi001 added inline comments.May 13 2022, 6:47 AM
lld/test/ELF/linkerscript/avr5.test
24 ↗(On Diff #429226)

AVR is harward CPU, it is common that program memory and data memory are isolated to two different regions.

MaskRay added inline comments.May 13 2022, 11:13 PM
lld/ELF/ScriptParser.cpp
440

move this after EM_386

lld/test/ELF/linkerscript/Inputs/avr5.s
6

These instructions are not meaningful to ld. One single rjmp _start is sufficient testing a relocation.

lld/test/ELF/linkerscript/avr5.test
2 ↗(On Diff #429226)

Use split-file

24 ↗(On Diff #429226)

Is it common to start at zero address?

benshi001 updated this revision to Diff 429449.May 14 2022, 7:20 AM
benshi001 marked an inline comment as done.
benshi001 marked 2 inline comments as done.May 14 2022, 7:27 AM
benshi001 added inline comments.
lld/test/ELF/linkerscript/Inputs/avr5.s
6

Unfortunately rjmp can not be decoded correctly by llvm-objdump, due to bugs in AVR Disassembler (But GNU's avr-bjdump can). Currently I have to use LDI, which load an int8 immediate to a register.

lld/test/ELF/linkerscript/avr5.test
24 ↗(On Diff #429226)

Yes. Most devices reset to PC = 0.

benshi001 marked an inline comment as done.May 14 2022, 7:28 AM
benshi001 marked an inline comment as done.
benshi001 added inline comments.
lld/test/ELF/linkerscript/avr5.test
2 ↗(On Diff #429226)

Done. Splited to two .test files.

benshi001 marked an inline comment as done.May 14 2022, 7:30 AM
benshi001 added inline comments.May 14 2022, 7:34 AM
lld/test/ELF/linkerscript/avr5-relocs.test
9

VMA of variable def is 0x802, so 2 => r24 and 8 => r25.

benshi001 updated this revision to Diff 429461.May 14 2022, 8:22 AM
MaskRay added inline comments.May 14 2022, 5:12 PM
lld/test/ELF/linkerscript/avr5-relocs.test
11
lld/test/ELF/linkerscript/avr5-sections.test
1

The tests should be merged into one.

Add a file-level comment explaining the purpose.

Use split-file to avoid Inputs/* files.

benshi001 updated this revision to Diff 429499.May 14 2022, 5:51 PM
benshi001 marked an inline comment as done.May 14 2022, 6:03 PM
benshi001 added inline comments.
lld/test/ELF/linkerscript/avr5-sections.test
1

I am not familiar with that.

do you mean:

  1. make a unique .s file with assembly
  2. echo to a temp linker script
  3. do all checks ?
MaskRay added inline comments.May 14 2022, 6:05 PM
lld/test/ELF/linkerscript/avr5-sections.test
1

rg split-file in this directory and see I use split-file.

benshi001 updated this revision to Diff 429501.May 14 2022, 6:50 PM
benshi001 marked 2 inline comments as done.
benshi001 added inline comments.
lld/test/ELF/linkerscript/avr5-sections.test
1

A file level comment is added.

1

I have combined all files into avr5.test with split-file.

benshi001 marked an inline comment as done.May 14 2022, 6:52 PM
benshi001 updated this revision to Diff 429502.May 14 2022, 7:10 PM
benshi001 added inline comments.
lld/test/ELF/linkerscript/avr5-relocs.test
11

I have added a check line for that OUTPUT_ARCH(avr:5) input:

# HEAD: 0x5, EF_AVR_ARCH_AVR5
MaskRay accepted this revision.May 17 2022, 11:13 AM
MaskRay added inline comments.
lld/test/ELF/linkerscript/avr5.test
3 ↗(On Diff #429502)
This revision is now accepted and ready to land.May 17 2022, 11:13 AM
MaskRay retitled this revision from [lld][ELF] Support linking 'elf32-avr' with linker scripts to [lld][ELF] Support elf32-avr BFD name.May 17 2022, 11:14 AM
MaskRay retitled this revision from [lld][ELF] Support elf32-avr BFD name to [lld][ELF] Support BFD name elf32-avr.
This revision was automatically updated to reflect the committed changes.