Skip to content

Conversation

@dorzel
Copy link
Member

@dorzel dorzel commented Nov 3, 2025

Description

I noticed when cross-building for ppc64le that make was erroring while trying to pass GO_BUILD_FLAGS as positional arguments. Cross-builds were also failing with CGO due to unknown ASM instructions while translating the assembly.

Also set GO_BUILD_BINDIR in the build step so one can run cross-builds first, without having already run make build. (It was assuming v1/bin/oc-mirror existed regardless of the value of GO_BUILD_BINDIR).

Github / Jira issue:

None

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code Improvements (Refactoring, Performance, CI upgrades, etc)
  • Internal repo assets (diagrams / docs on github repo)
  • This change requires a documentation update on openshift docs

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

make clean
make tidy
make cross-build
make build

Expected Outcome

Please describe the outcome expected from the tests.

cross-builds properly build and populate /bin without errors.

@openshift-ci openshift-ci bot requested review from aguidirh and r4f4 November 3, 2025 18:02
Copy link
Contributor

@aguidirh aguidirh left a comment

Choose a reason for hiding this comment

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

Hi @dorzel,

Thanks for the PR. I tested make cross-build and it worked fine as expected.

I added only one concern I have to the PR.

@dorzel dorzel changed the title Fixes for cross-build errors CLID-476: Fixes for cross-build errors Nov 4, 2025
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Nov 4, 2025
@openshift-ci-robot
Copy link

openshift-ci-robot commented Nov 4, 2025

@dorzel: This pull request references CLID-476 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.21.0" version, but no target version was set.

In response to this:

Description

I noticed when cross-building for ppc64le that make was erroring while trying to pass GO_BUILD_FLAGS as positional arguments. Cross-builds were also failing with CGO due to unknown ASM instructions while translating the assembly.

Also set GO_BUILD_BINDIR in the build step so one can run cross-builds first, without having already run make build. (It was assuming v1/bin/oc-mirror existed regardless of the value of GO_BUILD_BINDIR).

Github / Jira issue:

None

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code Improvements (Refactoring, Performance, CI upgrades, etc)
  • Internal repo assets (diagrams / docs on github repo)
  • This change requires a documentation update on openshift docs

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

make clean
make tidy
make cross-build
make build

Expected Outcome

Please describe the outcome expected from the tests.

cross-builds properly build and populate /bin without errors.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@dorzel
Copy link
Member Author

dorzel commented Nov 4, 2025

/jira refresh

@openshift-ci-robot
Copy link

openshift-ci-robot commented Nov 4, 2025

@dorzel: This pull request references CLID-476 which is a valid jira issue.

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@dorzel dorzel force-pushed the cross-builds branch 2 times, most recently from 1b00086 to 140e7ee Compare November 17, 2025 18:19
@dorzel
Copy link
Member Author

dorzel commented Nov 17, 2025

Ok, I think the latest changes solve it nicely. The conditional assignment allows for:

  • preserving all default CGO behavior (due to not exporting the variable)
  • defaulting cross-build targets to CGO_ENABLED=0 (makefile is not "broken" by default for standard users)
  • overrides for CGO_ENABLED passed via CLI are favored for all targets

@dorzel
Copy link
Member Author

dorzel commented Nov 17, 2025

/retest

@dorzel
Copy link
Member Author

dorzel commented Nov 17, 2025

/test v1-e2e

@dorzel
Copy link
Member Author

dorzel commented Nov 18, 2025

/retest

Copy link
Contributor

@aguidirh aguidirh left a comment

Choose a reason for hiding this comment

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

Thanks @dorzel for taking into account the suggestions.

I ran some tests and it worked as expected on my side.

I will approve and let LGTM to @r4f4.

Makefile Outdated
GO_BUILD_PACKAGES := ./cmd/oc-mirror
GO_PACKAGE = github.com/openshift/oc-mirror/v2

# Default to CGO_ENABLED=0 for cross-builds, but allow override from command line
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it would be nice to add in the comment the reason why it is needed to disable CGO for cross-builds.

Copy link
Contributor

Choose a reason for hiding this comment

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

Due to the complexity of managing C cross-compiler toolchains, cross-building with CGO_ENABLED on the non-native architecture is not supported.

@openshift-ci
Copy link

openshift-ci bot commented Nov 20, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aguidirh, dorzel

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 20, 2025
Copy link
Contributor

@r4f4 r4f4 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2025
@prb112
Copy link
Contributor

prb112 commented Dec 5, 2025

Hey @dorzel I was just made aware of this one. Do you happen to have the log of the failure?

@dorzel
Copy link
Member Author

dorzel commented Dec 5, 2025

Hey @prb112 the error occurs when CGO is enabled but the user does not have the required toolchains/compilers in place to properly use CGO for cross-compilation. This can be expected, but it does result in failure by default for the common use case for those users building from source, which is cross-compiling a static executable for a different arch.

Error ends up being many lines of "no such instruction", among others:

...
Makefile:53: warning: overriding recipe for target 'test-unit'
/home/dorzel/go/pkg/mod/github.com/openshift/[email protected]/make/targets/golang/test-unit.mk:7: warning: ignoring old recipe for target 'test-unit'
mkdir -p './bin/linux-ppc64le'
go build -mod=readonly -tags "json1 " -ldflags "-X github.com/openshift/oc-mirror/pkg/version.versionFromGit="v0.2.0-alpha.1-494-g140e7ee" -X github.com/openshift/oc-mirror/pkg/version.commitFromGit="140e7ee4" -X github.com/openshift/oc-mirror/pkg/version.gitTreeState="clean" -X github.com/openshift/oc-mirror/pkg/version.buildDate="2025-12-05T16:18:10Z" " -o './bin/linux-ppc64le/oc-mirror' github.com/openshift/oc-mirror/cmd/oc-mirror
gcc_linux_ppc64x.S: Assembler messages:
gcc_linux_ppc64x.S:50: Error: no such instruction: `mflr %r0'
gcc_linux_ppc64x.S:51: Error: bad register name `%r0'
gcc_linux_ppc64x.S:52: Error: no such instruction: `mfcr %r0'
gcc_linux_ppc64x.S:53: Error: bad register name `%r0'
gcc_linux_ppc64x.S:54: Error: no such instruction: `stdu %r1,-FRAME_SIZE(%r1)'
gcc_linux_ppc64x.S:55: Error: bad register name `%r2'
gcc_linux_ppc64x.S:20: Error: junk `(1)' after expression
gcc_linux_ppc64x.S:57:  Info: macro invoked from here
gcc_linux_ppc64x.S:20: Error: number of operands mismatch for `std'
gcc_linux_ppc64x.S:57:  Info: macro invoked from here
gcc_linux_ppc64x.S:20: Error: junk `(1)' after expression
gcc_linux_ppc64x.S:21:  Info: macro invoked from here
gcc_linux_ppc64x.S:57:   Info: macro invoked from here
gcc_linux_ppc64x.S:20: Error: number of operands mismatch for `std'
gcc_linux_ppc64x.S:21:  Info: macro invoked from here
gcc_linux_ppc64x.S:57:   Info: macro invoked from here
gcc_linux_ppc64x.S:20: Error: junk `(1)' after expression
gcc_linux_ppc64x.S:21:  Info: macro invoked from here
gcc_linux_ppc64x.S:21:   Info: macro invoked from here
gcc_linux_ppc64x.S:57:    Info: macro invoked from here
gcc_linux_ppc64x.S:20: Error: number of operands mismatch for `std'
gcc_linux_ppc64x.S:21:  Info: macro invoked from here
gcc_linux_ppc64x.S:21:   Info: macro invoked from here
gcc_linux_ppc64x.S:57:    Info: macro invoked from here
gcc_linux_ppc64x.S:20: Error: junk `(1)' after expression
gcc_linux_ppc64x.S:21:  Info: macro invoked from here
...
gcc_linux_ppc64x.S:76: Error: no such instruction: `ld %r2,24(%r1)'
gcc_linux_ppc64x.S:77: Error: no such instruction: `addi %r1,%r1,FRAME_SIZE'
gcc_linux_ppc64x.S:78: Error: no such instruction: `ld %r0,16(%r1)'
gcc_linux_ppc64x.S:79: Error: no such instruction: `mtlr %r0'
gcc_linux_ppc64x.S:80: Error: no such instruction: `ld %r0,8(%r1)'
gcc_linux_ppc64x.S:81: Error: no such instruction: `mtcr %r0'
gcc_linux_ppc64x.S:82: Error: no such instruction: `blr'
make[2]: *** [/home/dorzel/go/pkg/mod/github.com/openshift/[email protected]/make/targets/golang/build.mk:16: build] Error 1
make[1]: *** [Makefile:86: build] Error 2
make: *** [Makefile:97: cross-build-linux-ppc64le] Error 2

@prb112
Copy link
Contributor

prb112 commented Dec 5, 2025

Hey Dylan This doesn't feel like the right answer. It feel like there is an issue with the local golang source. e.g. you have multiple sources.
If you download golang again (you have two golang assembly files).

mkdir -p /usr/local2
subscription-manager repos --enable codeready-builder-for-rhel-9-ppc64le-rpms
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
dnf install -y  libassuan-devel gpgme-devel libgpg-error-devel btrfs-progs-devel.ppc64le podman git jq tar  gcc   make   git   gpgme-devel  libassuan-devel   wget   pigz   procps-ng 
GO_VERSION=go1.25.4 && curl -sL https://golang.org/dl/${GO_VERSION}.linux-ppc64le.tar.gz       \
        | tar xzvf - --directory /usr/local2/                                    \
     && /usr/local2/go/bin/go version                                            \
     && ln -f /usr/local2/go/bin/go /usr/bin/go
export PATH=/usr/local2/go/bin:$PATH:~/go/bin/:
export GOROOT="/usr/local2/go"

@prb112
Copy link
Contributor

prb112 commented Dec 5, 2025

better try on a fresh vm

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 9, 2025
@openshift-ci
Copy link

openshift-ci bot commented Dec 9, 2025

New changes are detected. LGTM label has been removed.

@openshift-ci
Copy link

openshift-ci bot commented Dec 9, 2025

@dorzel: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants