userspace: get rid of app section placeholders

We used to leave byte-long placeholder symbols to ensure
that empty application memory sections did not cause
build errors that were very difficult to understand.

Now we use some relatively portable inline assembly to
generate a symbol, but don't take up any extra space.

The malloc and libc partitions are now only instantiated
if there is some data to put in them.

Fixes: #13923

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2019-02-27 20:12:40 -08:00 committed by Andrew Boie
commit 7707060959
5 changed files with 53 additions and 8 deletions

View file

@ -67,6 +67,37 @@ struct z_app_region {
#define Z_APP_BSS_START(id) data_smem_##id##_bss_start
#define Z_APP_BSS_SIZE(id) data_smem_##id##_bss_size
/* If a partition is declared with K_APPMEM_PARTITION, but never has any
* data assigned to its contents, then no symbols with its prefix will end
* up in the symbol table. This prevents gen_app_partitions.py from detecting
* that the partition exists, and the linker symbols which specify partition
* bounds will not be generated, resulting in build errors.
*
* What this inline assembly code does is define a symbol with no data.
* This should work for all arches that produce ELF binaries, see
* https://sourceware.org/binutils/docs/as/Section.html
*
* We don't know what active flags/type of the pushed section were, so we are
* specific: "aw" indicates section is allocatable and writable,
* and "@progbits" indicates the section has data.
*/
#ifdef CONFIG_ARM
/* ARM has a quirk in that '@' denotes a comment, so we have to send
* %progbits to the assembler instead.
*/
#define Z_PROGBITS_SYM "\%"
#else
#define Z_PROGBITS_SYM "@"
#endif
#define Z_APPMEM_PLACEHOLDER(name) \
__asm__ ( \
".pushsection " STRINGIFY(K_APP_DMEM_SECTION(name)) \
",\"aw\"," Z_PROGBITS_SYM "progbits\n\t" \
".global " STRINGIFY(name) "_placeholder\n\t" \
STRINGIFY(name) "_placeholder:\n\t" \
".popsection\n\t")
/**
* @brief Define an application memory partition with linker support
*
@ -94,8 +125,7 @@ struct z_app_region {
.bss_start = &Z_APP_BSS_START(name), \
.bss_size = (size_t) &Z_APP_BSS_SIZE(name) \
}; \
K_APP_BMEM(name) char name##_placeholder;
Z_APPMEM_PLACEHOLDER(name);
#else
#define K_APP_BMEM(ptn)