Skip to content

fix: ensure -zlazy for systems that default to -znow#1729

Merged
debarshiray merged 3 commits into
containers:mainfrom
xandris:bugfix/ensure-z-lazy
Jun 11, 2026
Merged

fix: ensure -zlazy for systems that default to -znow#1729
debarshiray merged 3 commits into
containers:mainfrom
xandris:bugfix/ensure-z-lazy

Conversation

@xandris

@xandris xandris commented Nov 10, 2025

Copy link
Copy Markdown
Contributor

I see #1706 and #1722. this is more minimal change for systems that default to znow

@xandris xandris requested a review from debarshiray as a code owner November 10, 2025 01:08
xandris added a commit to xandris/toolbox that referenced this pull request Nov 10, 2025
Adds -zlazy to the go build wrapper and the 'go run' command for
generating completions. Some systems like Gentoo default to znow if it
is left unset.

See: containers#1729
Signed-off-by: Alexandra Parker <alex.iris.parker@gmail.com>
@xandris xandris force-pushed the bugfix/ensure-z-lazy branch from 59be97f to 73ed56e Compare November 10, 2025 01:11
@silverhadch

Copy link
Copy Markdown

Ping.

@debarshiray debarshiray left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for looking into this, @xandris , and my apologies for the delay! I always shudder at this linker hackery. :)

Comment thread src/go-build-wrapper Outdated
@debarshiray

Copy link
Copy Markdown
Member

recheck

@debarshiray debarshiray left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like this fixes #1706 Could you please link to the issue instead of the PR in the commit message?

@xandris xandris force-pushed the bugfix/ensure-z-lazy branch from 73ed56e to 8811838 Compare June 5, 2026 02:44
It's not necessary to prefix each external linker flag with its own -Wl
option.  One -Wl option can carry everything because the commas will be
used to split the string.

containers#1706
@debarshiray

Copy link
Copy Markdown
Member

Thanks for updating this PR, @xandris ! Let me try to rebase this against main. I am temporarily marking this as a draft while I do so.

@debarshiray debarshiray force-pushed the bugfix/ensure-z-lazy branch from 8811838 to ac96de9 Compare June 9, 2026 00:36
@debarshiray debarshiray marked this pull request as draft June 9, 2026 00:39
Many operating systems default to '-z now' in their linker flags to
harden binaries using Relocation Read-Only (or RELRO) [1].  Such as,
Fedora [2,3] and Gentoo [4,5,6,7,8,9].

Some, like Fedora, pass it through the LDFLAGS environment variable
that's usually injected into the clang(1) and gcc(1) compiler drivers'
command line by build systems like Meson.  Some, like Gentoo, use a
Clang configuration file or GCC specs instead.

The reference Go toolchain (ie., gc, not gccgo) in its external linking
mode always uses the clang(1) or gcc(1) compiler drivers [10], and
whether '-z now' gets used or not depends on which of the above
mechanisms are in use.

The Meson adapter scripts in Toolbx to connect Meson to 'go build' and
'go run', since Meson doesn't natively support Go [11], don't respect
the LDFLAGS environment variable.  So, anything passed through it gets
filtered out from the linker flags.  However, the default Clang
configuration files or the built-in GCC specs can't be avoided.  So,
if '-z now' is specified there, then it gets used.  This leads to a
broken toolbox(1) binary and fails to generate the shell completions.

[1] https://www.redhat.com/en/blog/hardening-elf-binaries-using-relocation-read-only-relro

[2] Fedora redhat-rpm-config commit 796b80f2f49f2301
    https://src.fedoraproject.org/rpms/redhat-rpm-config/c/796b80f2f49f2301

[3] Fedora redhat-rpm-config commit d9235d2d90873ff6
    https://src.fedoraproject.org/rpms/redhat-rpm-config/c/d9235d2d90873ff6
    https://bugzilla.redhat.com/show_bug.cgi?id=1192183
    https://fedoraproject.org/wiki/Changes/Harden_All_Packages

[4] Gentoo ebuild commit 8bfd8afef6dd8c66
    https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8bfd8afef6dd8c66
    https://bugs.gentoo.org/876923

[5] Gentoo gcc-patches commit 8ffd428773f8e1e6
    gentoo/gcc-patches@8ffd428773f8e1e6

[6] Gentoo ebuild commit 718448f923ae9302
    https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=718448f923ae9302

[7] Gentoo gcc-patches commit 98c1d96dbf03d704
    gentoo/gcc-patches@98c1d96dbf03d704
    https://bugs.gentoo.org/876923

[8] Gentoo ebuild commit adf44514cf590a86
    https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=adf44514cf590a86
    https://bugs.gentoo.org/876923

[9] Gentoo ebuild commit 975678507aa3cebb
    https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=975678507aa3cebb
    https://bugs.gentoo.org/876923

[10] https://pkg.go.dev/cmd/link

[11] mesonbuild/meson#123

containers#1706

Signed-off-by: Alexandra Parker <alex.iris.parker@gmail.com>
@debarshiray

Copy link
Copy Markdown
Member

I took the liberty to dump all the references you dug up for me in #1706 in the commit message for the sake of my future self.

@debarshiray debarshiray marked this pull request as ready for review June 9, 2026 21:44
@xandris

xandris commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

👀

@debarshiray

Copy link
Copy Markdown
Member

Build failed. https://gateway-cloud-softwarefactory.apps.ocp.cloud.ci.centos.org/zuul/t/local/buildset/2c9465a0661544b89f4c3822984dc1fe

system-test-fedora-rawhide-commands-options TIMED_OUT in 2h 00m 26s
system-test-fedora-44-commands-options TIMED_OUT in 1h 45m 29s

These are the same CI failures that showed up recently and is being debugged. See #1802 and #1805

So, let's ignore them here.

@debarshiray debarshiray merged commit 5fd129b into containers:main Jun 11, 2026
2 of 3 checks passed
@debarshiray

Copy link
Copy Markdown
Member

Thanks for all the insight and investigation, @xandris !

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