Skip to content

[AVR] clang LTO causes Arduino examples to break #127651

Open
@beakthoven

Description

@beakthoven

When compiling the Blink example from the Arduino IDE for AVR using Clang with LTO enabled, the program fails to function correctly. The LED blinks once and then remains stuck in the ON position indefinitely. Disabling LTO for wiring.c from Arduino AVR core resolves the issue.

LLVM version: 20.1.0-rc2

Blink example code:

#include <Arduino.h>

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH); 
  delay(1000); 
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000); 
}

Compiler flags used (other than -flto -fno-fat-lto-objects):

--target=avr -c -g -Os -Wall -Wextra --sysroot=/home/dakkshesh/.arduino15/packages/ClangBuiltArduino/tools/cba-avr-sysroot/12022025 -std=gnu11 -ffunction-sections -fdata-sections -MMD -mmcu=atmega2560 -DF_CPU=16000000L

Expected Behavior

The LED should continue blinking at a 1-second interval indefinitely.

Attachments

LLVM IR files for wiring.c with LTO turned on and off.
wiring.c-lto.ll.txt
wiring.c-nonlto.ll.txt

wiring.c: https://github.com/ClangBuiltArduino/core_arduino_avr/blob/8b327d7bede1c1245db99daeba4e168c92c11194/cores/arduino/wiring.c

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions