This is an archive of the discontinued LLVM Phabricator instance.

Fix __cfi_check not aligned to 4k on relocatable files with no executable code
ClosedPublic

Authored by kongyi on Jul 19 2023, 11:25 AM.

Details

Summary

CrossDSOCFIPass is supposed to replace this stub function to a properly aligned function. However the pass is not ran if the file has no executable code, thus producing incorrectly aligned __cfi_check.

Fixes https://github.com/llvm/llvm-project/issues/45638.

Diff Detail

Event Timeline

kongyi created this revision.Jul 19 2023, 11:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 11:25 AM
kongyi requested review of this revision.Jul 19 2023, 11:25 AM
kongyi added a reviewer: pcc.
kongyi edited the summary of this revision. (Show Details)Jul 19 2023, 11:32 AM

Hmm, this is not 100% correct. CFI by design respects caller's settings for -fsanitize-recover and -fsanitize-trap, communicated through the DiagData argument to __cfi_check. A better default implementation would call __cfi_check_fail instead of trap unconditionally.

I do not see straight away why CrossDSOCFI pass is not run on no-code modules. Do you know the reason? If that's hard to change, we could modify clang codegen to call __cfi_check_fail from the stub __cfi_check. In that case, we also would not need to add __cfi_check_fail to the used globals list.

kongyi updated this revision to Diff 543617.Jul 24 2023, 10:19 AM

Hmm, this is not 100% correct. CFI by design respects caller's settings for -fsanitize-recover and -fsanitize-trap, communicated through the DiagData argument to __cfi_check. A better default implementation would call __cfi_check_fail instead of trap unconditionally.

I do not see straight away why CrossDSOCFI pass is not run on no-code modules. Do you know the reason? If that's hard to change, we could modify clang codegen to call __cfi_check_fail from the stub __cfi_check. In that case, we also would not need to add __cfi_check_fail to the used globals list.

Seems quite difficult to make CrossDSOCFI run with no code (a lot of interactions with other passes). I implemented your alternative suggestion, ptal.

eugenis added inline comments.Aug 2 2023, 3:46 AM
clang/lib/CodeGen/CGExpr.cpp
3452

I think the order is actually reversed? Pls compare codegen with a module that has some code (so that the pass runs) but no valid cfi targets.

clang/test/CodeGen/cfi-cross-dso-align.c
7

Please check the generated code in the test.

kongyi updated this revision to Diff 546732.Aug 3 2023, 12:40 AM
kongyi marked 2 inline comments as done.
eugenis accepted this revision.Aug 3 2023, 3:24 AM

LGTM, thank you.

This revision is now accepted and ready to land.Aug 3 2023, 3:24 AM
This revision was landed with ongoing or failed builds.Aug 3 2023, 3:54 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 3:54 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ro added a subscriber: ro.Aug 3 2023, 5:03 AM

It seems this patch broke the Solaris/amd64 buildbot:

FAIL: Clang::cfi-check-fail.c
thakis added a subscriber: thakis.Aug 3 2023, 5:07 AM

Looks like this breaks check-clang: http://45.33.8.238/linux/114361/step_7.txt

Please take a look and revert for now if it takes a while to fix.