Use target compiler for user binaries in samples/
Subsystems (4)
RFC PATCH 1/1 Use target compiler for user binaries in samples/
The user-space binaries build in samples/ uses the installed headers for the kernel.
Therefore it is wrong that they use the host compiler to build the samples.
Following is an attempt to create some infrastructure for building user-space binaries that uses the uapi headers.
As my sparc cross toolchain does not supporting building user-space I have not been able to test this as good as I hoped...
But faking that my native gcc is a cross gcc seems to work.
This adds two new variables to the top-level Makefile:
UAPICC and UAPICFLAGS
The architectures that supports both 32 and 64 bit set the appropriate flags in UAPICFLAGS.
scripts/Makefile.uapiprogs cantains all the infrastructure.
I updated the samples for hidraw and seccomp to use the new infrastructure.
The file says:
+# Sample syntax (see Documentation/kbuild/makefiles.txt for reference)
But I did not bother to write this yet - awaiting feedback.
Sam
Makefile | 5 ++ arch/s390/Makefile | 2 + arch/sparc/Makefile | 2 + arch/x86/Makefile | 1 + samples/Makefile | 5 ++- samples/hidraw/Makefile | 10 +---- samples/seccomp/Makefile | 31 +--------------- scripts/Makefile.build | 6 ++- scripts/Makefile.uapiprogs | 88 ++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 109 insertions(+), 41 deletions(-)
Makefile +5 -0
@@ -244,6 +244,11 @@ HOSTCXX = g++ HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer HOSTCXXFLAGS = -O2 +UAPICC = $(CROSS_COMPILE)gcc +UAPICFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes +export UAPICC UAPICFLAGS + + # Decide whether to build built-in, modular, or both. # Normally, just do built-in.
arch/s390/Makefile +2 -0
@@ -18,6 +18,7 @@ LD_BFD := elf32-s390 LDFLAGS := -m elf_s390 KBUILD_CFLAGS += -m31 KBUILD_AFLAGS += -m31 +UAPICFLAGS += -m31 UTS_MACHINE := s390 STACK_SIZE := 8192 CHECKFLAGS += -D__s390__ -msize-long
@@ -28,6 +29,7 @@ KBUILD_AFLAGS_MODULE += -fPIC KBUILD_CFLAGS_MODULE += -fPIC KBUILD_CFLAGS += -m64 KBUILD_AFLAGS += -m64 +UAPICFLAGS += -m64 UTS_MACHINE := s390x STACK_SIZE := 16384 CHECKFLAGS += -D__s390__ -D__s390x__
arch/sparc/Makefile +2 -0
@@ -28,6 +28,7 @@ UTS_MACHINE := sparc KBUILD_CFLAGS += -m32 -mcpu=v8 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7 KBUILD_AFLAGS += -m32 -Wa,-Av8 +UAPICFLAGS += -m32 else #####
@@ -44,6 +45,7 @@ KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -fcall-used-g7 -Wno-sign-compare KBUILD_CFLAGS += -Wa,--undeclared-regs KBUILD_CFLAGS += $(call cc-option,-mtune=ultrasparc3) KBUILD_AFLAGS += -m64 -mcpu=ultrasparc -Wa,--undeclared-regs +UAPICFLAGS += -m64 ifeq ($(CONFIG_MCOUNT),y) KBUILD_CFLAGS += -pg
arch/x86/Makefile +1 -0
@@ -56,6 +56,7 @@ else KBUILD_AFLAGS += -m64 KBUILD_CFLAGS += -m64 + UAPICFLAGS += -m64 # Use -mpreferred-stack-boundary=3 if supported. KBUILD_CFLAGS += $(call cc-option,-mno-sse -mpreferred-stack-boundary=3)
samples/Makefile +4 -1
@@ -1,4 +1,7 @@ # Makefile for Linux samples code +uapiprogs-$(CONFIG_SAMPLES) += hidraw/ +uapiprogs-$(CONFIG_SAMPLES) += seccomp/ + obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ \ - hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ + hw_breakpoint/ kfifo/ kdb/ rpmsg/
samples/hidraw/Makefile +1 -9
@@ -1,10 +1,2 @@ -# kbuild trick to avoid linker error. Can be omitted if a module is built. -obj- := dummy.o - # List of programs to build -hostprogs-y := hid-example - -# Tell kbuild to always build the programs -always := $(hostprogs-y) - -HOSTCFLAGS_hid-example.o += -I$(objtree)/usr/include +uapiprogs-y := hid-example
samples/seccomp/Makefile +1 -30
@@ -1,42 +1,13 @@ -# kbuild trick to avoid linker error. Can be omitted if a module is built. -obj- := dummy.o -hostprogs-$(CONFIG_SECCOMP_FILTER) := bpf-fancy dropper bpf-direct +uapiprogs-$(CONFIG_SECCOMP_FILTER) := bpf-fancy dropper bpf-direct -HOSTCFLAGS_bpf-fancy.o += -I$(objtree)/usr/include HOSTCFLAGS_bpf-fancy.o += -idirafter $(objtree)/include -HOSTCFLAGS_bpf-helper.o += -I$(objtree)/usr/include HOSTCFLAGS_bpf-helper.o += -idirafter $(objtree)/include bpf-fancy-objs := bpf-fancy.o bpf-helper.o -HOSTCFLAGS_dropper.o += -I$(objtree)/usr/include HOSTCFLAGS_dropper.o += -idirafter $(objtree)/include dropper-objs := dropper.o -HOSTCFLAGS_bpf-direct.o += -I$(objtree)/usr/include HOSTCFLAGS_bpf-direct.o += -idirafter $(objtree)/include bpf-direct-objs := bpf-direct.o -# Try to match the kernel target. -ifndef CONFIG_64BIT -ifndef CROSS_COMPILE - -# s390 has -m31 flag to build 31 bit binaries -ifndef CONFIG_S390 -MFLAG = -m32 -else -MFLAG = -m31 -endif - -HOSTCFLAGS_bpf-direct.o += $(MFLAG) -HOSTCFLAGS_dropper.o += $(MFLAG) -HOSTCFLAGS_bpf-helper.o += $(MFLAG) -HOSTCFLAGS_bpf-fancy.o += $(MFLAG) -HOSTLOADLIBES_bpf-direct += $(MFLAG) -HOSTLOADLIBES_bpf-fancy += $(MFLAG) -HOSTLOADLIBES_dropper += $(MFLAG) -endif -endif - -# Tell kbuild to always build the programs -always := $(hostprogs-y)
scripts/Makefile.build +5 -1
@@ -115,6 +115,10 @@ ifneq ($(hostprogs-y)$(hostprogs-m),) include scripts/Makefile.host endif +ifdef uapiprogs-y +include scripts/Makefile.uapiprogs +endif + ifneq ($(KBUILD_SRC),) # Create output directory if not already present _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
@@ -144,7 +148,7 @@ modorder-target := $(obj)/modules.order __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \ - $(subdir-ym) $(always) + $(subdir-ym) $(always) $(subdir-uapi) @: # Linus' kernel sanity checking tool
scripts/Makefile.uapiprogs new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
1.6.0.6
Quoted 21 lines · Sam Ravnborg
The user-space binaries build in
samples/uses the installed headers for the kernel.
Therefore it is wrong that they use the host compiler to build the samples.Following is an attempt to create some infrastructure for building user-space binaries that uses the uapi headers.
As my sparc cross toolchain does not supporting building user-space I have not been able to test this as good as I hoped...
But faking that my native gcc is a cross gcc seems to work.
This adds two new variables to the top-level
Makefile:
UAPICC and UAPICFLAGSThe architectures that supports both 32 and 64 bit set the appropriate flags in UAPICFLAGS.
scripts/Makefile.uapiprogscantains all the infrastructure.
Quoted 7 lines
I updated the samples for hidraw and seccomp to use the new infrastructure.
The file says:
+# Sample syntax (seeDocumentation/kbuild/makefiles.txtfor reference)But I did not bother to write this yet - awaiting feedback.
I generally like the idea.
It'd be nice to know whether this fixes the ARCH=sparc allyesconfig builds Fengguang has been reporting. Fengguang ... ?
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Quoted 7 lines · Sam Ravnborg
The user-space binaries build in
samples/uses the installed headers for the kernel.
Therefore it is wrong that they use the host compiler to build the samples.Following is an attempt to create some infrastructure for building user-space binaries that uses the uapi headers.
Hi Sam,
I like the idea, I only have some minor remarks.
Quoted 5 lines
This adds two new variables to the top-level
Makefile:
UAPICC and UAPICFLAGSThe architectures that supports both 32 and 64 bit set the appropriate flags in UAPICFLAGS.
You can have a 64bit kernel and a 32bit-only userspace. OTOH, newer PPC distros stopped doing this, and the basic libraries have always been available in both modes. So using the same bitness for kernel and samples is probably OK.
arch/x86/Makefile else · line 59
Quoted 9 lines
arch/x86/Makefile +1
-0@@ -56,6 +56,7 @@ else KBUILD_AFLAGS += -m64 KBUILD_CFLAGS += -m64 + UAPICFLAGS += -m64
You need to add UAPICFLAGS += $(biarch) in the x86_32 case.
Quoted 6 lines
samples/seccomp/Makefile +0
-1@@ -1,42 +1,13 @@ -# kbuild trick to avoid linker error. Can be omitted if a module is built.
samples/seccomp/Makefile line 6
Quoted 10 lines
samples/seccomp/Makefile +1
-4-obj- := dummy.o -hostprogs-$(CONFIG_SECCOMP_FILTER) := bpf-fancy dropper bpf-direct +uapiprogs-$(CONFIG_SECCOMP_FILTER) := bpf-fancy dropper bpf-direct -HOSTCFLAGS_bpf-fancy.o += -I$(objtree)/usr/include HOSTCFLAGS_bpf-fancy.o += -idirafter $(objtree)/include -HOSTCFLAGS_bpf-helper.o += -I$(objtree)/usr/include HOSTCFLAGS_bpf-helper.o += -idirafter $(objtree)/include bpf-fancy-objs := bpf-fancy.o bpf-helper.o
The remaining HOSTCFLAGS_* assignments lose their meaning, so remove them all. I actually wonder why there was need for the ./include path, the samples are supposed to demonstrate usage of the exported headers, after all. And it builds without the include.
samples/seccomp/Makefile line 29
Quoted 10 lines
samples/seccomp/Makefile +0
-10-# Try to match the kernel target. -ifndef CONFIG_64BIT -ifndef CROSS_COMPILE - -# s390 has -m31 flag to build 31 bit binaries -ifndef CONFIG_S390 -MFLAG = -m32 -else -MFLAG = -m31 -endif
Nice cleanup as a side effect :).
Quoted 5 lines
scripts/Makefile.uapiprogs new file +0
-0
[...]
scripts/Makefile.uapiprogs line 23
Quoted 9 lines
scripts/Makefile.uapiprogs new file +9
-0+__uapiprogs := $(sort $(uapiprogs-y)) + +# sub-directories to visit +# uapiprogs-y := hidraw/ may have been specified. Retrieve directory +subdir-uapi := $(patsubst %/,%,$(filter %/, $(__uapiprogs))) + +# Drop all subdirs from list +__uapiprogs := $(filter-out %/, $(__uapiprogs)) +
Is it necessary to add subdirectory logic here? scripts/Makefile.host does not implement it either. Let's keep the established practice that subdirectories must be listed in $(obj-y) or $(obj-m). Then scripts/Makefile.build continues to be the "driver" for the whole build and includes scripts/Makefile.{host,uapiprogs} as needed. That way, you simplify this makefile a bit, you don't need to change scripts/Makefile.build beyond the include statement and you don't need to touch samples/Makefile.
scripts/Makefile.uapiprogs line 69
Quoted 6 lines
scripts/Makefile.uapiprogs new file +6
-0+# Link an executable based on list of .o files, all plain c +# uapi-cmulti -> executable +quiet_cmd_uapi-cmulti = UAPILD $@ + cmd_uapi-cmulti = $(UAPICC) -o $@ \ + $(addprefix $(obj)/,$($(@F)-objs)) +$(uapi-cmulti): $(obj)/%: $(uapi-cobjs) $(uapi-cshlib) FORCE
^^^^^^^^^^^
Copy&paste artefact from scripts/Makefile.host.
Last but not least, you need to add $(uapiprogs-y) to $(__clean-files) in scripts/Makefile.clean.
Michal