module: Sort exported symbols

This patch places every exported symbol in its own section
(i.e. "___ksymtab+printk").  Thus the linker will use its SORT() directive
to sort and finally merge all symbol in the right and final section
(i.e. "__ksymtab").

The symbol prefixed archs use an underscore as prefix for symbols.
To avoid collision we use a different character to create the temporary
section names.

This work was supported by a hardware donation from the CE Linux Forum.

Signed-off-by: Alessio Igor Bogani <abogani@kernel.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (folded in '+' fixup)
Tested-by: Dirk Behme <dirk.behme@googlemail.com>
This commit is contained in:
Alessio Igor Bogani 2011-04-14 14:59:39 +02:00 committed by Rusty Russell
parent de4d8d5346
commit f02e8a6596
3 changed files with 23 additions and 12 deletions

View file

@ -274,70 +274,70 @@
/* Kernel symbol table: Normal symbols */ \ /* Kernel symbol table: Normal symbols */ \
__ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \ __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___ksymtab) = .; \ VMLINUX_SYMBOL(__start___ksymtab) = .; \
*(__ksymtab) \ *(SORT(___ksymtab+*)) \
VMLINUX_SYMBOL(__stop___ksymtab) = .; \ VMLINUX_SYMBOL(__stop___ksymtab) = .; \
} \ } \
\ \
/* Kernel symbol table: GPL-only symbols */ \ /* Kernel symbol table: GPL-only symbols */ \
__ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \ __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \ VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \
*(__ksymtab_gpl) \ *(SORT(___ksymtab_gpl+*)) \
VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \ VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \
} \ } \
\ \
/* Kernel symbol table: Normal unused symbols */ \ /* Kernel symbol table: Normal unused symbols */ \
__ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \ __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \ VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \
*(__ksymtab_unused) \ *(SORT(___ksymtab_unused+*)) \
VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \ VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \
} \ } \
\ \
/* Kernel symbol table: GPL-only unused symbols */ \ /* Kernel symbol table: GPL-only unused symbols */ \
__ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \ __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \ VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \
*(__ksymtab_unused_gpl) \ *(SORT(___ksymtab_unused_gpl+*)) \
VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \ VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \
} \ } \
\ \
/* Kernel symbol table: GPL-future-only symbols */ \ /* Kernel symbol table: GPL-future-only symbols */ \
__ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \ __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \ VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \
*(__ksymtab_gpl_future) \ *(SORT(___ksymtab_gpl_future+*)) \
VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \ VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \
} \ } \
\ \
/* Kernel symbol table: Normal symbols */ \ /* Kernel symbol table: Normal symbols */ \
__kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \ __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___kcrctab) = .; \ VMLINUX_SYMBOL(__start___kcrctab) = .; \
*(__kcrctab) \ *(SORT(___kcrctab+*)) \
VMLINUX_SYMBOL(__stop___kcrctab) = .; \ VMLINUX_SYMBOL(__stop___kcrctab) = .; \
} \ } \
\ \
/* Kernel symbol table: GPL-only symbols */ \ /* Kernel symbol table: GPL-only symbols */ \
__kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \ __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___kcrctab_gpl) = .; \ VMLINUX_SYMBOL(__start___kcrctab_gpl) = .; \
*(__kcrctab_gpl) \ *(SORT(___kcrctab_gpl+*)) \
VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \ VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \
} \ } \
\ \
/* Kernel symbol table: Normal unused symbols */ \ /* Kernel symbol table: Normal unused symbols */ \
__kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \ __kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___kcrctab_unused) = .; \ VMLINUX_SYMBOL(__start___kcrctab_unused) = .; \
*(__kcrctab_unused) \ *(SORT(___kcrctab_unused+*)) \
VMLINUX_SYMBOL(__stop___kcrctab_unused) = .; \ VMLINUX_SYMBOL(__stop___kcrctab_unused) = .; \
} \ } \
\ \
/* Kernel symbol table: GPL-only unused symbols */ \ /* Kernel symbol table: GPL-only unused symbols */ \
__kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \ __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .; \ VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .; \
*(__kcrctab_unused_gpl) \ *(SORT(___kcrctab_unused_gpl+*)) \
VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .; \ VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .; \
} \ } \
\ \
/* Kernel symbol table: GPL-future-only symbols */ \ /* Kernel symbol table: GPL-future-only symbols */ \
__kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \ __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .; \ VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .; \
*(__kcrctab_gpl_future) \ *(SORT(___kcrctab_gpl_future+*)) \
VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \ VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \
} \ } \
\ \

View file

@ -224,7 +224,7 @@ struct module_use {
extern void *__crc_##sym __attribute__((weak)); \ extern void *__crc_##sym __attribute__((weak)); \
static const unsigned long __kcrctab_##sym \ static const unsigned long __kcrctab_##sym \
__used \ __used \
__attribute__((section("__kcrctab" sec), unused)) \ __attribute__((section("___kcrctab" sec "+" #sym), unused)) \
= (unsigned long) &__crc_##sym; = (unsigned long) &__crc_##sym;
#else #else
#define __CRC_SYMBOL(sym, sec) #define __CRC_SYMBOL(sym, sec)
@ -239,7 +239,7 @@ struct module_use {
= MODULE_SYMBOL_PREFIX #sym; \ = MODULE_SYMBOL_PREFIX #sym; \
static const struct kernel_symbol __ksymtab_##sym \ static const struct kernel_symbol __ksymtab_##sym \
__used \ __used \
__attribute__((section("__ksymtab" sec), unused)) \ __attribute__((section("___ksymtab" sec "+" #sym), unused)) \
= { (unsigned long)&sym, __kstrtab_##sym } = { (unsigned long)&sym, __kstrtab_##sym }
#define EXPORT_SYMBOL(sym) \ #define EXPORT_SYMBOL(sym) \

View file

@ -5,4 +5,15 @@
*/ */
SECTIONS { SECTIONS {
/DISCARD/ : { *(.discard) } /DISCARD/ : { *(.discard) }
__ksymtab : { *(SORT(___ksymtab+*)) }
__ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
__ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
__ksymtab_unused_gpl : { *(SORT(___ksymtab_unused_gpl+*)) }
__ksymtab_gpl_future : { *(SORT(___ksymtab_gpl_future+*)) }
__kcrctab : { *(SORT(___kcrctab+*)) }
__kcrctab_gpl : { *(SORT(___kcrctab_gpl+*)) }
__kcrctab_unused : { *(SORT(___kcrctab_unused+*)) }
__kcrctab_unused_gpl : { *(SORT(___kcrctab_unused_gpl+*)) }
__kcrctab_gpl_future : { *(SORT(___kcrctab_gpl_future+*)) }
} }