Skip to content

Conversation

@clan
Copy link

@clan clan commented Dec 18, 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.

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>
@github-actions github-actions bot added the storage Related to "storage" package label Dec 18, 2025
podmanbot pushed a commit to podmanbot/buildah that referenced this pull request Dec 18, 2025
@podmanbot
Copy link

✅ A new PR has been created in buildah to vendor these changes: containers/buildah#6606

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.

Thanks, LGTM

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

Labels

storage Related to "storage" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants