You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sunder allows implicit casting of a function with parameter types and/or a return type of type *T to a function type where those same parameter types and/or return type are of type *any. In the original NASM-flavored assembly emitted when Sunder was targeting x64 Linux, this function-to-function casting was explicitly permitted, as the stack-based Sunder calling convention guaranteed function calls with these types to be ABI-compatible. However, ISO C does not permit this form of casting, leading to undefined behavior when UBSan encounters a function call made using a function value that was the result of such a cast:
~/sources/sunder[main]$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble
~/sources/sunder[main]$ clang -v
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Candidate multilib: .;@m64
Selected multilib: .;@m64
~/sources/sunder[main]$ git rev-parse HEAD
b426793813d5d943fec12d6f005ae4294391580d
~/sources/sunder[main]$ SUNDER_CC=clang SUNDER_CFLAGS='-fsanitize=undefined' sunder-run examples/hello.sunder
a.out.tmp.c:4285:310: runtime error: call to functionstd_file_write through pointer to incorrect functiontype'struct std_result_TEMPLATE_BGN_usize_COMMA_pointer_to_std_error_info_TEMPLATE_END (*)(void *, __sunder_slice_of_byte)'
(/home/ashn/sources/sunder/a.out+0x50ae8): note: std_file_write defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior a.out.tmp.c:4285:310
Hello, world!
In practice, it is expected that these casts should be well behaved on modern Unix-like platforms, as one would expect all pointer types to be represented the same at the ABI level. However, there is no strict guarantee that this behavior will remain true for all current and future supported platforms.
Sunder allows implicit casting of a function with parameter types and/or a return type of type
*T
to a function type where those same parameter types and/or return type are of type*any
. In the original NASM-flavored assembly emitted when Sunder was targeting x64 Linux, this function-to-function casting was explicitly permitted, as the stack-based Sunder calling convention guaranteed function calls with these types to be ABI-compatible. However, ISO C does not permit this form of casting, leading to undefined behavior when UBSan encounters a function call made using a function value that was the result of such a cast:In practice, it is expected that these casts should be well behaved on modern Unix-like platforms, as one would expect all pointer types to be represented the same at the ABI level. However, there is no strict guarantee that this behavior will remain true for all current and future supported platforms.
See these comments in
codegen.c
for additional context.The text was updated successfully, but these errors were encountered: