Skip to content

Commit

Permalink
ANDROID: module: cfi: ensure __cfi_check alignment
Browse files Browse the repository at this point in the history
On modules with no executable code, LLVM generates a __cfi_check stub,
but won't align it to page size as expected. This change ensures the
function is at the beginning of the .text section and correctly aligned
for the CFI shadow.

Also discard the .eh_frame section, which LLD may emit with CFI_CLANG.

Bug: 145210207
Change-Id: I08923febb549aa64454282cc864ac80dadd717b9
Link: https://bugs.llvm.org/show_bug.cgi?id=46293
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
  • Loading branch information
samitolvanen authored and adelva1984 committed Jan 14, 2021
1 parent 6010ce3 commit 08f67ef
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion scripts/module.lds.S
Expand Up @@ -3,10 +3,17 @@
* Archs are free to supply their own linker scripts. ld will
* combine them automatically.
*/
#include <asm/page.h>

SECTIONS {
/DISCARD/ : {
*(.discard)
*(.discard.*)
/*
* LLD may emit .eh_frame with CONFIG_CFI_CLANG despite
* -fno-asynchronous-unwind-tables. Discard the section.
*/
*(.eh_frame)
}

__ksymtab 0 : { *(SORT(___ksymtab+*)) }
Expand Down Expand Up @@ -46,7 +53,16 @@ SECTIONS {
*(.rodata..L*)
}

.text : { *(.text .text.[0-9a-zA-Z_]*) }
#ifdef CONFIG_CFI_CLANG
/*
* With CFI_CLANG, ensure __cfi_check is at the beginning of the
* .text section, and that the section is aligned to page size.
*/
.text : ALIGN(PAGE_SIZE) {
*(.text.__cfi_check)
*(.text .text.[0-9a-zA-Z_]* .text..L.cfi*)
}
#endif
}

/* bring in arch-specific sections */
Expand Down

0 comments on commit 08f67ef

Please sign in to comment.