ed13fc33f7
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 <maco@android.com> Signed-off-by: Martijn Coenen <maco@android.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Jessica Yu <jeyu@kernel.org>
95 lines
2.1 KiB
C
95 lines
2.1 KiB
C
#ifndef __ASM_GENERIC_EXPORT_H
|
|
#define __ASM_GENERIC_EXPORT_H
|
|
|
|
#ifndef KSYM_FUNC
|
|
#define KSYM_FUNC(x) x
|
|
#endif
|
|
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
|
|
#define KSYM_ALIGN 4
|
|
#elif defined(CONFIG_64BIT)
|
|
#define KSYM_ALIGN 8
|
|
#else
|
|
#define KSYM_ALIGN 4
|
|
#endif
|
|
#ifndef KCRC_ALIGN
|
|
#define KCRC_ALIGN 4
|
|
#endif
|
|
|
|
.macro __put, val, name
|
|
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
|
|
.long \val - ., \name - .
|
|
#elif defined(CONFIG_64BIT)
|
|
.quad \val, \name
|
|
#else
|
|
.long \val, \name
|
|
#endif
|
|
.endm
|
|
|
|
/*
|
|
* note on .section use: @progbits vs %progbits nastiness doesn't matter,
|
|
* since we immediately emit into those sections anyway.
|
|
*/
|
|
.macro ___EXPORT_SYMBOL name,val,sec
|
|
#ifdef CONFIG_MODULES
|
|
.globl __ksymtab_\name
|
|
.section ___ksymtab\sec+\name,"a"
|
|
.balign KSYM_ALIGN
|
|
__ksymtab_\name:
|
|
__put \val, __kstrtab_\name
|
|
.previous
|
|
.section __ksymtab_strings,"a"
|
|
__kstrtab_\name:
|
|
.asciz "\name"
|
|
.previous
|
|
#ifdef CONFIG_MODVERSIONS
|
|
.section ___kcrctab\sec+\name,"a"
|
|
.balign KCRC_ALIGN
|
|
__kcrctab_\name:
|
|
#if defined(CONFIG_MODULE_REL_CRCS)
|
|
.long __crc_\name - .
|
|
#else
|
|
.long __crc_\name
|
|
#endif
|
|
.weak __crc_\name
|
|
.previous
|
|
#endif
|
|
#endif
|
|
.endm
|
|
#undef __put
|
|
|
|
#if defined(CONFIG_TRIM_UNUSED_KSYMS)
|
|
|
|
#include <linux/kconfig.h>
|
|
#include <generated/autoksyms.h>
|
|
|
|
.macro __ksym_marker sym
|
|
.section ".discard.ksym","a"
|
|
__ksym_marker_\sym:
|
|
.previous
|
|
.endm
|
|
|
|
#define __EXPORT_SYMBOL(sym, val, sec) \
|
|
__ksym_marker sym; \
|
|
__cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym))
|
|
#define __cond_export_sym(sym, val, sec, conf) \
|
|
___cond_export_sym(sym, val, sec, conf)
|
|
#define ___cond_export_sym(sym, val, sec, enabled) \
|
|
__cond_export_sym_##enabled(sym, val, sec)
|
|
#define __cond_export_sym_1(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
|
|
#define __cond_export_sym_0(sym, val, sec) /* nothing */
|
|
|
|
#else
|
|
#define __EXPORT_SYMBOL(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
|
|
#endif
|
|
|
|
#define EXPORT_SYMBOL(name) \
|
|
__EXPORT_SYMBOL(name, KSYM_FUNC(name),)
|
|
#define EXPORT_SYMBOL_GPL(name) \
|
|
__EXPORT_SYMBOL(name, KSYM_FUNC(name), _gpl)
|
|
#define EXPORT_DATA_SYMBOL(name) \
|
|
__EXPORT_SYMBOL(name, name,)
|
|
#define EXPORT_DATA_SYMBOL_GPL(name) \
|
|
__EXPORT_SYMBOL(name, name,_gpl)
|
|
|
|
#endif
|