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

runtime/cgo: improve Error Handling in gcc_stack_unix.c with Assertions #71896

Closed
froz42 opened this issue Feb 22, 2025 · 3 comments · May be fixed by #71897
Closed

runtime/cgo: improve Error Handling in gcc_stack_unix.c with Assertions #71896

froz42 opened this issue Feb 22, 2025 · 3 comments · May be fixed by #71897
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@froz42
Copy link

froz42 commented Feb 22, 2025

Description

The pthread function calls in gcc_stack_unix.c currently do not check return values, which may lead to silent failures in stack attribute retrieval. This issue proposes adding assert() statements to validate these function calls, ensuring that failures are detected early during development.

Affected File

  • src/runtime/cgo/gcc_stack_unix.c

Proposed Solution

  • Include <assert.h> to use assert().
  • Wrap the following function calls with assert() to verify their return values:
    • pthread_attr_init
    • pthread_getattr_np
    • pthread_attr_get_np
    • pthread_attr_getstack
  • This ensures that the program fails fast in case of errors instead of continuing with invalid data.

Rationale

  • Improves debugging by catching errors early.
  • Prevents undefined behavior due to uninitialized or incorrect stack attributes.

Steps to Reproduce

  1. Run the existing code with a failing pthread_attr_init or related function.
  2. Observe that errors might not be immediately visible without proper checks.

Expected Behavior

  • The program should assert when pthread functions fail, providing clear debugging information.
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 22, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/651756 mentions this issue: runtime/cgo: add assertions for safe stack retrieval on unix

@seankhliao
Copy link
Member

this doesn't look like a bug report?

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2025
@froz42
Copy link
Author

froz42 commented Feb 22, 2025

Sorry @seankhliao I made a mistake while copying and pasting my edited MR to fix the requirements for the Gopher Robot. I fixed it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants