Skip to content

Added LTO flags etc. to provide smaller/faster AVR code. #452

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

Merged
merged 2 commits into from
Sep 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions Arduino.mk
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,6 @@ ifndef OBJDUMP_NAME
OBJDUMP_NAME = avr-objdump
endif

ifndef AR_NAME
AR_NAME = avr-ar
endif

ifndef SIZE_NAME
SIZE_NAME = avr-size
endif
Expand Down Expand Up @@ -1031,16 +1027,32 @@ ifneq ($(CATERINA),)
CPPFLAGS += -DUSB_VID=$(USB_VID) -DUSB_PID=$(USB_PID)
endif

# avr-gcc version that we can do maths on
CC_VERNUM = $(shell $(CC) -dumpversion | sed 's/\.//g')

# moved from above so we can find version-dependant ar
ifndef AR_NAME
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
AR_NAME = avr-gcc-ar
else
AR_NAME = avr-ar
endif
endif

ifndef CFLAGS_STD
CFLAGS_STD =
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
CFLAGS_STD = -std=gnu11 -flto -fno-fat-lto-objects
else
CFLAGS_STD =
endif
$(call show_config_variable,CFLAGS_STD,[DEFAULT])
else
$(call show_config_variable,CFLAGS_STD,[USER])
endif

ifndef CXXFLAGS_STD
ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1)
CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics -flto
else
CXXFLAGS_STD =
endif
Expand All @@ -1050,9 +1062,15 @@ else
endif

CFLAGS += $(CFLAGS_STD)
CXXFLAGS += -fno-exceptions $(CXXFLAGS_STD)
CXXFLAGS += -fpermissive -fno-exceptions $(CXXFLAGS_STD)
ASFLAGS += -x assembler-with-cpp
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
ASFLAGS += -flto
endif
LDFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL)
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
LDFLAGS += -flto -fuse-linker-plugin
endif
SIZEFLAGS ?= --mcu=$(MCU) -C

# for backwards compatibility, grab ARDUINO_PORT if the user has it set
Expand Down
24 changes: 12 additions & 12 deletions arduino-mk-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ OBJDUMP_NAME = pic32-objdump

Archive utility.

Defaults to `avr-ar`
Defaults to `avr-ar` unless you're using toolchain > 4.8.0 in which case we use avr-gcc-ar.

**Example:**

Expand Down Expand Up @@ -894,22 +894,22 @@ OPTIMIZATION_LEVEL = 3

Controls, *exclusively*, which C standard is to be used for compilation.

Defaults to `undefined`
Defaults to `undefined` on 1.0.x or `-std=gnu11 -flto -fno-fat-lto-objects` on 1.5+ or if you install AVR toolchain > 4.8.0

Possible values:

* With `avr-gcc 4.3`, shipped with the Arduino IDE:
* With `avr-gcc 4.3`, shipped with the 1.0 Arduino IDE:
* `undefined`
* `-std=c99`
* `-std=gnu89` - This is the default for C code
* `-std=gnu99`
* With `avr-gcc 4.7, 4.8 or 4.9`, installed by you
* With `avr-gcc 4.7, 4.8 or 4.9`, installed by you or 1.5+ IDE:
* `undefined`
* `-std=c99`
* `-std=c11`
* `-std=gnu89` - This is the default for C code
* `-std=gnu89`
* `-std=gnu99`
* `-std=gnu11`
* `-std=gnu11 -flto -fno-fat-lto-objects` - This is the default for C code

For more information, please refer to the [Options Controlling C Dialect](https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html)

Expand All @@ -929,24 +929,24 @@ CFLAGS_STD = = -std=gnu89

Controls, *exclusively*, which C++ standard is to be used for compilation.

Defaults to `undefined` on 1.0 or `-std=gnu++11 -fno-threadsafe-statics` on 1.5+
Defaults to `undefined` on 1.0 or `-std=gnu++11 -fno-threadsafe-statics -flto` on AVR toolchain > 4.8.0 (e.g. IDE 1.5+)

Possible values:

* With `avr-gcc 4.3`, shipped with the Arduino IDE:
* With `avr-gcc 4.3`, shipped with the 1.0 Arduino IDE:
* `undefined`
* `-std=c++98`
* `-std=c++0x`
* `-std=gnu++98` - This is the default for C code
* `-std=gnu++0x`
* With `avr-gcc 4.7, 4.8 or 4.9`, installed by you
* With `avr-gcc 4.7, 4.8 or 4.9`, installed by you or 1.5+ IDE:
* `undefined`
* `-std=c++98`
* `-std=c++11`
* `-std=c++1y`
* `-std=c++14`
* `-std=gnu++98` - This is the default for C++ code
* `-std=gnu++11`
* `-std=gnu++98`
* `-std=gnu++11 -fno-threadsafe-statics -flto` - This is the default for C++ code
* `-std=gnu++1y`
* `-std=gnu++14`

Expand Down Expand Up @@ -988,7 +988,7 @@ CFLAGS += -my-c-only-flag
Flags passed to the compiler for files compiled as C++. Add more flags to this
variable using `+=`.

Defaults to all flags required for a typical build.
Defaults to `-fpermissive -fno-exceptions`

**Example:**

Expand Down