avr: errno does not link: __errno_location is not in the C library

Open Beginner friendly
#206 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Firat17aze is already working on this.

Since Nov 13, 2026.

  • #208 by @Firat17aze — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
embedded-iot

Research direction

Start with the AVR errno implementation and the conformance check in tests/conformance/test_smoke.c; confirm how other ports provide __errno_location and how AVR treats errno across threads. Add the AVR implementation so the reported program links and the errno check passes, then run the conformance test for the Uno target.

Written by the indexing model from the issue text.

Description

bug

An AVR program that uses errno does not link: <errno.h> defines errno as (*__errno_location()) for every target but Darwin, and the AVR C library does not define __errno_location. EmbCC 0.1.0 (macOS aarch64 release).

#include <errno.h>
#include <stdlib.h>
int main(void) { errno = 0; long v = strtol("99999999999999999999", 0, 10); return (errno == ERANGE && v != 0) ? 0 : 1; }
$ embcc --target=avr -mmcu=atmega328p -Os errno.c -o errno.elf
embld: undefined symbol '__errno_location' (referenced by errno-avr.elf.embcc-tmp.o)

Where EmbLinkRTOS meets it: tests/conformance/test_smoke.c checks errno after an out-of-range strtol, as the C library does it on every port; on the Uno it is the one image that fails to link for this reason.

A single static int and an __errno_location returning its address would do for AVR, which has no threads of its own; the RTOS's tests state that errno is not per thread there.

Part of #184 (AVR).

Dominant language
C
Stars
1
Forks
2
Avg merge
20h 55m
Merged PRs (30d)
73

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EmbLinkOs/EmbCC

All issues in EmbLinkOs/EmbCC

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.