klibc-bot for Bill Wendling
2020-Jul-25 20:57 UTC
[klibc] [klibc:master] Kbuild: add support for clang builds
Commit-ID: 9eddaf50ea1b837979e49f996a2609a012218837 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=9eddaf50ea1b837979e49f996a2609a012218837 Author: Bill Wendling <morbo at google.com> AuthorDate: Sun, 29 Mar 2020 04:38:30 -0700 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 25 Jul 2020 20:45:34 +0100 [klibc] Kbuild: add support for clang builds Add cc-name to klibc/scripts/Kbuild.include. Make optimization flags not supported by clang conditional on cc-name. Use "--print-file-name=include" and "--print-libgcc-file-name" when using clang. Use cc-option to enable compiler-specific flags. Mark "bcmp" as not a builtin to prevent clang from using it. Signed-off-by: Bill Wendling <morbo at google.com> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- scripts/Kbuild.include | 8 ++++++-- scripts/Kbuild.klibc | 13 +++++++++---- usr/klibc/Kbuild | 4 ++-- usr/klibc/arch/x86_64/MCONFIG | 6 ++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index a048ec7a..5604b3e3 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -110,12 +110,12 @@ as-instr = $(call try-run,\ # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) cc-option = $(call try-run,\ - $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2)) + $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -Werror -c -xc /dev/null -o "$$TMP",$(1),$(2)) # cc-option-yn # Usage: flag := $(call cc-option-yn,-march=winchip-c6) cc-option-yn = $(call try-run,\ - $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",y,n) + $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -Werror -c -xc /dev/null -o "$$TMP",y,n) # cc-option-align # Prefix align with either -falign or -malign @@ -127,6 +127,10 @@ cc-option-align = $(subst -functions=0,,\ cc-disable-warning = $(call try-run,\ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -xc /dev/null -o "$$TMP",-Wno-$(strip $(1))) +# cc-name +# Expands to either gcc or clang +cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) + # cc-version # Usage gcc-ver := $(call cc-version) cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) diff --git a/scripts/Kbuild.klibc b/scripts/Kbuild.klibc index d1c78ce6..ce646212 100644 --- a/scripts/Kbuild.klibc +++ b/scripts/Kbuild.klibc @@ -69,6 +69,7 @@ include $(srctree)/scripts/Kbuild.include KLIBCREQFLAGS := $(call cc-option, -fno-stack-protector, ) \ $(call cc-option, -fwrapv, ) \ $(call cc-option, -fno-PIE, ) \ + $(call cc-option, -fno-builtin-bcmp, ) \ -ggdb KLIBCARCHREQFLAGS : KLIBCOPTFLAGS :@@ -108,10 +109,14 @@ KLIBCOBJDUMP := $(OBJDUMP) # klibc include paths KLIBCCPPFLAGS := -nostdinc -iwithprefix include \ - -I$(KLIBCINC)/arch/$(KLIBCARCHDIR) \ + -I$(KLIBCINC)/arch/$(KLIBCARCHDIR) \ -I$(KLIBCINC)/bits$(KLIBCBITSIZE) \ - -I$(KLIBCOBJ)/../include \ + -I$(KLIBCOBJ)/../include \ -I$(KLIBCINC) +ifeq ($(cc-name),clang) +KLIBCCPPFLAGS += -I$(shell $(KLIBCCC) $(KLIBCCFLAGS) --print-file-name=include) +endif + # kernel include paths KLIBCKERNELSRC ?= $(srctree) KLIBCCPPFLAGS += -I$(KLIBCKERNELSRC)/include \ @@ -131,8 +136,8 @@ KLIBCCFLAGS += $(KLIBCCPPFLAGS) $(KLIBCREQFLAGS) $(KLIBCARCHREQFLAGS) \ KLIBCAFLAGS += -D__ASSEMBLY__ $(KLIBCCFLAGS) KLIBCSTRIPFLAGS += --strip-all -R .comment -R .note -KLIBCLIBGCC_DEF := $(shell $(KLIBCCC) $(KLIBCCFLAGS) --print-libgcc) -KLIBCLIBGCC ?= $(KLIBCLIBGCC_DEF) +KLIBCLIBGCC_DEF := $(shell $(KLIBCCC) $(KLIBCCFLAGS) $(if $(filter gcc,$(cc-name)),--print-libgcc,--print-libgcc-file-name)) +KLIBCLIBGCC ?= $(KLIBCLIBGCC_DEF) KLIBCCRT0 := $(KLIBCOBJ)/arch/$(KLIBCARCHDIR)/crt0.o KLIBCLIBC := $(KLIBCOBJ)/libc.a KLIBCCRTSHARED := $(KLIBCOBJ)/interp.o diff --git a/usr/klibc/Kbuild b/usr/klibc/Kbuild index c6338851..ae5eb6dc 100644 --- a/usr/klibc/Kbuild +++ b/usr/klibc/Kbuild @@ -85,8 +85,8 @@ endif # These pass a huge maximum length to the corresponding length-limiting # functions -KLIBCCFLAGS_sprintf.o += -Wno-format-truncation -KLIBCCFLAGS_vsprintf.o += -Wno-format-truncation +KLIBCCFLAGS_sprintf.o += $(call cc-option,-Wno-format-truncation, ) +KLIBCCFLAGS_vsprintf.o += $(call cc-option,-Wno-format-truncation, ) # sigsuspend.c includes <klibc/havesyscall.h> generated by syscalls/ # build, so require that to build first diff --git a/usr/klibc/arch/x86_64/MCONFIG b/usr/klibc/arch/x86_64/MCONFIG index 1f5f99c7..c2947c6a 100644 --- a/usr/klibc/arch/x86_64/MCONFIG +++ b/usr/klibc/arch/x86_64/MCONFIG @@ -15,8 +15,10 @@ # debugging using gdb. # KLIBCARCHREQFLAGS = -m64 -KLIBCOPTFLAGS += -Os -fomit-frame-pointer -mno-sse \ - -falign-functions=1 -falign-jumps=1 -falign-loops=1 +KLIBCOPTFLAGS += -Os -fomit-frame-pointer -mno-sse \ + $(call cc-option,-falign-functions=1, ) \ + $(call cc-option,-falign-jumps=1, ) \ + $(call cc-option,-falign-loops=1, ) ifeq ($(DEBUG),y) KLIBCOPTFLAGS += -g else
Apparently Analagous Threads
- [kvm-unit-tests PATCH v3 1/4] Kbuild: add support for clang builds
- [PATCH v2 1/5] Kbuild: add support for clang builds
- [PATCH v2 1/5] Kbuild: add support for clang builds
- [klibc 19/43] klibc basic build infrastructure
- [kvm-unit-tests PATCH v3 0/4] Update patch set