Skip to content

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

Closed as not planned
@froz42

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions