Skip to content

Commit

Permalink
CMakeLists.txt: Enable -fno-common globally.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
AdithyaBaglody authored and nashif committed Dec 7, 2018
1 parent a65df22 commit 3e784bc
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ zephyr_compile_options(
-imacros ${AUTOCONF_H}
-ffreestanding
-Wno-main
-fno-common
${NOSTDINC_F}
${TOOLCHAIN_C_FLAGS}
)
Expand Down

0 comments on commit 3e784bc

Please sign in to comment.