Skip to content
Browse files

CMakeLists.txt: -fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR

In commit 28a5657 we stopped ZEPHYR_BASE from leaking into
__FILE__ and other macros.  This works great for apps inside ZEPHYR_BASE
but does nothing for apps outside ZEPHYR_BASE.
-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR does it.

To avoid collisions and for consistency change:

Quickest test/demo:

 - Copy samples/hello_word/ to ~/home_world/
 - Add "%s", __FILE__  to printf in ~/home_world/src/main.c

 cmake -B build  -S ~/home_world/  -DBOARD=qemu_x86
 make  -C build  run

     ~/home_world/src/main.c says Hello World! qemu_x86

 CMAKE_SOURCE_DIR/src/main.c says Hello World! qemu_x86

objdump -h $(find build -name *.c.obj) | grep noinit

  9 .noinit."ZEPHYR_BASE/kernel/system_work_q.c".0 0000
 17 .noinit."ZEPHYR_BASE/kernel/init.c".2 00000100  000
 18 .noinit."ZEPHYR_BASE/kernel/init.c".1 00000400  000
 19 .noinit."ZEPHYR_BASE/kernel/init.c".3 00000800  000
 16 .noinit."ZEPHYR_BASE/kernel/mailbox.c".2 00000348
 18 .noinit."ZEPHYR_BASE/kernel/mailbox.c".1 00000028
 20 .noinit."ZEPHYR_BASE/kernel/pipes.c".2 00000280  00
 22 .noinit."ZEPHYR_BASE/kernel/pipes.c".1 00000028  00

Signed-off-by: Marc Herbert <>
  • Loading branch information...
marc-hb authored and nashif committed May 31, 2019
1 parent b20f288 commit f67dcdbdf893a867b1816e4497d82e7a64e4fca5
Showing with 7 additions and 1 deletion.
  1. +7 −1 CMakeLists.txt
@@ -329,7 +329,13 @@ zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage)
# application code. This saves some memory, stops leaking user locations
# in binaries, makes failure logs more deterministic and most
# importantly makes builds more deterministic

# If both match then the last one wins. This matters for tests/ and
# samples/ inside *both* CMAKE_SOURCE_DIR and ZEPHYR_BASE: for them
# let's strip the shortest prefix.
# TODO: -fmacro-prefix-map=modules/etc. "build/zephyr_modules.txt" might help.

# TODO: Archiver arguments
# ar_option(D)

0 comments on commit f67dcdb

Please sign in to comment.
You can’t perform that action at this time.