]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/modpost-file2alias-go-back-to-simple-devtable-lookup.patch
Linux 4.14.114
[thirdparty/kernel/stable-queue.git] / queue-4.19 / modpost-file2alias-go-back-to-simple-devtable-lookup.patch
1 From 00032cc74576ada61fb8057f08b655d703b9c9f1 Mon Sep 17 00:00:00 2001
2 From: Masahiro Yamada <yamada.masahiro@socionext.com>
3 Date: Thu, 22 Nov 2018 13:28:41 +0900
4 Subject: modpost: file2alias: go back to simple devtable lookup
5
6 [ Upstream commit ec91e78d378cc5d4b43805a1227d8e04e5dfa17d ]
7
8 Commit e49ce14150c6 ("modpost: use linker section to generate table.")
9 was not so cool as we had expected first; it ended up with ugly section
10 hacks when commit dd2a3acaecd7 ("mod/file2alias: make modpost compile
11 on darwin again") came in.
12
13 Given a certain degree of unknowledge about the link stage of host
14 programs, I really want to see simple, stupid table lookup so that
15 this works in the same way regardless of the underlying executable
16 format.
17
18 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
19 Acked-by: Mathieu Malaterre <malat@debian.org>
20 Signed-off-by: Sasha Levin <sashal@kernel.org>
21 ---
22 scripts/mod/file2alias.c | 144 +++++++++++++--------------------------
23 1 file changed, 49 insertions(+), 95 deletions(-)
24
25 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
26 index 7be43697ff84..9f3ebde7a0cd 100644
27 --- a/scripts/mod/file2alias.c
28 +++ b/scripts/mod/file2alias.c
29 @@ -50,46 +50,6 @@ struct devtable {
30 void *function;
31 };
32
33 -#define ___cat(a,b) a ## b
34 -#define __cat(a,b) ___cat(a,b)
35 -
36 -/* we need some special handling for this host tool running eventually on
37 - * Darwin. The Mach-O section handling is a bit different than ELF section
38 - * handling. The differnces in detail are:
39 - * a) we have segments which have sections
40 - * b) we need a API call to get the respective section symbols */
41 -#if defined(__MACH__)
42 -#include <mach-o/getsect.h>
43 -
44 -#define INIT_SECTION(name) do { \
45 - unsigned long name ## _len; \
46 - char *__cat(pstart_,name) = getsectdata("__TEXT", \
47 - #name, &__cat(name,_len)); \
48 - char *__cat(pstop_,name) = __cat(pstart_,name) + \
49 - __cat(name, _len); \
50 - __cat(__start_,name) = (void *)__cat(pstart_,name); \
51 - __cat(__stop_,name) = (void *)__cat(pstop_,name); \
52 - } while (0)
53 -#define SECTION(name) __attribute__((section("__TEXT, " #name)))
54 -
55 -struct devtable **__start___devtable, **__stop___devtable;
56 -#else
57 -#define INIT_SECTION(name) /* no-op for ELF */
58 -#define SECTION(name) __attribute__((section(#name)))
59 -
60 -/* We construct a table of pointers in an ELF section (pointers generally
61 - * go unpadded by gcc). ld creates boundary syms for us. */
62 -extern struct devtable *__start___devtable[], *__stop___devtable[];
63 -#endif /* __MACH__ */
64 -
65 -#if !defined(__used)
66 -# if __GNUC__ == 3 && __GNUC_MINOR__ < 3
67 -# define __used __attribute__((__unused__))
68 -# else
69 -# define __used __attribute__((__used__))
70 -# endif
71 -#endif
72 -
73 /* Define a variable f that holds the value of field f of struct devid
74 * based at address m.
75 */
76 @@ -102,16 +62,6 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
77 #define DEF_FIELD_ADDR(m, devid, f) \
78 typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
79
80 -/* Add a table entry. We test function type matches while we're here. */
81 -#define ADD_TO_DEVTABLE(device_id, type, function) \
82 - static struct devtable __cat(devtable,__LINE__) = { \
83 - device_id + 0*sizeof((function)((const char *)NULL, \
84 - (void *)NULL, \
85 - (char *)NULL)), \
86 - SIZE_##type, (function) }; \
87 - static struct devtable *SECTION(__devtable) __used \
88 - __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
89 -
90 #define ADD(str, sep, cond, field) \
91 do { \
92 strcat(str, sep); \
93 @@ -431,7 +381,6 @@ static int do_hid_entry(const char *filename,
94
95 return 1;
96 }
97 -ADD_TO_DEVTABLE("hid", hid_device_id, do_hid_entry);
98
99 /* Looks like: ieee1394:venNmoNspNverN */
100 static int do_ieee1394_entry(const char *filename,
101 @@ -456,7 +405,6 @@ static int do_ieee1394_entry(const char *filename,
102 add_wildcard(alias);
103 return 1;
104 }
105 -ADD_TO_DEVTABLE("ieee1394", ieee1394_device_id, do_ieee1394_entry);
106
107 /* Looks like: pci:vNdNsvNsdNbcNscNiN. */
108 static int do_pci_entry(const char *filename,
109 @@ -500,7 +448,6 @@ static int do_pci_entry(const char *filename,
110 add_wildcard(alias);
111 return 1;
112 }
113 -ADD_TO_DEVTABLE("pci", pci_device_id, do_pci_entry);
114
115 /* looks like: "ccw:tNmNdtNdmN" */
116 static int do_ccw_entry(const char *filename,
117 @@ -524,7 +471,6 @@ static int do_ccw_entry(const char *filename,
118 add_wildcard(alias);
119 return 1;
120 }
121 -ADD_TO_DEVTABLE("ccw", ccw_device_id, do_ccw_entry);
122
123 /* looks like: "ap:tN" */
124 static int do_ap_entry(const char *filename,
125 @@ -535,7 +481,6 @@ static int do_ap_entry(const char *filename,
126 sprintf(alias, "ap:t%02X*", dev_type);
127 return 1;
128 }
129 -ADD_TO_DEVTABLE("ap", ap_device_id, do_ap_entry);
130
131 /* looks like: "css:tN" */
132 static int do_css_entry(const char *filename,
133 @@ -546,7 +491,6 @@ static int do_css_entry(const char *filename,
134 sprintf(alias, "css:t%01X", type);
135 return 1;
136 }
137 -ADD_TO_DEVTABLE("css", css_device_id, do_css_entry);
138
139 /* Looks like: "serio:tyNprNidNexN" */
140 static int do_serio_entry(const char *filename,
141 @@ -566,7 +510,6 @@ static int do_serio_entry(const char *filename,
142 add_wildcard(alias);
143 return 1;
144 }
145 -ADD_TO_DEVTABLE("serio", serio_device_id, do_serio_entry);
146
147 /* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B" or "acpi:LNXVIDEO" or
148 * "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if)
149 @@ -604,7 +547,6 @@ static int do_acpi_entry(const char *filename,
150 }
151 return 1;
152 }
153 -ADD_TO_DEVTABLE("acpi", acpi_device_id, do_acpi_entry);
154
155 /* looks like: "pnp:dD" */
156 static void do_pnp_device_entry(void *symval, unsigned long size,
157 @@ -725,7 +667,6 @@ static int do_pcmcia_entry(const char *filename,
158 add_wildcard(alias);
159 return 1;
160 }
161 -ADD_TO_DEVTABLE("pcmcia", pcmcia_device_id, do_pcmcia_entry);
162
163 static int do_vio_entry(const char *filename, void *symval,
164 char *alias)
165 @@ -745,7 +686,6 @@ static int do_vio_entry(const char *filename, void *symval,
166 add_wildcard(alias);
167 return 1;
168 }
169 -ADD_TO_DEVTABLE("vio", vio_device_id, do_vio_entry);
170
171 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
172
173 @@ -818,7 +758,6 @@ static int do_input_entry(const char *filename, void *symval,
174 do_input(alias, *swbit, 0, INPUT_DEVICE_ID_SW_MAX);
175 return 1;
176 }
177 -ADD_TO_DEVTABLE("input", input_device_id, do_input_entry);
178
179 static int do_eisa_entry(const char *filename, void *symval,
180 char *alias)
181 @@ -830,7 +769,6 @@ static int do_eisa_entry(const char *filename, void *symval,
182 strcat(alias, "*");
183 return 1;
184 }
185 -ADD_TO_DEVTABLE("eisa", eisa_device_id, do_eisa_entry);
186
187 /* Looks like: parisc:tNhvNrevNsvN */
188 static int do_parisc_entry(const char *filename, void *symval,
189 @@ -850,7 +788,6 @@ static int do_parisc_entry(const char *filename, void *symval,
190 add_wildcard(alias);
191 return 1;
192 }
193 -ADD_TO_DEVTABLE("parisc", parisc_device_id, do_parisc_entry);
194
195 /* Looks like: sdio:cNvNdN. */
196 static int do_sdio_entry(const char *filename,
197 @@ -867,7 +804,6 @@ static int do_sdio_entry(const char *filename,
198 add_wildcard(alias);
199 return 1;
200 }
201 -ADD_TO_DEVTABLE("sdio", sdio_device_id, do_sdio_entry);
202
203 /* Looks like: ssb:vNidNrevN. */
204 static int do_ssb_entry(const char *filename,
205 @@ -884,7 +820,6 @@ static int do_ssb_entry(const char *filename,
206 add_wildcard(alias);
207 return 1;
208 }
209 -ADD_TO_DEVTABLE("ssb", ssb_device_id, do_ssb_entry);
210
211 /* Looks like: bcma:mNidNrevNclN. */
212 static int do_bcma_entry(const char *filename,
213 @@ -903,7 +838,6 @@ static int do_bcma_entry(const char *filename,
214 add_wildcard(alias);
215 return 1;
216 }
217 -ADD_TO_DEVTABLE("bcma", bcma_device_id, do_bcma_entry);
218
219 /* Looks like: virtio:dNvN */
220 static int do_virtio_entry(const char *filename, void *symval,
221 @@ -919,7 +853,6 @@ static int do_virtio_entry(const char *filename, void *symval,
222 add_wildcard(alias);
223 return 1;
224 }
225 -ADD_TO_DEVTABLE("virtio", virtio_device_id, do_virtio_entry);
226
227 /*
228 * Looks like: vmbus:guid
229 @@ -942,7 +875,6 @@ static int do_vmbus_entry(const char *filename, void *symval,
230
231 return 1;
232 }
233 -ADD_TO_DEVTABLE("vmbus", hv_vmbus_device_id, do_vmbus_entry);
234
235 /* Looks like: rpmsg:S */
236 static int do_rpmsg_entry(const char *filename, void *symval,
237 @@ -953,7 +885,6 @@ static int do_rpmsg_entry(const char *filename, void *symval,
238
239 return 1;
240 }
241 -ADD_TO_DEVTABLE("rpmsg", rpmsg_device_id, do_rpmsg_entry);
242
243 /* Looks like: i2c:S */
244 static int do_i2c_entry(const char *filename, void *symval,
245 @@ -964,7 +895,6 @@ static int do_i2c_entry(const char *filename, void *symval,
246
247 return 1;
248 }
249 -ADD_TO_DEVTABLE("i2c", i2c_device_id, do_i2c_entry);
250
251 /* Looks like: spi:S */
252 static int do_spi_entry(const char *filename, void *symval,
253 @@ -975,7 +905,6 @@ static int do_spi_entry(const char *filename, void *symval,
254
255 return 1;
256 }
257 -ADD_TO_DEVTABLE("spi", spi_device_id, do_spi_entry);
258
259 static const struct dmifield {
260 const char *prefix;
261 @@ -1030,7 +959,6 @@ static int do_dmi_entry(const char *filename, void *symval,
262 strcat(alias, ":");
263 return 1;
264 }
265 -ADD_TO_DEVTABLE("dmi", dmi_system_id, do_dmi_entry);
266
267 static int do_platform_entry(const char *filename,
268 void *symval, char *alias)
269 @@ -1039,7 +967,6 @@ static int do_platform_entry(const char *filename,
270 sprintf(alias, PLATFORM_MODULE_PREFIX "%s", *name);
271 return 1;
272 }
273 -ADD_TO_DEVTABLE("platform", platform_device_id, do_platform_entry);
274
275 static int do_mdio_entry(const char *filename,
276 void *symval, char *alias)
277 @@ -1064,7 +991,6 @@ static int do_mdio_entry(const char *filename,
278
279 return 1;
280 }
281 -ADD_TO_DEVTABLE("mdio", mdio_device_id, do_mdio_entry);
282
283 /* Looks like: zorro:iN. */
284 static int do_zorro_entry(const char *filename, void *symval,
285 @@ -1075,7 +1001,6 @@ static int do_zorro_entry(const char *filename, void *symval,
286 ADD(alias, "i", id != ZORRO_WILDCARD, id);
287 return 1;
288 }
289 -ADD_TO_DEVTABLE("zorro", zorro_device_id, do_zorro_entry);
290
291 /* looks like: "pnp:dD" */
292 static int do_isapnp_entry(const char *filename,
293 @@ -1091,7 +1016,6 @@ static int do_isapnp_entry(const char *filename,
294 (function >> 12) & 0x0f, (function >> 8) & 0x0f);
295 return 1;
296 }
297 -ADD_TO_DEVTABLE("isapnp", isapnp_device_id, do_isapnp_entry);
298
299 /* Looks like: "ipack:fNvNdN". */
300 static int do_ipack_entry(const char *filename,
301 @@ -1107,7 +1031,6 @@ static int do_ipack_entry(const char *filename,
302 add_wildcard(alias);
303 return 1;
304 }
305 -ADD_TO_DEVTABLE("ipack", ipack_device_id, do_ipack_entry);
306
307 /*
308 * Append a match expression for a single masked hex digit.
309 @@ -1178,7 +1101,6 @@ static int do_amba_entry(const char *filename,
310
311 return 1;
312 }
313 -ADD_TO_DEVTABLE("amba", amba_id, do_amba_entry);
314
315 /*
316 * looks like: "mipscdmm:tN"
317 @@ -1194,7 +1116,6 @@ static int do_mips_cdmm_entry(const char *filename,
318 sprintf(alias, "mipscdmm:t%02X*", type);
319 return 1;
320 }
321 -ADD_TO_DEVTABLE("mipscdmm", mips_cdmm_device_id, do_mips_cdmm_entry);
322
323 /* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,*
324 * All fields are numbers. It would be nicer to use strings for vendor
325 @@ -1219,7 +1140,6 @@ static int do_x86cpu_entry(const char *filename, void *symval,
326 sprintf(alias + strlen(alias), "%04X*", feature);
327 return 1;
328 }
329 -ADD_TO_DEVTABLE("x86cpu", x86_cpu_id, do_x86cpu_entry);
330
331 /* LOOKS like cpu:type:*:feature:*FEAT* */
332 static int do_cpu_entry(const char *filename, void *symval, char *alias)
333 @@ -1229,7 +1149,6 @@ static int do_cpu_entry(const char *filename, void *symval, char *alias)
334 sprintf(alias, "cpu:type:*:feature:*%04X*", feature);
335 return 1;
336 }
337 -ADD_TO_DEVTABLE("cpu", cpu_feature, do_cpu_entry);
338
339 /* Looks like: mei:S:uuid:N:* */
340 static int do_mei_entry(const char *filename, void *symval,
341 @@ -1248,7 +1167,6 @@ static int do_mei_entry(const char *filename, void *symval,
342
343 return 1;
344 }
345 -ADD_TO_DEVTABLE("mei", mei_cl_device_id, do_mei_entry);
346
347 /* Looks like: rapidio:vNdNavNadN */
348 static int do_rio_entry(const char *filename,
349 @@ -1268,7 +1186,6 @@ static int do_rio_entry(const char *filename,
350 add_wildcard(alias);
351 return 1;
352 }
353 -ADD_TO_DEVTABLE("rapidio", rio_device_id, do_rio_entry);
354
355 /* Looks like: ulpi:vNpN */
356 static int do_ulpi_entry(const char *filename, void *symval,
357 @@ -1281,7 +1198,6 @@ static int do_ulpi_entry(const char *filename, void *symval,
358
359 return 1;
360 }
361 -ADD_TO_DEVTABLE("ulpi", ulpi_device_id, do_ulpi_entry);
362
363 /* Looks like: hdaudio:vNrNaN */
364 static int do_hda_entry(const char *filename, void *symval, char *alias)
365 @@ -1298,7 +1214,6 @@ static int do_hda_entry(const char *filename, void *symval, char *alias)
366 add_wildcard(alias);
367 return 1;
368 }
369 -ADD_TO_DEVTABLE("hdaudio", hda_device_id, do_hda_entry);
370
371 /* Looks like: sdw:mNpN */
372 static int do_sdw_entry(const char *filename, void *symval, char *alias)
373 @@ -1313,7 +1228,6 @@ static int do_sdw_entry(const char *filename, void *symval, char *alias)
374 add_wildcard(alias);
375 return 1;
376 }
377 -ADD_TO_DEVTABLE("sdw", sdw_device_id, do_sdw_entry);
378
379 /* Looks like: fsl-mc:vNdN */
380 static int do_fsl_mc_entry(const char *filename, void *symval,
381 @@ -1325,7 +1239,6 @@ static int do_fsl_mc_entry(const char *filename, void *symval,
382 sprintf(alias, "fsl-mc:v%08Xd%s", vendor, *obj_type);
383 return 1;
384 }
385 -ADD_TO_DEVTABLE("fslmc", fsl_mc_device_id, do_fsl_mc_entry);
386
387 /* Looks like: tbsvc:kSpNvNrN */
388 static int do_tbsvc_entry(const char *filename, void *symval, char *alias)
389 @@ -1350,7 +1263,6 @@ static int do_tbsvc_entry(const char *filename, void *symval, char *alias)
390 add_wildcard(alias);
391 return 1;
392 }
393 -ADD_TO_DEVTABLE("tbsvc", tb_service_id, do_tbsvc_entry);
394
395 /* Looks like: typec:idNmN */
396 static int do_typec_entry(const char *filename, void *symval, char *alias)
397 @@ -1363,7 +1275,6 @@ static int do_typec_entry(const char *filename, void *symval, char *alias)
398
399 return 1;
400 }
401 -ADD_TO_DEVTABLE("typec", typec_device_id, do_typec_entry);
402
403 /* Does namelen bytes of name exactly match the symbol? */
404 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
405 @@ -1396,6 +1307,48 @@ static void do_table(void *symval, unsigned long size,
406 }
407 }
408
409 +static const struct devtable devtable[] = {
410 + {"hid", SIZE_hid_device_id, do_hid_entry},
411 + {"ieee1394", SIZE_ieee1394_device_id, do_ieee1394_entry},
412 + {"pci", SIZE_pci_device_id, do_pci_entry},
413 + {"ccw", SIZE_ccw_device_id, do_ccw_entry},
414 + {"ap", SIZE_ap_device_id, do_ap_entry},
415 + {"css", SIZE_css_device_id, do_css_entry},
416 + {"serio", SIZE_serio_device_id, do_serio_entry},
417 + {"acpi", SIZE_acpi_device_id, do_acpi_entry},
418 + {"pcmcia", SIZE_pcmcia_device_id, do_pcmcia_entry},
419 + {"vio", SIZE_vio_device_id, do_vio_entry},
420 + {"input", SIZE_input_device_id, do_input_entry},
421 + {"eisa", SIZE_eisa_device_id, do_eisa_entry},
422 + {"parisc", SIZE_parisc_device_id, do_parisc_entry},
423 + {"sdio", SIZE_sdio_device_id, do_sdio_entry},
424 + {"ssb", SIZE_ssb_device_id, do_ssb_entry},
425 + {"bcma", SIZE_bcma_device_id, do_bcma_entry},
426 + {"virtio", SIZE_virtio_device_id, do_virtio_entry},
427 + {"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
428 + {"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
429 + {"i2c", SIZE_i2c_device_id, do_i2c_entry},
430 + {"spi", SIZE_spi_device_id, do_spi_entry},
431 + {"dmi", SIZE_dmi_system_id, do_dmi_entry},
432 + {"platform", SIZE_platform_device_id, do_platform_entry},
433 + {"mdio", SIZE_mdio_device_id, do_mdio_entry},
434 + {"zorro", SIZE_zorro_device_id, do_zorro_entry},
435 + {"isapnp", SIZE_isapnp_device_id, do_isapnp_entry},
436 + {"ipack", SIZE_ipack_device_id, do_ipack_entry},
437 + {"amba", SIZE_amba_id, do_amba_entry},
438 + {"mipscdmm", SIZE_mips_cdmm_device_id, do_mips_cdmm_entry},
439 + {"x86cpu", SIZE_x86_cpu_id, do_x86cpu_entry},
440 + {"cpu", SIZE_cpu_feature, do_cpu_entry},
441 + {"mei", SIZE_mei_cl_device_id, do_mei_entry},
442 + {"rapidio", SIZE_rio_device_id, do_rio_entry},
443 + {"ulpi", SIZE_ulpi_device_id, do_ulpi_entry},
444 + {"hdaudio", SIZE_hda_device_id, do_hda_entry},
445 + {"sdw", SIZE_sdw_device_id, do_sdw_entry},
446 + {"fslmc", SIZE_fsl_mc_device_id, do_fsl_mc_entry},
447 + {"tbsvc", SIZE_tb_service_id, do_tbsvc_entry},
448 + {"typec", SIZE_typec_device_id, do_typec_entry},
449 +};
450 +
451 /* Create MODULE_ALIAS() statements.
452 * At this time, we cannot write the actual output C source yet,
453 * so we write into the mod->dev_table_buf buffer. */
454 @@ -1450,13 +1403,14 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
455 else if (sym_is(name, namelen, "pnp_card"))
456 do_pnp_card_entries(symval, sym->st_size, mod);
457 else {
458 - struct devtable **p;
459 - INIT_SECTION(__devtable);
460 + int i;
461 +
462 + for (i = 0; i < ARRAY_SIZE(devtable); i++) {
463 + const struct devtable *p = &devtable[i];
464
465 - for (p = __start___devtable; p < __stop___devtable; p++) {
466 - if (sym_is(name, namelen, (*p)->device_id)) {
467 - do_table(symval, sym->st_size, (*p)->id_size,
468 - (*p)->device_id, (*p)->function, mod);
469 + if (sym_is(name, namelen, p->device_id)) {
470 + do_table(symval, sym->st_size, p->id_size,
471 + p->device_id, p->function, mod);
472 break;
473 }
474 }
475 --
476 2.19.1
477