Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Macros
Pw_must_place_size

Macros

#define PW_MUST_PLACE_SIZE(isection, isize)    _PW_MUST_PLACE_SIZE(isection, isize, __section_place_, __COUNTER__)
 

Detailed Description

Macro Definition Documentation

◆ PW_MUST_PLACE_SIZE

#define PW_MUST_PLACE_SIZE (   isection,
  isize 
)     _PW_MUST_PLACE_SIZE(isection, isize, __section_place_, __COUNTER__)

PW_MUST_PLACE_SIZE is a macro intended for use in linker scripts to ensure inputs are an expected size.

This is helpful for shared memory placements between multiple cores.

Imagine the following code is consumed while linking for 2 separate cores:

SECTIONS
{
.shared_memory
{
*/src/path/libspecial_code.a:shared_memory.o(.bss.shared_memory)
}
}

This works but is fragile as it will silently break if the size of .bss.shared_memory changes on a single core. This may occur if compiler or other parameters are changed on one core and not the other.

#include "pw_build/must_place.ld.h"
SECTIONS
{
.special_code
{
PW_MUST_PLACE_SIZE(*/src/path/libspecial_code.a:shared_memory.o(.bss.shared_memory), 16)
}
}
#define PW_MUST_PLACE_SIZE(isection, isize)
Definition: must_place.ld.h:150

If the wildcard match results in a different size from what was specified PW_MUST_PLACE_SIZE will generate an error.

Error: Pattern did not match expected size
*/src/path/libspecial_code.a:shared_memory.o(.bss.shared_memory)

This could be because you had a typo, the path changed, the symbols changed in size (either because the symbol was changed or compilation settings were changed), symbols were dropped due to linker section garbage collection. In the latter case, you can choose to add KEEP() around your input to prevent garbage collection.