mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-28 14:44:10 +08:00
71810db27c
The modversion symbol CRCs are emitted as ELF symbols, which allows us
to easily populate the kcrctab sections by relying on the linker to
associate each kcrctab slot with the correct value.
This has a couple of downsides:
- Given that the CRCs are treated as memory addresses, we waste 4 bytes
for each CRC on 64 bit architectures,
- On architectures that support runtime relocation, a R_<arch>_RELATIVE
relocation entry is emitted for each CRC value, which identifies it
as a quantity that requires fixing up based on the actual runtime
load offset of the kernel. This results in corrupted CRCs unless we
explicitly undo the fixup (and this is currently being handled in the
core module code)
- Such runtime relocation entries take up 24 bytes of __init space
each, resulting in a x8 overhead in [uncompressed] kernel size for
CRCs.
Switching to explicit 32 bit values on 64 bit architectures fixes most
of these issues, given that 32 bit values are not treated as quantities
that require fixing up based on the actual runtime load offset. Note
that on some ELF64 architectures [such as PPC64], these 32-bit values
are still emitted as [absolute] runtime relocatable quantities, even if
the value resolves to a build time constant. Since relative relocations
are always resolved at build time, this patch enables MODULE_REL_CRCS on
powerpc when CONFIG_RELOCATABLE=y, which turns the absolute CRC
references into relative references into .rodata where the actual CRC
value is stored.
So redefine all CRC fields and variables as u32, and redefine the
__CRC_SYMBOL() macro for 64 bit builds to emit the CRC reference using
inline assembler (which is necessary since 64-bit C code cannot use
32-bit types to hold memory addresses, even if they are ultimately
resolved using values that do not exceed 0xffffffff). To avoid
potential problems with legacy 32-bit architectures using legacy
toolchains, the equivalent C definition of the kcrctab entry is retained
for 32-bit architectures.
Note that this mostly reverts commit d4703aefdb
("module: handle ppc64
relocating kcrctabs when CONFIG_RELOCATABLE=y")
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
96 lines
2.2 KiB
C
96 lines
2.2 KiB
C
#ifndef __ASM_GENERIC_EXPORT_H
|
|
#define __ASM_GENERIC_EXPORT_H
|
|
|
|
#ifndef KSYM_FUNC
|
|
#define KSYM_FUNC(x) x
|
|
#endif
|
|
#ifdef CONFIG_64BIT
|
|
#define __put .quad
|
|
#ifndef KSYM_ALIGN
|
|
#define KSYM_ALIGN 8
|
|
#endif
|
|
#else
|
|
#define __put .long
|
|
#ifndef KSYM_ALIGN
|
|
#define KSYM_ALIGN 4
|
|
#endif
|
|
#endif
|
|
#ifndef KCRC_ALIGN
|
|
#define KCRC_ALIGN 4
|
|
#endif
|
|
|
|
#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
|
|
#define KSYM(name) _##name
|
|
#else
|
|
#define KSYM(name) name
|
|
#endif
|
|
|
|
/*
|
|
* 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 KSYM(__ksymtab_\name)
|
|
.section ___ksymtab\sec+\name,"a"
|
|
.balign KSYM_ALIGN
|
|
KSYM(__ksymtab_\name):
|
|
__put \val, KSYM(__kstrtab_\name)
|
|
.previous
|
|
.section __ksymtab_strings,"a"
|
|
KSYM(__kstrtab_\name):
|
|
#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
|
|
.asciz "_\name"
|
|
#else
|
|
.asciz "\name"
|
|
#endif
|
|
.previous
|
|
#ifdef CONFIG_MODVERSIONS
|
|
.section ___kcrctab\sec+\name,"a"
|
|
.balign KCRC_ALIGN
|
|
KSYM(__kcrctab_\name):
|
|
#if defined(CONFIG_MODULE_REL_CRCS)
|
|
.long KSYM(__crc_\name) - .
|
|
#else
|
|
.long KSYM(__crc_\name)
|
|
#endif
|
|
.weak KSYM(__crc_\name)
|
|
.previous
|
|
#endif
|
|
#endif
|
|
.endm
|
|
#undef __put
|
|
|
|
#if defined(__KSYM_DEPS__)
|
|
|
|
#define __EXPORT_SYMBOL(sym, val, sec) === __KSYM_##sym ===
|
|
|
|
#elif defined(CONFIG_TRIM_UNUSED_KSYMS)
|
|
|
|
#include <linux/kconfig.h>
|
|
#include <generated/autoksyms.h>
|
|
|
|
#define __EXPORT_SYMBOL(sym, val, sec) \
|
|
__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(KSYM(name)),)
|
|
#define EXPORT_SYMBOL_GPL(name) \
|
|
__EXPORT_SYMBOL(name, KSYM_FUNC(KSYM(name)), _gpl)
|
|
#define EXPORT_DATA_SYMBOL(name) \
|
|
__EXPORT_SYMBOL(name, KSYM(name),)
|
|
#define EXPORT_DATA_SYMBOL_GPL(name) \
|
|
__EXPORT_SYMBOL(name, KSYM(name),_gpl)
|
|
|
|
#endif
|