220-gc_sections.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. @@ -106,6 +106,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. @@ -100,24 +100,24 @@ SECTIONS
  41. }
  42. .init.arch.info : {
  43. __arch_info_begin = .;
  44. - *(.arch.info.init)
  45. + KEEP(*(.arch.info.init))
  46. __arch_info_end = .;
  47. }
  48. .init.tagtable : {
  49. __tagtable_begin = .;
  50. - *(.taglist.init)
  51. + KEEP(*(.taglist.init))
  52. __tagtable_end = .;
  53. }
  54. #ifdef CONFIG_SMP_ON_UP
  55. .init.smpalt : {
  56. __smpalt_begin = .;
  57. - *(.alt.smp.init)
  58. + KEEP(*(.alt.smp.init))
  59. __smpalt_end = .;
  60. }
  61. #endif
  62. .init.pv_table : {
  63. __pv_table_begin = .;
  64. - *(.pv_table)
  65. + KEEP(*(.pv_table))
  66. __pv_table_end = .;
  67. }
  68. --- a/arch/arm/kernel/vmlinux.lds.h
  69. +++ b/arch/arm/kernel/vmlinux.lds.h
  70. @@ -22,13 +22,13 @@
  71. #define ARM_MMU_DISCARD(x)
  72. #else
  73. #define ARM_MMU_KEEP(x)
  74. -#define ARM_MMU_DISCARD(x) x
  75. +#define ARM_MMU_DISCARD(x) KEEP(x)
  76. #endif
  77. #define PROC_INFO \
  78. . = ALIGN(4); \
  79. __proc_info_begin = .; \
  80. - *(.proc.info.init) \
  81. + KEEP(*(.proc.info.init)) \
  82. __proc_info_end = .;
  83. #define HYPERVISOR_TEXT \
  84. @@ -39,11 +39,11 @@
  85. #define IDMAP_TEXT \
  86. ALIGN_FUNCTION(); \
  87. __idmap_text_start = .; \
  88. - *(.idmap.text) \
  89. + KEEP(*(.idmap.text)) \
  90. __idmap_text_end = .; \
  91. . = ALIGN(PAGE_SIZE); \
  92. __hyp_idmap_text_start = .; \
  93. - *(.hyp.idmap.text) \
  94. + KEEP(*(.hyp.idmap.text)) \
  95. __hyp_idmap_text_end = .;
  96. #define ARM_DISCARD \
  97. @@ -86,12 +86,12 @@
  98. . = ALIGN(8); \
  99. .ARM.unwind_idx : { \
  100. __start_unwind_idx = .; \
  101. - *(.ARM.exidx*) \
  102. + KEEP(*(.ARM.exidx*)) \
  103. __stop_unwind_idx = .; \
  104. } \
  105. .ARM.unwind_tab : { \
  106. __start_unwind_tab = .; \
  107. - *(.ARM.extab*) \
  108. + KEEP(*(.ARM.extab*)) \
  109. __stop_unwind_tab = .; \
  110. }
  111. @@ -102,14 +102,14 @@
  112. #define ARM_VECTORS \
  113. __vectors_start = .; \
  114. .vectors 0xffff0000 : AT(__vectors_start) { \
  115. - *(.vectors) \
  116. + KEEP(*(.vectors)) \
  117. } \
  118. . = __vectors_start + SIZEOF(.vectors); \
  119. __vectors_end = .; \
  120. \
  121. __stubs_start = .; \
  122. .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { \
  123. - *(.stubs) \
  124. + KEEP(*(.stubs)) \
  125. } \
  126. . = __stubs_start + SIZEOF(.stubs); \
  127. __stubs_end = .; \