avr: inline assembly with lo8()/hi8() cuts symbols longer than 16 characters
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c
- Domain
- compilers, embedded-iot
Research direction
The issue provides a minimal C example using inline assembly and reproduces the symbol truncation with AVR target flags; start by reading that example and tracing how EmbCC parses or emits inline assembly containing lo8() or hi8(). Check the AVR port context in arch/avr/avr_context.c for the affected long symbols. Done means the example compiles with those symbols intact and the AVR RTOS library can build.
Written by the indexing model from the issue text.
Description
On AVR, an inline-assembly template that uses lo8() or hi8() anywhere has every symbol longer than 16 characters cut to its first 16, and the assembler then refuses it. EmbCC 0.1.0 (macOS aarch64 release), --target=avr -mmcu=atmega328p -Os.
void abcdefghijklmnopqrst(void);
void g(void) { __asm__ __volatile__("ldi r18, lo8(2303)\n\tcall abcdefghijklmnopqrst" ::: "r18"); }
embcc: g.c:2: error: 'abcdefghijklmnop' is not a number, a register or an expression this assembler knows
What changes the result:
| Template | Result |
|---|---|
ldi r18, lo8(2303) then call abcdefghijklmnopqrst |
error |
ldi r18, hi8(2303) then call … |
error |
call … first, then ldi r18, lo8(2303) |
error |
ldi r18, lo8(2303), nop, then jmp … |
error |
ldi r18, 7 then call abcdefghijklmnopqrst |
compiles |
call abcdefghijklmnopqrst alone, with or without operands |
compiles |
a 16-character name after lo8() |
compiles |
So the cut follows the presence of lo8/hi8 in the block, not their position or the operands.
Where EmbLinkRTOS meets it: the AVR port's kernel start, arch/avr/avr_context.c, loads the stack pointer with lo8(%[top])/hi8(%[top]) and then calls emb_arch_switch_to and jumps to embk_thread_launch, both 18 characters. The port's library does not compile, so no Uno image links. Passing the two bytes as separate "i" operands avoids it; the RTOS keeps lo8/hi8, which avr-gcc and Clang accept.
Part of #184 (AVR).
- Dominant language
- C
- Stars
- 1
- Forks
- 2
- Avg merge
- 20h 55m
- Merged PRs (30d)
- 73
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EmbLinkOs/EmbCC
-
avr: errno does not link: __errno_location is not in the C libraryPossibly taken @Firat17aze claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 50/100
Maintainers usually reply within 1 day
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
SPIDevice selects an active-high device as soon as it is createdPossibly taken @mikeysklar claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
adafruit/circuitpython#11869 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
gnif/LookingGlass#1352 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100