Skip to content

clang --target=avr cannot find avr-libc #168685

@airtower-luna

Description

@airtower-luna

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

llvm::Optional<std::string> AVRToolChain::findAVRLibcInstallation() const {
// Search avr-libc installation according to avr-gcc installation.
std::string GCCParent(GCCInstallation.getParentLibPath());
std::string Path(GCCParent + "/avr");
if (llvm::sys::fs::is_directory(Path))
return Path;
Path = GCCParent + "/../avr";
if (llvm::sys::fs::is_directory(Path))
return Path;
// Search avr-libc installation from possible locations, and return the first
// one that exists, if there is no avr-gcc installed.
for (StringRef PossiblePath : PossibleAVRLibcLocations) {
std::string Path = getDriver().SysRoot + PossiblePath.str();
if (llvm::sys::fs::is_directory(Path))
return Path;
}
return llvm::None;
}
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 #50567 (comment) indicates I'm not the only one hitting this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:driver'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions