-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive with -fsanitize=function on macOS #109074
Comments
Yes. Mach-O's
Some linker features ( Perhaps we should just make |
Thank you for the background, that certainly explains the behaviour I observed.
To me, it would be preferable to disable it for Mach-O. Having UBSan fail unpredictably on correct code seems like a serious issue. |
Summary: `-fsanitize=function` relies on storing data before a function pointer that describes the type of the function. However, on Apple platforms, this data gets treated as part of the preceding function and can be moved around or deleted. This results in UBSan false positives. To address this, pass `-fno-sanitize=function` when compiling for Apple platforms with UBSan enabled. See llvm/llvm-project#109074 Reviewed By: fbmal7 Differential Revision: D62921741 fbshipit-source-id: da7fe78fc09840c90a48e6dfcf32ed14c514c323
"-fsanitize=function" is designed to catch when calling a function through a pointer of the wrong type (much like "-fsanitize=cfi-*call", but a completely different mechanism). However, this is currently known to have issues on macOS [0]. [0] llvm/llvm-project#109074 Change-Id: I66f51d8190f6105f852676a8faaf694e7f0dbcca Reviewed-on: https://skia-review.googlesource.com/c/skia/+/903958 Reviewed-by: Kaylee Lubick <kjlubick@google.com>
Seeing failures with
-fsanitize=function
when building on macOS for function calls where the type signature is actually correct. It seems like the type hash is not being preserved through linking.Verified with:
Minimised repro (note that the exact ordering is important to get things in the right order in the final binary):
foo.cpp:
foo2.cpp:
Build and run (add
-arch x86_64
if needed):Result:
To my untrained eye, it looks like the linker may be treating the type hash placed before
myFn
as part of the preceding function, and when that function occurs in multiple object files (as is the case formyT<void>
), only one copy is kept. As a result, the bytes precedingmyFn
no longer represent its correct type hash.The text was updated successfully, but these errors were encountered: