Skip to content

cmake: Use of -ffreestanding disables many useful optimizations and compiler warnings #45157

@keith-packard

Description

@keith-packard

Zephyr unconditionally enables the C compiler flag -ffreestanding which is only necessary when the environment does not include the standard C library. This may be necessary when using the minimal C library, but it's not helpful when using a POSIX compatible C library such as newlib or picolibc.

Not only does -freestanding disable many builtin functions, it also disables compile-time warnings about buffer overflows for libc functions, disables optimizations based on internal compiler knowledge of libc semantics and generally makes code less secure and less performant.

Disabling this option isn't something that can be done casually though; any code which redefines libc functions, or which uses libc functions in ways that the compiler may think could cause a buffer overflow will generate compile errors or warnings. Which makes this a project policy issue, not just a bug in the build system...

Metadata

Metadata

Assignees

Labels

area: Build SystembugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions