Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow turning off LTO #673

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

ivoshopov
Copy link

By default LTO (Link Time Optimization) of AVR GCC is enabled. On
atmega328p this remove most of the debugging data from the ELF file.
As a result avr-gdb can not be used fully.
For example lets take the simple Hello World application:

#include <Arduino.h>

void setup() {
  Serial1.begin(9600);
}

void loop() {
  Serial1.print("Hello World\n");
}

following output shows that nither Print.c nither the test_app.cpp
are writen in the ELF file as a referance to the source code for
debugging porpose (the code is compiled with -g):

$ avr-objdump -x build-a-star328PB/test_app.elf | grep df
00000000 l    df *ABS*  00000000 malloc.c
00000000 l    df *ABS*  00000000
00000000 l    df *ABS*  00000000 _clear_bss.o
00000000 l    df *ABS*  00000000
00000000 l    df *ABS*  00000000 realloc.c
00000000 l    df *ABS*  00000000 _udivmodsi4.o
00000000 l    df *ABS*  00000000 _exit.o

As a result this ELF file can not be used by GDB. It can not find the
source code of the currently executed code.

When we disable the LTO the output is:

$ avr-objdump -x build-a-star328PB/test_app.elf | grep df
00000000 l    df *ABS*  00000000 test_app.cpp
00000000 l    df *ABS*  00000000 Print.cpp
00000000 l    df *ABS*  00000000 HardwareSerial.cpp
00000000 l    df *ABS*  00000000 _clear_bss.o
00000000 l    df *ABS*  00000000 main.cpp
00000000 l    df *ABS*  00000000 wiring.c
00000000 l    df *ABS*  00000000 new.cpp
00000000 l    df *ABS*  00000000 _udivmodsi4.o
00000000 l    df *ABS*  00000000 _exit.o
00000000 l    df *ABS*  00000000

Now all source files are depicted by the ELF file. As a result avr-gdb
can use this ELF file for debugging. It depict the current source line.

Also the size of the .text section (Flash memory) is not optimiezed.
With LTO the simple Helloe World take 20264 bytes (.text). While the
build without LTO generate 3860 bytes (.text) for atmega328p.

This patch allow disabling of LTO by setting LTO=n. While keeping
LTO on by default.

Signed-off-by: Ivo Shopov ivoshopov@gmail.com

By default LTO (Link Time Optimization) of AVR GCC is enabled. On
atmega328p this remove most of the debugging data from the ELF file.
As a result avr-gdb can not be used fully.
For example lets take the simple Hello World application:

	#include <Arduino.h>

	void setup() {
	  Serial1.begin(9600);
	}

	void loop() {
	  Serial1.print("Hello World\n");
	}

following output shows that nither Print.c nither the test_app.cpp
are writen in the ELF file as a referance to the source code for
debugging porpose (the code is compiled with -g):

	$ avr-objdump -x build-a-star328PB/test_app.elf | grep df
	00000000 l    df *ABS*  00000000 malloc.c
	00000000 l    df *ABS*  00000000
	00000000 l    df *ABS*  00000000 _clear_bss.o
	00000000 l    df *ABS*  00000000
	00000000 l    df *ABS*  00000000 realloc.c
	00000000 l    df *ABS*  00000000 _udivmodsi4.o
	00000000 l    df *ABS*  00000000 _exit.o

As a result this ELF file can not be used by GDB. It can not find the
source code of the currently executed code.

When we disable the LTO the output is:

	$ avr-objdump -x build-a-star328PB/test_app.elf | grep df
	00000000 l    df *ABS*  00000000 test_app.cpp
	00000000 l    df *ABS*  00000000 Print.cpp
	00000000 l    df *ABS*  00000000 HardwareSerial.cpp
	00000000 l    df *ABS*  00000000 _clear_bss.o
	00000000 l    df *ABS*  00000000 main.cpp
	00000000 l    df *ABS*  00000000 wiring.c
	00000000 l    df *ABS*  00000000 new.cpp
	00000000 l    df *ABS*  00000000 _udivmodsi4.o
	00000000 l    df *ABS*  00000000 _exit.o
	00000000 l    df *ABS*  00000000

Now all source files are depicted by the ELF file. As a result avr-gdb
can use this ELF file for debugging. It depict the current source line.

Also the size of the .text section (Flash memory) is not optimiezed.
With LTO the simple Helloe World take 20264 bytes (.text). While the
build without LTO generate 3860 bytes (.text) for atmega328p.

This patch allow disabling of LTO by setting LTO=n. While keeping
LTO on by default.

Signed-off-by: Ivo Shopov <ivoshopov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant