Skip to content

Commit ed13fc3

Browse files
mettiJessica Yu
authored andcommitted
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: Martijn Coenen <[email protected]> Signed-off-by: Martijn Coenen <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Matthias Maennich <[email protected]> Signed-off-by: Jessica Yu <[email protected]>
1 parent c5e4a06 commit ed13fc3

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

arch/m68k/include/asm/export.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
#define KSYM_ALIGN 2
21
#define KCRC_ALIGN 2
32
#include <asm-generic/export.h>

include/asm-generic/export.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
#ifndef KSYM_FUNC
55
#define KSYM_FUNC(x) x
66
#endif
7-
#ifdef CONFIG_64BIT
8-
#ifndef KSYM_ALIGN
7+
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
8+
#define KSYM_ALIGN 4
9+
#elif defined(CONFIG_64BIT)
910
#define KSYM_ALIGN 8
10-
#endif
1111
#else
12-
#ifndef KSYM_ALIGN
1312
#define KSYM_ALIGN 4
1413
#endif
15-
#endif
1614
#ifndef KCRC_ALIGN
1715
#define KCRC_ALIGN 4
1816
#endif

include/linux/export.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern struct module __this_module;
5252
#define __KSYMTAB_ENTRY(sym, sec) \
5353
__ADDRESSABLE(sym) \
5454
asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
55-
" .balign 8 \n" \
55+
" .balign 4 \n" \
5656
"__ksymtab_" #sym ": \n" \
5757
" .long " #sym "- . \n" \
5858
" .long __kstrtab_" #sym "- . \n" \
@@ -66,6 +66,7 @@ struct kernel_symbol {
6666
#define __KSYMTAB_ENTRY(sym, sec) \
6767
static const struct kernel_symbol __ksymtab_##sym \
6868
__attribute__((section("___ksymtab" sec "+" #sym), used)) \
69+
__aligned(sizeof(void *)) \
6970
= { (unsigned long)&sym, __kstrtab_##sym }
7071

7172
struct kernel_symbol {

0 commit comments

Comments
 (0)