在编译Linux 新版本内核时可以使用clang LLVM工具链进行编译
make LLVM=1 menuconfig
启用LLVM工具链编译,可以在Linux内核启用 LTO=thin链接时优化
在编译randstruct时,clang内置了数据结构随机化功能,不再需要gcc 插件编译使能randstruct
CONFIG_RANDSTRUCT_FULL=y
CONFIG_RANDSTRUCT=y
GCC使能randstruct需要手动编译位于内核代码树的
linux-7.0/scripts/gcc-plugins/randomize_layout_plugin.c
然后使用此插件完成对内核所有打标签的数据结构进行随机化例如
struct task_struct {
/*
* This begins the randomizable portion of task_struct. Only
* scheduling-critical items should be added above here.
*/
randomized_struct_fields_start
随机化编译器指令之间的数据结构字段
.....
/*
* New fields for task_struct should be added above here, so that
* they are included in the randomized portion of task_struct.
*/
randomized_struct_fields_end
}
或者整个数据结构随机化
struct linux_binprm {
......
} __randomize_layout;
在完成编译之后需要使用
make LLVM=1 modules_install
make LLVM=1 install
安装内核
发表回复