Skip to content

Commit 6543bec

Browse files
andreas-schwabmichal42
authored andcommitted
mod/file2alias: make modalias generation safe for cross compiling
Use the target compiler to compute the offsets for the fields of the device_id structures, so that it won't be broken by different alignments between the host and target ABIs. This also fixes missing endian corrections for some modaliases. Signed-off-by: Andreas Schwab <schwab@linux-m68k.org> Signed-off-by: Michal Marek <mmarek@suse.cz>
1 parent a49f0d1 commit 6543bec

8 files changed

Lines changed: 591 additions & 368 deletions

File tree

‎Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
191191
# "make" in the configured kernel build directory always uses that.
192192
# Default value for CROSS_COMPILE is not to prefix executables
193193
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
194-
export KBUILD_BUILDHOST := $(SUBARCH)
195194
ARCH ?= $(SUBARCH)
196195
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
197196

‎include/linux/mod_devicetable.h‎

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ struct ieee1394_device_id {
3333
__u32 model_id;
3434
__u32 specifier_id;
3535
__u32 version;
36-
kernel_ulong_t driver_data
37-
__attribute__((aligned(sizeof(kernel_ulong_t))));
36+
kernel_ulong_t driver_data;
3837
};
3938

4039

@@ -148,8 +147,7 @@ struct hid_device_id {
148147
__u16 group;
149148
__u32 vendor;
150149
__u32 product;
151-
kernel_ulong_t driver_data
152-
__attribute__((aligned(sizeof(kernel_ulong_t))));
150+
kernel_ulong_t driver_data;
153151
};
154152

155153
/* s390 CCW devices */
@@ -173,8 +171,6 @@ struct ccw_device_id {
173171
struct ap_device_id {
174172
__u16 match_flags; /* which fields to match against */
175173
__u8 dev_type; /* device type */
176-
__u8 pad1;
177-
__u32 pad2;
178174
kernel_ulong_t driver_info;
179175
};
180176

@@ -184,13 +180,10 @@ struct ap_device_id {
184180
struct css_device_id {
185181
__u8 match_flags;
186182
__u8 type; /* subchannel type */
187-
__u16 pad2;
188-
__u32 pad3;
189183
kernel_ulong_t driver_data;
190184
};
191185

192-
#define ACPI_ID_LEN 16 /* only 9 bytes needed here, 16 bytes are used */
193-
/* to workaround crosscompile issues */
186+
#define ACPI_ID_LEN 9
194187

195188
struct acpi_device_id {
196189
__u8 id[ACPI_ID_LEN];
@@ -231,11 +224,7 @@ struct of_device_id
231224
char name[32];
232225
char type[32];
233226
char compatible[128];
234-
#ifdef __KERNEL__
235227
const void *data;
236-
#else
237-
kernel_ulong_t data;
238-
#endif
239228
};
240229

241230
/* VIO */
@@ -260,24 +249,14 @@ struct pcmcia_device_id {
260249
/* for pseudo multi-function devices */
261250
__u8 device_no;
262251

263-
__u32 prod_id_hash[4]
264-
__attribute__((aligned(sizeof(__u32))));
252+
__u32 prod_id_hash[4];
265253

266254
/* not matched against in kernelspace*/
267-
#ifdef __KERNEL__
268255
const char * prod_id[4];
269-
#else
270-
kernel_ulong_t prod_id[4]
271-
__attribute__((aligned(sizeof(kernel_ulong_t))));
272-
#endif
273256

274257
/* not matched against */
275258
kernel_ulong_t driver_info;
276-
#ifdef __KERNEL__
277259
char * cisfile;
278-
#else
279-
kernel_ulong_t cisfile;
280-
#endif
281260
};
282261

283262
#define PCMCIA_DEV_ID_MATCH_MANF_ID 0x0001
@@ -373,8 +352,7 @@ struct sdio_device_id {
373352
__u8 class; /* Standard interface or SDIO_ANY_ID */
374353
__u16 vendor; /* Vendor or SDIO_ANY_ID */
375354
__u16 device; /* Device ID or SDIO_ANY_ID */
376-
kernel_ulong_t driver_data /* Data private to the driver */
377-
__attribute__((aligned(sizeof(kernel_ulong_t))));
355+
kernel_ulong_t driver_data; /* Data private to the driver */
378356
};
379357

380358
/* SSB core, see drivers/ssb/ */
@@ -420,8 +398,7 @@ struct virtio_device_id {
420398
*/
421399
struct hv_vmbus_device_id {
422400
__u8 guid[16];
423-
kernel_ulong_t driver_data /* Data private to the driver */
424-
__attribute__((aligned(sizeof(kernel_ulong_t))));
401+
kernel_ulong_t driver_data; /* Data private to the driver */
425402
};
426403

427404
/* rpmsg */
@@ -440,8 +417,7 @@ struct rpmsg_device_id {
440417

441418
struct i2c_device_id {
442419
char name[I2C_NAME_SIZE];
443-
kernel_ulong_t driver_data /* Data private to the driver */
444-
__attribute__((aligned(sizeof(kernel_ulong_t))));
420+
kernel_ulong_t driver_data; /* Data private to the driver */
445421
};
446422

447423
/* spi */
@@ -451,8 +427,7 @@ struct i2c_device_id {
451427

452428
struct spi_device_id {
453429
char name[SPI_NAME_SIZE];
454-
kernel_ulong_t driver_data /* Data private to the driver */
455-
__attribute__((aligned(sizeof(kernel_ulong_t))));
430+
kernel_ulong_t driver_data; /* Data private to the driver */
456431
};
457432

458433
/* dmi */
@@ -484,15 +459,6 @@ struct dmi_strmatch {
484459
char substr[79];
485460
};
486461

487-
#ifndef __KERNEL__
488-
struct dmi_system_id {
489-
kernel_ulong_t callback;
490-
kernel_ulong_t ident;
491-
struct dmi_strmatch matches[4];
492-
kernel_ulong_t driver_data
493-
__attribute__((aligned(sizeof(kernel_ulong_t))));
494-
};
495-
#else
496462
struct dmi_system_id {
497463
int (*callback)(const struct dmi_system_id *);
498464
const char *ident;
@@ -506,7 +472,6 @@ struct dmi_system_id {
506472
* error: storage size of '__mod_dmi_device_table' isn't known
507473
*/
508474
#define dmi_device_id dmi_system_id
509-
#endif
510475

511476
#define DMI_MATCH(a, b) { a, b }
512477

@@ -515,8 +480,7 @@ struct dmi_system_id {
515480

516481
struct platform_device_id {
517482
char name[PLATFORM_NAME_SIZE];
518-
kernel_ulong_t driver_data
519-
__attribute__((aligned(sizeof(kernel_ulong_t))));
483+
kernel_ulong_t driver_data;
520484
};
521485

522486
#define MDIO_MODULE_PREFIX "mdio:"
@@ -572,11 +536,7 @@ struct isapnp_device_id {
572536
struct amba_id {
573537
unsigned int id;
574538
unsigned int mask;
575-
#ifndef __KERNEL__
576-
kernel_ulong_t data;
577-
#else
578539
void *data;
579-
#endif
580540
};
581541

582542
/*

‎scripts/Makefile.modpost‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o)))
6666
# Stop after building .o files if NOFINAL is set. Makes compile tests quicker
6767
_modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
6868

69-
ifneq ($(KBUILD_BUILDHOST),$(ARCH))
70-
cross_build := 1
71-
endif
72-
7369
# Step 2), invoke modpost
7470
# Includes step 3,4
7571
modpost = scripts/mod/modpost \
@@ -80,8 +76,7 @@ modpost = scripts/mod/modpost \
8076
$(if $(KBUILD_EXTRA_SYMBOLS), $(patsubst %, -e %,$(KBUILD_EXTRA_SYMBOLS))) \
8177
$(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
8278
$(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \
83-
$(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) \
84-
$(if $(cross_build),-c)
79+
$(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w)
8580

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

‎scripts/mod/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
elfconfig.h
22
mk_elfconfig
33
modpost
4+
devicetable-offsets.h
45

‎scripts/mod/Makefile‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,44 @@ always := $(hostprogs-y) empty.o
33

44
modpost-objs := modpost.o file2alias.o sumversion.o
55

6+
devicetable-offsets-file := devicetable-offsets.h
7+
8+
define sed-y
9+
"/^->/{s:->#\(.*\):/* \1 */:; \
10+
s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
11+
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
12+
s:->::; p;}"
13+
endef
14+
15+
quiet_cmd_offsets = GEN $@
16+
define cmd_offsets
17+
(set -e; \
18+
echo "#ifndef __DEVICEVTABLE_OFFSETS_H__"; \
19+
echo "#define __DEVICEVTABLE_OFFSETS_H__"; \
20+
echo "/*"; \
21+
echo " * DO NOT MODIFY."; \
22+
echo " *"; \
23+
echo " * This file was generated by Kbuild"; \
24+
echo " *"; \
25+
echo " */"; \
26+
echo ""; \
27+
sed -ne $(sed-y) $<; \
28+
echo ""; \
29+
echo "#endif" ) > $@
30+
endef
31+
32+
# We use internal kbuild rules to avoid the "is up to date" message from make
33+
scripts/mod/devicetable-offsets.s: scripts/mod/devicetable-offsets.c FORCE
34+
$(Q)mkdir -p $(dir $@)
35+
$(call if_changed_dep,cc_s_c)
36+
37+
$(obj)/$(devicetable-offsets-file): scripts/mod/devicetable-offsets.s
38+
$(call cmd,offsets)
39+
640
# dependencies on generated files need to be listed explicitly
741

842
$(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h
43+
$(obj)/file2alias.o: $(obj)/$(devicetable-offsets-file)
944

1045
quiet_cmd_elfconfig = MKELF $@
1146
cmd_elfconfig = $(obj)/mk_elfconfig < $< > $@

0 commit comments

Comments
 (0)