llvm/llvm-project

`-mfunction-return=thunk-extern` does not affect sanitizer constructors

nickdesaulniers opened this issue · 5 comments

As reported by @nathanchance here, mixing -mfunction-return=thunk-extern with various sanitizers is not producing mitigated sanitizer constructor functions.

I know exactly what this is; the front-end attributes functions during clang's CodeGen of LLVM IR that they should be fn_ret_thunk_extern. Then LLVM synthesizes new functions without knowledge that new functions should have these attributes. We've seen this before, I think with stack protectors (nossp, ssp, etc).

I will fix this, but marking it a blocker for the clang-15 release, and to have something to point to so I can pause ongoing backporting issues related to retbleed for this.

cc @topperc @AaronBallman @kees

@llvm/issue-subscribers-bug

@nathanchance mentioned that this is a similar problem we've had with PAC/BTI: a88c722.

It's not just the sanitizers, CONFIG_GCOV_KERNEL=y + CONFIG_GCOV_PROFILE_ALL=y also has this issue:

...
drivers/base/platform.o: warning: objtool: __llvm_gcov_reset+0xa94: 'naked' return found in RETHUNK build
net/core/netpoll.o: warning: objtool: __llvm_gcov_reset+0xde3: 'naked' return found in RETHUNK build
net/netfilter/nf_conntrack_netlink.o: warning: objtool: __llvm_gcov_reset+0x1b94: 'naked' return found in RETHUNK build
fs/fs_parser.o: warning: objtool: __llvm_gcov_reset+0x344: 'naked' return found in RETHUNK build
drivers/acpi/debugfs.o: warning: objtool: __llvm_gcov_reset+0xb: 'naked' return found in RETHUNK build
mm/pagewalk.o: warning: objtool: __llvm_gcov_reset+0x77f: 'naked' return found in RETHUNK build
drivers/tty/serial/8250/8250_pnp.o: warning: objtool: __llvm_gcov_reset+0x231: 'naked' return found in RETHUNK build
fs/init.o: warning: objtool: __llvm_gcov_reset+0x2f7: 'naked' return found in RETHUNK build
drivers/gpu/drm/drm_fourcc.o: warning: objtool: __llvm_gcov_reset+0x1ce: 'naked' return found in RETHUNK build
...

so I should test gcov, too.

Something more like
commit 2786e67 ("[IR][sanitizer] Add module flag "frame-pointer" and set it for cc1 -mframe-pointer={non-leaf,all}")
and less like
commit b7926ce ("[IR] add fn attr for no_stack_protector; prevent inlining on mismatch")
is probably a good solution here.

@llvm/issue-subscribers-clang-codegen