Merge pull request #5742 from kaspar030/fix_lto

LTO fixes
pr/spi.typo
Joakim Nohlgård 7 years ago committed by GitHub
commit 455fb6cd4d

@ -23,7 +23,7 @@ ${DIRS:%=CLEAN--%}:
"$(MAKE)" -C ${@:CLEAN--%=%} clean
ifeq ($(strip $(SRC)),)
SRC := $(wildcard *.c)
SRC := $(filter-out $(SRC_NOLTO), $(wildcard *.c))
endif
ifeq ($(strip $(SRCXX)),)
SRCXX := $(wildcard *.cpp)
@ -35,10 +35,12 @@ ifeq ($(strip $(ASSMSRC)),)
ASSMSRC := $(wildcard *.S)
endif
OBJC := $(SRC:%.c=$(BINDIR)$(MODULE)/%.o)
OBJCXX := $(SRCXX:%.cpp=$(BINDIR)$(MODULE)/%.o)
ASMOBJ := $(ASMSRC:%.s=$(BINDIR)$(MODULE)/%.o)
ASSMOBJ := $(ASSMSRC:%.S=$(BINDIR)$(MODULE)/%.o)
OBJC_LTO := $(SRC:%.c=$(BINDIR)$(MODULE)/%.o)
OBJC_NOLTO := $(SRC_NOLTO:%.c=$(BINDIR)$(MODULE)/%.o)
OBJC := $(OBJC_NOLTO) $(OBJC_LTO)
OBJCXX := $(SRCXX:%.cpp=$(BINDIR)$(MODULE)/%.o)
ASMOBJ := $(ASMSRC:%.s=$(BINDIR)$(MODULE)/%.o)
ASSMOBJ := $(ASSMSRC:%.S=$(BINDIR)$(MODULE)/%.o)
OBJ := $(OBJC) $(OBJCXX) $(ASMOBJ) $(ASSMOBJ)
DEP := $(OBJC:.o=.d) $(OBJCXX:.o=.d) $(ASSMOBJ:.o=.d)
@ -56,6 +58,8 @@ CXXFLAGS = $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS)
# compile and generate dependency info
$(OBJC_LTO): CFLAGS+=$(LTOFLAGS)
$(OBJC): $(BINDIR)$(MODULE)/%.o: %.c $(RIOTBUILD_CONFIG_HEADER_C)
$(AD)$(CCACHE) $(CC) \
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \

@ -42,10 +42,9 @@ endif
# Unwanted flags for c++
CXXUWFLAGS += -std=%
ifeq ($(LTO),yes)
$(info Building with Link-Time-Optimizations is currently an experimental feature. Expect broken binaries.)
LTOFLAGS = -flto -ffat-lto-objects
CFLAGS += ${LTOFLAGS}
ifeq ($(LTO),1)
$(warning Building with Link-Time-Optimizations is currently an experimental feature. Expect broken binaries.)
LTOFLAGS = -flto
LINKFLAGS += ${LTOFLAGS}
endif

@ -35,6 +35,7 @@ export AS # The assembler.
export ASFLAGS # Flags for the assembler.
export LINK # The command used to link the files. Must take the same parameters as GCC, i.e. "ld" won't work.
export LINKFLAGS # Flags to supply in the linking step.
export LTOFLAGS # extra CFLAGS for compiling with link time optimization
export OBJCOPY # The command used to create the HEXFILE.
export OFLAGS # The parameter for OBJCOPY, e.g. to strip the debug information.
export OBJDUMP # The command used to create the assembly listing.

@ -44,3 +44,10 @@ export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG)
export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -Wl,--gc-sections -static -lgcc -e reset_handler
export OFLAGS += -j .text -j .data -O ihex
export FFLAGS += -p m2560 -c $(PROGRAMMER) $(PROGRAMMER_FLAGS) -F -D -U flash:w:bin/$(BOARD)/$(PROJECT)$(APPLICATION).hex
ifeq ($(LTO),1)
# avr-gcc <4.8.3 has a bug when using LTO which causes a warning to be printed always:
# '_vector_25' appears to be a misspelled signal handler [enabled by default]
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396
export LINKFLAGS += -Wno-error
endif

@ -14,7 +14,11 @@ USEMODULE += native-drivers
export PREFIX =
export CC ?= $(PREFIX)gcc
export CXX ?= $(PREFIX)g++
export AR ?= $(PREFIX)ar
ifeq ($(LTO),1)
export AR = $(PREFIX)gcc-ar
else
export AR = $(PREFIX)ar
endif
export AS ?= $(PREFIX)as
export LINK ?= $(PREFIX)gcc
export SIZE ?= $(PREFIX)size
@ -41,7 +45,6 @@ export GPROF ?= gprof
# basic cflags:
export CFLAGS += -Wall -Wextra -pedantic
export CFLAGS += -ffunction-sections -fdata-sections
ifeq ($(shell uname -m),x86_64)
export CFLAGS += -m32
endif
@ -73,6 +76,10 @@ else
export LINKFLAGS += -ldl
endif
# clean up unused functions
export CFLAGS += -ffunction-sections -fdata-sections
export LINKFLAGS += -Wl,--gc-sections
# set the tap interface for term/valgrind
ifneq (,$(filter netdev2_tap,$(USEMODULE)))
export PORT ?= tap0

@ -32,7 +32,11 @@ export CPU = x86
# toolchain config
export CC ?= $(PREFIX)gcc
export AR ?= $(PREFIX)ar
ifeq ($(LTO),1)
export AR = $(PREFIX)gcc-ar
else
export AR = $(PREFIX)ar
endif
export AS ?= $(PREFIX)as
export RANLIB ?= $(PREFIX)ranlib
export LINK ?= $(RIOTBASE)/boards/x86-multiboot-common/dist/link $(PREFIX)gcc
@ -46,6 +50,11 @@ LINKFLAGS += -m32 -nostdlib -nostdinc -nostartfiles -nodefaultlibs \
--prefix=$(NEWLIB_BASE) \
-Wl,-rpath,$(NEWLIB_BASE)/lib \
-T$(RIOTBASE)/boards/x86-multiboot-common/linker.ld
# clean up unused functions
export CFLAGS += -ffunction-sections -fdata-sections
export LINKFLAGS += -Wl,--gc-sections
UNDEF += $(BINDIR)x86-multiboot-common/startup.o
BASELIBS += $(NEWLIB_BASE)/lib/libc.a \

@ -58,7 +58,7 @@ static void (*sched_cb) (uint32_t timestamp, uint32_t value) = NULL;
schedstat sched_pidlist[KERNEL_PID_LAST + 1];
#endif
int sched_run(void)
int __attribute__((used)) sched_run(void)
{
sched_context_switch_request = 0;

@ -1,7 +1,11 @@
export GDBPREFIX ?= $(PREFIX)
export CC = $(PREFIX)gcc
export CXX = $(PREFIX)g++
ifeq ($(LTO),1)
export AR = $(PREFIX)gcc-ar
else
export AR = $(PREFIX)ar
endif
export AS = $(PREFIX)as
export LINK = $(PREFIX)gcc
export SIZE = $(PREFIX)size

@ -43,19 +43,20 @@ extern void __libc_init_array(void);
* which should never be reached but just in case jumps to exit.
* This way there should be no way to call main directly.
*/
void init7_ovr(void) __attribute__((naked)) __attribute__((section(".init7")));
void init8_ovr(void) __attribute__((naked)) __attribute__((section(".init8")));
void init7_ovr(void) __attribute__((section(".init7")));
void init8_ovr(void) __attribute__((section(".init8")));
void init7_ovr(void)
__attribute__((used,naked)) void init7_ovr(void)
{
__asm__("call reset_handler");
}
void init8_ovr(void)
__attribute__((used,naked)) void init8_ovr(void)
{
__asm__("jmp exit");
}
/**
* @brief This function is the entry point after a system reset
*
@ -63,7 +64,7 @@ void init8_ovr(void)
* 1. initialize the board (sync clock, setup std-IO)
* 2. initialize and start RIOTs kernel
*/
void reset_handler(void)
__attribute__((used)) void reset_handler(void)
{
/* initialize the board and startup the kernel */
board_init();

@ -9,4 +9,7 @@ ifneq (,$(filter cc2538_rf,$(USEMODULE)))
DIRS += radio
endif
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# Add a list of subdirectories, that should also be built:
DIRS = periph $(RIOTCPU)/cortexm_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -1 +1,5 @@
# thread_arch.c's inline assembler breaks when compiling with link time
# optimization. see #5774.
SRC_NOLTO += thread_arch.c
include $(RIOTBASE)/Makefile.base

@ -296,17 +296,12 @@ void thread_arch_yield(void)
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
}
__attribute__((naked)) void arch_context_switch(void)
{
void __attribute__((naked)) __attribute__((used)) isr_pendsv(void) {
__asm__ volatile (
/* PendSV handler entry point */
".global isr_pendsv \n"
".thumb_func \n"
"isr_pendsv: \n"
/* save context by pushing unsaved registers to the stack */
/* {r0-r3,r12,LR,PC,xPSR} are saved automatically on exception entry */
".thumb_func \n"
"context_save:"
"mrs r0, psp \n" /* get stack pointer from user mode */
#if defined(CPU_ARCH_CORTEX_M0) || defined(CPU_ARCH_CORTEX_M0PLUS)
"mov r12, sp \n" /* remember the exception SP */
@ -332,11 +327,15 @@ __attribute__((naked)) void arch_context_switch(void)
"ldr r1, =sched_active_thread \n" /* load address of current tcb */
"ldr r1, [r1] \n" /* dereference pdc */
"str r0, [r1] \n" /* write r0 to pdc->sp */
"bl isr_svc \n" /* continue with svc */
);
}
void __attribute__((naked)) __attribute__((used)) isr_svc(void) {
__asm__ volatile (
/* SVC handler entry point */
/* PendSV will continue from above and through this part as well */
".global isr_svc \n"
/* PendSV will continue here as well (via jump) */
".thumb_func \n"
"isr_svc: \n"
/* perform scheduling */
"bl sched_run \n"
/* restore context and return from exception */

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common $(KINETIS_COMMON)
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -19,7 +19,7 @@ export CFLAGS += -DCPU_ARCH_$(ARCH)
export COMMON_STARTUP = $(KINETIS_COMMON)
# add the CPU specific system calls implementations for the linker
export UNDEF += $(BINDIR)cpu/vector.o
export UNDEF += $(BINDIR)cpu/vectors.o
export UNDEF += $(BINDIR)cpu/ssp.o
include $(RIOTCPU)/Makefile.include.cortexm_common

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common $(KINETIS_COMMON)
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common $(KINETIS_COMMON)
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -19,6 +19,6 @@ export CFLAGS += -DCPU_ARCH_$(ARCH)
export COMMON_STARTUP = $(KINETIS_COMMON)
# add the CPU specific system calls implementations for the linker
export UNDEF += $(BINDIR)cpu/vector.o
export UNDEF += $(BINDIR)cpu/vectors.o
include $(RIOTCPU)/Makefile.include.cortexm_common

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -70,7 +70,7 @@ WEAK_DEFAULT void isr_qei(void);
WEAK_DEFAULT void isr_pll1(void);
/* interrupt vector table */
__attribute__ ((section(".vectors")))
__attribute__ ((used,section(".vectors")))
const void *interrupt_vector[] = {
/* Exception stack pointer */
(void*) (&_estack), /* pointer to the top of the stack */

@ -9,4 +9,7 @@ ifneq (,$(filter radio_nrfmin,$(USEMODULE)))
DIRS += radio/nrfmin
endif
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/nrf5x_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/sam21_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/sam21_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/stm32_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS += periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/stm32_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/stm32_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/stm32_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -4,4 +4,7 @@ MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS += periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/stm32_common
# (file triggers compiler bug. see #5775)
SRC_NOLTO += vectors.c
include $(RIOTBASE)/Makefile.base

@ -169,7 +169,7 @@ static void continue_after_intr(void)
}
static unsigned in_intr_handler = 0, old_intr;
void x86_int_handler(void)
__attribute__((used)) void x86_int_handler(void)
{
switch (in_intr_handler++) {
case 0:
@ -213,7 +213,7 @@ void x86_int_handler(void)
__builtin_unreachable();
}
void ASM_FUN_ATTRIBUTES NORETURN x86_int_entry(void)
__attribute__((used)) void ASM_FUN_ATTRIBUTES NORETURN x86_int_entry(void)
{
__asm__ volatile ("mov %eax, (4*0 + x86_interrupted_ctx)");
__asm__ volatile ("mov %ecx, (4*1 + x86_interrupted_ctx)");
@ -239,7 +239,7 @@ void ASM_FUN_ATTRIBUTES NORETURN x86_int_entry(void)
__builtin_unreachable();
}
void ASM_FUN_ATTRIBUTES NORETURN x86_int_exit(void)
__attribute__((used)) void ASM_FUN_ATTRIBUTES NORETURN x86_int_exit(void)
{
__asm__ volatile ("mov (4*0 + x86_interrupted_ctx), %eax");
__asm__ volatile ("mov (4*1 + x86_interrupted_ctx), %ecx");

@ -66,7 +66,8 @@ void _init(void)
/**
* @brief Free resources on NewLib de-initialization, not used for RIOT
*/
void _fini(void)
/* __attribute__((used)) fixes linker errors when building with LTO, but without nano.specs */
__attribute__((used)) void _fini(void)
{
/* nothing to do here */
}

Loading…
Cancel
Save