Skip to content
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

jl_error() and jl_errorf() unsafe to call if LLVM not fully initialized #45847

Open
staticfloat opened this issue Jun 29, 2022 · 1 comment
Open
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@staticfloat
Copy link
Member

If the runtime errors out early on in the bringup process, we can end up attempting to construct a backtrace and failing due to data structures not having been initialized yet. A historical example (which I am about to replace with jl_printf() and exit()):

jl_errorf("Invalid CPU name \"%s\".", TheCPU.c_str());

Because jl_errorf unconditionally subs off to jl_throw, we end up attempting to construct a backtrace. jl_error, in contrast, contains a guarding if statement, however it too fails in this case, as we are far enough to have initialized jl_errorexception_type as a tag from the system image, but not far enough yet to have fully initialized LLVM.

We should have some way of denoting to the rest of the runtime that LLVM is initialized. Jeff recommended that we:

Maybe we should have jl_init_llvm handle filling in the libjulia-codegen function pointers, so the system just behaves as if codegen is not available before it's initialized?

@staticfloat staticfloat added the bug Indicates an unexpected problem or unintended behavior label Jun 29, 2022
@gbaraldi
Copy link
Member

There's a couple options, the first thing is to just not call jl_error from there, but more generally the check inside jl_error or more precisely jl_vexceptionf is not safe, because that type get's filled in before we've actually finished initializing julia. Maybe instead of using sentinels like that we should use explicit variables, like a is_initialized global or something like it.

staticfloat added a commit that referenced this issue Apr 24, 2023
This is the same as #45765 where
we use `jl_error()` too early to get backtraces, but too late to fail
the supposed guard `if` statement that should prevent us from trying to
take a backtrace.  X-ref: #45847
staticfloat added a commit that referenced this issue Apr 24, 2023
This is the same as #45765 where
we use `jl_error()` too early to get backtraces, but too late to fail
the supposed guard `if` statement that should prevent us from trying to
take a backtrace.  X-ref: #45847
staticfloat added a commit that referenced this issue Apr 24, 2023
This is the same as #45765 where
we use `jl_error()` too early to get backtraces, but too late to fail
the supposed guard `if` statement that should prevent us from trying to
take a backtrace.  X-ref: #45847
staticfloat added a commit that referenced this issue Apr 24, 2023
This is the same as #45765 where
we use `jl_error()` too early to get backtraces, but too late to fail
the supposed guard `if` statement that should prevent us from trying to
take a backtrace.  X-ref: #45847

(cherry picked from commit fa21589)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants