Skip to content

Commit 63d14f3

Browse files
add dummy SUPER_REALLOC/CALLOC calls to alloc wrappers
This code prevents the ARMC6 compiler/linker from removing SUB_REALLOC/CALLOC symbols from image when LTO is enabled Fixes below error: L6137E: Symbol $Sub$$calloc was not preserved by the LTO codegen but is needed by the image.
1 parent 783953e commit 63d14f3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

platform/source/mbed_alloc_wrappers.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ extern "C" void *SUB_REALLOC(void *ptr, size_t size)
347347
memcpy(new_ptr, (void *)ptr, copy_size);
348348
free(ptr);
349349
}
350+
351+
{
352+
volatile uint8_t dummy = 0;
353+
if (dummy != 0) { // always false
354+
// this code will never be executed
355+
// it's just to tell the compiler/linker to preserve SUB_REALLOC symbol
356+
// when LTO enabled
357+
SUPER_REALLOC(NULL, 0);
358+
}
359+
}
350360
#else // #if MBED_HEAP_STATS_ENABLED
351361
new_ptr = SUPER_REALLOC(ptr, size);
352362
#endif // #if MBED_HEAP_STATS_ENABLED
@@ -369,6 +379,16 @@ extern "C" void *SUB_CALLOC(size_t nmemb, size_t size)
369379
if (ptr != NULL) {
370380
memset(ptr, 0, nmemb * size);
371381
}
382+
383+
{
384+
volatile uint8_t dummy = 0;
385+
if (dummy != 0) { // always false
386+
// this code will never be executed
387+
// it's just to tell the compiler/linker to preserve SUB_CALLOC symbol
388+
// when LTO enabled
389+
SUPER_CALLOC(NULL, 0);
390+
}
391+
}
372392
#else // #if MBED_HEAP_STATS_ENABLED
373393
ptr = SUPER_CALLOC(nmemb, size);
374394
#endif // #if MBED_HEAP_STATS_ENABLED

0 commit comments

Comments
 (0)