Skip to content

Conversation

@clan
Copy link

@clan clan commented Dec 17, 2025

On musl-based systems, stderr is declared as FILE *const.

Referencing stderr directly from Go code (via C.stderr) causes cgo to generate assignment code for a const-qualified pointer, which is invalid C and fails to compile.

Both gcc and clang reject the generated code with error messages below:

clang:

cgo-gcc-prolog:85:9: error: cannot assign to variable '_cgo_r' with const-qualified type 'typeof (_cgo_a->r)' (aka 'struct _IO_FILE *const')
cgo-gcc-prolog:83:24: note: variable '_cgo_r' declared const here
cgo-gcc-prolog:88:12: error: cannot assign to non-static data member 'r' with const-qualified type 'FILE *const' (aka 'struct _IO_FILE *const')
cgo-gcc-prolog:80:15: note: non-static data member 'r' declared const here

gcc:

cgo-gcc-prolog:85:9: error: assignment of read-only variable '_cgo_r'
cgo-gcc-prolog:88:12: error: assignment of read-only member 'r'

This patch avoids referencing C.stderr from Go code and instead returns stderr from a small C helper function. This keeps the usage entirely in C and avoids cgo’s broken handling for const-qualified global objects.

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all
    commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

None

On musl-based systems, stderr is declared as FILE *const.

Referencing stderr directly from Go code (via C.stderr) causes cgo to
generate assignment code for a const-qualified pointer, which is invalid C
and fails to compile.

Both gcc and clang reject the generated code with error messages below:

clang:
> cgo-gcc-prolog:85:9: error: cannot assign to variable '_cgo_r' with const-qualified type 'typeof (_cgo_a->r)' (aka 'struct _IO_FILE *const')
> cgo-gcc-prolog:83:24: note: variable '_cgo_r' declared const here
> cgo-gcc-prolog:88:12: error: cannot assign to non-static data member 'r' with const-qualified type 'FILE *const' (aka 'struct _IO_FILE *const')
> cgo-gcc-prolog:80:15: note: non-static data member 'r' declared const here

gcc:
> cgo-gcc-prolog:85:9: error: assignment of read-only variable '_cgo_r'
> cgo-gcc-prolog:88:12: error: assignment of read-only member 'r'

This patch avoids referencing C.stderr from Go code and instead returns
stderr from a small C helper function. This keeps the usage entirely in
C and avoids cgo’s broken handling for const-qualified global objects.

Signed-off-by: Z. Liu <zhixu.liu@gmail.com>
Copy link
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

Unfortunately, this change is not possible in Podman because the code you modified is in the vendor directory. Please submit this change to https://github.com/containers/container-libs instead.

I am not sure if testing is possible this way. It works locally, but I am unsure about upstream CI. I think you need to make the change in containers-libs first, and then create a vendor PR in Podman that includes the new version of storage from your branch.

@mheon
Copy link
Member

mheon commented Dec 17, 2025

This doesn't look like a breaking change, so it should be sufficient to make the container-libs PR and then wait for us to pick up the new version of the library prior to our next release.

@clan
Copy link
Author

clan commented Dec 18, 2025

thanks, pr submitted at containers/container-libs#559

@clan
Copy link
Author

clan commented Jan 6, 2026

merged by upstream, close this one

@clan clan closed this Jan 6, 2026
@clan clan deleted the musl branch January 6, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants