1
0

203-kallsyms_uncompressed.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Subject: kernel: add a config option for keeping the kallsyms table uncompressed, saving ~9kb kernel size after lzma on ar71xx
  3. [john@phrozen.org: added to my upstream queue 30.12.2016]
  4. lede-commit: e0e3509b5ce2ccf93d4d67ea907613f5f7ec2eed
  5. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  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. @@ -1370,6 +1370,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. @@ -113,6 +113,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. @@ -145,6 +150,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. @@ -61,6 +61,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 = 0;
  60. +static int uncompressed = 0;
  61. static int absolute_percpu = 0;
  62. static char symbol_prefix_char = '\0';
  63. static int base_relative = 0;
  64. @@ -446,6 +447,9 @@ static void write_src(void)
  65. free(markers);
  66. + if (uncompressed)
  67. + return;
  68. +
  69. output_label("kallsyms_token_table");
  70. off = 0;
  71. for (i = 0; i < 256; i++) {
  72. @@ -504,6 +508,9 @@ static void *find_token(unsigned char *s
  73. {
  74. int i;
  75. + if (uncompressed)
  76. + return NULL;
  77. +
  78. for (i = 0; i < len - 1; i++) {
  79. if (str[i] == token[0] && str[i+1] == token[1])
  80. return &str[i];
  81. @@ -576,6 +583,9 @@ static void optimize_result(void)
  82. {
  83. int i, best;
  84. + if (uncompressed)
  85. + return;
  86. +
  87. /* using the '\0' symbol last allows compress_symbols to use standard
  88. * fast string functions */
  89. for (i = 255; i >= 0; i--) {
  90. @@ -764,6 +774,8 @@ int main(int argc, char **argv)
  91. symbol_prefix_char = *p;
  92. } else if (strcmp(argv[i], "--base-relative") == 0)
  93. base_relative = 1;
  94. + else if (strcmp(argv[i], "--uncompressed") == 0)
  95. + uncompressed = 1;
  96. else
  97. usage();
  98. }
  99. --- a/scripts/link-vmlinux.sh
  100. +++ b/scripts/link-vmlinux.sh
  101. @@ -136,6 +136,10 @@ kallsyms()
  102. kallsymopt="${kallsymopt} --base-relative"
  103. fi
  104. + if [ -n "${CONFIG_KALLSYMS_UNCOMPRESSED}" ]; then
  105. + kallsymopt="${kallsymopt} --uncompressed"
  106. + fi
  107. +
  108. local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
  109. ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"