203-kallsyms_uncompressed.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. @@ -1145,6 +1145,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. @@ -74,6 +74,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. @@ -106,6 +111,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 int base_relative = 0;
  63. @@ -439,6 +440,9 @@ static void write_src(void)
  64. free(markers);
  65. + if (uncompressed)
  66. + return;
  67. +
  68. output_label("kallsyms_token_table");
  69. off = 0;
  70. for (i = 0; i < 256; i++) {
  71. @@ -497,6 +501,9 @@ static void *find_token(unsigned char *s
  72. {
  73. int i;
  74. + if (uncompressed)
  75. + return NULL;
  76. +
  77. for (i = 0; i < len - 1; i++) {
  78. if (str[i] == token[0] && str[i+1] == token[1])
  79. return &str[i];
  80. @@ -569,6 +576,9 @@ static void optimize_result(void)
  81. {
  82. int i, best;
  83. + if (uncompressed)
  84. + return;
  85. +
  86. /* using the '\0' symbol last allows compress_symbols to use standard
  87. * fast string functions */
  88. for (i = 255; i >= 0; i--) {
  89. @@ -751,6 +761,8 @@ int main(int argc, char **argv)
  90. absolute_percpu = 1;
  91. else if (strcmp(argv[i], "--base-relative") == 0)
  92. base_relative = 1;
  93. + else if (strcmp(argv[i], "--uncompressed") == 0)
  94. + uncompressed = 1;
  95. else
  96. usage();
  97. }
  98. --- a/scripts/link-vmlinux.sh
  99. +++ b/scripts/link-vmlinux.sh
  100. @@ -133,6 +133,10 @@ kallsyms()
  101. kallsymopt="${kallsymopt} --base-relative"
  102. fi
  103. + if [ -n "${CONFIG_KALLSYMS_UNCOMPRESSED}" ]; then
  104. + kallsymopt="${kallsymopt} --uncompressed"
  105. + fi
  106. +
  107. local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
  108. ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"