modpost: file2alias: go back to simple devtable lookup

commit ec91e78d378cc5d4b43805a1227d8e04e5dfa17d upstream.

Commit e49ce14150 ("modpost: use linker section to generate table.")
was not so cool as we had expected first; it ended up with ugly section
hacks when commit dd2a3acaec ("mod/file2alias: make modpost compile
on darwin again") came in.

Given a certain degree of unknowledge about the link stage of host
programs, I really want to see simple, stupid table lookup so that
this works in the same way regardless of the underlying executable
format.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Mathieu Malaterre <malat@debian.org>
[nc: Omit rpmsg, sdw, fslmc, tbsvc, and typec as they don't exist here
     Add of to avoid backporting two larger patches]
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kevin F. Haggerty <haggertk@lineageos.org>
Change-Id: Ic632eaa7777338109f80c76535e67917f5b9761c
This commit is contained in:
Masahiro Yamada
2020-11-16 18:32:39 +01:00
committed by Francescodario Cuzzocrea
parent 076c3095c0
commit a147d59097
+38 -82
View File
@@ -47,44 +47,6 @@ struct devtable {
void *function;
};
#define ___cat(a,b) a ## b
#define __cat(a,b) ___cat(a,b)
/* we need some special handling for this host tool running eventually on
* Darwin. The Mach-O section handling is a bit different than ELF section
* handling. The differnces in detail are:
* a) we have segments which have sections
* b) we need a API call to get the respective section symbols */
#if defined(__MACH__)
#include <mach-o/getsect.h>
#define INIT_SECTION(name) do { \
unsigned long name ## _len; \
char *__cat(pstart_,name) = getsectdata("__TEXT", \
#name, &__cat(name,_len)); \
char *__cat(pstop_,name) = __cat(pstart_,name) + \
__cat(name, _len); \
__cat(__start_,name) = (void *)__cat(pstart_,name); \
__cat(__stop_,name) = (void *)__cat(pstop_,name); \
} while (0)
#define SECTION(name) __attribute__((section("__TEXT, " #name)))
struct devtable **__start___devtable, **__stop___devtable;
#else
#define INIT_SECTION(name) /* no-op for ELF */
#define SECTION(name) __attribute__((section(#name)))
/* We construct a table of pointers in an ELF section (pointers generally
* go unpadded by gcc). ld creates boundary syms for us. */
extern struct devtable *__start___devtable[], *__stop___devtable[];
#endif /* __MACH__ */
#if __GNUC__ == 3 && __GNUC_MINOR__ < 3
# define __used __attribute__((__unused__))
#else
# define __used __attribute__((__used__))
#endif
/* Define a variable f that holds the value of field f of struct devid
* based at address m.
*/
@@ -97,16 +59,6 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
#define DEF_FIELD_ADDR(m, devid, f) \
typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
/* Add a table entry. We test function type matches while we're here. */
#define ADD_TO_DEVTABLE(device_id, type, function) \
static struct devtable __cat(devtable,__LINE__) = { \
device_id + 0*sizeof((function)((const char *)NULL, \
(void *)NULL, \
(char *)NULL)), \
SIZE_##type, (function) }; \
static struct devtable *SECTION(__devtable) __used \
__cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
#define ADD(str, sep, cond, field) \
do { \
strcat(str, sep); \
@@ -371,7 +323,6 @@ static int do_hid_entry(const char *filename,
return 1;
}
ADD_TO_DEVTABLE("hid", hid_device_id, do_hid_entry);
/* Looks like: ieee1394:venNmoNspNverN */
static int do_ieee1394_entry(const char *filename,
@@ -396,7 +347,6 @@ static int do_ieee1394_entry(const char *filename,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("ieee1394", ieee1394_device_id, do_ieee1394_entry);
/* Looks like: pci:vNdNsvNsdNbcNscNiN. */
static int do_pci_entry(const char *filename,
@@ -440,7 +390,6 @@ static int do_pci_entry(const char *filename,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("pci", pci_device_id, do_pci_entry);
/* looks like: "ccw:tNmNdtNdmN" */
static int do_ccw_entry(const char *filename,
@@ -464,7 +413,6 @@ static int do_ccw_entry(const char *filename,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("ccw", ccw_device_id, do_ccw_entry);
/* looks like: "ap:tN" */
static int do_ap_entry(const char *filename,
@@ -475,7 +423,6 @@ static int do_ap_entry(const char *filename,
sprintf(alias, "ap:t%02X*", dev_type);
return 1;
}
ADD_TO_DEVTABLE("ap", ap_device_id, do_ap_entry);
/* looks like: "css:tN" */
static int do_css_entry(const char *filename,
@@ -486,7 +433,6 @@ static int do_css_entry(const char *filename,
sprintf(alias, "css:t%01X", type);
return 1;
}
ADD_TO_DEVTABLE("css", css_device_id, do_css_entry);
/* Looks like: "serio:tyNprNidNexN" */
static int do_serio_entry(const char *filename,
@@ -506,7 +452,6 @@ static int do_serio_entry(const char *filename,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("serio", serio_device_id, do_serio_entry);
/* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */
static int do_acpi_entry(const char *filename,
@@ -516,7 +461,6 @@ static int do_acpi_entry(const char *filename,
sprintf(alias, "acpi*:%s:*", *id);
return 1;
}
ADD_TO_DEVTABLE("acpi", acpi_device_id, do_acpi_entry);
/* looks like: "pnp:dD" */
static void do_pnp_device_entry(void *symval, unsigned long size,
@@ -637,7 +581,6 @@ static int do_pcmcia_entry(const char *filename,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("pcmcia", pcmcia_device_id, do_pcmcia_entry);
static int do_of_entry (const char *filename, void *symval, char *alias)
{
@@ -664,7 +607,6 @@ static int do_of_entry (const char *filename, void *symval, char *alias)
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("of", of_device_id, do_of_entry);
static int do_vio_entry(const char *filename, void *symval,
char *alias)
@@ -684,7 +626,6 @@ static int do_vio_entry(const char *filename, void *symval,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("vio", vio_device_id, do_vio_entry);
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
@@ -757,7 +698,6 @@ static int do_input_entry(const char *filename, void *symval,
do_input(alias, *swbit, 0, INPUT_DEVICE_ID_SW_MAX);
return 1;
}
ADD_TO_DEVTABLE("input", input_device_id, do_input_entry);
static int do_eisa_entry(const char *filename, void *symval,
char *alias)
@@ -769,7 +709,6 @@ static int do_eisa_entry(const char *filename, void *symval,
strcat(alias, "*");
return 1;
}
ADD_TO_DEVTABLE("eisa", eisa_device_id, do_eisa_entry);
/* Looks like: parisc:tNhvNrevNsvN */
static int do_parisc_entry(const char *filename, void *symval,
@@ -789,7 +728,6 @@ static int do_parisc_entry(const char *filename, void *symval,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("parisc", parisc_device_id, do_parisc_entry);
/* Looks like: sdio:cNvNdN. */
static int do_sdio_entry(const char *filename,
@@ -806,7 +744,6 @@ static int do_sdio_entry(const char *filename,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("sdio", sdio_device_id, do_sdio_entry);
/* Looks like: ssb:vNidNrevN. */
static int do_ssb_entry(const char *filename,
@@ -823,7 +760,6 @@ static int do_ssb_entry(const char *filename,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("ssb", ssb_device_id, do_ssb_entry);
/* Looks like: bcma:mNidNrevNclN. */
static int do_bcma_entry(const char *filename,
@@ -842,7 +778,6 @@ static int do_bcma_entry(const char *filename,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("bcma", bcma_device_id, do_bcma_entry);
/* Looks like: virtio:dNvN */
static int do_virtio_entry(const char *filename, void *symval,
@@ -858,7 +793,6 @@ static int do_virtio_entry(const char *filename, void *symval,
add_wildcard(alias);
return 1;
}
ADD_TO_DEVTABLE("virtio", virtio_device_id, do_virtio_entry);
/*
* Looks like: vmbus:guid
@@ -881,7 +815,6 @@ static int do_vmbus_entry(const char *filename, void *symval,
return 1;
}
ADD_TO_DEVTABLE("vmbus", hv_vmbus_device_id, do_vmbus_entry);
/* Looks like: i2c:S */
static int do_i2c_entry(const char *filename, void *symval,
@@ -892,7 +825,6 @@ static int do_i2c_entry(const char *filename, void *symval,
return 1;
}
ADD_TO_DEVTABLE("i2c", i2c_device_id, do_i2c_entry);
/* Looks like: spi:S */
static int do_spi_entry(const char *filename, void *symval,
@@ -903,7 +835,6 @@ static int do_spi_entry(const char *filename, void *symval,
return 1;
}
ADD_TO_DEVTABLE("spi", spi_device_id, do_spi_entry);
static const struct dmifield {
const char *prefix;
@@ -958,7 +889,6 @@ static int do_dmi_entry(const char *filename, void *symval,
strcat(alias, ":");
return 1;
}
ADD_TO_DEVTABLE("dmi", dmi_system_id, do_dmi_entry);
static int do_platform_entry(const char *filename,
void *symval, char *alias)
@@ -967,7 +897,6 @@ static int do_platform_entry(const char *filename,
sprintf(alias, PLATFORM_MODULE_PREFIX "%s", *name);
return 1;
}
ADD_TO_DEVTABLE("platform", platform_device_id, do_platform_entry);
static int do_mdio_entry(const char *filename,
void *symval, char *alias)
@@ -992,7 +921,6 @@ static int do_mdio_entry(const char *filename,
return 1;
}
ADD_TO_DEVTABLE("mdio", mdio_device_id, do_mdio_entry);
/* Looks like: zorro:iN. */
static int do_zorro_entry(const char *filename, void *symval,
@@ -1003,7 +931,6 @@ static int do_zorro_entry(const char *filename, void *symval,
ADD(alias, "i", id != ZORRO_WILDCARD, id);
return 1;
}
ADD_TO_DEVTABLE("zorro", zorro_device_id, do_zorro_entry);
/* looks like: "pnp:dD" */
static int do_isapnp_entry(const char *filename,
@@ -1019,7 +946,6 @@ static int do_isapnp_entry(const char *filename,
(function >> 12) & 0x0f, (function >> 8) & 0x0f);
return 1;
}
ADD_TO_DEVTABLE("isapnp", isapnp_device_id, do_isapnp_entry);
/*
* Append a match expression for a single masked hex digit.
@@ -1090,7 +1016,6 @@ static int do_amba_entry(const char *filename,
return 1;
}
ADD_TO_DEVTABLE("amba", amba_id, do_amba_entry);
/* LOOKS like x86cpu:vendor:VVVV:family:FFFF:model:MMMM:feature:*,FEAT,*
* All fields are numbers. It would be nicer to use strings for vendor
@@ -1115,7 +1040,6 @@ static int do_x86cpu_entry(const char *filename, void *symval,
sprintf(alias + strlen(alias), "%04X*", feature);
return 1;
}
ADD_TO_DEVTABLE("x86cpu", x86_cpu_id, do_x86cpu_entry);
/* Does namelen bytes of name exactly match the symbol? */
static bool sym_is(const char *name, unsigned namelen, const char *symbol)
@@ -1148,6 +1072,37 @@ static void do_table(void *symval, unsigned long size,
}
}
static const struct devtable devtable[] = {
{"hid", SIZE_hid_device_id, do_hid_entry},
{"ieee1394", SIZE_ieee1394_device_id, do_ieee1394_entry},
{"pci", SIZE_pci_device_id, do_pci_entry},
{"ccw", SIZE_ccw_device_id, do_ccw_entry},
{"ap", SIZE_ap_device_id, do_ap_entry},
{"css", SIZE_css_device_id, do_css_entry},
{"serio", SIZE_serio_device_id, do_serio_entry},
{"acpi", SIZE_acpi_device_id, do_acpi_entry},
{"pcmcia", SIZE_pcmcia_device_id, do_pcmcia_entry},
{"vio", SIZE_vio_device_id, do_vio_entry},
{"input", SIZE_input_device_id, do_input_entry},
{"eisa", SIZE_eisa_device_id, do_eisa_entry},
{"parisc", SIZE_parisc_device_id, do_parisc_entry},
{"sdio", SIZE_sdio_device_id, do_sdio_entry},
{"ssb", SIZE_ssb_device_id, do_ssb_entry},
{"bcma", SIZE_bcma_device_id, do_bcma_entry},
{"virtio", SIZE_virtio_device_id, do_virtio_entry},
{"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
{"i2c", SIZE_i2c_device_id, do_i2c_entry},
{"spi", SIZE_spi_device_id, do_spi_entry},
{"dmi", SIZE_dmi_system_id, do_dmi_entry},
{"platform", SIZE_platform_device_id, do_platform_entry},
{"mdio", SIZE_mdio_device_id, do_mdio_entry},
{"zorro", SIZE_zorro_device_id, do_zorro_entry},
{"isapnp", SIZE_isapnp_device_id, do_isapnp_entry},
{"amba", SIZE_amba_id, do_amba_entry},
{"x86cpu", SIZE_x86_cpu_id, do_x86cpu_entry},
{"of", SIZE_of_device_id, do_of_entry},
};
/* Create MODULE_ALIAS() statements.
* At this time, we cannot write the actual output C source yet,
* so we write into the mod->dev_table_buf buffer. */
@@ -1197,13 +1152,14 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
else if (sym_is(name, namelen, "pnp_card"))
do_pnp_card_entries(symval, sym->st_size, mod);
else {
struct devtable **p;
INIT_SECTION(__devtable);
int i;
for (p = __start___devtable; p < __stop___devtable; p++) {
if (sym_is(name, namelen, (*p)->device_id)) {
do_table(symval, sym->st_size, (*p)->id_size,
(*p)->device_id, (*p)->function, mod);
for (i = 0; i < ARRAY_SIZE(devtable); i++) {
const struct devtable *p = &devtable[i];
if (sym_is(name, namelen, p->device_id)) {
do_table(symval, sym->st_size, p->id_size,
p->device_id, p->function, mod);
break;
}
}