Skip to content

Commit

Permalink
Merge pull request #18845 from maribu/llvm-compat
Browse files Browse the repository at this point in the history
build system: fix compilation with LLVM
  • Loading branch information
benpicco authored Nov 7, 2022
2 parents 13eef00 + 0077e9a commit 8a811e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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))
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

0 comments on commit 8a811e8

Please sign in to comment.