220-arm-gc_sections.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. --- a/arch/arm/Kconfig
  12. +++ b/arch/arm/Kconfig
  13. @@ -118,6 +118,7 @@ config ARM
  14. select HAVE_UID16
  15. select HAVE_VIRT_CPU_ACCOUNTING_GEN
  16. select IRQ_FORCED_THREADING
  17. + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
  18. select MODULES_USE_ELF_REL
  19. select NEED_DMA_MAP_STATE
  20. select OF_EARLY_FLATTREE if OF
  21. --- a/arch/arm/boot/compressed/Makefile
  22. +++ b/arch/arm/boot/compressed/Makefile
  23. @@ -92,6 +92,7 @@ endif
  24. ifeq ($(CONFIG_USE_OF),y)
  25. OBJS += $(libfdt_objs) fdt_check_mem_start.o
  26. endif
  27. +KBUILD_CFLAGS_KERNEL := $(patsubst -f%-sections,,$(KBUILD_CFLAGS_KERNEL))
  28. # -fstack-protector-strong triggers protection checks in this code,
  29. # but it is being used too early to link to meaningful stack_chk logic.
  30. --- a/arch/arm/kernel/vmlinux.lds.S
  31. +++ b/arch/arm/kernel/vmlinux.lds.S
  32. @@ -75,7 +75,7 @@ SECTIONS
  33. . = ALIGN(4);
  34. __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
  35. __start___ex_table = .;
  36. - ARM_MMU_KEEP(*(__ex_table))
  37. + KEEP(*(__ex_table))
  38. __stop___ex_table = .;
  39. }
  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/include/asm/vmlinux.lds.h
  69. +++ b/arch/arm/include/asm/vmlinux.lds.h
  70. @@ -42,13 +42,13 @@
  71. #define PROC_INFO \
  72. . = ALIGN(4); \
  73. __proc_info_begin = .; \
  74. - *(.proc.info.init) \
  75. + KEEP(*(.proc.info.init)) \
  76. __proc_info_end = .;
  77. #define IDMAP_TEXT \
  78. ALIGN_FUNCTION(); \
  79. __idmap_text_start = .; \
  80. - *(.idmap.text) \
  81. + KEEP(*(.idmap.text)) \
  82. __idmap_text_end = .; \
  83. #define ARM_DISCARD \
  84. @@ -109,12 +109,12 @@
  85. . = ALIGN(8); \
  86. .ARM.unwind_idx : { \
  87. __start_unwind_idx = .; \
  88. - *(.ARM.exidx*) \
  89. + KEEP(*(.ARM.exidx*)) \
  90. __stop_unwind_idx = .; \
  91. } \
  92. .ARM.unwind_tab : { \
  93. __start_unwind_tab = .; \
  94. - *(.ARM.extab*) \
  95. + KEEP(*(.ARM.extab*)) \
  96. __stop_unwind_tab = .; \
  97. }
  98. @@ -126,7 +126,7 @@
  99. __vectors_lma = .; \
  100. OVERLAY 0xffff0000 : NOCROSSREFS AT(__vectors_lma) { \
  101. .vectors { \
  102. - *(.vectors) \
  103. + KEEP(*(.vectors)) \
  104. } \
  105. .vectors.bhb.loop8 { \
  106. *(.vectors.bhb.loop8) \
  107. @@ -144,7 +144,7 @@
  108. \
  109. __stubs_lma = .; \
  110. .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_lma) { \
  111. - *(.stubs) \
  112. + KEEP(*(.stubs)) \
  113. } \
  114. ARM_LMA(__stubs, .stubs); \
  115. . = __stubs_lma + SIZEOF(.stubs); \