Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build system: fix compilation with LLVM #18845

Merged
merged 2 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions makefiles/cflags.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ ifeq ($(LTO),1)
LINKFLAGS += $(LTOFLAGS) -ffunction-sections -fdata-sections
endif

# Cannot test with `BUILD_IN_DOCKER=1`, as this is only the case when the
# actual build is done in the docker container and we are still running in the
# host's context.
ifeq (1,$(BUILD_IN_DOCKER))
LINKER_SUPPORTS_NOEXECSTACK := determine-later-inside-docker
endif

# Check if linker supports `-z noexecstack`. Handle BUILD_IN_DOCKER separately,
# as this is run in the host environment rather than inside the container. We
# just hardcode this in the BUILD_IN_DOCKER case for now.
LINKER_SUPPORTS_NOEXECSTACK ?= $(shell echo "int main(){} void _exit(int n) {(void)n;while(1);}" | LC_ALL=C $(LINK) -xc - -o /dev/null -lc -Wall -Wextra -pedantic -z noexecstack 2> /dev/null && echo 1 || echo 0)

# As we do not use nested functions or other stuff requiring trampoline code,
# we can safely mark the stack as not executable. This avoids warnings on newer
# toolchains.
ifeq (1,$(LINKER_SUPPORTS_NOEXECSTACK))
benpicco marked this conversation as resolved.
Show resolved Hide resolved
LINKFLAGS += -z noexecstack
endif

# Forbid common symbols to prevent accidental aliasing.
CFLAGS += -fno-common

Expand Down
2 changes: 1 addition & 1 deletion makefiles/libc/newlib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ifneq (,$(filter newlib_nano,$(USEMODULE)))
# Test if nano.specs is available
ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
USE_NEWLIB_NANO = 1
ifeq ($(shell echo "int main(){} void _exit(int n) {(void)n;while(1);}" | LC_ALL=C $(CC) -xc - -o /dev/null -lc -specs=nano.specs -Wall -Wextra -pedantic 2>&1 | grep -q "use of wchar_t values across objects may fail" ; echo $$?),0)
ifeq ($(shell echo "int main(){} void _exit(int n) {(void)n;while(1);}" | LC_ALL=C $(LINK) -xc - -o /dev/null -lc -specs=nano.specs -Wall -Wextra -pedantic 2>&1 | grep -q "use of wchar_t values across objects may fail" ; echo $$?),0)
CFLAGS += -fshort-wchar
LINKFLAGS += -Wl,--no-wchar-size-warning
endif
Expand Down
2 changes: 1 addition & 1 deletion makefiles/libc/picolibc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ifneq (,$(filter picolibc,$(USEMODULE)))
# Test if picolibc.specs is available
ifeq ($(shell $(LINK) -specs=picolibc.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
USE_PICOLIBC = 1
ifeq ($(shell echo "int main(){} void _exit(int n) {(void)n;while(1);}" | LC_ALL=C $(CC) -xc - -o /dev/null -lc -specs=picolibc.specs -Wall -Wextra -pedantic 2>&1 | grep -q "use of wchar_t values across objects may fail" ; echo $$?),0)
ifeq ($(shell echo "int main(){} void _exit(int n) {(void)n;while(1);}" | LC_ALL=C $(LINK) -xc - -o /dev/null -lc -specs=picolibc.specs -Wall -Wextra -pedantic 2>&1 | grep -q "use of wchar_t values across objects may fail" ; echo $$?),0)
CFLAGS += -fshort-wchar
LINKFLAGS += -Wl,--no-wchar-size-warning
endif
Expand Down