220-arm-gc_sections.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. From e3d8676f5722b7622685581e06e8f53e6138e3ab Mon Sep 17 00:00:00 2001
  2. From: Felix Fietkau <[email protected]>
  3. Date: Sat, 15 Jul 2017 23:42:36 +0200
  4. Subject: use -ffunction-sections, -fdata-sections and --gc-sections
  5. In combination with kernel symbol export stripping this significantly reduces
  6. the kernel image size. Used on both ARM and MIPS architectures.
  7. Signed-off-by: Felix Fietkau <[email protected]>
  8. Signed-off-by: Jonas Gorski <[email protected]>
  9. Signed-off-by: Gabor Juhos <[email protected]>
  10. ---
  11. Makefile | 10 +++----
  12. arch/arm/Kconfig | 1 +
  13. arch/arm/boot/compressed/Makefile | 1 +
  14. arch/arm/kernel/vmlinux.lds.S | 26 ++++++++--------
  15. arch/mips/Kconfig | 1 +
  16. arch/mips/kernel/vmlinux.lds.S | 4 +--
  17. include/asm-generic/vmlinux.lds.h | 63 ++++++++++++++++++++-------------------
  18. 7 files changed, 55 insertions(+), 51 deletions(-)
  19. --- a/arch/arm/Kconfig
  20. +++ b/arch/arm/Kconfig
  21. @@ -111,6 +111,7 @@ config ARM
  22. select HAVE_UID16
  23. select HAVE_VIRT_CPU_ACCOUNTING_GEN
  24. select IRQ_FORCED_THREADING
  25. + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
  26. select MODULES_USE_ELF_REL
  27. select NEED_DMA_MAP_STATE
  28. select OF_EARLY_FLATTREE if OF
  29. --- a/arch/arm/boot/compressed/Makefile
  30. +++ b/arch/arm/boot/compressed/Makefile
  31. @@ -108,6 +108,7 @@ ifeq ($(CONFIG_FUNCTION_TRACER),y)
  32. ORIG_CFLAGS := $(KBUILD_CFLAGS)
  33. KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
  34. endif
  35. +KBUILD_CFLAGS_KERNEL := $(patsubst -f%-sections,,$(KBUILD_CFLAGS_KERNEL))
  36. # -fstack-protector-strong triggers protection checks in this code,
  37. # but it is being used too early to link to meaningful stack_chk logic.
  38. --- a/arch/arm/kernel/vmlinux.lds.S
  39. +++ b/arch/arm/kernel/vmlinux.lds.S
  40. @@ -73,7 +73,7 @@ SECTIONS
  41. . = ALIGN(4);
  42. __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
  43. __start___ex_table = .;
  44. - ARM_MMU_KEEP(*(__ex_table))
  45. + KEEP(*(__ex_table))
  46. __stop___ex_table = .;
  47. }
  48. @@ -100,24 +100,24 @@ SECTIONS
  49. }
  50. .init.arch.info : {
  51. __arch_info_begin = .;
  52. - *(.arch.info.init)
  53. + KEEP(*(.arch.info.init))
  54. __arch_info_end = .;
  55. }
  56. .init.tagtable : {
  57. __tagtable_begin = .;
  58. - *(.taglist.init)
  59. + KEEP(*(.taglist.init))
  60. __tagtable_end = .;
  61. }
  62. #ifdef CONFIG_SMP_ON_UP
  63. .init.smpalt : {
  64. __smpalt_begin = .;
  65. - *(.alt.smp.init)
  66. + KEEP(*(.alt.smp.init))
  67. __smpalt_end = .;
  68. }
  69. #endif
  70. .init.pv_table : {
  71. __pv_table_begin = .;
  72. - *(.pv_table)
  73. + KEEP(*(.pv_table))
  74. __pv_table_end = .;
  75. }
  76. --- a/arch/arm/kernel/vmlinux.lds.h
  77. +++ b/arch/arm/kernel/vmlinux.lds.h
  78. @@ -28,7 +28,7 @@
  79. #define PROC_INFO \
  80. . = ALIGN(4); \
  81. __proc_info_begin = .; \
  82. - *(.proc.info.init) \
  83. + KEEP(*(.proc.info.init)) \
  84. __proc_info_end = .;
  85. #define HYPERVISOR_TEXT \
  86. @@ -39,11 +39,11 @@
  87. #define IDMAP_TEXT \
  88. ALIGN_FUNCTION(); \
  89. __idmap_text_start = .; \
  90. - *(.idmap.text) \
  91. + KEEP(*(.idmap.text)) \
  92. __idmap_text_end = .; \
  93. . = ALIGN(PAGE_SIZE); \
  94. __hyp_idmap_text_start = .; \
  95. - *(.hyp.idmap.text) \
  96. + KEEP(*(.hyp.idmap.text)) \
  97. __hyp_idmap_text_end = .;
  98. #define ARM_DISCARD \
  99. @@ -86,12 +86,12 @@
  100. . = ALIGN(8); \
  101. .ARM.unwind_idx : { \
  102. __start_unwind_idx = .; \
  103. - *(.ARM.exidx*) \
  104. + KEEP(*(.ARM.exidx*)) \
  105. __stop_unwind_idx = .; \
  106. } \
  107. .ARM.unwind_tab : { \
  108. __start_unwind_tab = .; \
  109. - *(.ARM.extab*) \
  110. + KEEP(*(.ARM.extab*)) \
  111. __stop_unwind_tab = .; \
  112. }
  113. @@ -102,14 +102,14 @@
  114. #define ARM_VECTORS \
  115. __vectors_start = .; \
  116. .vectors 0xffff0000 : AT(__vectors_start) { \
  117. - *(.vectors) \
  118. + KEEP(*(.vectors)) \
  119. } \
  120. . = __vectors_start + SIZEOF(.vectors); \
  121. __vectors_end = .; \
  122. \
  123. __stubs_start = .; \
  124. .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { \
  125. - *(.stubs) \
  126. + KEEP(*(.stubs)) \
  127. } \
  128. . = __stubs_start + SIZEOF(.stubs); \
  129. __stubs_end = .; \