Skip to content

Commit 4ce6efe

Browse files
author
Sam Ravnborg
committed
kbuild: soften modpost checks when doing cross builds
The module alias support in the kernel have a consistency check where it is checked that the size of a structure in the kernel and on the build host are the same. For cross builds this check does not make sense so detect when we do cross builds and silently skip the check in these situations. This fixes a build bug for a wireless driver when cross building for arm. Acked-by: Michael Buesch <mb@bu3sch.de> Tested-by: Gordon Farquharson <gordonfarquharson@gmail.com> Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Cc: stable@kernel.org
1 parent d2532dd commit 4ce6efe

5 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
189189
# Alternatively CROSS_COMPILE can be set in the environment.
190190
# Default value for CROSS_COMPILE is not to prefix executables
191191
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
192-
192+
export KBUILD_BUILDHOST := $(SUBARCH)
193193
ARCH ?= $(SUBARCH)
194194
CROSS_COMPILE ?=
195195

‎scripts/Makefile.modpost‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o)))
5858
# Stop after building .o files if NOFINAL is set. Makes compile tests quicker
5959
_modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
6060

61+
ifneq ($(KBUILD_BUILDHOST),$(ARCH))
62+
cross_build := 1
63+
endif
6164

6265
# Step 2), invoke modpost
6366
# Includes step 3,4
@@ -70,7 +73,8 @@ modpost = scripts/mod/modpost \
7073
$(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \
7174
$(if $(CONFIG_MARKERS),-K $(kernelmarkersfile)) \
7275
$(if $(CONFIG_MARKERS),-M $(markersfile)) \
73-
$(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w)
76+
$(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) \
77+
$(if $(cross_build),-c)
7478

7579
quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules
7680
cmd_modpost = $(modpost) -s

‎scripts/mod/file2alias.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ do { \
5151
sprintf(str + strlen(str), "*"); \
5252
} while(0)
5353

54+
unsigned int cross_build = 0;
5455
/**
5556
* Check that sizeof(device_id type) are consistent with size of section
5657
* in .o file. If in-consistent then userspace and kernel does not agree
5758
* on actual size which is a bug.
5859
* Also verify that the final entry in the table is all zeros.
60+
* Ignore both checks if build host differ from target host and size differs.
5961
**/
6062
static void device_id_check(const char *modname, const char *device_id,
6163
unsigned long size, unsigned long id_size,
@@ -64,6 +66,8 @@ static void device_id_check(const char *modname, const char *device_id,
6466
int i;
6567

6668
if (size % id_size || size < id_size) {
69+
if (cross_build != 0)
70+
return;
6771
fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
6872
"of the size of section __mod_%s_device_table=%lu.\n"
6973
"Fix definition of struct %s_device_id "

‎scripts/mod/modpost.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ int main(int argc, char **argv)
20262026
int opt;
20272027
int err;
20282028

2029-
while ((opt = getopt(argc, argv, "i:I:msSo:awM:K:")) != -1) {
2029+
while ((opt = getopt(argc, argv, "i:I:cmsSo:awM:K:")) != -1) {
20302030
switch (opt) {
20312031
case 'i':
20322032
kernel_read = optarg;
@@ -2035,6 +2035,9 @@ int main(int argc, char **argv)
20352035
module_read = optarg;
20362036
external_module = 1;
20372037
break;
2038+
case 'c':
2039+
cross_build = 1;
2040+
break;
20382041
case 'm':
20392042
modversions = 1;
20402043
break;

‎scripts/mod/modpost.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct elf_info {
135135
};
136136

137137
/* file2alias.c */
138+
extern unsigned int cross_build;
138139
void handle_moddevtable(struct module *mod, struct elf_info *info,
139140
Elf_Sym *sym, const char *symname);
140141
void add_moddevtable(struct buffer *buf, struct module *mod);

0 commit comments

Comments
 (0)