This is an archive of the discontinued LLVM Phabricator instance.

[cfi] Set function attributes for __cfi_* functions.
Needs ReviewPublic

Authored by eugenis on Sep 8 2017, 5:57 PM.

Details

Reviewers
pcc
echristo
Summary

Set target_cpu and target_features attributes on cfi_check_fail and
cfi_check. Make cfi_check use Thumb encoding on ARM target.

Event Timeline

eugenis created this revision.Sep 8 2017, 5:57 PM
echristo added inline comments.Sep 21 2017, 5:36 PM
clang/lib/CodeGen/CGExpr.cpp
2917

I don't think we should be force setting thumb anywhere, it should be handled on a function by function basis the way we do all of the target attribute stuff.

2926–2935

All of this should be handled in lib/Basic/Targets/ARM.cpp ARMTargetInfo::initFeatureMap ?

2934–2936

This is odd. Can you explain this a bit more?

eugenis added inline comments.Sep 21 2017, 5:57 PM
clang/lib/CodeGen/CGExpr.cpp
2917

We want this function to be Thumb even if the rest of the module is ARM. It lets us use 2x less memory in the implementation of __cfi_slowpath here:
https://clang.llvm.org/docs/ControlFlowIntegrityDesign.html#cfi-slowpath

This function does not have source, so it can not have target attributes, too.

Are you suggesting faking a piece of AST (FunctionDecl with attached attributes) and then using the regular attribute setting code?

2934–2936

__cfi_check is called from compiler-rt or libdl.so, so it can not have any fancy calling convention. It must use what's standard on the platform.

OK, __cfi_check has no floating-point parameters, so -mhard-float would not be a problem.

echristo added inline comments.Sep 21 2017, 6:27 PM
clang/lib/CodeGen/CGExpr.cpp
2917

Aha. Didn't remember that part of the design.

And yeah, that sounds good. And it doesn't really matter if the function has any source code as to whether or not it has attributes. There's no inheritance structure going on here so every function should have them.

2934–2936

Yeah, I think this falls in on the earlier comment. Should probably add the defaults to a bit of AST or something?

eugenis updated this revision to Diff 116618.Sep 25 2017, 2:38 PM

Switched to SetLLVMFunctionAttributes

llvm/lib/Transforms/IPO/CrossDSOCFI.cpp