GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: fix backtrace with [[noreturn]] abort by legendecas · Pull Request #50849 · nodejs/node

Conversation

@legendecas

@legendecas legendecas commented Nov 22, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

Dumps the backtrace in the ABORT macro instead to avoid calling
backtrace in a [[noreturn]] call. Removes the [[noreturn]]
attribute if a function calls backtrace.

[[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.

Refs: #50761

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@legendecas
src: fix backtrace with tail [[noreturn]] abort
10d80a3
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.
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Nov 22, 2023
@legendecas legendecas mentioned this pull request Nov 22, 2023
parallel/test-worker-nearheaplimit-deadlock is flaky #50761
Closed
anonrig
anonrig reviewed Nov 23, 2023
View reviewed changes
Comment thread src/node_errors.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/util.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

joyeecheung
joyeecheung reviewed Nov 23, 2023
View reviewed changes
Comment thread src/util.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/node_errors.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/node_errors.cc Resolved

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Nov 23, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

By the way does it matter if abort is tail called or not? I think as long as the caller is marked as [[noreturn]], the compiler is completely free to just not maintain the frame pointer/link register for backtrace (it seems LLVM is particularly eager to do this which I guess is why we are seeing this showing up more on macOS). So the rule of thumb here is to just not mark [[noreturn]] for any caller of backtrace().

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@legendecas legendecas changed the title src: fix backtrace with tail [[noreturn]] abort src: fix backtrace with [[noreturn]] abort Nov 23, 2023
@legendecas

legendecas commented Nov 23, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

By the way does it matter if abort is tail called or not? I think as long as the caller is marked as [[noreturn]], the compiler is completely free to just not maintain the frame pointer/link register for backtrace (it seems LLVM is particularly eager to do this which I guess is why we are seeing this showing up more on macOS). So the rule of thumb here is to just not mark [[noreturn]] for any caller of backtrace().

I checked different call sites and their generated code, and I found that a tail call to [[noreturn]] is more eager to be optimized. For example, the following snippet would print the correct backtrace when it reaches the abort:

MaybeLocal<String> BuiltinLoader::LoadBuiltinSource(Isolate* isolate,
                                                    const char* id) const {
  auto source = source_.read();
  const auto source_it = source->find(id);
  if (UNLIKELY(source_it == source->end())) {
    fprintf(stderr, "Cannot find native builtin: \"%s\".\n", id);
    node::Abort();
  }
  return source_it->second.ToStringChecked(isolate);
}

But, yes, the rule should be that we should not mark functions as [[noreturn]] for callers of backtrace().

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Nov 28, 2023

Copy link
Copy Markdown
Member

@legendecas Do you have time to address the comments? test-worker-nearheaplimit-deadlock has been haunting the CI for some time, so I'd like to see this landed soon-ish to get some more information out of the flakes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@legendecas
fixup! src: fix backtrace with [[noreturn]] abort
090a9a4
joyeecheung
joyeecheung approved these changes Nov 28, 2023
View reviewed changes

@joyeecheung joyeecheung left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a suggestion to comments

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/util.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

legendecas and others added 2 commits November 28, 2023 23:23
@legendecas @joyeecheung
fixup! src: fix backtrace with [[noreturn]] abort
536823a
Co-authored-by: Joyee Cheung <[email protected]>
@legendecas
fixup! src: fix backtrace with [[noreturn]] abort
3b89fba
joyeecheung
joyeecheung approved these changes Nov 28, 2023
View reviewed changes
@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 28, 2023
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 28, 2023
@nodejs-github-bot

nodejs-github-bot commented Nov 28, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/55989/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Nov 29, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/56009/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@legendecas legendecas added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Nov 29, 2023
@joyeecheung joyeecheung added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Dec 3, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Dec 3, 2023
@nodejs-github-bot
nodejs-github-bot merged commit 16a5479 into nodejs:main Dec 3, 2023
@nodejs-github-bot

nodejs-github-bot commented Dec 3, 2023

Copy link
Copy Markdown
Collaborator

Landed in 16a5479

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@legendecas
legendecas deleted the backtrace-noreturn branch December 3, 2023 17:47
targos pushed a commit that referenced this pull request Dec 4, 2023
@legendecas @targos
src: fix backtrace with tail [[noreturn]] abort
f6ff11c
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: #50849
Refs: #50761
Reviewed-By: Joyee Cheung <[email protected]>
@targos targos mentioned this pull request Dec 4, 2023
v21.4.0 release proposal #51043
Merged
richardlau pushed a commit that referenced this pull request Mar 25, 2024
@legendecas @richardlau
src: fix backtrace with tail [[noreturn]] abort
d82b0d4
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: #50849
Refs: #50761
Reviewed-By: Joyee Cheung <[email protected]>
@richardlau richardlau mentioned this pull request Mar 25, 2024
v20.12.0 proposal #52212
Merged
@joyeecheung

joyeecheung commented Mar 30, 2024

Copy link
Copy Markdown
Member

Actually I noticed in https://ci.nodejs.org/job/node-test-binary-windows-js-suites/26795/RUN_SUBSET=1,nodes=win2022-COMPILED_BY-vs2022/console that this change is breaking most of the places being converted to use ABORT() without marking themselves as [[noreturn]]. I think the original point about not making [[noreturn]] Abort() should be revisited:

int MyFunction(int value) {
  if (value >= 0) {
    return value;
  }
  // if Abort is not marked as [[noreturn]], compiler 
  // will complain about no return value in this branch.
  Abort();
};

In this case the function should be rewritten like this:

int MyFunction(int value) {
  if (value < 0) {
    Abort();
  }
  return value;
};

Otherwise every caller of the ABORT() macro has to be marked as [[noreturn]] and the chain is infectious, which is probably not practical.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Mar 30, 2024

Copy link
Copy Markdown
Member

Oh wait, I think I got it the other way around. Callers of ABORT() must not be macro. Though it seems with msvc, the macro is causing some problems to properly backtrace..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@legendecas

legendecas commented Mar 31, 2024

Copy link
Copy Markdown
Member Author

@joyeecheung sorry, but the link you provided didn't report a compiler error. Is the link correct?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Mar 31, 2024

Copy link
Copy Markdown
Member

The issue is in the crashed test-buffer-isascii with incorrect native stack traces, what we originally tried to fix

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung mentioned this pull request Jun 5, 2024
vm module regression #53346
Closed
@legendecas legendecas mentioned this pull request Jun 6, 2024
Inaccurate windows stacktrace printer #53361
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@anonrig anonrig anonrig left review comments
@joyeecheung joyeecheung joyeecheung approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash PRs the Commit Queue should land as one squashed commit. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@legendecas @joyeecheung @nodejs-github-bot @anonrig
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.