Skip to content
Draft
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
1 change: 1 addition & 0 deletions examples/arduino_nano/color/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:arduino-nano</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/arduino_nano/color</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/black_pill_f411/usbfatfs/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:black-pill-f411</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/black_pill_f411/usb_fatfs</option>
<option name="modm:tinyusb:config">device.msc, device.cdc</option>
</options>
Expand Down
1 change: 1 addition & 0 deletions examples/feather_m4/usbserial/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<extends>modm:feather-m4</extends>
<options>
<option name="modm:tinyusb:config">device.cdc</option>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/feather_m4/usbserial</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/nrf51422-dk/uart_logging/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:nrf51422-dk</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/nrf51422-dk/uart_logging</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_f031k6/sk6812/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:nucleo-f031k6</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/nucleo_f031k6/sk6812</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_f303k8/rtos/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:nucleo-f303k8</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/nucleo_f303k8/rtos</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_f767zi/ethernet/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:nucleo-f767zi</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/nucleo_f767zi/ethernet</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_f767zi/freertos_blink/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:nucleo-f767zi</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/nucleo_f767zi/freertos_blink</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_g071rb/amnb/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:nucleo-g071rb</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/nucleo_g071rb/amnb</option>
<option name="modm:communication:amnb:with_heap">no</option>
</options>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_g071rb/apa102/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:nucleo-g071rb</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/nucleo_g071rb/apa102</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_l452re/lvgl/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:nucleo-l452re</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/nucleo_l452re/lvgl</option>
<option name="modm:platform:cortex-m:main_stack_size">5Ki</option>
</options>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_l552ze-q/freertos_blink/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:nucleo-l552ze-q</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/nucleo_l552ze-q/freertos_blink</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/samd/usbserial/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<extends>modm:feather-m0</extends>
<!-- <extends>modm:samd21-mini</extends> -->
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/samd/usbserial</option>
<option name="modm:tinyusb:config">device.cdc</option>
</options>
Expand Down
1 change: 1 addition & 0 deletions examples/weact_u585ci/usb/project.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<library>
<extends>modm:weact-u585ci</extends>
<options>
<option name="modm:build:lto">yes</option>
<option name="modm:build:build.path">../../../build/weact_u585ci/usb</option>
<option name="modm:tinyusb:config">device.dfu_rt,device.cdc,device.msc</option>
</options>
Expand Down
4 changes: 2 additions & 2 deletions ext/aws/modm_port.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ void vApplicationStackOverflowHook(TaskHandle_t /*pxTask*/, char *pcTaskName)
// Make the Newlib heap thread-safe with FreeRTOS

extern "C" void __malloc_lock(struct _reent *);
void __malloc_lock(struct _reent *)
void modm_used __malloc_lock(struct _reent *)
{
vTaskSuspendAll();
}

extern "C" void __malloc_unlock(struct _reent *);
void __malloc_unlock(struct _reent *)
void modm_used __malloc_unlock(struct _reent *)
{
xTaskResumeAll();
}
Expand Down
4 changes: 2 additions & 2 deletions src/modm/architecture/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
#define modm_deprecated(msg) __attribute__((deprecated(msg)))
#define modm_likely(x) __builtin_expect(!!(x), 1)
#define modm_unlikely(x) __builtin_expect(!!(x), 0)
#define modm_section(s) __attribute__((section(s)))
#define modm_section(s) __attribute__((section(s), used))
#define modm_fallthrough __attribute__((fallthrough))
#define modm_noreturn __attribute__((noreturn))
#define modm_warn_unused_result __attribute__((warn_unused_result))
Expand All @@ -159,7 +159,7 @@
// - __attribute__ ((weak, alias ("__aliasedFunction"))) seems to work on Windows
# define modm_weak
#else
# define modm_weak __attribute__((weak))
# define modm_weak __attribute__((weak, used))
#endif

#if defined(MODM_OS_HOSTED) || defined(MODM_CPU_AVR)
Expand Down
8 changes: 4 additions & 4 deletions src/modm/platform/heap/cortex/heap_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void __modm_initialize_memory(void)
extern void __malloc_lock(struct _reent *);
extern void __malloc_unlock(struct _reent *);

void* __wrap__malloc_r(struct _reent *r, size_t size)
void* modm_used __wrap__malloc_r(struct _reent *r, size_t size)
{
__malloc_lock(r);
void *ptr = allocator.allocate(size);
Expand All @@ -65,22 +65,22 @@ void* __wrap__malloc_r(struct _reent *r, size_t size)
return ptr;
}

void* __wrap__calloc_r(struct _reent *r, size_t size)
void* modm_used __wrap__calloc_r(struct _reent *r, size_t size)
{
void *ptr = __wrap__malloc_r(r, size);
if (ptr) memset(ptr, 0, size);
return ptr;
}

void* __wrap__realloc_r(struct _reent *r, void *p, size_t size)
void* modm_used __wrap__realloc_r(struct _reent *r, void *p, size_t size)
{
if (!p) return __wrap__malloc_r(r, size);
// NOT IMPLEMENTED!
modm_assert(0, "realloc", "Realloc is not implemented for Block heap!", size);
return NULL;
}

void __wrap__free_r(struct _reent *r, void *p)
void modm_used __wrap__free_r(struct _reent *r, void *p)
{
__malloc_lock(r);
allocator.free(p);
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/heap/cortex/heap_newlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void __modm_initialize_memory(void)
* Note: This implementation is not thread safe (despite taking a
* _reent structure as a parameter).
*/
void *
void * modm_used
_sbrk_r(struct _reent *, ptrdiff_t size)
{
const uint8_t *const heap = heap_top;
Expand Down
8 changes: 4 additions & 4 deletions src/modm/platform/heap/cortex/heap_tlsf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ void * malloc_traits(size_t size, uint32_t traits)
return NULL;
}

void *__wrap__malloc_r(struct _reent *, size_t size)
void *modm_used __wrap__malloc_r(struct _reent *, size_t size)
{
// default is accessible by S-Bus and DMA-able
return malloc_traits(size, uint32_t(modm::MemoryTrait::AccessSBus) |
uint32_t(modm::MemoryTrait::AccessDMA));
}

void *__wrap__calloc_r(struct _reent *r, size_t size)
void *modm_used __wrap__calloc_r(struct _reent *r, size_t size)
{
void *ptr = __wrap__malloc_r(r, size);
if (ptr) memset(ptr, 0, size);
return ptr;
}

void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
void *modm_used __wrap__realloc_r(struct _reent *r, void *p, size_t size)
{
if (!p) return __wrap__malloc_r(r, size);

Expand All @@ -156,7 +156,7 @@ void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
return ptr;
}

void __wrap__free_r(struct _reent *r, void *p)
void modm_used __wrap__free_r(struct _reent *r, void *p)
{
// do nothing if NULL pointer
if (!p) return;
Expand Down
6 changes: 3 additions & 3 deletions src/modm/platform/spi/stm32/spi_master_dma.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ private:
static void
handleDmaTransmitComplete();

static inline bool dmaError { false };
static inline bool dmaTransmitComplete { false };
static inline bool dmaReceiveComplete { false };
static inline volatile bool dmaError { false };
static inline volatile bool dmaTransmitComplete { false };
static inline volatile bool dmaReceiveComplete { false };

// needed for transfers where no RX or TX buffers are given
static inline uint8_t dmaDummy { 0 };
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/uart/nrf/uart_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BufferedUart<Hal, UartTxBuffer<SIZE>, Buffers...>: public BufferedUart<Hal
static_assert(not Parent::TxBufferSize, "BufferedUart accepts at most one TxBuffer type");
static inline UartTxBuffer<SIZE> txBuffer;
static inline uint8_t txBurstBuffer[SIZE];
static inline std::size_t txBurstLength = 0;
static inline volatile std::size_t txBurstLength = 0;

static inline void
serviceTxBurst()
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/uart/nrfe/uart_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BufferedUart<Hal, UartTxBuffer<SIZE>, Buffers...>: public BufferedUart<Hal
static_assert(not Parent::TxBufferSize, "BufferedUart accepts at most one TxBuffer type");
static inline UartTxBuffer<SIZE> txBuffer;
static inline uint8_t dmaTxBuffer[SIZE];
static inline std::size_t dmaTxLength = 0;
static inline volatile std::size_t dmaTxLength = 0;

static inline void
serviceDmaTx()
Expand Down
4 changes: 2 additions & 2 deletions src/modm/processing/fiber/context_arm_m.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ modm_context_jump(modm_context_t*, modm_context_t*)
%#
MODM_POP_CONTEXT()

"1: b modm_context_end \n\t"
"1: bl modm_context_end \n\t"
%% if not with_psplim
:: "i" (StackWatermark)
%% endif
);
}

void modm_naked
void modm_naked modm_used
modm_context_end(uintptr_t)
{
asm volatile
Expand Down
2 changes: 1 addition & 1 deletion src/modm/processing/fiber/context_avr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ modm_context_start(modm_context_t *to)
return modm_context_jump_entry((modm_context_t*)&main_context_sp, to);
}

void
void modm_used
modm_context_end(uintptr_t retval)
{
modm_context_jump_return(retval, (modm_context_t*)&main_context_sp);
Expand Down
6 changes: 5 additions & 1 deletion tools/build_script_generator/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,12 @@ def common_compiler_flags(compiler, target):
flags["cflags"].append("-g3")
flags["cxxflags"].append("-g3")
# flags for the linker
flags["linkflags"] = [
"-ffunction-sections",
"-fdata-sections",
]
if target.identifier["family"] != "darwin":
flags["linkflags"] = [
flags["linkflags"] += [
"-Wl,--fatal-warnings",
"-Wl,--gc-sections",
"-Wl,--relax",
Expand Down
11 changes: 5 additions & 6 deletions tools/build_script_generator/make/resources/compiler.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ ASM := $(CC)

ifeq ($(C_SUFFIX),)
AS := $(C_PREFIX)as
AR := $(C_PREFIX)ar
NM := $(C_PREFIX)nm
RANLIB := $(C_PREFIX)ranlib
else
AS := $(CXX)
AR := $(C_PREFIX)gcc-ar$(C_SUFFIX)
NM := $(C_PREFIX)gcc-nm$(C_SUFFIX)
RANLIB := $(C_PREFIX)gcc-ranlib$(C_SUFFIX)
endif

_probe = $(if $(shell command -v $(1) 2>/dev/null),$(1),$(2))
AR := $(call _probe,$(C_PREFIX)gcc-ar$(C_SUFFIX),$(C_PREFIX)ar)
NM := $(call _probe,$(C_PREFIX)gcc-nm$(C_SUFFIX),$(C_PREFIX)nm)
RANLIB := $(call _probe,$(C_PREFIX)gcc-ranlib$(C_SUFFIX),$(C_PREFIX)ranlib)

OBJCOPY := $(C_PREFIX)objcopy
OBJDUMP := $(C_PREFIX)objdump
SIZE := $(C_PREFIX)size
Expand Down
21 changes: 21 additions & 0 deletions tools/build_script_generator/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def prepare(module, options):
module.add_option(
BooleanOption(name="info.build", default=False,
description=descr_info_build))
module.add_option(
BooleanOption(name="lto", default=False,
description=descr_lto))

if platform in ["avr"]:
module.add_option(
Expand Down Expand Up @@ -186,6 +189,10 @@ def build(env):
for flag, values in common_compiler_flags("gcc", env[":target"]).items():
env.collect(flag, *values)

if env["lto"]:
env.collect(":build:ccflags", "-flto=auto")
env.collect(":build:linkflags", "-flto=auto")

# Copy python tools folder
platform = env[":target"].identifier["platform"]
is_cortex_m = env[":target"].has_driver("core:cortex-m*")
Expand Down Expand Up @@ -301,6 +308,20 @@ descr_info_git = """# Generate git repository state information

descr_info_build = """# Generate build state information"""

descr_lto = """# Enable Link-Time Optimization

Compiles with `-flto=auto`, which defers code generation to link time so that
the optimizer can inline and eliminate code across translation units. This
typically shrinks the binary noticeably at the cost of a slower link step.

!!! warning "LTO cannot see references from the linkerscript or inline assembly"
The optimizer decides what is reachable *before* the linkerscript is
applied, so `KEEP()` does not protect a symbol from being deleted. Anything
that is only referenced by the hardware (like the vector table), by the
linkerscript, or from an inline assembly string must be marked `modm_used`.
modm does this for its own symbols.
"""

descr_openocd_cfg = """# Path to a custom OpenOCD configuration file

If you have a custom configuration file for your target, it will get included
Expand Down
15 changes: 6 additions & 9 deletions tools/build_script_generator/scons/site_tools/gcc_retarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,12 @@ def generate(env, **kw):
env['CXX'] = prefix + 'g++' + suffix
env['AR'] = prefix + 'ar'
env['RANLIB'] = prefix + 'ranlib'
if suffix == '':
env['AS'] = prefix + 'as'
env['NM'] = prefix + 'nm'
else:
env['AS'] = prefix + 'gcc' + suffix
env['NM'] = prefix + 'gcc-nm' + suffix
if sys.platform != "darwin":
env['AR'] = prefix + 'gcc-ar' + suffix
env['RANLIB'] = prefix + 'gcc-ranlib' + suffix
env['AS'] = prefix + 'as' if suffix == '' else prefix + 'gcc' + suffix

env['NM'] = prefix + 'nm'
for var, wrapper in [('AR', 'gcc-ar'), ('RANLIB', 'gcc-ranlib'), ('NM', 'gcc-nm')]:
if shutil.which(prefix + wrapper + suffix) is not None:
env[var] = prefix + wrapper + suffix

env['OBJCOPY'] = prefix + 'objcopy'
env['OBJDUMP'] = prefix + 'objdump'
Expand Down
9 changes: 9 additions & 0 deletions tools/modm_tools/size.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def format(source, device_memories):
else:
memories["rom"].append(memory)

for name, mems in list(memories.items()):
merged = []
for memory in sorted(mems, key=lambda m: m["start"]):
if merged and (merged[-1]["start"] + merged[-1]["size"] == memory["start"]):
merged[-1]["size"] += memory["size"]
else:
merged.append(dict(memory))
memories[name] = merged

memory_sections = []
with open(source, "rb") as src:
elffile = ELFFile(src)
Expand Down
Loading