提交 b112082c 编写于 作者: J Johan Hovold 提交者: Jessica Yu

module: simplify version-attribute handling

Instead of using the array-of-pointers trick to avoid having gcc mess up
the built-in module-version array stride, specify type alignment when
declaring entries to prevent gcc from increasing alignment.

This is essentially an alternative (one-line) fix to the problem
addressed by commit b4bc8428 ("module: deal with alignment issues in
built-in module versions").

gcc can increase the alignment of larger objects with static extent as
an optimisation, but this can be suppressed by using the aligned
attribute when declaring variables.

Note that we have been relying on this behaviour for kernel parameters
for 16 years and it indeed hasn't changed since the introduction of the
aligned attribute in gcc-3.1.

Link: https://lore.kernel.org/lkml/20201103175711.10731-1-johan@kernel.orgSigned-off-by: NJohan Hovold <johan@kernel.org>
Signed-off-by: NJessica Yu <jeyu@kernel.org>
上级 0801a007
...@@ -266,7 +266,10 @@ extern typeof(name) __mod_##type##__##name##_device_table \ ...@@ -266,7 +266,10 @@ extern typeof(name) __mod_##type##__##name##_device_table \
#else #else
#define MODULE_VERSION(_version) \ #define MODULE_VERSION(_version) \
MODULE_INFO(version, _version); \ MODULE_INFO(version, _version); \
static struct module_version_attribute ___modver_attr = { \ static struct module_version_attribute __modver_attr \
__used __section("__modver") \
__aligned(__alignof__(struct module_version_attribute)) \
= { \
.mattr = { \ .mattr = { \
.attr = { \ .attr = { \
.name = "version", \ .name = "version", \
...@@ -276,10 +279,7 @@ extern typeof(name) __mod_##type##__##name##_device_table \ ...@@ -276,10 +279,7 @@ extern typeof(name) __mod_##type##__##name##_device_table \
}, \ }, \
.module_name = KBUILD_MODNAME, \ .module_name = KBUILD_MODNAME, \
.version = _version, \ .version = _version, \
}; \ };
static const struct module_version_attribute \
__used __section("__modver") \
* __moduleparam_const __modver_attr = &___modver_attr
#endif #endif
/* Optional firmware file (or files) needed by the module /* Optional firmware file (or files) needed by the module
......
...@@ -843,18 +843,16 @@ ssize_t __modver_version_show(struct module_attribute *mattr, ...@@ -843,18 +843,16 @@ ssize_t __modver_version_show(struct module_attribute *mattr,
return scnprintf(buf, PAGE_SIZE, "%s\n", vattr->version); return scnprintf(buf, PAGE_SIZE, "%s\n", vattr->version);
} }
extern const struct module_version_attribute *__start___modver[]; extern const struct module_version_attribute __start___modver[];
extern const struct module_version_attribute *__stop___modver[]; extern const struct module_version_attribute __stop___modver[];
static void __init version_sysfs_builtin(void) static void __init version_sysfs_builtin(void)
{ {
const struct module_version_attribute **p; const struct module_version_attribute *vattr;
struct module_kobject *mk; struct module_kobject *mk;
int err; int err;
for (p = __start___modver; p < __stop___modver; p++) { for (vattr = __start___modver; vattr < __stop___modver; vattr++) {
const struct module_version_attribute *vattr = *p;
mk = locate_module_kobject(vattr->module_name); mk = locate_module_kobject(vattr->module_name);
if (mk) { if (mk) {
err = sysfs_create_file(&mk->kobj, &vattr->mattr.attr); err = sysfs_create_file(&mk->kobj, &vattr->mattr.attr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册