Skip to content

Commit f02e8a6

Browse files
aboganirustyrussell
authored andcommitted
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>
1 parent de4d8d5 commit f02e8a6

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎include/asm-generic/vmlinux.lds.h‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,70 +274,70 @@
274274
/* Kernel symbol table: Normal symbols */ \
275275
__ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
276276
VMLINUX_SYMBOL(__start___ksymtab) = .; \
277-
*(__ksymtab) \
277+
*(SORT(___ksymtab+*)) \
278278
VMLINUX_SYMBOL(__stop___ksymtab) = .; \
279279
} \
280280
\
281281
/* Kernel symbol table: GPL-only symbols */ \
282282
__ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \
283283
VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \
284-
*(__ksymtab_gpl) \
284+
*(SORT(___ksymtab_gpl+*)) \
285285
VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \
286286
} \
287287
\
288288
/* Kernel symbol table: Normal unused symbols */ \
289289
__ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \
290290
VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \
291-
*(__ksymtab_unused) \
291+
*(SORT(___ksymtab_unused+*)) \
292292
VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \
293293
} \
294294
\
295295
/* Kernel symbol table: GPL-only unused symbols */ \
296296
__ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
297297
VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \
298-
*(__ksymtab_unused_gpl) \
298+
*(SORT(___ksymtab_unused_gpl+*)) \
299299
VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \
300300
} \
301301
\
302302
/* Kernel symbol table: GPL-future-only symbols */ \
303303
__ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
304304
VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \
305-
*(__ksymtab_gpl_future) \
305+
*(SORT(___ksymtab_gpl_future+*)) \
306306
VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \
307307
} \
308308
\
309309
/* Kernel symbol table: Normal symbols */ \
310310
__kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \
311311
VMLINUX_SYMBOL(__start___kcrctab) = .; \
312-
*(__kcrctab) \
312+
*(SORT(___kcrctab+*)) \
313313
VMLINUX_SYMBOL(__stop___kcrctab) = .; \
314314
} \
315315
\
316316
/* Kernel symbol table: GPL-only symbols */ \
317317
__kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \
318318
VMLINUX_SYMBOL(__start___kcrctab_gpl) = .; \
319-
*(__kcrctab_gpl) \
319+
*(SORT(___kcrctab_gpl+*)) \
320320
VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \
321321
} \
322322
\
323323
/* Kernel symbol table: Normal unused symbols */ \
324324
__kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \
325325
VMLINUX_SYMBOL(__start___kcrctab_unused) = .; \
326-
*(__kcrctab_unused) \
326+
*(SORT(___kcrctab_unused+*)) \
327327
VMLINUX_SYMBOL(__stop___kcrctab_unused) = .; \
328328
} \
329329
\
330330
/* Kernel symbol table: GPL-only unused symbols */ \
331331
__kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \
332332
VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .; \
333-
*(__kcrctab_unused_gpl) \
333+
*(SORT(___kcrctab_unused_gpl+*)) \
334334
VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .; \
335335
} \
336336
\
337337
/* Kernel symbol table: GPL-future-only symbols */ \
338338
__kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
339339
VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .; \
340-
*(__kcrctab_gpl_future) \
340+
*(SORT(___kcrctab_gpl_future+*)) \
341341
VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \
342342
} \
343343
\

‎include/linux/module.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ struct module_use {
224224
extern void *__crc_##sym __attribute__((weak)); \
225225
static const unsigned long __kcrctab_##sym \
226226
__used \
227-
__attribute__((section("__kcrctab" sec), unused)) \
227+
__attribute__((section("___kcrctab" sec "+" #sym), unused)) \
228228
= (unsigned long) &__crc_##sym;
229229
#else
230230
#define __CRC_SYMBOL(sym, sec)
@@ -239,7 +239,7 @@ struct module_use {
239239
= MODULE_SYMBOL_PREFIX #sym; \
240240
static const struct kernel_symbol __ksymtab_##sym \
241241
__used \
242-
__attribute__((section("__ksymtab" sec), unused)) \
242+
__attribute__((section("___ksymtab" sec "+" #sym), unused)) \
243243
= { (unsigned long)&sym, __kstrtab_##sym }
244244

245245
#define EXPORT_SYMBOL(sym) \

‎scripts/module-common.lds‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,15 @@
55
*/
66
SECTIONS {
77
/DISCARD/ : { *(.discard) }
8+
9+
__ksymtab : { *(SORT(___ksymtab+*)) }
10+
__ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
11+
__ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
12+
__ksymtab_unused_gpl : { *(SORT(___ksymtab_unused_gpl+*)) }
13+
__ksymtab_gpl_future : { *(SORT(___ksymtab_gpl_future+*)) }
14+
__kcrctab : { *(SORT(___kcrctab+*)) }
15+
__kcrctab_gpl : { *(SORT(___kcrctab_gpl+*)) }
16+
__kcrctab_unused : { *(SORT(___kcrctab_unused+*)) }
17+
__kcrctab_unused_gpl : { *(SORT(___kcrctab_unused_gpl+*)) }
18+
__kcrctab_gpl_future : { *(SORT(___kcrctab_gpl_future+*)) }
819
}

0 commit comments

Comments
 (0)