-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[mono] Make mono_inst_name less misleading #83545
Comments
/cc @steveisok @SamMonoRT |
luckily |
Hi, I'm Abu Sayeed Khan, a final year computer science student. I came across this issue, and I think it's a great opportunity for me to learn more about dotnet. I'm interested in working on this issue, and I'd appreciate any guidance or advice you can provide. Thank you! |
Is it okay to define a dummy macro to create compilation error? Something like this: #ifndef DISABLE_LOGGING
const char* mono_inst_name (int op);
#else
#define mono_inst_name(op) _static_assert_disabled_logging()
static inline void _static_assert_disabled_logging(void)
{
static_assert(0, "mono_inst_name is not available when DISABLE_LOGGING is defined.");
}
#endif |
Sure, give it a go. Thanks for helping us!
I don't think we need a specialized assertion. Just something like this is enough: /* in mini.h */
....
#ifndef DISABLE_LOGGING
const char *mono_inst_name (int op);
#endif The C compiler should error if some code in another file tries to call We compile mono as C99, so The actual issue is, I don't think using a #define mono_inst_name(op) _STATIC_COMPILE_ERROR("Not available with DISABLED_LOGGING")
#define _STATIC_COMPILE_ERROR(msg) extern void _fail_the_build(int [sizeof(char[-2])] ) if I call $ clang -std=c99 -c foo.c -DFAILME
foo.c:19:2: error: array size is negative
mono_inst_name(123);
^~~~~~~~~~~~~~~~~
foo.c:5:28: note: expanded from macro 'mono_inst_name'
#define mono_inst_name(op) _STATIC_COMPILE_ERROR("Not available with DISABLED_LOGGING")
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo.c:7:81: note: expanded from macro '_STATIC_COMPILE_ERROR'
#define _STATIC_COMPILE_ERROR(msg) extern void _fail_the_build(int [sizeof(char[-2])] )
^~
1 error generated.
$ gcc -std=c99 -c foo.c -DFAILME
foo.c: In function ‘main’:
foo.c:7:80: error: size of unnamed array is negative
7 | #define _STATIC_COMPILE_ERROR(msg) extern void _fail_the_build(int [sizeof(char[-2])] )
| ^
foo.c:5:28: note: in expansion of macro ‘_STATIC_COMPILE_ERROR’
5 | #define mono_inst_name(op) _STATIC_COMPILE_ERROR("Not available with DISABLED_LOGGING")
| ^~~~~~~~~~~~~~~~~~~~~
foo.c:19:9: note: in expansion of macro ‘mono_inst_name’
19 | mono_inst_name(123);
| ^~~~~~~~~~~~~~ |
Wouldn't it be easier to change We also seem to be embedding CIL opcodes in |
Moving this to 9.0.0 |
Fixes #83545 Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com> Co-authored-by: Steve Pfister <stpfiste@microsoft.com> Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Fixes dotnet#83545 Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com> Co-authored-by: Steve Pfister <stpfiste@microsoft.com> Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Fixes dotnet#83545 Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com> Co-authored-by: Steve Pfister <stpfiste@microsoft.com> Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Currently
mono_inst_name
is defined like this:The problem is that when logging is disabled, this function is uncallable (the
#else
branch, above). Any call to it will crash the runtime.On Android, iOS and WASM we build the runtime with
DISABLE_LOGGING
defined. Below is Android, but wasm and ios are similar:Why this is bad:
If someone incorrectly leaves in a call to
mono_inst_name
in a branch that isn't guarded by#ifndef DISABLE_LOGGING
, the runtime will crash. We tend to usemono_inst_name
in code that is trying to provide additional diagnostics. So something bad has already happened, we try to gather more info, and instead we crash the runtime.What we should do instead:
Wrap both the declaration and definition of
mono_inst_name
in#ifndef DISABLE_LOGGING
. Turn any use ofmono_inst_name
that isn't protected by#ifndef DISABLE_LOGGING
into a compile-time error that will fail to build the runtime.That way, we don't get random crashes during unrelated investigations just because we called some diagnostic functionality
The text was updated successfully, but these errors were encountered: