====== GCC ====== ===== preprocesor files ===== ''-save-temps=obj'' ===== Linker ===== * **--as-needed** - do not load symbols from libraries specified in command line when they are not needed. This option couses many unresolved symbol errors when order of libraries specified in command line is not correct. [[http://savannah.gnu.org/forum/forum.php?forum_id=5655]] * **--hash-style** - insert faster GNU hash table instead of SysV table. But looses compatiblity with older systems. [[http://stackoverflow.com/questions/11741816/only-one-hash-style-in-embedded-linux-why]] ===== ld script ===== [[https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/assignments.html [[https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/sections.html]] [[https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/expressions.html]] [[https://ftp.gnu.org/pub/old-gnu/Manuals/ld-2.9.1/html_node/ld_21.html]] [[https://sourceware.org/binutils/docs-2.27/ld/Builtin-Functions.html]] [[http://www.math.utah.edu/docs/info/ld_3.html]] === Place const variables === .crc 0x7FFE : { KEEP(*(.crc)) } or .crc (ORIGIN(rom)+LENGTH(rom)-2): { _crcstart = .; KEEP(*(.crc)) _crcend = .; } >rom const uint32_t crcValue __attribute__ ((section (".crc"))) = 0xDEADBEEF; === Place some symbols === .bss : { _bss = .; *(EXCLUDE_FILE (*redoznes.co) .bss*) /* *(.bss*)*/ *(COMMON) _ebss = .; } > SRAM ._user_heap_stack : { *redzones.co(.bss.redzone1) . = ALIGN(4); end = .; _heap = .; /* "end" for newlib's syscalls, "_heap" for sbrk heap boundary checks */ . = . + _Min_Heap_Size; _eheap = .; *redoznes.co(.bss.redzone2) . = . + _Min_Stack_Size; . = ALIGN(4); } > SRAM _redzone2_begin = .; . = . + 16; _redzone2_end = .; and access them from C code: extern uint8_t _redzone1_begin; extern uint8_t _redzone1_end; ... checkRedzone(&_redzone1_begin, &_redzone1_end - &_redzone1_begin); empty_ram_size = _estack - ABSOLUTE(.) - _Min_Stack_Size - 16; . = . + empty_ram_size; ===== Optimize per function ===== int foo(int i) __attribute__((optimize("-O3")));