203-kallsyms_uncompressed.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. From: Felix Fietkau <[email protected]>
  2. Subject: kernel: add a config option for keeping the kallsyms table uncompressed, saving ~9kb kernel size after lzma on ar71xx
  3. [[email protected]: added to my upstream queue 30.12.2016]
  4. lede-commit: e0e3509b5ce2ccf93d4d67ea907613f5f7ec2eed
  5. Signed-off-by: Felix Fietkau <[email protected]>
  6. ---
  7. init/Kconfig | 11 +++++++++++
  8. kernel/kallsyms.c | 8 ++++++++
  9. scripts/kallsyms.c | 12 ++++++++++++
  10. scripts/link-vmlinux.sh | 4 ++++
  11. 4 files changed, 35 insertions(+)
  12. --- a/init/Kconfig
  13. +++ b/init/Kconfig
  14. @@ -1482,6 +1482,17 @@ config SYSCTL_ARCH_UNALIGN_ALLOW
  15. the unaligned access emulation.
  16. see arch/parisc/kernel/unaligned.c for reference
  17. +config KALLSYMS_UNCOMPRESSED
  18. + bool "Keep kallsyms uncompressed"
  19. + depends on KALLSYMS
  20. + help
  21. + Normally kallsyms contains compressed symbols (using a token table),
  22. + reducing the uncompressed kernel image size. Keeping the symbol table
  23. + uncompressed significantly improves the size of this part in compressed
  24. + kernel images.
  25. +
  26. + Say N unless you need compressed kernel images to be small.
  27. +
  28. config HAVE_PCSPKR_PLATFORM
  29. bool
  30. --- a/kernel/kallsyms.c
  31. +++ b/kernel/kallsyms.c
  32. @@ -69,6 +69,11 @@ static unsigned int kallsyms_expand_symb
  33. * For every byte on the compressed symbol data, copy the table
  34. * entry for that byte.
  35. */
  36. +#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
  37. + memcpy(result, data + 1, len - 1);
  38. + result += len - 1;
  39. + len = 0;
  40. +#endif
  41. while (len) {
  42. tptr = &kallsyms_token_table[kallsyms_token_index[*data]];
  43. data++;
  44. @@ -101,6 +106,9 @@ tail:
  45. */
  46. static char kallsyms_get_symbol_type(unsigned int off)
  47. {
  48. +#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
  49. + return kallsyms_names[off + 1];
  50. +#endif
  51. /*
  52. * Get just the first code, look it up in the token table,
  53. * and return the first char from this token.
  54. --- a/scripts/kallsyms.c
  55. +++ b/scripts/kallsyms.c
  56. @@ -77,6 +77,7 @@ static struct addr_range percpu_range =
  57. static struct sym_entry **table;
  58. static unsigned int table_size, table_cnt;
  59. static int all_symbols;
  60. +static int uncompressed;
  61. static int absolute_percpu;
  62. static int base_relative;
  63. static int lto_clang;
  64. @@ -605,6 +606,9 @@ static void write_src(void)
  65. printf("\t.long\t%u\n", table[i]->seq);
  66. printf("\n");
  67. + if (uncompressed)
  68. + return;
  69. +
  70. output_label("kallsyms_token_table");
  71. off = 0;
  72. for (i = 0; i < 256; i++) {
  73. @@ -656,6 +660,9 @@ static unsigned char *find_token(unsigne
  74. {
  75. int i;
  76. + if (uncompressed)
  77. + return NULL;
  78. +
  79. for (i = 0; i < len - 1; i++) {
  80. if (str[i] == token[0] && str[i+1] == token[1])
  81. return &str[i];
  82. @@ -728,6 +735,9 @@ static void optimize_result(void)
  83. {
  84. int i, best;
  85. + if (uncompressed)
  86. + return;
  87. +
  88. /* using the '\0' symbol last allows compress_symbols to use standard
  89. * fast string functions */
  90. for (i = 255; i >= 0; i--) {
  91. @@ -889,6 +899,7 @@ int main(int argc, char **argv)
  92. {"absolute-percpu", no_argument, &absolute_percpu, 1},
  93. {"base-relative", no_argument, &base_relative, 1},
  94. {"lto-clang", no_argument, &lto_clang, 1},
  95. + {"uncompressed", no_argument, &uncompressed, 1},
  96. {},
  97. };
  98. --- a/scripts/link-vmlinux.sh
  99. +++ b/scripts/link-vmlinux.sh
  100. @@ -160,6 +160,10 @@ kallsyms()
  101. kallsymopt="${kallsymopt} --lto-clang"
  102. fi
  103. + if is_enabled CONFIG_KALLSYMS_UNCOMPRESSED; then
  104. + kallsymopt="${kallsymopt} --uncompressed"
  105. + fi
  106. +
  107. info KSYMS ${2}
  108. scripts/kallsyms ${kallsymopt} ${1} > ${2}
  109. }