203-kallsyms_uncompressed.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. @@ -1451,6 +1451,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. @@ -62,6 +62,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. @@ -453,13 +454,15 @@ static void write_src(void)
  65. }
  66. printf("\n");
  67. - /*
  68. - * Now that we wrote out the compressed symbol names, restore the
  69. - * original names, which are needed in some of the later steps.
  70. - */
  71. - for (i = 0; i < table_cnt; i++) {
  72. - expand_symbol(table[i]->sym, table[i]->len, buf);
  73. - strcpy((char *)table[i]->sym, buf);
  74. + if (!uncompressed) {
  75. + /*
  76. + * Now that we wrote out the compressed symbol names, restore the
  77. + * original names, which are needed in some of the later steps.
  78. + */
  79. + for (i = 0; i < table_cnt; i++) {
  80. + expand_symbol(table[i]->sym, table[i]->len, buf);
  81. + strcpy((char *)table[i]->sym, buf);
  82. + }
  83. }
  84. output_label("kallsyms_markers");
  85. @@ -469,20 +472,22 @@ static void write_src(void)
  86. free(markers);
  87. - output_label("kallsyms_token_table");
  88. - off = 0;
  89. - for (i = 0; i < 256; i++) {
  90. - best_idx[i] = off;
  91. - expand_symbol(best_table[i], best_table_len[i], buf);
  92. - printf("\t.asciz\t\"%s\"\n", buf);
  93. - off += strlen(buf) + 1;
  94. - }
  95. - printf("\n");
  96. + if (!uncompressed) {
  97. + output_label("kallsyms_token_table");
  98. + off = 0;
  99. + for (i = 0; i < 256; i++) {
  100. + best_idx[i] = off;
  101. + expand_symbol(best_table[i], best_table_len[i], buf);
  102. + printf("\t.asciz\t\"%s\"\n", buf);
  103. + off += strlen(buf) + 1;
  104. + }
  105. + printf("\n");
  106. - output_label("kallsyms_token_index");
  107. - for (i = 0; i < 256; i++)
  108. - printf("\t.short\t%d\n", best_idx[i]);
  109. - printf("\n");
  110. + output_label("kallsyms_token_index");
  111. + for (i = 0; i < 256; i++)
  112. + printf("\t.short\t%d\n", best_idx[i]);
  113. + printf("\n");
  114. + }
  115. if (!base_relative)
  116. output_label("kallsyms_addresses");
  117. @@ -582,6 +587,9 @@ static unsigned char *find_token(unsigne
  118. {
  119. int i;
  120. + if (uncompressed)
  121. + return NULL;
  122. +
  123. for (i = 0; i < len - 1; i++) {
  124. if (str[i] == token[0] && str[i+1] == token[1])
  125. return &str[i];
  126. @@ -654,6 +662,9 @@ static void optimize_result(void)
  127. {
  128. int i, best;
  129. + if (uncompressed)
  130. + return;
  131. +
  132. /* using the '\0' symbol last allows compress_symbols to use standard
  133. * fast string functions */
  134. for (i = 255; i >= 0; i--) {
  135. @@ -815,6 +826,7 @@ int main(int argc, char **argv)
  136. {"absolute-percpu", no_argument, &absolute_percpu, 1},
  137. {"base-relative", no_argument, &base_relative, 1},
  138. {"lto-clang", no_argument, &lto_clang, 1},
  139. + {"uncompressed", no_argument, &uncompressed, 1},
  140. {},
  141. };
  142. --- a/scripts/link-vmlinux.sh
  143. +++ b/scripts/link-vmlinux.sh
  144. @@ -165,6 +165,10 @@ kallsyms()
  145. kallsymopt="${kallsymopt} --lto-clang"
  146. fi
  147. + if is_enabled CONFIG_KALLSYMS_UNCOMPRESSED; then
  148. + kallsymopt="${kallsymopt} --uncompressed"
  149. + fi
  150. +
  151. info KSYMS ${2}
  152. scripts/kallsyms ${kallsymopt} ${1} > ${2}
  153. }