contiki/cpu/x86/Makefile.x86_common

25 lines
491 B
Makefile
Raw Normal View History

CONTIKI_CPU_DIRS += . init/common
CONTIKI_SOURCEFILES += gdt.c helpers.S idt.c cpu.c
CC = gcc
LD = gcc
AS = as
OBJCOPY = objcopy
SIZE = size
STRIP = strip
x86: Reduce .eh_frame section size When generating binaries, gcc will always add information of what it calls "the exception handler framework" into its own section: .eh_frame. This section is based on the DWARF format's call frame information (CFI) [1] and holds information that can be useful for debuggers but also for language constructs that relies on always having stack unwinding information (i.e. exceptions). Such constructs, however, are pretty much useless for the C language and are mainly just used on C++. Furthermore, this section is one of the loadable sections of a binary, meaning it will take extra space on flash. When .eh_frame is not present, debuggers can still get the exact same information they need for unwinding a stack frame and for restoring registers thanks to yet another section: .debug_frame. This section is generated by '-g' gcc option and friends. It is actually defined by DWARF and, as opposed to .eh_frame, is not a loadable section. In other words, it is 'strippable' while .eh_frame is not. Since all we need is the debug information we can get from .debug_frame, we can disable the generation of these large and unused information tables by using gcc's '-fno-asynchronous-unwind-tables'. The .eh_frame section stays around but the code size issue is heavily tackled. This is the same approach taken on other projects that target small code size generation [2] [3]. Pratically speaking, on a DEBUG build of the all-timers appplication, before this patch we had: text data bss dec hex filename 21319 1188 12952 35459 8a83 all-timers.galileo And now, after this patch: text data bss dec hex filename 16347 1188 12952 30487 7717 all-timers.galileo This means a ~5Kb reduction on the loadable text segment (.text + .rodata + .eh_frame). The flag is applied regardless of build type, DEBUG or RELEASE, since it benefits both. Note that when release builds apply --gc-sections, they will remove .eh_frame section entirely. [1] http://comments.gmane.org/gmane.comp.standards.dwarf/222 [2] https://github.com/gfto/toybox/commit/0d74ad383b8bb8aa82e9cb6449b509ec6d4794a5 [3] http://git.musl-libc.org/cgit/musl/commit/?id=b439c051c7eee4eb4b93fc382f993aa6305ce530 [4] https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
2015-10-06 12:44:03 +00:00
CFLAGS += -Wall -fno-asynchronous-unwind-tables
LDFLAGS += -Wl,-Map=contiki-$(TARGET).map,--build-id=none
ifeq ($(BUILD_RELEASE),1)
CFLAGS += -Os -fno-strict-aliasing
LDFLAGS += -Wl,--strip-all
x86: Improve debugging experience This patch appends some gcc options to CFLAGS when building the default image in order to improve the debugging experience on GDB. We use the '-ggdb' option which produces debugging information used by GDB (including GDB extensions) with level 3 which includes preprocessor macros information. We also use '-Og' which enables optimizations that do not interfere with debugging. According to gcc manpage, it should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience. Also, this patch removes the '-g' option from the default CFLAGS because there is no point in using it when BUILD_RELEASE=1. As expected, the overall ELF image increases (due to -ggdb3 option) while the .text section is reduced (due to -Og). For the sake of comparison, below follows the output of 'size'. Before patch: $ size -A hello-world.galileo hello-world.galileo : section size addr .text 13766 1048576 .rodata 241 1064960 .eh_frame 5160 1065204 .eh_frame_hdr 1212 1070364 .data 1188 1073152 .bss 12808 1077248 .debug_info 14351 0 .debug_abbrev 6281 0 .debug_aranges 768 0 .debug_line 6443 0 .debug_str 4805 0 .comment 17 0 .note 40 0 .debug_ranges 24 0 Total 67104 After patch: $ size -A hello-world.galileo hello-world.galileo : section size addr .text 11718 1048576 .rodata 249 1060864 .eh_frame 5496 1061116 .eh_frame_hdr 1204 1066612 .data 1156 1069056 .bss 12808 1073152 .debug_info 16727 0 .debug_abbrev 7254 0 .debug_loc 2083 0 .debug_aranges 768 0 .debug_macro 17273 0 .debug_line 13433 0 .debug_str 42192 0 .comment 17 0 .note 40 0 Total 132418
2015-07-10 14:44:28 +00:00
else
ifeq ($(findstring clang,$(CC)),clang)
CFLAGS += -O0 -g
else
CFLAGS += -Og -ggdb3
endif
endif