Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitedb4d95

Browse files
committed
jit: Do not try to shut down LLVM state in case of LLVM triggered errors.
If an allocation failed within LLVM it is not safe to call back into LLVM asLLVM is not generally safe against exceptions / stack-unwinding. Thus errorswhile in LLVM code are promoted to FATAL. However llvm_shutdown() did callback into LLVM even in such cases, while llvm_release_context() was carefulnot to do so.We cannot generally skip shutting down LLVM, as that can break profiling. Butit's OK to do so if there was an error from within LLVM.Reported-By: Jelte Fennema <Jelte.Fennema@microsoft.com>Author: Andres Freund <andres@anarazel.de>Author: Justin Pryzby <pryzby@telsasoft.com>Discussion:https://postgr.es/m/AM5PR83MB0178C52CCA0A8DEA0207DC14F7FF9@AM5PR83MB0178.EURPRD83.prod.outlook.comBackpatch: 11-, where jit was introduced
1 parent026ed8e commitedb4d95

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

‎src/backend/jit/llvm/llvmjit.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ llvm_release_context(JitContext *context)
172172
{
173173
LLVMJitContext*llvm_context= (LLVMJitContext*)context;
174174

175-
llvm_enter_fatal_on_oom();
176-
177175
/*
178176
* When this backend is exiting, don't clean up LLVM. As an error might
179177
* have occurred from within LLVM, we do not want to risk reentering. All
@@ -182,6 +180,8 @@ llvm_release_context(JitContext *context)
182180
if (proc_exit_inprogress)
183181
return;
184182

183+
llvm_enter_fatal_on_oom();
184+
185185
if (llvm_context->module)
186186
{
187187
LLVMDisposeModule(llvm_context->module);
@@ -885,6 +885,20 @@ llvm_session_initialize(void)
885885
staticvoid
886886
llvm_shutdown(intcode,Datumarg)
887887
{
888+
/*
889+
* If llvm_shutdown() is reached while in a fatal-on-oom section an error
890+
* has occurred in the middle of LLVM code. It is not safe to call back
891+
* into LLVM (which is why a FATAL error was thrown).
892+
*
893+
* We do need to shutdown LLVM in other shutdown cases, otherwise
894+
* e.g. profiling data won't be written out.
895+
*/
896+
if (llvm_in_fatal_on_oom())
897+
{
898+
Assert(proc_exit_inprogress);
899+
return;
900+
}
901+
888902
#ifLLVM_VERSION_MAJOR>11
889903
{
890904
if (llvm_opt3_orc)

‎src/backend/jit/llvm/llvmjit_error.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ llvm_leave_fatal_on_oom(void)
8383
}
8484
}
8585

86+
/*
87+
* Are we currently in an fatal-on-oom section? Useful to skip cleanup in case
88+
* of errors.
89+
*/
90+
bool
91+
llvm_in_fatal_on_oom(void)
92+
{
93+
return fatal_new_handler_depth >0;
94+
}
95+
8696
/*
8797
* Reset fatal error handling. This should only be called in error recovery
8898
* loops like PostgresMain()'s.

‎src/include/jit/llvmjit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern LLVMValueRef AttributeTemplate;
8484

8585
externvoidllvm_enter_fatal_on_oom(void);
8686
externvoidllvm_leave_fatal_on_oom(void);
87+
externboolllvm_in_fatal_on_oom(void);
8788
externvoidllvm_reset_after_error(void);
8889
externvoidllvm_assert_in_fatal_section(void);
8990

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp