Commit ed13fc33 authored by Matthias Maennich's avatar Matthias Maennich Committed by Jessica Yu

export: explicitly align struct kernel_symbol

This change allows growing struct kernel_symbol without wasting bytes to
alignment. It also concretized the alignment of ksymtab entries if
relative references are used for ksymtab entries.

struct kernel_symbol was already implicitly being aligned to the word
size, except on x86_64 and m68k, where it is aligned to 16 and 2 bytes,
respectively.

As far as I can tell there is no requirement for aligning struct
kernel_symbol to 16 bytes on x86_64, but gcc aligns structs to their
size, and the linker aligns the custom __ksymtab sections to the largest
data type contained within, so setting KSYM_ALIGN to 16 was necessary to
stay consistent with the code generated for non-ASM EXPORT_SYMBOL(). Now
that non-ASM EXPORT_SYMBOL() explicitly aligns to word size (8),
KSYM_ALIGN is no longer necessary.

In case of relative references, the alignment has been changed
accordingly to not waste space when adding new struct members.

As for m68k, struct kernel_symbol is aligned to 2 bytes even though the
structure itself is 8 bytes; using a 4-byte alignment shouldn't hurt.

I manually verified the output of the __ksymtab sections didn't change
on x86, x86_64, arm, arm64 and m68k. As expected, the section contents
didn't change, and the ELF section alignment only changed on x86_64 and
m68k. Feedback from other archs more than welcome.
Co-developed-by: default avatarMartijn Coenen <maco@android.com>
Signed-off-by: default avatarMartijn Coenen <maco@android.com>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarMatthias Maennich <maennich@google.com>
Signed-off-by: default avatarJessica Yu <jeyu@kernel.org>
parent c5e4a062
#define KSYM_ALIGN 2
#define KCRC_ALIGN 2 #define KCRC_ALIGN 2
#include <asm-generic/export.h> #include <asm-generic/export.h>
...@@ -4,15 +4,13 @@ ...@@ -4,15 +4,13 @@
#ifndef KSYM_FUNC #ifndef KSYM_FUNC
#define KSYM_FUNC(x) x #define KSYM_FUNC(x) x
#endif #endif
#ifdef CONFIG_64BIT #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
#ifndef KSYM_ALIGN #define KSYM_ALIGN 4
#elif defined(CONFIG_64BIT)
#define KSYM_ALIGN 8 #define KSYM_ALIGN 8
#endif
#else #else
#ifndef KSYM_ALIGN
#define KSYM_ALIGN 4 #define KSYM_ALIGN 4
#endif #endif
#endif
#ifndef KCRC_ALIGN #ifndef KCRC_ALIGN
#define KCRC_ALIGN 4 #define KCRC_ALIGN 4
#endif #endif
......
...@@ -52,7 +52,7 @@ extern struct module __this_module; ...@@ -52,7 +52,7 @@ extern struct module __this_module;
#define __KSYMTAB_ENTRY(sym, sec) \ #define __KSYMTAB_ENTRY(sym, sec) \
__ADDRESSABLE(sym) \ __ADDRESSABLE(sym) \
asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
" .balign 8 \n" \ " .balign 4 \n" \
"__ksymtab_" #sym ": \n" \ "__ksymtab_" #sym ": \n" \
" .long " #sym "- . \n" \ " .long " #sym "- . \n" \
" .long __kstrtab_" #sym "- . \n" \ " .long __kstrtab_" #sym "- . \n" \
...@@ -66,6 +66,7 @@ struct kernel_symbol { ...@@ -66,6 +66,7 @@ struct kernel_symbol {
#define __KSYMTAB_ENTRY(sym, sec) \ #define __KSYMTAB_ENTRY(sym, sec) \
static const struct kernel_symbol __ksymtab_##sym \ static const struct kernel_symbol __ksymtab_##sym \
__attribute__((section("___ksymtab" sec "+" #sym), used)) \ __attribute__((section("___ksymtab" sec "+" #sym), used)) \
__aligned(sizeof(void *)) \
= { (unsigned long)&sym, __kstrtab_##sym } = { (unsigned long)&sym, __kstrtab_##sym }
struct kernel_symbol { struct kernel_symbol {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment