Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: build riscv64 binary, build static PIE if supported #3446

Merged
merged 9 commits into from
May 19, 2022

Conversation

kolyshkin
Copy link
Contributor

This can be split into a few groups:

  1. Dockerfile fixes.
  2. Makefile fixes.
  3. Enabling static PIE for arm64 and amd64.
  4. Enabling riscv64.

See individual commits for details.

@kolyshkin kolyshkin requested review from cyphar, thaJeztah and AkihiroSuda and removed request for thaJeztah April 1, 2022 23:17
@kolyshkin kolyshkin added this to the 1.2.0 milestone Apr 1, 2022
AkihiroSuda
AkihiroSuda previously approved these changes Apr 2, 2022
@kolyshkin
Copy link
Contributor Author

@cyphar @thaJeztah PTAL 🙏🏻

@AkihiroSuda
Copy link
Member

Enabling riscv64.

seccomp stuffs has to be updated too.
Opened PR #3463

@thaJeztah
Copy link
Member

Opened PR #3463

Slightly confused now; can these be merged independently, or should they be merged in a specific order? 😅

@AkihiroSuda
Copy link
Member

Opened PR #3463

Slightly confused now; can these be merged independently, or should they be merged in a specific order? 😅

In arbitrary order, but merging one will need rebasing another one.

@kolyshkin
Copy link
Contributor Author

Let me try to pick your changes @AkihiroSuda

@kolyshkin
Copy link
Contributor Author

Picked the libseccomp-golang bump commit from #3463

PTAL @AkihiroSuda @thaJeztah

@kolyshkin kolyshkin mentioned this pull request Apr 29, 2022
@kolyshkin kolyshkin requested a review from AkihiroSuda April 29, 2022 01:13
AkihiroSuda
AkihiroSuda previously approved these changes Apr 30, 2022
@AkihiroSuda
Copy link
Member

Needs rebase

@kolyshkin
Copy link
Contributor Author

Rebased; PTAL @AkihiroSuda @thaJeztah @mrunalp

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

This seems needed as well

diff --git a/libcontainer/seccomp/patchbpf/enosys_linux.go b/libcontainer/seccomp/patchbpf/enosys_linux.go
index dfb8a0a8..d1ee0c2b 100644
--- a/libcontainer/seccomp/patchbpf/enosys_linux.go
+++ b/libcontainer/seccomp/patchbpf/enosys_linux.go
@@ -67,6 +67,7 @@ const uint32_t C_AUDIT_ARCH_PPC64        = AUDIT_ARCH_PPC64;
 const uint32_t C_AUDIT_ARCH_PPC64LE      = AUDIT_ARCH_PPC64LE;
 const uint32_t C_AUDIT_ARCH_S390         = AUDIT_ARCH_S390;
 const uint32_t C_AUDIT_ARCH_S390X        = AUDIT_ARCH_S390X;
+const uint32_t C_AUDIT_ARCH_RISCV64      = AUDIT_ARCH_RISCV64;
 */
 import "C"
 
@@ -197,6 +198,8 @@ func archToNative(arch libseccomp.ScmpArch) (nativeArch, error) {
                return nativeArch(C.C_AUDIT_ARCH_S390), nil
        case libseccomp.ArchS390X:
                return nativeArch(C.C_AUDIT_ARCH_S390X), nil
+       case libseccomp.ArchRISCV64:
+               return nativeArch(C.C_AUDIT_ARCH_RISCV64), nil
        default:
                return invalidArch, fmt.Errorf("unknown architecture: %v", arch)
        }

@AkihiroSuda
Copy link
Member

@kolyshkin Could you update the PR? ↑

@kolyshkin
Copy link
Contributor Author

+const uint32_t C_AUDIT_ARCH_RISCV64      = AUDIT_ARCH_RISCV64;

Alas this breaks the compilation on centos 7; I have added a workaround.

AkihiroSuda
AkihiroSuda previously approved these changes May 12, 2022
kolyshkin and others added 9 commits May 11, 2022 17:23
We do not use all the files from scripts, only seccomp.sh and lib.sh.

This prevents unneeded rebuild of the image if e.g.
scripts/release_build.sh has changed.

Signed-off-by: Kir Kolyshkin <[email protected]>
Dockerfile used to install libseccomp-dev packages for different
architectures. This is no longer true since commit f30244e, which
changed to cross-compiling libseccomp (so we can get a static library
to link against).

Thus, adding extra architectures is no longer needed.

Signed-off-by: Kir Kolyshkin <[email protected]>
All we need is gcc, libc-dev, and binutils. In addition to that,
crossbuild-essential installs g++, libstdc++-dev, and a bunch of perl
packages and libraries which we do not need.

This should speed up image building, as well as make it smaller.

Signed-off-by: Kir Kolyshkin <[email protected]>
LDFLAGS_COMMON are used from two places, so it makes sense to dedup.

LDFLAGS_STATIC is a preparation for the next commit.

Signed-off-by: Kir Kolyshkin <[email protected]>
1. Set to empty value by default.

2. Assume Linux (remove GOOS check, since we do not support other OSes).

3. Instead of using a "not-supported" list, use a "supported" list
   (as Go release notes usually say which platforms are supported).
   As of today, -buildmode=pie is supported for:

 * linux/386, linux/amd64, linux/arm, linux/arm64, and linux/ppc64le
   (since Go 1.6, see https://tip.golang.org/doc/go1.6#compiler)

 * linux/s390x (since Go 1.7, which adds the initial port)

 * linux/riscv64 (since Go 1.16, see
   https://tip.golang.org/doc/go1.16#riscv)

   NOTE this does not mean we support these architectures; it is merely
   a way to see if -buildmode=pie can be used.

Signed-off-by: Kir Kolyshkin <[email protected]>
It doesn't matter whether static or dynamic linking is used, runc
always needs libcontainer/nsenter, which is written in C and thus
requires cgo. Same is true for libcontainer/integration.

In addition, contrib/pkg/seccompagent also needs cgo (if seccomp build
tag is set), as it need to be linked against libseccomp C library.

By default, cgo is disabled when cross-compiling, meaning that
CGO_ENABLED=1 has to be set explicitly in such cases.

In all other cases (e.g. other contrib binaries) we do not need cgo.

Remove CGO_ENABLED=1 from GO_BUILD_STATIC (as it does not have anything
to do with static linking), and add it to all targets that require it.

Signed-off-by: Kir Kolyshkin <[email protected]>
Co-authored-by: Kir Kolyshkin <[email protected]>
Signed-off-by: Akihiro Suda <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
Copy link
Member

Do we need another check from @crazy-max on this PR? (#3463 (comment))

endif
GO_BUILDMODE :=
# Enable dynamic PIE executables on supported platforms.
ifneq (,$(filter $(GOARCH),386 amd64 arm arm64 ppc64le riscv64 s390x))
Copy link
Contributor

Choose a reason for hiding this comment

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

afaik -buildmode=pie is not supported only on windows arm64 and linux mips*, ppc64be. should work on riscv64. see https://github.com/golang/go/blob/4aa1efed4853ea067d665a952eee77c52faac774/src/cmd/internal/sys/supported.go#L125-L131

Copy link
Contributor Author

@kolyshkin kolyshkin May 19, 2022

Choose a reason for hiding this comment

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

So, this is a list of supported platforms. Meaning, we do enable -buildmode=pie for riscv64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See commit description at ab5c60d

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@crazy-max PTAL ^^^

@brandond
Copy link

Is there any particular reason that this hasn't been made available in a 1.x release yet? Trying to get k3s running on riscv64 and this looks like one of the last blockers.

@AkihiroSuda
Copy link
Member

release

This will be in v1.2.
I think we can have a RC soon.

@kolyshkin
Copy link
Contributor Author

Is there any particular reason that this hasn't been made available in a 1.x release yet? Trying to get k3s running on riscv64 and this looks like one of the last blockers.

This is a new feature, and we don't want to backport new features into an old release unless it's absolutely necessary.

If you need a binary, you can get one from any recent PR "Actions" tab. In there, click on "validate" in the left column, scroll all the way down to see "Artifacts", and in the zip will you will find a binary.

@lifubang lifubang added the backport/1.1-done A PR in main branch which has been backported to release-1.1 label Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.1-done A PR in main branch which has been backported to release-1.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants