Skip to content

Commit 84d5f77

Browse files
hjl-toolssuryasaimadhu
authored andcommitted
x86, vmlinux.lds: Add RUNTIME_DISCARD_EXIT to generic DISCARDS
In the x86 kernel, .exit.text and .exit.data sections are discarded at runtime, not by the linker. Add RUNTIME_DISCARD_EXIT to generic DISCARDS and define it in the x86 kernel linker script to keep them. The sections are added before the DISCARD directive so document here only the situation explicitly as this change doesn't have any effect on the generated kernel. Also, other architectures like ARM64 will use it too so generalize the approach with the RUNTIME_DISCARD_EXIT define. [ bp: Massage and extend commit message. ] Signed-off-by: H.J. Lu <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 645e646 commit 84d5f77

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

arch/x86/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define LOAD_OFFSET __START_KERNEL_map
2222
#endif
2323

24+
#define RUNTIME_DISCARD_EXIT
2425
#define EMITS_PT_NOTE
2526
#define RO_EXCEPTION_TABLE_ALIGN 16
2627

include/asm-generic/vmlinux.lds.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,17 @@
894894
* section definitions so that such archs put those in earlier section
895895
* definitions.
896896
*/
897+
#ifdef RUNTIME_DISCARD_EXIT
898+
#define EXIT_DISCARDS
899+
#else
900+
#define EXIT_DISCARDS \
901+
EXIT_TEXT \
902+
EXIT_DATA
903+
#endif
904+
897905
#define DISCARDS \
898906
/DISCARD/ : { \
899-
EXIT_TEXT \
900-
EXIT_DATA \
907+
EXIT_DISCARDS \
901908
EXIT_CALL \
902909
*(.discard) \
903910
*(.discard.*) \

0 commit comments

Comments
 (0)