src: fix backtrace with tail [[noreturn]] abort

A function tail calls [[noreturn]] node::Abort will print an incorrect
call stack because the frame pc was advanced when calling node::Abort
to an invalid op, which may vary on different platforms.

Dumps the backtrace in the ABORT macro instead to avoid calling
backtrace in a tail [[noreturn]] call. Removes the [[noreturn]]
attribute if a function calls backtrace and may be called as a tail
statement.

[[noreturn]] attribute of public functions like `napi_fatal_error` and
`node::OnFatalError` can not be removed as compilers may complain
about no return values after the removal.

PR-URL: https://github.com/nodejs/node/pull/50849
Refs: https://github.com/nodejs/node/issues/50761
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Chengzhong Wu
2023-12-04 00:42:57 +08:00
committed by GitHub
parent 6b03e6061b
commit 16a54794df
7 changed files with 45 additions and 35 deletions

View File

@@ -734,7 +734,7 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
}
} else if (per_process::cli_options->disable_proto != "") {
// Validated in ProcessGlobalArgs
OnFatalError("InitializeContextRuntime()", "invalid --disable-proto mode");
UNREACHABLE("invalid --disable-proto mode");
}
return Just(true);