LKML Archive on lore.kernel.org help / color / mirror / Atom feed
* [PATCH] tools: fix cross-compile var export @ 2018-01-06 20:16 Martin Kelly 2018-01-07 16:11 ` Paul Gortmaker 2018-01-07 21:40 ` [PATCH v2] tools: fix cross-compile var clobbering Martin Kelly 0 siblings, 2 replies; 14+ messages in thread From: Martin Kelly @ 2018-01-06 20:16 UTC (permalink / raw) To: kernel-kbuild, kernel-janitors, linux-embedded Cc: Paul Gortmaker, David Woodhouse, Matt Mackall, Masahiro Yamada, Michal Marek, linux-kernel, Martin Kelly From: Martin Kelly <martin@martingkelly.com> Currently in a number of Makefiles, we clobber the CC, LD, and/or STRIP env vars when cross-compiling, which breaks any additional flags that might be set (such as sysroot). This easily shows up by using, for instance, a Yocto SDK. Fix this by more carefully overriding the flags in the way that the perf Makefile does. This patch does not fix cross-compile for all the tools (some have other bugs), but it does appear to fix it for these: - cgroup - freefall - gpio - hv - iio - leds - spi - vm - wmi Signed-off-by: Martin Kelly <martin@martingkelly.com> --- This patch touches multiple subsystems, and there doesn't appear to be a global tools maintainer, so I sent this to linux-embedded kernel-janitors, and linux-kbuild. Please let me know if there is a better place for it. tools/cgroup/Makefile | 1 - tools/gpio/Makefile | 2 -- tools/hv/Makefile | 1 - tools/iio/Makefile | 2 -- tools/laptop/freefall/Makefile | 1 - tools/leds/Makefile | 1 - tools/perf/Makefile.perf | 6 ------ tools/power/acpi/Makefile.config | 3 --- tools/scripts/Makefile.include | 18 ++++++++++++++++++ tools/spi/Makefile | 2 -- tools/usb/Makefile | 1 - tools/vm/Makefile | 1 - tools/wmi/Makefile | 1 - 13 files changed, 18 insertions(+), 22 deletions(-) diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile index 860fa151640a..ffca068e4a76 100644 --- a/tools/cgroup/Makefile +++ b/tools/cgroup/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for cgroup tools -CC = $(CROSS_COMPILE)gcc CFLAGS = -Wall -Wextra all: cgroup_event_listener diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile index 805a2c0cf4cd..240eda014b37 100644 --- a/tools/gpio/Makefile +++ b/tools/gpio/Makefile @@ -12,8 +12,6 @@ endif # (this improves performance and avoids hard-to-debug behaviour); MAKEFLAGS += -r -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)ld CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon diff --git a/tools/hv/Makefile b/tools/hv/Makefile index 31503819454d..68c2d7b059b3 100644 --- a/tools/hv/Makefile +++ b/tools/hv/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Hyper-V tools -CC = $(CROSS_COMPILE)gcc WARNINGS = -Wall -Wextra CFLAGS = $(WARNINGS) -g $(shell getconf LFS_CFLAGS) diff --git a/tools/iio/Makefile b/tools/iio/Makefile index a08e7a47d6a3..332ed2f6c2c2 100644 --- a/tools/iio/Makefile +++ b/tools/iio/Makefile @@ -12,8 +12,6 @@ endif # (this improves performance and avoids hard-to-debug behaviour); MAKEFLAGS += -r -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)ld CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer diff --git a/tools/laptop/freefall/Makefile b/tools/laptop/freefall/Makefile index 5f758c489a20..b572d94255f6 100644 --- a/tools/laptop/freefall/Makefile +++ b/tools/laptop/freefall/Makefile @@ -2,7 +2,6 @@ PREFIX ?= /usr SBINDIR ?= sbin INSTALL ?= install -CC = $(CROSS_COMPILE)gcc TARGET = freefall diff --git a/tools/leds/Makefile b/tools/leds/Makefile index c379af003807..7b6bed13daaa 100644 --- a/tools/leds/Makefile +++ b/tools/leds/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for LEDs tools -CC = $(CROSS_COMPILE)gcc CFLAGS = -Wall -Wextra -g -I../../include/uapi all: uledmon led_hw_brightness_mon diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 68cf1360a3f3..3035ce5f6b36 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -144,12 +144,6 @@ define allow-override $(eval $(1) = $(2))) endef -# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix. -$(call allow-override,CC,$(CROSS_COMPILE)gcc) -$(call allow-override,AR,$(CROSS_COMPILE)ar) -$(call allow-override,LD,$(CROSS_COMPILE)ld) -$(call allow-override,CXX,$(CROSS_COMPILE)g++) - LD += $(EXTRA_LDFLAGS) HOSTCC ?= gcc diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config index a1883bbb0144..2cccbba64418 100644 --- a/tools/power/acpi/Makefile.config +++ b/tools/power/acpi/Makefile.config @@ -56,9 +56,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} # to compile vs uClibc, that can be done here as well. CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- CROSS_COMPILE ?= $(CROSS) -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)gcc -STRIP = $(CROSS_COMPILE)strip HOSTCC = gcc # check if compiler option is supported diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include index 3fab179b1aba..09b2d0f07f66 100644 --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include @@ -42,6 +42,24 @@ EXTRA_WARNINGS += -Wformat CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) +# Makefiles suck: This macro sets a default value of $(2) for the +# variable named by $(1), unless the variable has been set by +# environment or command line. This is necessary for CC and AR +# because make sets default values, so the simpler ?= approach +# won't work as expected. +define allow-override + $(if $(or $(findstring environment,$(origin $(1))),\ + $(findstring command line,$(origin $(1)))),,\ + $(eval $(1) = $(2))) +endef + +# Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix. +$(call allow-override,CC,$(CROSS_COMPILE)gcc) +$(call allow-override,AR,$(CROSS_COMPILE)ar) +$(call allow-override,LD,$(CROSS_COMPILE)ld) +$(call allow-override,CXX,$(CROSS_COMPILE)g++) +$(call allow-override,CXX,$(CROSS_COMPILE)strip) + ifeq ($(CC_NO_CLANG), 1) EXTRA_WARNINGS += -Wstrict-aliasing=3 endif diff --git a/tools/spi/Makefile b/tools/spi/Makefile index 90615e10c79a..815d15589177 100644 --- a/tools/spi/Makefile +++ b/tools/spi/Makefile @@ -11,8 +11,6 @@ endif # (this improves performance and avoids hard-to-debug behaviour); MAKEFLAGS += -r -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)ld CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include ALL_TARGETS := spidev_test spidev_fdx diff --git a/tools/usb/Makefile b/tools/usb/Makefile index 4e6506078494..01d758d73b6d 100644 --- a/tools/usb/Makefile +++ b/tools/usb/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for USB tools -CC = $(CROSS_COMPILE)gcc PTHREAD_LIBS = -lpthread WARNINGS = -Wall -Wextra CFLAGS = $(WARNINGS) -g -I../include diff --git a/tools/vm/Makefile b/tools/vm/Makefile index be320b905ea7..20f6cf04377f 100644 --- a/tools/vm/Makefile +++ b/tools/vm/Makefile @@ -6,7 +6,6 @@ TARGETS=page-types slabinfo page_owner_sort LIB_DIR = ../lib/api LIBS = $(LIB_DIR)/libapi.a -CC = $(CROSS_COMPILE)gcc CFLAGS = -Wall -Wextra -I../lib/ LDFLAGS = $(LIBS) diff --git a/tools/wmi/Makefile b/tools/wmi/Makefile index e664f1167388..e0e87239126b 100644 --- a/tools/wmi/Makefile +++ b/tools/wmi/Makefile @@ -2,7 +2,6 @@ PREFIX ?= /usr SBINDIR ?= sbin INSTALL ?= install CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include -CC = $(CROSS_COMPILE)gcc TARGET = dell-smbios-example -- 2.11.0 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] tools: fix cross-compile var export 2018-01-06 20:16 [PATCH] tools: fix cross-compile var export Martin Kelly @ 2018-01-07 16:11 ` Paul Gortmaker 2018-01-07 18:31 ` Martin Kelly 2018-01-07 21:40 ` [PATCH v2] tools: fix cross-compile var clobbering Martin Kelly 1 sibling, 1 reply; 14+ messages in thread From: Paul Gortmaker @ 2018-01-07 16:11 UTC (permalink / raw) To: Martin Kelly Cc: kernel-kbuild, kernel-janitors, linux-embedded, David Woodhouse, Matt Mackall, Masahiro Yamada, Michal Marek, linux-kernel [[PATCH] tools: fix cross-compile var export] On 06/01/2018 (Sat 12:16) Martin Kelly wrote: > From: Martin Kelly <martin@martingkelly.com> > > Currently in a number of Makefiles, we clobber the CC, LD, and/or STRIP env vars > when cross-compiling, which breaks any additional flags that might be set (such > as sysroot). This easily shows up by using, for instance, a Yocto SDK. > > Fix this by more carefully overriding the flags in the way that the perf > Makefile does. > > This patch does not fix cross-compile for all the tools (some have other bugs), > but it does appear to fix it for these: > > - cgroup > - freefall > - gpio > - hv > - iio > - leds > - spi > - vm > - wmi > > Signed-off-by: Martin Kelly <martin@martingkelly.com> > --- > This patch touches multiple subsystems, and there doesn't appear to be a global > tools maintainer, so I sent this to linux-embedded kernel-janitors, and > linux-kbuild. Please let me know if there is a better place for it. I think you will have better luck if you go subsystem by subsystem, e.g. send gpio change to gpio maintainer, usb change to usb maintainer and so on. In addition, you'll want to try and understand/explain why those lines were added in the 1st place and how it won't break other existing use cases by removing them. Maybe "git blame" will help for that... P. -- > > tools/cgroup/Makefile | 1 - > tools/gpio/Makefile | 2 -- > tools/hv/Makefile | 1 - > tools/iio/Makefile | 2 -- > tools/laptop/freefall/Makefile | 1 - > tools/leds/Makefile | 1 - > tools/perf/Makefile.perf | 6 ------ > tools/power/acpi/Makefile.config | 3 --- > tools/scripts/Makefile.include | 18 ++++++++++++++++++ > tools/spi/Makefile | 2 -- > tools/usb/Makefile | 1 - > tools/vm/Makefile | 1 - > tools/wmi/Makefile | 1 - > 13 files changed, 18 insertions(+), 22 deletions(-) > > diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile > index 860fa151640a..ffca068e4a76 100644 > --- a/tools/cgroup/Makefile > +++ b/tools/cgroup/Makefile > @@ -1,7 +1,6 @@ > # SPDX-License-Identifier: GPL-2.0 > # Makefile for cgroup tools > > -CC = $(CROSS_COMPILE)gcc > CFLAGS = -Wall -Wextra > > all: cgroup_event_listener > diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile > index 805a2c0cf4cd..240eda014b37 100644 > --- a/tools/gpio/Makefile > +++ b/tools/gpio/Makefile > @@ -12,8 +12,6 @@ endif > # (this improves performance and avoids hard-to-debug behaviour); > MAKEFLAGS += -r > > -CC = $(CROSS_COMPILE)gcc > -LD = $(CROSS_COMPILE)ld > CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include > > ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon > diff --git a/tools/hv/Makefile b/tools/hv/Makefile > index 31503819454d..68c2d7b059b3 100644 > --- a/tools/hv/Makefile > +++ b/tools/hv/Makefile > @@ -1,7 +1,6 @@ > # SPDX-License-Identifier: GPL-2.0 > # Makefile for Hyper-V tools > > -CC = $(CROSS_COMPILE)gcc > WARNINGS = -Wall -Wextra > CFLAGS = $(WARNINGS) -g $(shell getconf LFS_CFLAGS) > > diff --git a/tools/iio/Makefile b/tools/iio/Makefile > index a08e7a47d6a3..332ed2f6c2c2 100644 > --- a/tools/iio/Makefile > +++ b/tools/iio/Makefile > @@ -12,8 +12,6 @@ endif > # (this improves performance and avoids hard-to-debug behaviour); > MAKEFLAGS += -r > > -CC = $(CROSS_COMPILE)gcc > -LD = $(CROSS_COMPILE)ld > CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include > > ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer > diff --git a/tools/laptop/freefall/Makefile b/tools/laptop/freefall/Makefile > index 5f758c489a20..b572d94255f6 100644 > --- a/tools/laptop/freefall/Makefile > +++ b/tools/laptop/freefall/Makefile > @@ -2,7 +2,6 @@ > PREFIX ?= /usr > SBINDIR ?= sbin > INSTALL ?= install > -CC = $(CROSS_COMPILE)gcc > > TARGET = freefall > > diff --git a/tools/leds/Makefile b/tools/leds/Makefile > index c379af003807..7b6bed13daaa 100644 > --- a/tools/leds/Makefile > +++ b/tools/leds/Makefile > @@ -1,7 +1,6 @@ > # SPDX-License-Identifier: GPL-2.0 > # Makefile for LEDs tools > > -CC = $(CROSS_COMPILE)gcc > CFLAGS = -Wall -Wextra -g -I../../include/uapi > > all: uledmon led_hw_brightness_mon > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > index 68cf1360a3f3..3035ce5f6b36 100644 > --- a/tools/perf/Makefile.perf > +++ b/tools/perf/Makefile.perf > @@ -144,12 +144,6 @@ define allow-override > $(eval $(1) = $(2))) > endef > > -# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix. > -$(call allow-override,CC,$(CROSS_COMPILE)gcc) > -$(call allow-override,AR,$(CROSS_COMPILE)ar) > -$(call allow-override,LD,$(CROSS_COMPILE)ld) > -$(call allow-override,CXX,$(CROSS_COMPILE)g++) > - > LD += $(EXTRA_LDFLAGS) > > HOSTCC ?= gcc > diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config > index a1883bbb0144..2cccbba64418 100644 > --- a/tools/power/acpi/Makefile.config > +++ b/tools/power/acpi/Makefile.config > @@ -56,9 +56,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} > # to compile vs uClibc, that can be done here as well. > CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- > CROSS_COMPILE ?= $(CROSS) > -CC = $(CROSS_COMPILE)gcc > -LD = $(CROSS_COMPILE)gcc > -STRIP = $(CROSS_COMPILE)strip > HOSTCC = gcc > > # check if compiler option is supported > diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include > index 3fab179b1aba..09b2d0f07f66 100644 > --- a/tools/scripts/Makefile.include > +++ b/tools/scripts/Makefile.include > @@ -42,6 +42,24 @@ EXTRA_WARNINGS += -Wformat > > CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) > > +# Makefiles suck: This macro sets a default value of $(2) for the > +# variable named by $(1), unless the variable has been set by > +# environment or command line. This is necessary for CC and AR > +# because make sets default values, so the simpler ?= approach > +# won't work as expected. > +define allow-override > + $(if $(or $(findstring environment,$(origin $(1))),\ > + $(findstring command line,$(origin $(1)))),,\ > + $(eval $(1) = $(2))) > +endef > + > +# Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix. > +$(call allow-override,CC,$(CROSS_COMPILE)gcc) > +$(call allow-override,AR,$(CROSS_COMPILE)ar) > +$(call allow-override,LD,$(CROSS_COMPILE)ld) > +$(call allow-override,CXX,$(CROSS_COMPILE)g++) > +$(call allow-override,CXX,$(CROSS_COMPILE)strip) > + > ifeq ($(CC_NO_CLANG), 1) > EXTRA_WARNINGS += -Wstrict-aliasing=3 > endif > diff --git a/tools/spi/Makefile b/tools/spi/Makefile > index 90615e10c79a..815d15589177 100644 > --- a/tools/spi/Makefile > +++ b/tools/spi/Makefile > @@ -11,8 +11,6 @@ endif > # (this improves performance and avoids hard-to-debug behaviour); > MAKEFLAGS += -r > > -CC = $(CROSS_COMPILE)gcc > -LD = $(CROSS_COMPILE)ld > CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include > > ALL_TARGETS := spidev_test spidev_fdx > diff --git a/tools/usb/Makefile b/tools/usb/Makefile > index 4e6506078494..01d758d73b6d 100644 > --- a/tools/usb/Makefile > +++ b/tools/usb/Makefile > @@ -1,7 +1,6 @@ > # SPDX-License-Identifier: GPL-2.0 > # Makefile for USB tools > > -CC = $(CROSS_COMPILE)gcc > PTHREAD_LIBS = -lpthread > WARNINGS = -Wall -Wextra > CFLAGS = $(WARNINGS) -g -I../include > diff --git a/tools/vm/Makefile b/tools/vm/Makefile > index be320b905ea7..20f6cf04377f 100644 > --- a/tools/vm/Makefile > +++ b/tools/vm/Makefile > @@ -6,7 +6,6 @@ TARGETS=page-types slabinfo page_owner_sort > LIB_DIR = ../lib/api > LIBS = $(LIB_DIR)/libapi.a > > -CC = $(CROSS_COMPILE)gcc > CFLAGS = -Wall -Wextra -I../lib/ > LDFLAGS = $(LIBS) > > diff --git a/tools/wmi/Makefile b/tools/wmi/Makefile > index e664f1167388..e0e87239126b 100644 > --- a/tools/wmi/Makefile > +++ b/tools/wmi/Makefile > @@ -2,7 +2,6 @@ PREFIX ?= /usr > SBINDIR ?= sbin > INSTALL ?= install > CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include > -CC = $(CROSS_COMPILE)gcc > > TARGET = dell-smbios-example > > -- > 2.11.0 > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] tools: fix cross-compile var export 2018-01-07 16:11 ` Paul Gortmaker @ 2018-01-07 18:31 ` Martin Kelly 2018-01-07 18:51 ` Martin Kelly 2018-01-07 19:04 ` Paul Gortmaker 0 siblings, 2 replies; 14+ messages in thread From: Martin Kelly @ 2018-01-07 18:31 UTC (permalink / raw) To: Paul Gortmaker Cc: kernel-kbuild, kernel-janitors, linux-embedded, David Woodhouse, Matt Mackall, Masahiro Yamada, Michal Marek, linux-kernel On 01/07/2018 08:11 AM, Paul Gortmaker wrote: > [[PATCH] tools: fix cross-compile var export] On 06/01/2018 (Sat 12:16) Martin Kelly wrote: > >> From: Martin Kelly <martin@martingkelly.com> >> >> Currently in a number of Makefiles, we clobber the CC, LD, and/or STRIP env vars >> when cross-compiling, which breaks any additional flags that might be set (such >> as sysroot). This easily shows up by using, for instance, a Yocto SDK. >> >> Fix this by more carefully overriding the flags in the way that the perf >> Makefile does. >> >> This patch does not fix cross-compile for all the tools (some have other bugs), >> but it does appear to fix it for these: >> >> - cgroup >> - freefall >> - gpio >> - hv >> - iio >> - leds >> - spi >> - vm >> - wmi >> >> Signed-off-by: Martin Kelly <martin@martingkelly.com> >> --- >> This patch touches multiple subsystems, and there doesn't appear to be a global >> tools maintainer, so I sent this to linux-embedded kernel-janitors, and >> linux-kbuild. Please let me know if there is a better place for it. > > I think you will have better luck if you go subsystem by subsystem, e.g. > send gpio change to gpio maintainer, usb change to usb maintainer and so > on. In addition, you'll want to try and understand/explain why those > lines were added in the 1st place and how it won't break other existing > use cases by removing them. Maybe "git blame" will help for that... > > P. > -- > I can send patches subsystem-by-subsystem, but this patch fixes a single bug that applies to many Makefiles. It fixes it by putting the correct logic into tools/scripts/Makefile.include, which each Makefiles includes. If I do this subsystem-by-subsystem, we will just duplicate these lines into every Makefile: +$(call allow-override,CC,$(CROSS_COMPILE)gcc) +$(call allow-override,AR,$(CROSS_COMPILE)ar) +$(call allow-override,LD,$(CROSS_COMPILE)ld) +$(call allow-override,CXX,$(CROSS_COMPILE)g++) +$(call allow-override,CXX,$(CROSS_COMPILE)strip) We could do this, but it's a lot of code duplication and means that anyone making a new Makefile must also copy the lines or their Makefile will have this bug. Since the bug fix generically applies everywhere, I think it's most correct for it to go into the common Makefile. If there is really no maintainer for the tools/scripts/Makefile.include file, then maybe I have to send subsystem-by-subsystem, but that seems less than ideal. I do understand why the CC = $(CROSS_COMPILE)gcc lines exist; it is to enable cross-compile when you set the $CROSS_COMPILE env var and to use native gcc when that is not set. The bug is that if you already have $CC set to your cross-compiler (which is what the Yocto SDK and other toolchains do), then most of your command-line gets clobbered. Here's an example from an ARM Yocto SDK I have: $ echo $CC arm-poky-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a8 --sysroot=/home/martin/src/poky/build/sdk/sysroots/cortexa8hf-neon-poky-linux-gnueabi $ echo $CROSS_COMPILE arm-poky-linux-gnueabi- $ echo ${CROSS_COMPILE}gcc arm-poky-linux-gnueabi-gcc Although arm-poky-linux-gnueabi-gcc is a cross-compiler, we've lost many build flags, notably --sysroot, which enables us to find the right libraries to link against. Without this change, I get this kind of error in all the affected Makefiles: martin@cascade:~/src/linux/tools$ make iio [snip] iio_event_monitor.c:18:10: fatal error: unistd.h: No such file or directory #include <unistd.h> ^~~~~~~~~~ This occurs because unistd.h is in the sysroot, but we've dropped the --sysroot flag: $ find /home/martin/src/poky/build/sdk/sysroots -path '*/usr/include/unistd.h' /home/martin/src/poky/build/sdk/sysroots/cortexa8hf-neon-poky-linux-gnueabi/usr/include/unistd.h With the change, we add do CC = $(CROSS_COMPILE)gcc if and only if CC is not already set. I'm happy to add all these details to the commit description. >> >> tools/cgroup/Makefile | 1 - >> tools/gpio/Makefile | 2 -- >> tools/hv/Makefile | 1 - >> tools/iio/Makefile | 2 -- >> tools/laptop/freefall/Makefile | 1 - >> tools/leds/Makefile | 1 - >> tools/perf/Makefile.perf | 6 ------ >> tools/power/acpi/Makefile.config | 3 --- >> tools/scripts/Makefile.include | 18 ++++++++++++++++++ >> tools/spi/Makefile | 2 -- >> tools/usb/Makefile | 1 - >> tools/vm/Makefile | 1 - >> tools/wmi/Makefile | 1 - >> 13 files changed, 18 insertions(+), 22 deletions(-) >> >> diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile >> index 860fa151640a..ffca068e4a76 100644 >> --- a/tools/cgroup/Makefile >> +++ b/tools/cgroup/Makefile >> @@ -1,7 +1,6 @@ >> # SPDX-License-Identifier: GPL-2.0 >> # Makefile for cgroup tools >> >> -CC = $(CROSS_COMPILE)gcc >> CFLAGS = -Wall -Wextra >> >> all: cgroup_event_listener >> diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile >> index 805a2c0cf4cd..240eda014b37 100644 >> --- a/tools/gpio/Makefile >> +++ b/tools/gpio/Makefile >> @@ -12,8 +12,6 @@ endif >> # (this improves performance and avoids hard-to-debug behaviour); >> MAKEFLAGS += -r >> >> -CC = $(CROSS_COMPILE)gcc >> -LD = $(CROSS_COMPILE)ld >> CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include >> >> ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon >> diff --git a/tools/hv/Makefile b/tools/hv/Makefile >> index 31503819454d..68c2d7b059b3 100644 >> --- a/tools/hv/Makefile >> +++ b/tools/hv/Makefile >> @@ -1,7 +1,6 @@ >> # SPDX-License-Identifier: GPL-2.0 >> # Makefile for Hyper-V tools >> >> -CC = $(CROSS_COMPILE)gcc >> WARNINGS = -Wall -Wextra >> CFLAGS = $(WARNINGS) -g $(shell getconf LFS_CFLAGS) >> >> diff --git a/tools/iio/Makefile b/tools/iio/Makefile >> index a08e7a47d6a3..332ed2f6c2c2 100644 >> --- a/tools/iio/Makefile >> +++ b/tools/iio/Makefile >> @@ -12,8 +12,6 @@ endif >> # (this improves performance and avoids hard-to-debug behaviour); >> MAKEFLAGS += -r >> >> -CC = $(CROSS_COMPILE)gcc >> -LD = $(CROSS_COMPILE)ld >> CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include >> >> ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer >> diff --git a/tools/laptop/freefall/Makefile b/tools/laptop/freefall/Makefile >> index 5f758c489a20..b572d94255f6 100644 >> --- a/tools/laptop/freefall/Makefile >> +++ b/tools/laptop/freefall/Makefile >> @@ -2,7 +2,6 @@ >> PREFIX ?= /usr >> SBINDIR ?= sbin >> INSTALL ?= install >> -CC = $(CROSS_COMPILE)gcc >> >> TARGET = freefall >> >> diff --git a/tools/leds/Makefile b/tools/leds/Makefile >> index c379af003807..7b6bed13daaa 100644 >> --- a/tools/leds/Makefile >> +++ b/tools/leds/Makefile >> @@ -1,7 +1,6 @@ >> # SPDX-License-Identifier: GPL-2.0 >> # Makefile for LEDs tools >> >> -CC = $(CROSS_COMPILE)gcc >> CFLAGS = -Wall -Wextra -g -I../../include/uapi >> >> all: uledmon led_hw_brightness_mon >> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf >> index 68cf1360a3f3..3035ce5f6b36 100644 >> --- a/tools/perf/Makefile.perf >> +++ b/tools/perf/Makefile.perf >> @@ -144,12 +144,6 @@ define allow-override >> $(eval $(1) = $(2))) >> endef >> >> -# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix. >> -$(call allow-override,CC,$(CROSS_COMPILE)gcc) >> -$(call allow-override,AR,$(CROSS_COMPILE)ar) >> -$(call allow-override,LD,$(CROSS_COMPILE)ld) >> -$(call allow-override,CXX,$(CROSS_COMPILE)g++) >> - >> LD += $(EXTRA_LDFLAGS) >> >> HOSTCC ?= gcc >> diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config >> index a1883bbb0144..2cccbba64418 100644 >> --- a/tools/power/acpi/Makefile.config >> +++ b/tools/power/acpi/Makefile.config >> @@ -56,9 +56,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} >> # to compile vs uClibc, that can be done here as well. >> CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- >> CROSS_COMPILE ?= $(CROSS) >> -CC = $(CROSS_COMPILE)gcc >> -LD = $(CROSS_COMPILE)gcc >> -STRIP = $(CROSS_COMPILE)strip >> HOSTCC = gcc >> >> # check if compiler option is supported >> diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include >> index 3fab179b1aba..09b2d0f07f66 100644 >> --- a/tools/scripts/Makefile.include >> +++ b/tools/scripts/Makefile.include >> @@ -42,6 +42,24 @@ EXTRA_WARNINGS += -Wformat >> >> CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) >> >> +# Makefiles suck: This macro sets a default value of $(2) for the >> +# variable named by $(1), unless the variable has been set by >> +# environment or command line. This is necessary for CC and AR >> +# because make sets default values, so the simpler ?= approach >> +# won't work as expected. >> +define allow-override >> + $(if $(or $(findstring environment,$(origin $(1))),\ >> + $(findstring command line,$(origin $(1)))),,\ >> + $(eval $(1) = $(2))) >> +endef >> + >> +# Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix. >> +$(call allow-override,CC,$(CROSS_COMPILE)gcc) >> +$(call allow-override,AR,$(CROSS_COMPILE)ar) >> +$(call allow-override,LD,$(CROSS_COMPILE)ld) >> +$(call allow-override,CXX,$(CROSS_COMPILE)g++) >> +$(call allow-override,CXX,$(CROSS_COMPILE)strip) >> + >> ifeq ($(CC_NO_CLANG), 1) >> EXTRA_WARNINGS += -Wstrict-aliasing=3 >> endif >> diff --git a/tools/spi/Makefile b/tools/spi/Makefile >> index 90615e10c79a..815d15589177 100644 >> --- a/tools/spi/Makefile >> +++ b/tools/spi/Makefile >> @@ -11,8 +11,6 @@ endif >> # (this improves performance and avoids hard-to-debug behaviour); >> MAKEFLAGS += -r >> >> -CC = $(CROSS_COMPILE)gcc >> -LD = $(CROSS_COMPILE)ld >> CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include >> >> ALL_TARGETS := spidev_test spidev_fdx >> diff --git a/tools/usb/Makefile b/tools/usb/Makefile >> index 4e6506078494..01d758d73b6d 100644 >> --- a/tools/usb/Makefile >> +++ b/tools/usb/Makefile >> @@ -1,7 +1,6 @@ >> # SPDX-License-Identifier: GPL-2.0 >> # Makefile for USB tools >> >> -CC = $(CROSS_COMPILE)gcc >> PTHREAD_LIBS = -lpthread >> WARNINGS = -Wall -Wextra >> CFLAGS = $(WARNINGS) -g -I../include >> diff --git a/tools/vm/Makefile b/tools/vm/Makefile >> index be320b905ea7..20f6cf04377f 100644 >> --- a/tools/vm/Makefile >> +++ b/tools/vm/Makefile >> @@ -6,7 +6,6 @@ TARGETS=page-types slabinfo page_owner_sort >> LIB_DIR = ../lib/api >> LIBS = $(LIB_DIR)/libapi.a >> >> -CC = $(CROSS_COMPILE)gcc >> CFLAGS = -Wall -Wextra -I../lib/ >> LDFLAGS = $(LIBS) >> >> diff --git a/tools/wmi/Makefile b/tools/wmi/Makefile >> index e664f1167388..e0e87239126b 100644 >> --- a/tools/wmi/Makefile >> +++ b/tools/wmi/Makefile >> @@ -2,7 +2,6 @@ PREFIX ?= /usr >> SBINDIR ?= sbin >> INSTALL ?= install >> CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include >> -CC = $(CROSS_COMPILE)gcc >> >> TARGET = dell-smbios-example >> >> -- >> 2.11.0 >> ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] tools: fix cross-compile var export 2018-01-07 18:31 ` Martin Kelly @ 2018-01-07 18:51 ` Martin Kelly 2018-01-08 11:45 ` Dan Carpenter 2018-01-07 19:04 ` Paul Gortmaker 1 sibling, 1 reply; 14+ messages in thread From: Martin Kelly @ 2018-01-07 18:51 UTC (permalink / raw) To: Paul Gortmaker Cc: linux-kbuild, kernel-janitors, linux-embedded, David Woodhouse, Matt Mackall, Masahiro Yamada, Michal Marek, linux-kernel On 01/07/2018 10:31 AM, Martin Kelly wrote: > On 01/07/2018 08:11 AM, Paul Gortmaker wrote: >> [[PATCH] tools: fix cross-compile var export] On 06/01/2018 (Sat >> 12:16) Martin Kelly wrote: >> >>> From: Martin Kelly <martin@martingkelly.com> >>> >>> Currently in a number of Makefiles, we clobber the CC, LD, and/or >>> STRIP env vars >>> when cross-compiling, which breaks any additional flags that might be >>> set (such >>> as sysroot). This easily shows up by using, for instance, a Yocto SDK. >>> >>> Fix this by more carefully overriding the flags in the way that the perf >>> Makefile does. >>> >>> This patch does not fix cross-compile for all the tools (some have >>> other bugs), >>> but it does appear to fix it for these: >>> >>> - cgroup >>> - freefall >>> - gpio >>> - hv >>> - iio >>> - leds >>> - spi >>> - vm >>> - wmi >>> >>> Signed-off-by: Martin Kelly <martin@martingkelly.com> >>> --- >>> This patch touches multiple subsystems, and there doesn't appear to >>> be a global >>> tools maintainer, so I sent this to linux-embedded kernel-janitors, and >>> linux-kbuild. Please let me know if there is a better place for it. >> >> I think you will have better luck if you go subsystem by subsystem, e.g. >> send gpio change to gpio maintainer, usb change to usb maintainer and so >> on. In addition, you'll want to try and understand/explain why those >> lines were added in the 1st place and how it won't break other existing >> use cases by removing them. Maybe "git blame" will help for that... >> >> P. >> -- >> > > I can send patches subsystem-by-subsystem, but this patch fixes a single > bug that applies to many Makefiles. It fixes it by putting the correct > logic into tools/scripts/Makefile.include, which each Makefiles > includes. If I do this subsystem-by-subsystem, we will just duplicate > these lines into every Makefile: > > +$(call allow-override,CC,$(CROSS_COMPILE)gcc) > +$(call allow-override,AR,$(CROSS_COMPILE)ar) > +$(call allow-override,LD,$(CROSS_COMPILE)ld) > +$(call allow-override,CXX,$(CROSS_COMPILE)g++) > +$(call allow-override,CXX,$(CROSS_COMPILE)strip) > > We could do this, but it's a lot of code duplication and means that > anyone making a new Makefile must also copy the lines or their Makefile > will have this bug. Since the bug fix generically applies everywhere, I > think it's most correct for it to go into the common Makefile. > > If there is really no maintainer for the tools/scripts/Makefile.include > file, then maybe I have to send subsystem-by-subsystem, but that seems > less than ideal. > > I do understand why the CC = $(CROSS_COMPILE)gcc lines exist; it is to > enable cross-compile when you set the $CROSS_COMPILE env var and to use > native gcc when that is not set. The bug is that if you already have $CC > set to your cross-compiler (which is what the Yocto SDK and other > toolchains do), then most of your command-line gets clobbered. Here's an > example from an ARM Yocto SDK I have: > > $ echo $CC > arm-poky-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-abi=hard > -mcpu=cortex-a8 > --sysroot=/home/martin/src/poky/build/sdk/sysroots/cortexa8hf-neon-poky-linux-gnueabi > > > $ echo $CROSS_COMPILE > arm-poky-linux-gnueabi- > > $ echo ${CROSS_COMPILE}gcc > arm-poky-linux-gnueabi-gcc > > Although arm-poky-linux-gnueabi-gcc is a cross-compiler, we've lost many > build flags, notably --sysroot, which enables us to find the right > libraries to link against. Without this change, I get this kind of error > in all the affected Makefiles: > > martin@cascade:~/src/linux/tools$ make iio > [snip] > iio_event_monitor.c:18:10: fatal error: unistd.h: No such file or directory > #include <unistd.h> > ^~~~~~~~~~ > > This occurs because unistd.h is in the sysroot, but we've dropped the > --sysroot flag: > $ find /home/martin/src/poky/build/sdk/sysroots -path > '*/usr/include/unistd.h' > /home/martin/src/poky/build/sdk/sysroots/cortexa8hf-neon-poky-linux-gnueabi/usr/include/unistd.h > > > With the change, we add do CC = $(CROSS_COMPILE)gcc if and only if CC is > not already set. I'm happy to add all these details to the commit > description. > Urg, I accidentally sent to kernel-kbuild instead of linux-kbuild, changed now. It appears that past changes to tools/scripts/Makefile.include have been handled by linux-kbuild and often Masahiro Yamada. Perhaps the best sequence here is to send a patch to kbuild adding the call-override function and calls to it to the main common Makefile. Then I can send individual subsystem patches dropping the individual CC = lines and similar. It will be 13 patches instead of 1 but will eventually result in the same thing. Paul, any thoughts? >>> >>> tools/cgroup/Makefile | 1 - >>> tools/gpio/Makefile | 2 -- >>> tools/hv/Makefile | 1 - >>> tools/iio/Makefile | 2 -- >>> tools/laptop/freefall/Makefile | 1 - >>> tools/leds/Makefile | 1 - >>> tools/perf/Makefile.perf | 6 ------ >>> tools/power/acpi/Makefile.config | 3 --- >>> tools/scripts/Makefile.include | 18 ++++++++++++++++++ >>> tools/spi/Makefile | 2 -- >>> tools/usb/Makefile | 1 - >>> tools/vm/Makefile | 1 - >>> tools/wmi/Makefile | 1 - >>> 13 files changed, 18 insertions(+), 22 deletions(-) >>> >>> diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile >>> index 860fa151640a..ffca068e4a76 100644 >>> --- a/tools/cgroup/Makefile >>> +++ b/tools/cgroup/Makefile >>> @@ -1,7 +1,6 @@ >>> # SPDX-License-Identifier: GPL-2.0 >>> # Makefile for cgroup tools >>> -CC = $(CROSS_COMPILE)gcc >>> CFLAGS = -Wall -Wextra >>> all: cgroup_event_listener >>> diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile >>> index 805a2c0cf4cd..240eda014b37 100644 >>> --- a/tools/gpio/Makefile >>> +++ b/tools/gpio/Makefile >>> @@ -12,8 +12,6 @@ endif >>> # (this improves performance and avoids hard-to-debug behaviour); >>> MAKEFLAGS += -r >>> -CC = $(CROSS_COMPILE)gcc >>> -LD = $(CROSS_COMPILE)ld >>> CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include >>> ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon >>> diff --git a/tools/hv/Makefile b/tools/hv/Makefile >>> index 31503819454d..68c2d7b059b3 100644 >>> --- a/tools/hv/Makefile >>> +++ b/tools/hv/Makefile >>> @@ -1,7 +1,6 @@ >>> # SPDX-License-Identifier: GPL-2.0 >>> # Makefile for Hyper-V tools >>> -CC = $(CROSS_COMPILE)gcc >>> WARNINGS = -Wall -Wextra >>> CFLAGS = $(WARNINGS) -g $(shell getconf LFS_CFLAGS) >>> diff --git a/tools/iio/Makefile b/tools/iio/Makefile >>> index a08e7a47d6a3..332ed2f6c2c2 100644 >>> --- a/tools/iio/Makefile >>> +++ b/tools/iio/Makefile >>> @@ -12,8 +12,6 @@ endif >>> # (this improves performance and avoids hard-to-debug behaviour); >>> MAKEFLAGS += -r >>> -CC = $(CROSS_COMPILE)gcc >>> -LD = $(CROSS_COMPILE)ld >>> CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include >>> ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer >>> diff --git a/tools/laptop/freefall/Makefile >>> b/tools/laptop/freefall/Makefile >>> index 5f758c489a20..b572d94255f6 100644 >>> --- a/tools/laptop/freefall/Makefile >>> +++ b/tools/laptop/freefall/Makefile >>> @@ -2,7 +2,6 @@ >>> PREFIX ?= /usr >>> SBINDIR ?= sbin >>> INSTALL ?= install >>> -CC = $(CROSS_COMPILE)gcc >>> TARGET = freefall >>> diff --git a/tools/leds/Makefile b/tools/leds/Makefile >>> index c379af003807..7b6bed13daaa 100644 >>> --- a/tools/leds/Makefile >>> +++ b/tools/leds/Makefile >>> @@ -1,7 +1,6 @@ >>> # SPDX-License-Identifier: GPL-2.0 >>> # Makefile for LEDs tools >>> -CC = $(CROSS_COMPILE)gcc >>> CFLAGS = -Wall -Wextra -g -I../../include/uapi >>> all: uledmon led_hw_brightness_mon >>> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf >>> index 68cf1360a3f3..3035ce5f6b36 100644 >>> --- a/tools/perf/Makefile.perf >>> +++ b/tools/perf/Makefile.perf >>> @@ -144,12 +144,6 @@ define allow-override >>> $(eval $(1) = $(2))) >>> endef >>> -# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix. >>> -$(call allow-override,CC,$(CROSS_COMPILE)gcc) >>> -$(call allow-override,AR,$(CROSS_COMPILE)ar) >>> -$(call allow-override,LD,$(CROSS_COMPILE)ld) >>> -$(call allow-override,CXX,$(CROSS_COMPILE)g++) >>> - >>> LD += $(EXTRA_LDFLAGS) >>> HOSTCC ?= gcc >>> diff --git a/tools/power/acpi/Makefile.config >>> b/tools/power/acpi/Makefile.config >>> index a1883bbb0144..2cccbba64418 100644 >>> --- a/tools/power/acpi/Makefile.config >>> +++ b/tools/power/acpi/Makefile.config >>> @@ -56,9 +56,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} >>> # to compile vs uClibc, that can be done here as well. >>> CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- >>> CROSS_COMPILE ?= $(CROSS) >>> -CC = $(CROSS_COMPILE)gcc >>> -LD = $(CROSS_COMPILE)gcc >>> -STRIP = $(CROSS_COMPILE)strip >>> HOSTCC = gcc >>> # check if compiler option is supported >>> diff --git a/tools/scripts/Makefile.include >>> b/tools/scripts/Makefile.include >>> index 3fab179b1aba..09b2d0f07f66 100644 >>> --- a/tools/scripts/Makefile.include >>> +++ b/tools/scripts/Makefile.include >>> @@ -42,6 +42,24 @@ EXTRA_WARNINGS += -Wformat >>> CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq >>> "__clang__"; echo $$?) >>> +# Makefiles suck: This macro sets a default value of $(2) for the >>> +# variable named by $(1), unless the variable has been set by >>> +# environment or command line. This is necessary for CC and AR >>> +# because make sets default values, so the simpler ?= approach >>> +# won't work as expected. >>> +define allow-override >>> + $(if $(or $(findstring environment,$(origin $(1))),\ >>> + $(findstring command line,$(origin $(1)))),,\ >>> + $(eval $(1) = $(2))) >>> +endef >>> + >>> +# Allow setting various cross-compile vars or setting CROSS_COMPILE >>> as a prefix. >>> +$(call allow-override,CC,$(CROSS_COMPILE)gcc) >>> +$(call allow-override,AR,$(CROSS_COMPILE)ar) >>> +$(call allow-override,LD,$(CROSS_COMPILE)ld) >>> +$(call allow-override,CXX,$(CROSS_COMPILE)g++) >>> +$(call allow-override,CXX,$(CROSS_COMPILE)strip) >>> + >>> ifeq ($(CC_NO_CLANG), 1) >>> EXTRA_WARNINGS += -Wstrict-aliasing=3 >>> endif >>> diff --git a/tools/spi/Makefile b/tools/spi/Makefile >>> index 90615e10c79a..815d15589177 100644 >>> --- a/tools/spi/Makefile >>> +++ b/tools/spi/Makefile >>> @@ -11,8 +11,6 @@ endif >>> # (this improves performance and avoids hard-to-debug behaviour); >>> MAKEFLAGS += -r >>> -CC = $(CROSS_COMPILE)gcc >>> -LD = $(CROSS_COMPILE)ld >>> CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include >>> ALL_TARGETS := spidev_test spidev_fdx >>> diff --git a/tools/usb/Makefile b/tools/usb/Makefile >>> index 4e6506078494..01d758d73b6d 100644 >>> --- a/tools/usb/Makefile >>> +++ b/tools/usb/Makefile >>> @@ -1,7 +1,6 @@ >>> # SPDX-License-Identifier: GPL-2.0 >>> # Makefile for USB tools >>> -CC = $(CROSS_COMPILE)gcc >>> PTHREAD_LIBS = -lpthread >>> WARNINGS = -Wall -Wextra >>> CFLAGS = $(WARNINGS) -g -I../include >>> diff --git a/tools/vm/Makefile b/tools/vm/Makefile >>> index be320b905ea7..20f6cf04377f 100644 >>> --- a/tools/vm/Makefile >>> +++ b/tools/vm/Makefile >>> @@ -6,7 +6,6 @@ TARGETS=page-types slabinfo page_owner_sort >>> LIB_DIR = ../lib/api >>> LIBS = $(LIB_DIR)/libapi.a >>> -CC = $(CROSS_COMPILE)gcc >>> CFLAGS = -Wall -Wextra -I../lib/ >>> LDFLAGS = $(LIBS) >>> diff --git a/tools/wmi/Makefile b/tools/wmi/Makefile >>> index e664f1167388..e0e87239126b 100644 >>> --- a/tools/wmi/Makefile >>> +++ b/tools/wmi/Makefile >>> @@ -2,7 +2,6 @@ PREFIX ?= /usr >>> SBINDIR ?= sbin >>> INSTALL ?= install >>> CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include >>> -CC = $(CROSS_COMPILE)gcc >>> TARGET = dell-smbios-example >>> -- >>> 2.11.0 >>> ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] tools: fix cross-compile var export 2018-01-07 18:51 ` Martin Kelly @ 2018-01-08 11:45 ` Dan Carpenter 0 siblings, 0 replies; 14+ messages in thread From: Dan Carpenter @ 2018-01-08 11:45 UTC (permalink / raw) To: Martin Kelly Cc: Paul Gortmaker, linux-kbuild, kernel-janitors, linux-embedded, David Woodhouse, Matt Mackall, Masahiro Yamada, Michal Marek, linux-kernel On Sun, Jan 07, 2018 at 10:51:21AM -0800, Martin Kelly wrote: > Urg, I accidentally sent to kernel-kbuild instead of linux-kbuild, changed > now. It appears that past changes to tools/scripts/Makefile.include have > been handled by linux-kbuild and often Masahiro Yamada. > > Perhaps the best sequence here is to send a patch to kbuild adding the > call-override function and calls to it to the main common Makefile. Then I > can send individual subsystem patches dropping the individual CC = lines and > similar. It will be 13 patches instead of 1 but will eventually result in > the same thing. > > Paul, any thoughts? > That sounds good. regards, dan carpenter ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] tools: fix cross-compile var export 2018-01-07 18:31 ` Martin Kelly 2018-01-07 18:51 ` Martin Kelly @ 2018-01-07 19:04 ` Paul Gortmaker 2018-01-07 21:43 ` Martin Kelly 1 sibling, 1 reply; 14+ messages in thread From: Paul Gortmaker @ 2018-01-07 19:04 UTC (permalink / raw) To: Martin Kelly Cc: kernel-kbuild, kernel-janitors, linux-embedded, David Woodhouse, Matt Mackall, Masahiro Yamada, Michal Marek, linux-kernel [Re: [PATCH] tools: fix cross-compile var export] On 07/01/2018 (Sun 10:31) Martin Kelly wrote: [...] > With the change, we add do CC = $(CROSS_COMPILE)gcc if and only if CC is not > already set. I'm happy to add all these details to the commit description. That is probably a step in the right direction. I contribute to yocto on a regular basis and hence am sympathetic to these frustrating SDK type issues. But after a quick scan of this patch it wasn't obvious to me that existing behaviour was preserved, or that it would be a pain to separate it into chunks. (key word here being "quick") So I'd recommend updating the commit log, and adding a Cc: line for the maintainers of each subsystem below, and then if nobody complains you might get akpm to pick it up as he does for other patches w/o a clear maintainer or subsystem. P. -- > > >> > >> tools/cgroup/Makefile | 1 - > >> tools/gpio/Makefile | 2 -- > >> tools/hv/Makefile | 1 - > >> tools/iio/Makefile | 2 -- > >> tools/laptop/freefall/Makefile | 1 - > >> tools/leds/Makefile | 1 - > >> tools/perf/Makefile.perf | 6 ------ > >> tools/power/acpi/Makefile.config | 3 --- > >> tools/scripts/Makefile.include | 18 ++++++++++++++++++ > >> tools/spi/Makefile | 2 -- > >> tools/usb/Makefile | 1 - > >> tools/vm/Makefile | 1 - > >> tools/wmi/Makefile | 1 - > >> 13 files changed, 18 insertions(+), 22 deletions(-) > >> ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] tools: fix cross-compile var export 2018-01-07 19:04 ` Paul Gortmaker @ 2018-01-07 21:43 ` Martin Kelly 0 siblings, 0 replies; 14+ messages in thread From: Martin Kelly @ 2018-01-07 21:43 UTC (permalink / raw) To: Paul Gortmaker Cc: linux-kbuild, kernel-janitors, linux-embedded, David Woodhouse, Matt Mackall, Masahiro Yamada, Michal Marek, linux-kernel On 01/07/2018 11:04 AM, Paul Gortmaker wrote: > [Re: [PATCH] tools: fix cross-compile var export] On 07/01/2018 (Sun 10:31) Martin Kelly wrote: > > [...] > >> With the change, we add do CC = $(CROSS_COMPILE)gcc if and only if CC is not >> already set. I'm happy to add all these details to the commit description. > > That is probably a step in the right direction. I contribute to yocto > on a regular basis and hence am sympathetic to these frustrating SDK > type issues. But after a quick scan of this patch it wasn't obvious to > me that existing behaviour was preserved, or that it would be a pain to > separate it into chunks. (key word here being "quick") > > So I'd recommend updating the commit log, and adding a Cc: line for the > maintainers of each subsystem below, and then if nobody complains you > might get akpm to pick it up as he does for other patches w/o a clear > maintainer or subsystem. > > P Thanks, I have done so. I also contribute to Yocto and indeed, SDK issues are all-to-common. ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2] tools: fix cross-compile var clobbering 2018-01-06 20:16 [PATCH] tools: fix cross-compile var export Martin Kelly 2018-01-07 16:11 ` Paul Gortmaker @ 2018-01-07 21:40 ` Martin Kelly 2018-01-08 11:22 ` Mark Brown 2018-04-04 13:20 ` Jiri Slaby 1 sibling, 2 replies; 14+ messages in thread From: Martin Kelly @ 2018-01-07 21:40 UTC (permalink / raw) To: linux-kbuild Cc: Martin Kelly, Tejun Heo, Li Zefan, Johannes Weiner, Linus Walleij, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Jonathan Cameron, Pali Rohár, Richard Purdie, Jacek Anaszewski, Pavel Machek, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Robert Moore, Lv Zheng, Rafael J. Wysocki, Mark Brown, Greg Kroah-Hartman, Valentina Manea, Shuah Khan, Shuah Khan, Mario Limonciello, Andrew Morton, linux-kernel From: Martin Kelly <martin@martingkelly.com> Currently a number of Makefiles break when used with toolchains that pass extra flags in CC and other cross-compile related variables (such as --sysroot). Thus we get this error when we use a toolchain that puts --sysroot in the CC var: ~/src/linux/tools$ make iio [snip] iio_event_monitor.c:18:10: fatal error: unistd.h: No such file or directory #include <unistd.h> ^~~~~~~~~~ This occurs because we clobber several env vars related to cross-compiling with lines like this: CC = $(CROSS_COMPILE)gcc Although this will point to a valid cross-compiler, we lose any extra flags that might exist in the CC variable, which can break toolchains that rely on them (for example, those that use --sysroot). This easily shows up using a Yocto SDK: $ . [snip]/sdk/environment-setup-cortexa8hf-neon-poky-linux-gnueabi $ echo $CC arm-poky-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a8 --sysroot=[snip]/sdk/sysroots/cortexa8hf-neon-poky-linux-gnueabi $ echo $CROSS_COMPILE arm-poky-linux-gnueabi- $ echo ${CROSS_COMPILE}gcc krm-poky-linux-gnueabi-gcc Although arm-poky-linux-gnueabi-gcc is a cross-compiler, we've lost the --sysroot and other flags that enable us to find the right libraries to link against, so we can't find unistd.h and other libraries and headers. Normally with the --sysroot flag we would find unistd.h in the sdk directory in the sysroot: $ find [snip]/sdk/sysroots -path '*/usr/include/unistd.h' [snip]/sdk/sysroots/cortexa8hf-neon-poky-linux-gnueabi/usr/include/unistd.h The perf Makefile adds CC = $(CROSS_COMPILE)gcc if and only if CC is not already set, and it compiles correctly with the above toolchain. So, generalize the logic that perf uses in the common Makefile and remove the manual CC = $(CROSS_COMPILE)gcc lines from each Makefile. Note that this patch does not fix cross-compile for all the tools (some have other bugs), but it does fix it for all except usb and acpi, which still have other unrelated issues. I tested both with and without the patch on native and cross-build and there appear to be no regressions. Cc: Tejun Heo <tj@kernel.org> Cc: Li Zefan <lizefan@huawei.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: "K. Y. Srinivasan" <kys@microsoft.com> Cc: Haiyang Zhang <haiyangz@microsoft.com> Cc: Stephen Hemminger <sthemmin@microsoft.com> Cc: Jonathan Cameron <jic23@kernel.org> Cc: Pali Rohár <pali.rohar@gmail.com> Cc: Richard Purdie <rpurdie@rpsys.net> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com> Cc: Pavel Machek <pavel@ucw.cz> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Robert Moore <robert.moore@intel.com> Cc: Lv Zheng <lv.zheng@intel.com> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com> Cc: Mark Brown <broonie@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Valentina Manea <valentina.manea.m@gmail.com> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Mario Limonciello <mario.limonciello@dell.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: linux-kernel@vger.kernel.org Signed-off-by: Martin Kelly <martin@martingkelly.com> --- Since there is no globals tools maintainer, I'm sending this to linux-kbuild as the closest match and CC-ing all affected subsystem maintainers. If no one has objections, I'm hoping Andrew Morton can pull in the patch. v2: - Expand commit description to fill in more detail and CC all relevant maintainers. - Fix small typo related to the STRIP variable. tools/cgroup/Makefile | 1 - tools/gpio/Makefile | 2 -- tools/hv/Makefile | 1 - tools/iio/Makefile | 2 -- tools/laptop/freefall/Makefile | 1 - tools/leds/Makefile | 1 - tools/perf/Makefile.perf | 6 ------ tools/power/acpi/Makefile.config | 3 --- tools/scripts/Makefile.include | 18 ++++++++++++++++++ tools/spi/Makefile | 2 -- tools/usb/Makefile | 1 - tools/vm/Makefile | 1 - tools/wmi/Makefile | 1 - 13 files changed, 18 insertions(+), 22 deletions(-) diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile index 860fa151640a..ffca068e4a76 100644 --- a/tools/cgroup/Makefile +++ b/tools/cgroup/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for cgroup tools -CC = $(CROSS_COMPILE)gcc CFLAGS = -Wall -Wextra all: cgroup_event_listener diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile index 805a2c0cf4cd..240eda014b37 100644 --- a/tools/gpio/Makefile +++ b/tools/gpio/Makefile @@ -12,8 +12,6 @@ endif # (this improves performance and avoids hard-to-debug behaviour); MAKEFLAGS += -r -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)ld CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon diff --git a/tools/hv/Makefile b/tools/hv/Makefile index 31503819454d..68c2d7b059b3 100644 --- a/tools/hv/Makefile +++ b/tools/hv/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Hyper-V tools -CC = $(CROSS_COMPILE)gcc WARNINGS = -Wall -Wextra CFLAGS = $(WARNINGS) -g $(shell getconf LFS_CFLAGS) diff --git a/tools/iio/Makefile b/tools/iio/Makefile index a08e7a47d6a3..332ed2f6c2c2 100644 --- a/tools/iio/Makefile +++ b/tools/iio/Makefile @@ -12,8 +12,6 @@ endif # (this improves performance and avoids hard-to-debug behaviour); MAKEFLAGS += -r -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)ld CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer diff --git a/tools/laptop/freefall/Makefile b/tools/laptop/freefall/Makefile index 5f758c489a20..b572d94255f6 100644 --- a/tools/laptop/freefall/Makefile +++ b/tools/laptop/freefall/Makefile @@ -2,7 +2,6 @@ PREFIX ?= /usr SBINDIR ?= sbin INSTALL ?= install -CC = $(CROSS_COMPILE)gcc TARGET = freefall diff --git a/tools/leds/Makefile b/tools/leds/Makefile index c379af003807..7b6bed13daaa 100644 --- a/tools/leds/Makefile +++ b/tools/leds/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for LEDs tools -CC = $(CROSS_COMPILE)gcc CFLAGS = -Wall -Wextra -g -I../../include/uapi all: uledmon led_hw_brightness_mon diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 68cf1360a3f3..3035ce5f6b36 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -144,12 +144,6 @@ define allow-override $(eval $(1) = $(2))) endef -# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix. -$(call allow-override,CC,$(CROSS_COMPILE)gcc) -$(call allow-override,AR,$(CROSS_COMPILE)ar) -$(call allow-override,LD,$(CROSS_COMPILE)ld) -$(call allow-override,CXX,$(CROSS_COMPILE)g++) - LD += $(EXTRA_LDFLAGS) HOSTCC ?= gcc diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config index a1883bbb0144..2cccbba64418 100644 --- a/tools/power/acpi/Makefile.config +++ b/tools/power/acpi/Makefile.config @@ -56,9 +56,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} # to compile vs uClibc, that can be done here as well. CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- CROSS_COMPILE ?= $(CROSS) -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)gcc -STRIP = $(CROSS_COMPILE)strip HOSTCC = gcc # check if compiler option is supported diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include index 3fab179b1aba..853e5e949c61 100644 --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include @@ -42,6 +42,24 @@ EXTRA_WARNINGS += -Wformat CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) +# Makefiles suck: This macro sets a default value of $(2) for the +# variable named by $(1), unless the variable has been set by +# environment or command line. This is necessary for CC and AR +# because make sets default values, so the simpler ?= approach +# won't work as expected. +define allow-override + $(if $(or $(findstring environment,$(origin $(1))),\ + $(findstring command line,$(origin $(1)))),,\ + $(eval $(1) = $(2))) +endef + +# Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix. +$(call allow-override,CC,$(CROSS_COMPILE)gcc) +$(call allow-override,AR,$(CROSS_COMPILE)ar) +$(call allow-override,LD,$(CROSS_COMPILE)ld) +$(call allow-override,CXX,$(CROSS_COMPILE)g++) +$(call allow-override,STRIP,$(CROSS_COMPILE)strip) + ifeq ($(CC_NO_CLANG), 1) EXTRA_WARNINGS += -Wstrict-aliasing=3 endif diff --git a/tools/spi/Makefile b/tools/spi/Makefile index 90615e10c79a..815d15589177 100644 --- a/tools/spi/Makefile +++ b/tools/spi/Makefile @@ -11,8 +11,6 @@ endif # (this improves performance and avoids hard-to-debug behaviour); MAKEFLAGS += -r -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)ld CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include ALL_TARGETS := spidev_test spidev_fdx diff --git a/tools/usb/Makefile b/tools/usb/Makefile index 4e6506078494..01d758d73b6d 100644 --- a/tools/usb/Makefile +++ b/tools/usb/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for USB tools -CC = $(CROSS_COMPILE)gcc PTHREAD_LIBS = -lpthread WARNINGS = -Wall -Wextra CFLAGS = $(WARNINGS) -g -I../include diff --git a/tools/vm/Makefile b/tools/vm/Makefile index be320b905ea7..20f6cf04377f 100644 --- a/tools/vm/Makefile +++ b/tools/vm/Makefile @@ -6,7 +6,6 @@ TARGETS=page-types slabinfo page_owner_sort LIB_DIR = ../lib/api LIBS = $(LIB_DIR)/libapi.a -CC = $(CROSS_COMPILE)gcc CFLAGS = -Wall -Wextra -I../lib/ LDFLAGS = $(LIBS) diff --git a/tools/wmi/Makefile b/tools/wmi/Makefile index e664f1167388..e0e87239126b 100644 --- a/tools/wmi/Makefile +++ b/tools/wmi/Makefile @@ -2,7 +2,6 @@ PREFIX ?= /usr SBINDIR ?= sbin INSTALL ?= install CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include -CC = $(CROSS_COMPILE)gcc TARGET = dell-smbios-example -- 2.11.0 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2] tools: fix cross-compile var clobbering 2018-01-07 21:40 ` [PATCH v2] tools: fix cross-compile var clobbering Martin Kelly @ 2018-01-08 11:22 ` Mark Brown 2018-04-04 13:20 ` Jiri Slaby 1 sibling, 0 replies; 14+ messages in thread From: Mark Brown @ 2018-01-08 11:22 UTC (permalink / raw) To: Martin Kelly Cc: linux-kbuild, Tejun Heo, Li Zefan, Johannes Weiner, Linus Walleij, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Jonathan Cameron, Pali Rohár, Richard Purdie, Jacek Anaszewski, Pavel Machek, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Robert Moore, Lv Zheng, Rafael J. Wysocki, Greg Kroah-Hartman, Valentina Manea, Shuah Khan, Shuah Khan, Mario Limonciello, Andrew Morton, linux-kernel [-- Attachment #1: Type: text/plain, Size: 409 bytes --] On Sun, Jan 07, 2018 at 01:40:28PM -0800, Martin Kelly wrote: > From: Martin Kelly <martin@martingkelly.com> > > Currently a number of Makefiles break when used with toolchains that pass > extra flags in CC and other cross-compile related variables (such as > --sysroot). Thus we get this error when we use a toolchain that puts > --sysroot in the CC var: Acked-by: Mark Brown <broonie@kernel.org> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2] tools: fix cross-compile var clobbering 2018-01-07 21:40 ` [PATCH v2] tools: fix cross-compile var clobbering Martin Kelly 2018-01-08 11:22 ` Mark Brown @ 2018-04-04 13:20 ` Jiri Slaby 2018-04-04 16:31 ` Martin Kelly 1 sibling, 1 reply; 14+ messages in thread From: Jiri Slaby @ 2018-04-04 13:20 UTC (permalink / raw) To: Martin Kelly, linux-kbuild Cc: Tejun Heo, Li Zefan, Johannes Weiner, Linus Walleij, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Jonathan Cameron, Pali Rohár, Richard Purdie, Jacek Anaszewski, Pavel Machek, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Robert Moore, Lv Zheng, Rafael J. Wysocki, Mark Brown, Greg Kroah-Hartman, Valentina Manea, Shuah Khan, Shuah Khan, Mario Limonciello, Andrew Morton, linux-kernel On 01/07/2018, 10:40 PM, Martin Kelly wrote: > From: Martin Kelly <martin@martingkelly.com> ... > --- a/tools/power/acpi/Makefile.config > +++ b/tools/power/acpi/Makefile.config > @@ -56,9 +56,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} > # to compile vs uClibc, that can be done here as well. > CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- > CROSS_COMPILE ?= $(CROSS) > -CC = $(CROSS_COMPILE)gcc > -LD = $(CROSS_COMPILE)gcc This one makes difference -- acpi is special. This used to be: LD = gcc Now it is: LD = ld And due to that, we get: ld: unrecognized option '-D_LINUX' Should we do: LD = $(CC) or fix this elsewhere differently? thanks, -- js suse labs ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2] tools: fix cross-compile var clobbering 2018-04-04 13:20 ` Jiri Slaby @ 2018-04-04 16:31 ` Martin Kelly 2018-04-24 7:43 ` [PATCH 1/1] tools: power/acpi, revert to LD = gcc Jiri Slaby 0 siblings, 1 reply; 14+ messages in thread From: Martin Kelly @ 2018-04-04 16:31 UTC (permalink / raw) To: Jiri Slaby, linux-kbuild Cc: Tejun Heo, Li Zefan, Johannes Weiner, Linus Walleij, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Jonathan Cameron, Pali Rohár, Richard Purdie, Jacek Anaszewski, Pavel Machek, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Robert Moore, Lv Zheng, Rafael J. Wysocki, Mark Brown, Greg Kroah-Hartman, Valentina Manea, Shuah Khan, Shuah Khan, Mario Limonciello, Andrew Morton, linux-kernel On 04/04/2018 06:20 AM, Jiri Slaby wrote: > On 01/07/2018, 10:40 PM, Martin Kelly wrote: >> From: Martin Kelly <martin@martingkelly.com> > ... >> --- a/tools/power/acpi/Makefile.config >> +++ b/tools/power/acpi/Makefile.config >> @@ -56,9 +56,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} >> # to compile vs uClibc, that can be done here as well. >> CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- >> CROSS_COMPILE ?= $(CROSS) >> -CC = $(CROSS_COMPILE)gcc >> -LD = $(CROSS_COMPILE)gcc > > This one makes difference -- acpi is special. This used to be: > LD = gcc > > Now it is: > LD = ld > > And due to that, we get: > ld: unrecognized option '-D_LINUX' > > Should we do: > LD = $(CC) > > or fix this elsewhere differently? > > thanks, > Yes, I think LD = $(CC) should work. $(CC) will be defaulted to $(CROSS_COMPILE)gcc due to the call to $(call allow-override,CC,$(CROSS_COMPILE)gcc) in tools/scripts/Makefile.include. The allow-override function will correctly handle env and command-line settings. This will clobber any special $(LD) settings that the user has set, but that was true as well for the acpi Makefile before this patch. ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] tools: power/acpi, revert to LD = gcc 2018-04-04 16:31 ` Martin Kelly @ 2018-04-24 7:43 ` Jiri Slaby 2018-04-24 16:38 ` Martin Kelly 2018-04-30 8:00 ` Rafael J. Wysocki 0 siblings, 2 replies; 14+ messages in thread From: Jiri Slaby @ 2018-04-24 7:43 UTC (permalink / raw) To: rjw Cc: linux-kernel, Jiri Slaby, Martin Kelly, Len Brown, Robert Moore, Erik Schmauss, linux-acpi, devel Commit 7ed1c1901fe5 (tools: fix cross-compile var clobbering) removed setting of LD to $(CROSS_COMPILE)gcc. This broke build of acpica (acpidump) in power/acpi: ld: unrecognized option '-D_LINUX' The tools pass CFLAGS to the linker (incl. -D_LINUX), so revert this particular change and let LD be $(CC) again. Note that the old behaviour was a bit different, it used $(CROSS_COMPILE)gcc which was eliminated by the commit 7ed1c1901fe5. We use $(CC) for that reason. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Martin Kelly <martin@martingkelly.com> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> Cc: Len Brown <lenb@kernel.org> Cc: Robert Moore <robert.moore@intel.com> Cc: Erik Schmauss <erik.schmauss@intel.com> Cc: linux-acpi@vger.kernel.org Cc: devel@acpica.org --- tools/power/acpi/Makefile.config | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config index 2cccbba64418..f304be71c278 100644 --- a/tools/power/acpi/Makefile.config +++ b/tools/power/acpi/Makefile.config @@ -56,6 +56,7 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} # to compile vs uClibc, that can be done here as well. CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- CROSS_COMPILE ?= $(CROSS) +LD = $(CC) HOSTCC = gcc # check if compiler option is supported -- 2.16.3 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/1] tools: power/acpi, revert to LD = gcc 2018-04-24 7:43 ` [PATCH 1/1] tools: power/acpi, revert to LD = gcc Jiri Slaby @ 2018-04-24 16:38 ` Martin Kelly 2018-04-30 8:00 ` Rafael J. Wysocki 1 sibling, 0 replies; 14+ messages in thread From: Martin Kelly @ 2018-04-24 16:38 UTC (permalink / raw) To: Jiri Slaby Cc: rjw, linux-kernel, Len Brown, Robert Moore, Erik Schmauss, linux-acpi, devel On Tue, Apr 24, 2018 at 12:43 AM, Jiri Slaby <jslaby@suse.cz> wrote: > Commit 7ed1c1901fe5 (tools: fix cross-compile var clobbering) removed > setting of LD to $(CROSS_COMPILE)gcc. This broke build of acpica > (acpidump) in power/acpi: > ld: unrecognized option '-D_LINUX' > > The tools pass CFLAGS to the linker (incl. -D_LINUX), so revert this > particular change and let LD be $(CC) again. Note that the old behaviour > was a bit different, it used $(CROSS_COMPILE)gcc which was eliminated by > the commit 7ed1c1901fe5. We use $(CC) for that reason. > > Signed-off-by: Jiri Slaby <jslaby@suse.cz> > Cc: Martin Kelly <martin@martingkelly.com> > Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> > Cc: Len Brown <lenb@kernel.org> > Cc: Robert Moore <robert.moore@intel.com> > Cc: Erik Schmauss <erik.schmauss@intel.com> > Cc: linux-acpi@vger.kernel.org > Cc: devel@acpica.org > --- > tools/power/acpi/Makefile.config | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config > index 2cccbba64418..f304be71c278 100644 > --- a/tools/power/acpi/Makefile.config > +++ b/tools/power/acpi/Makefile.config > @@ -56,6 +56,7 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} > # to compile vs uClibc, that can be done here as well. > CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- > CROSS_COMPILE ?= $(CROSS) > +LD = $(CC) > HOSTCC = gcc > > # check if compiler option is supported > -- > 2.16.3 > Reviewed-by: Martin Kelly <martin@martingkelly.com> Thanks for noticing this and sorry I missed it! ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/1] tools: power/acpi, revert to LD = gcc 2018-04-24 7:43 ` [PATCH 1/1] tools: power/acpi, revert to LD = gcc Jiri Slaby 2018-04-24 16:38 ` Martin Kelly @ 2018-04-30 8:00 ` Rafael J. Wysocki 1 sibling, 0 replies; 14+ messages in thread From: Rafael J. Wysocki @ 2018-04-30 8:00 UTC (permalink / raw) To: Jiri Slaby Cc: linux-kernel, Martin Kelly, Len Brown, Robert Moore, Erik Schmauss, linux-acpi, devel On Tuesday, April 24, 2018 9:43:44 AM CEST Jiri Slaby wrote: > Commit 7ed1c1901fe5 (tools: fix cross-compile var clobbering) removed > setting of LD to $(CROSS_COMPILE)gcc. This broke build of acpica > (acpidump) in power/acpi: > ld: unrecognized option '-D_LINUX' > > The tools pass CFLAGS to the linker (incl. -D_LINUX), so revert this > particular change and let LD be $(CC) again. Note that the old behaviour > was a bit different, it used $(CROSS_COMPILE)gcc which was eliminated by > the commit 7ed1c1901fe5. We use $(CC) for that reason. > > Signed-off-by: Jiri Slaby <jslaby@suse.cz> > Cc: Martin Kelly <martin@martingkelly.com> > Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> > Cc: Len Brown <lenb@kernel.org> > Cc: Robert Moore <robert.moore@intel.com> > Cc: Erik Schmauss <erik.schmauss@intel.com> > Cc: linux-acpi@vger.kernel.org > Cc: devel@acpica.org > --- > tools/power/acpi/Makefile.config | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config > index 2cccbba64418..f304be71c278 100644 > --- a/tools/power/acpi/Makefile.config > +++ b/tools/power/acpi/Makefile.config > @@ -56,6 +56,7 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} > # to compile vs uClibc, that can be done here as well. > CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- > CROSS_COMPILE ?= $(CROSS) > +LD = $(CC) > HOSTCC = gcc > > # check if compiler option is supported > Applied, thanks! ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2018-04-30 8:01 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-01-06 20:16 [PATCH] tools: fix cross-compile var export Martin Kelly 2018-01-07 16:11 ` Paul Gortmaker 2018-01-07 18:31 ` Martin Kelly 2018-01-07 18:51 ` Martin Kelly 2018-01-08 11:45 ` Dan Carpenter 2018-01-07 19:04 ` Paul Gortmaker 2018-01-07 21:43 ` Martin Kelly 2018-01-07 21:40 ` [PATCH v2] tools: fix cross-compile var clobbering Martin Kelly 2018-01-08 11:22 ` Mark Brown 2018-04-04 13:20 ` Jiri Slaby 2018-04-04 16:31 ` Martin Kelly 2018-04-24 7:43 ` [PATCH 1/1] tools: power/acpi, revert to LD = gcc Jiri Slaby 2018-04-24 16:38 ` Martin Kelly 2018-04-30 8:00 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).