Skip to contentSkip to conversation

buildid: fix build when CONFIG_MODULES is not set

PATCH In review Randy Dunlap 2 participants 2 messages May 13, 2021 – May 14, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 buildid: fix build when CONFIG_MODULES is not set

Omit the static_assert() when CONFIG_MODULES is not set/enabled. Fixes these build errors:

../kernel/kallsyms.c: In function ‘__sprint_symbol’:
../include/linux/kernel.h:53:43: error: dereferencing pointer to incomplete type ‘struct module’

 #define typeof_member(T, m) typeof(((T*)0)->m)
                                           ^
../include/linux/build_bug.h:78:41: error: static assertion failed: "sizeof(typeof_member(struct module, build_id)) == 20"
 #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
                                         ^
../kernel/kallsyms.c:454:4: note: in expansion of macro ‘static_assert’
    static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
    ^~~~~~~~~~~~~
Cc Stephen Boyd <[email protected]>
Cc Andrew Morton <[email protected]>
---
 kernel/kallsyms.c |    2 ++
 1 file changed, 2 insertions(+)
kernel/kallsyms.c +2 -0
@@ -451,7 +451,9 @@ static int __sprint_symbol(char *buffer,
 #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
 		if (add_buildid && buildid) {
 			/* build ID should match length of sprintf */
+#if IS_ENABLED(CONFIG_MODULES)
 			static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
+#endif
 			len += sprintf(buffer + len, " %20phN", buildid);
 		}
 #endif
Reviewed-by on v1 1/1
#1 lore raw

Quoting Randy Dunlap (2021-05-13 10:15:10)

Quoted 14 lines

Omit the static_assert() when CONFIG_MODULES is not set/enabled. Fixes these build errors:

../kernel/kallsyms.c: In function ‘__sprint_symbol’:
../include/linux/kernel.h:53:43: error: dereferencing pointer to incomplete type ‘struct module’

 #define typeof_member(T, m) typeof(((T*)0)->m)
                                           ^
../include/linux/build_bug.h:78:41: error: static assertion failed: "sizeof(typeof_member(struct module, build_id)) == 20"
 #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
                                         ^
../kernel/kallsyms.c:454:4: note: in expansion of macro ‘static_assert’
    static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
    ^~~~~~~~~~~~~
Quoted 4 lines
Cc Stephen Boyd <[email protected]>
Cc Andrew Morton <[email protected]>

---

Thanks. I didn't realize that there was an ifdef around the definition of 'struct module'.