220-arm-gc_sections.patch 3.2 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. @@ -124,6 +124,7 @@ config ARM
  14. select HAVE_VIRT_CPU_ACCOUNTING_GEN
  15. select IRQ_FORCED_THREADING
  16. select LOCK_MM_AND_FIND_VMA
  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. @@ -91,6 +91,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. OBJS += lib1funcs.o ashldi3.o bswapsdi2.o
  29. --- a/arch/arm/kernel/vmlinux.lds.S
  30. +++ b/arch/arm/kernel/vmlinux.lds.S
  31. @@ -75,7 +75,7 @@ SECTIONS
  32. . = ALIGN(4);
  33. __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
  34. __start___ex_table = .;
  35. - ARM_MMU_KEEP(*(__ex_table))
  36. + KEEP(*(__ex_table))
  37. __stop___ex_table = .;
  38. }
  39. @@ -100,24 +100,24 @@ SECTIONS
  40. }
  41. .init.arch.info : {
  42. __arch_info_begin = .;
  43. - *(.arch.info.init)
  44. + KEEP(*(.arch.info.init))
  45. __arch_info_end = .;
  46. }
  47. .init.tagtable : {
  48. __tagtable_begin = .;
  49. - *(.taglist.init)
  50. + KEEP(*(.taglist.init))
  51. __tagtable_end = .;
  52. }
  53. #ifdef CONFIG_SMP_ON_UP
  54. .init.smpalt : {
  55. __smpalt_begin = .;
  56. - *(.alt.smp.init)
  57. + KEEP(*(.alt.smp.init))
  58. __smpalt_end = .;
  59. }
  60. #endif
  61. .init.pv_table : {
  62. __pv_table_begin = .;
  63. - *(.pv_table)
  64. + KEEP(*(.pv_table))
  65. __pv_table_end = .;
  66. }
  67. --- a/arch/arm/include/asm/vmlinux.lds.h
  68. +++ b/arch/arm/include/asm/vmlinux.lds.h
  69. @@ -42,13 +42,13 @@
  70. #define PROC_INFO \
  71. . = ALIGN(4); \
  72. __proc_info_begin = .; \
  73. - *(.proc.info.init) \
  74. + KEEP(*(.proc.info.init)) \
  75. __proc_info_end = .;
  76. #define IDMAP_TEXT \
  77. ALIGN_FUNCTION(); \
  78. __idmap_text_start = .; \
  79. - *(.idmap.text) \
  80. + KEEP(*(.idmap.text)) \
  81. __idmap_text_end = .; \
  82. #define ARM_DISCARD \
  83. @@ -109,12 +109,12 @@
  84. . = ALIGN(8); \
  85. .ARM.unwind_idx : { \
  86. __start_unwind_idx = .; \
  87. - *(.ARM.exidx*) \
  88. + KEEP(*(.ARM.exidx*)) \
  89. __stop_unwind_idx = .; \
  90. } \
  91. .ARM.unwind_tab : { \
  92. __start_unwind_tab = .; \
  93. - *(.ARM.extab*) \
  94. + KEEP(*(.ARM.extab*)) \
  95. __stop_unwind_tab = .; \
  96. }
  97. @@ -126,7 +126,7 @@
  98. __vectors_lma = .; \
  99. OVERLAY 0xffff0000 : NOCROSSREFS AT(__vectors_lma) { \
  100. .vectors { \
  101. - *(.vectors) \
  102. + KEEP(*(.vectors)) \
  103. } \
  104. .vectors.bhb.loop8 { \
  105. *(.vectors.bhb.loop8) \
  106. @@ -144,7 +144,7 @@
  107. \
  108. __stubs_lma = .; \
  109. .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_lma) { \
  110. - *(.stubs) \
  111. + KEEP(*(.stubs)) \
  112. } \
  113. ARM_LMA(__stubs, .stubs); \
  114. . = __stubs_lma + SIZEOF(.stubs); \