From 3e784bc6b5b47f88dee3ab2c62ad6830a05882b9 Mon Sep 17 00:00:00 2001 From: Adithya Baglody Date: Tue, 27 Nov 2018 15:13:33 +0530 Subject: [PATCH] CMakeLists.txt: Enable -fno-common globally. This is needed to force the .common type to .bss type. This will force the .common variables to go into bss section in the compiled object file. As of now the movement to the .bss section was happening only during the final linking stage. The -fno-common option specifies that the compiler should place uninitialized global variables in the data section of the object file, rather than generating them as common blocks. This has the effect that if the same variable is declared (without "extern") in two different compilations, you will get a multiple-definition error when you link them. e.g: // file a.c // file-scope int b; // file b.c // file-scope int b; If there exist two non-extern declarations of the same variable then no-common will cause a linker error. This sequence would have compiled before, but will now cause a linker error. Signed-off-by: Adithya Baglody --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d1c3cd0970faf..190172d30499b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,7 @@ zephyr_compile_options( -imacros ${AUTOCONF_H} -ffreestanding -Wno-main + -fno-common ${NOSTDINC_F} ${TOOLCHAIN_C_FLAGS} )