LTO Compile Error

Not open for further replies.


Senior Member+
I'm occasional working at a debug library to share and asked for a FASTER LTO compile so I could watch my windows disk traffic.

Turns out the code won't compile 2 of my 3 examples: HardFaults, DebugTest fail but a third Asserts doesn't have any trouble compiling/uploading/running? Using default compile optimizations I've never seen trouble.

Nothing magic about the library - it just adds live code for the Hard Faults [off by default in PJRC release] and then keeps the I/O alive {using PJRC code] to push out text messages to give feedback and allow USB to stay alive to reprogram without button.

I'm compiling for a T_3.6, but not sure that matters - no special code expected to work on all the ARMS.

The Error text I get on the above sketch 'DebugTest' in examples of the library with FAST/FASTER w/LTO below appears as:
Linking everything together...
"T:\\arduino_1.8.5_142_TYC\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-gcc" -O2 -flto -fno-fat-lto-objects -Wl,--gc-sections,--relax,--defsym=__rtc_localtime=1534210583 "-TT:\\arduino_1.8.5_142_TYC\\hardware\\teensy\\avr\\cores\\teensy3/mk66fx1m0.ld" -lstdc++ -fuse-linker-plugin -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -o "T:\\TEMP\\arduino_build_723063/DebugTest.ino.elf" "T:\\TEMP\\arduino_build_723063\\sketch\\DebugTest.ino.cpp.o" "T:\\TEMP\\arduino_build_723063\\libraries\\debug_t3\\debug_t3.cpp.o" "T:\\TEMP\\arduino_build_723063/..\\arduino_cache_508721\\core\\core_teensy_avr_teensy36_usb_serial,speed_180,opt_o2lto,keys_en-us_6eba4e858d7c3fc764c7c08715f56282.a" "-LT:\\TEMP\\arduino_build_723063" -larm_cortexM4lf_math -lm
t:/arduino_1.8.5_142_tyc/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-closer.o): In function `_close_r':
closer.c:(.text._close_r+0xc): undefined reference to `_close'

t:/arduino_1.8.5_142_tyc/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text._fstat_r+0x10): undefined reference to `_fstat'

t:/arduino_1.8.5_142_tyc/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'

t:/arduino_1.8.5_142_tyc/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c:(.text._lseek_r+0x12): undefined reference to `_lseek'

t:/arduino_1.8.5_142_tyc/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text._read_r+0x12): undefined reference to `_read'

collect2.exe: error: ld returned 1 exit status

Using library debug_t3 in folder: t:\tcode\libraries\debug_t3 (legacy)
Error compiling for board Teensy 3.6.

Here is the WIP to unzip into active libraries folder - problem sketches are in the examples folder::
View attachment
Found it - two places in both those examples - where one evolved from the other to show Hard Faults, and the Asserts had those removed.

This compiles and links only without LTO:
printf("%f\n", x); // Hard Fault

But with LTO the core lib compile requires this:
Serial.printf("%f\n", x); // Hard Fault

Not surprising ... I picked that up from the web

FUNNY thing the "Serial.printf" just prints "-inf" or "nan", and the "printf" Does a Hard Fault when compiled and run as 'Faster'

A preview of use without having to download and unzip:
//#define DEBUG_OFF // defining this only shows Hard Faults, no other debug output
#include "debug_t3.h"

void setup() {
  while (!Serial && millis() < 5000 );
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  if ( !DebState(LED_BUILTIN) ) { // specify Blink Pin
    Serial.println("\n Not FAULTED.");

  deb_t3( 2, micros() );
  float x = log (0);
  haltif_t3( isfinite( x ) ); // Halt if float not NAN or INF
  deb_t3( 3, 0x101101 );
  Serial.printf("INF >> %f\n", x); // Hard Fault with printf()
  deb_t3( 6, millis() );
  x = 0.0 / 0.0;
  deb_t3( 100, 0x111011 );
  assert_t3( !isinf( x ) ); // Testing here - passes isinf()
  Serial.printf("NAN >> %f\n", x); // Hard Fault with printf()
  Serial.println("\n DONE! All Good");

void loop() {

Here's the output:
T:\tCode\libraries\debug_t3\examples\DebugTest2\DebugTest2.ino Aug 14 2018 21:40:16

___ HALT in ___ FILE >> T:\tCode\libraries\debug_t3\examples\DebugTest2\DebugTest2.ino
___ in function >> setup() at LINE# >> 14
Expression >> isfinite( x )

>>>> HALT If true >>>> program Paused Debug Info:
2 => 432010 0x6978A [L#12_C#1 _<< last func::setup

??: 599
??: 0
??: 1FFF1790
lr: 7F24
r3: 0
r2: 0
r1: E
r0: 7EAC
r4: 7E9C
lr: 7F24

___ HALT Triggered ___ 'y' to continue ...
INF >> -inf

#### Debug trace Show Debug Info:
2 => 432010 0x6978A [L#12_C#1
3 => 1052929 0x101101 [L#15_C#2
6 => 9763 0x2623 [L#17_C#3 _<< last func::setup
NAN >> nan

DONE! All Good
Not open for further replies.