llvm / llvm/llvm-project

Some builtin functions are still missing in clang, which gcc has

Open
#168,685 13 comments 0 reactions 0 assignees View on GitHub
backend:AVR clang:driver
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I'm trying to compile a small (blinking LED) example with `clang` instead of `avr-gcc` on Debian, with all parts from the respective Debian packages (`avr-libc`, `gcc-avr`, `clang-19`). `clang` fails to find avr-libc when linking:

```
clang -I. -g -Os -Wall -mmcu=attiny85 -DF_CPU=16500000 -DBOOTLOADER_ADDRESS=0x1980 --target=avr --sysroot=/usr/lib/avr -I/usr/lib/avr/include -c -o main.o main.c
main.c:18:1: warning: unused function 'wdr' [-Wunused-function]
18 | wdr(void)
| ^~~
1 warning generated.
clang -I. -g -Os -Wall -mmcu=attiny85 -DF_CPU=16500000 -DBOOTLOADER_ADDRESS=0x1980 --target=avr --sysroot=/usr/lib/avr -I/usr/lib/avr/include -Wl,-Map=main.map -v -o main.elf main.o
Debian clang version 19.1.7 (10.1)
Target: avr
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
clang: warning: no avr-libc installation can be found on the system, cannot link standard libraries [-Wavr-rtlib-linking-quirks]
clang: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked [-Wavr-rtlib-linking-quirks]
"/usr/bin/avr-ld" -o main.elf --gc-sections --defsym=__DATA_REGION_ORIGIN__=0x800060 -Map=main.map main.o -mavr25
```

Looking at https://github.com/llvm/llvm-project/blob/b31199bab4865deef4e778d7a028c8ec64285654/clang/lib/Driver/ToolChains/AVR.cpp#L455-L474 I suspect part of the issue may be that the Debian package install `avr-libc` in `/usr/lib/avr/`, not within `/usr/lib/gcc/avr/14.2.0/`, but I don't understand the code well enough to be certain yet.

The comment https://github.com/llvm/llvm-project/issues/50567#issuecomment-2416778152 indicates I'm not the only one hitting this problem.

Contributor guide

Open the contributing guide

Research direction

Start with clang/lib/Driver/ToolChains/AVR.cpp around lines 455-474 and reproduce the Debian commands shown in the issue. Compare how clang searches for avr-libc with the Debian installation under /usr/lib/avr/, then determine how the missing AVR runtime or builtins should be handled. Done means the reported AVR example links successfully without the missing-library warnings and the relevant behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.