This is an archive of the discontinued LLVM Phabricator instance.

[X86][CET] Support to build LLVM toolchain with CET enabled.
Needs ReviewPublic

Authored by xiongji90 on Jul 7 2021, 7:11 PM.

Details

Summary

This patch is the first one of a series of patches aiming to support to build llvm toolchain(compiler, tools, libraries) with CET enabled. Currently, CET has been implemented in x86 Linux target and in order to compile source code with CET enabled, "-fcf-protection=full" should be added. CET introduces 'IBT' which restricts the target of indirect jumps and 'SHSTK' is also introduced which aims to check the return address when a function is going to return to caller. This patch introduces the option "LLVM_BUILD_CET_ENABLE", if you want to build compiler and libraries with CET enabled, you can set this option to ON:
cmake -G "Unix Makefiles" -DLLVM_BUILD_CET_ENABLE=ON ...
The default value is OFF. Not all subprojects support building with CET, so we don't add any CET build option in this patch. For those subprojects which have already supported CET, they can add CET building option based on "LLVM_BUILD_CET_ENABLE" option.

Diff Detail

Event Timeline

xiongji90 created this revision.Jul 7 2021, 7:11 PM
xiongji90 requested review of this revision.Jul 7 2021, 7:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2021, 7:11 PM
manojgupta added inline comments.Jul 19 2021, 10:13 AM
llvm/cmake/modules/HandleLLVMOptions.cmake
372

I am not an expert in CMake but I think we need to add support for this option per subproject as well since the projects can be built independent of LLVM e.g. : compiler-rt, libcxx, libcxxbi, libunwind can be built separately without compiling llvm.

xiongji90 added inline comments.Jul 20 2021, 12:23 AM
llvm/cmake/modules/HandleLLVMOptions.cmake
372

Hi, @manojgupta
Agree on your suggestion. Enabling CET for each subproject one by one should be the correct practice.
I will update the patch to remove adding CET compiling options here, do you think we can keep "LLVM_BUILD_CET_ENABLE" here? When all subprojects have been enabled CET building, we can use this option to build whole llvm toolchain with CET enabled.
Thanks very much!

xiongji90 updated this revision to Diff 360689.Jul 21 2021, 8:45 PM
xiongji90 edited the summary of this revision. (Show Details)