This is an archive of the discontinued LLVM Phabricator instance.

[lld][ELF] Support relocations R_AVR_LO8_LDI_GS/R_AVR_HI8_LDI_GS
ClosedPublic

Authored by benshi001 on Mar 31 2023, 5:36 PM.

Details

Summary

Relocations R_AVR_LO8_LDI_GS/R_AVR_HI8_LDI_GS (indirect calls
via function pointers) only cover range 128KiB. They are
equivalent to R_AVR_LO8_LDI_PM/R_AVR_HI8_LDI_PM within this
range.

But for function addresses beyond this range, GNU-ld emits
trampolines. And this patch implements corresponding thunks
for them in lld.

Diff Detail

Event Timeline

benshi001 created this revision.Mar 31 2023, 5:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 31 2023, 5:36 PM
benshi001 requested review of this revision.Mar 31 2023, 5:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 31 2023, 5:36 PM
benshi001 updated this revision to Diff 513054.Apr 12 2023, 8:34 PM
benshi001 retitled this revision from [lld][ELF] Add thunks for relocations R_AVR_LO8_LDI_GS/R_AVR_HI8_LDI_GS to [lld][ELF] Support relocations R_AVR_LO8_LDI_GS/R_AVR_HI8_LDI_GS.
benshi001 edited the summary of this revision. (Show Details)
benshi001 set the repository for this revision to rG LLVM Github Monorepo.

Sorry for my belated review. I finished a long trip and had a very long task queue....

lld/ELF/Arch/AVR.cpp
113

If s.getVA() & 1 is not rejected by previous checks, we should not have this check.

Don't add a period for messages. See https://llvm.org/docs/CodingStandards.html#error-and-warning-messages

lld/ELF/Thunks.cpp
295

Don't copy the MIPS LA25 thunk comment. It doesn't provide any value for a reader.

Use a short description.

906

Just write the instruction form, as an example for other architectures: // b .+4

lld/test/ELF/avr-thunk.s
8 ↗(On Diff #513054)

Where is 000110b4 referenced in the CHECK lines?

19 ↗(On Diff #513054)

Is this intended to be a local symbol?

benshi001 marked an inline comment as done.Apr 19 2023, 6:34 PM
benshi001 added inline comments.
lld/test/ELF/avr-thunk.s
8 ↗(On Diff #513054)

000110b4 is reffered by

; CHECK-NEXT:    ldi     r30, 0x5a
; CHECK-NEXT:    ldi     r31, 0x88

that is ((0x88 << 8) + 0x5a) == 0x110b4

benshi001 marked an inline comment as done.Apr 19 2023, 6:34 PM
benshi001 added inline comments.
lld/test/ELF/avr-thunk.s
8 ↗(On Diff #513054)

((0x88 << 8) + 0x5a) << 1 == 0x110b4

benshi001 updated this revision to Diff 515176.Apr 19 2023, 7:05 PM
benshi001 marked an inline comment as done.
benshi001 edited the summary of this revision. (Show Details)
benshi001 marked 3 inline comments as done.
benshi001 added inline comments.
lld/ELF/Arch/AVR.cpp
113

The redundant assert is removed.

benshi001 marked an inline comment as done.Apr 19 2023, 7:07 PM
benshi001 added inline comments.Apr 19 2023, 7:15 PM
lld/test/ELF/avr-thunk.s
19 ↗(On Diff #513054)

this symbol is not important, I just want it to be a seperator between the original code and the auto generated thunk code.

MaskRay added inline comments.Apr 19 2023, 7:38 PM
lld/test/ELF/avr-thunk.s
8 ↗(On Diff #513054)

I'd add a ;; CHECK-NEXT just before ; CHECK-NEXT: ldi r30, 0x5a. You can see my past updates to ppc-* or aarch64-* tests.

benshi001 added inline comments.Apr 19 2023, 9:07 PM
lld/test/ELF/avr-thunk.s
8 ↗(On Diff #513054)

I did not catch your point here, do you mean, it would be better to be

;; CHECK:       [[ADDR0:[0-9]+]] <__AVRThunk_b>:
;; CHECK-NEXT:    jmp   0x20000
;; CHECK-NEXT:    ldi     r30, [[ADDR0]]
;; CHECK-NEXT:    ldi     r31, [[ADDR0]]

But this does not work, since ADDR0 is broken to 0x88 and 0x5a.

MaskRay added inline comments.Apr 19 2023, 9:16 PM
lld/test/ELF/avr-thunk.s
8 ↗(On Diff #513054)

Sorry, I mean you can add comments how 0x5a and 0x88 are computed

;; (0x20000 ... ) = 0x5a
;; (0x20000 ... ) = 0x88
benshi001 updated this revision to Diff 515213.Apr 19 2023, 9:40 PM
benshi001 marked 2 inline comments as done.
MaskRay added inline comments.Apr 25 2023, 3:02 PM
lld/test/ELF/avr-thunk.s
1 ↗(On Diff #515213)

If there can be other thunks, I'd suggest a filename with more information, e.g. avr-thunk-ldi-gs.s

8 ↗(On Diff #515213)
; CHECK-LABEL: <__AVRThunk_b>:
; CHECK-NEXT:   000110b4 jmp 0x20000

(Then use llvm-objdump ... --no-show-raw-insn

This idea is that <__AVRThunk_b> will always match. If the address changes, the NEXT: pattern ensures that FileCheck can locate the exact failure line. Technically such issues can be fixed by a sufficiently smart auto tool.

000110b4 <__AVRThunk_b>: may not give FileCheck sufficient information to locate a line.

benshi001 updated this revision to Diff 517008.Apr 25 2023, 6:17 PM
benshi001 marked 2 inline comments as done.

I have renamed the file to avr-thunk-ldi-gs.s, Thanks!

MaskRay accepted this revision.Apr 27 2023, 8:30 PM
This revision is now accepted and ready to land.Apr 27 2023, 8:30 PM