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

libct/dmz: Support compiling on all arches #4076

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions libcontainer/dmz/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# Get CC values for cross-compilation.
# Get GO, GOARCH and CC values for cross-compilation.
include ../../cc_platform.mk

# We use the flags suggested in nolibc/nolibc.h, it makes the binary very small.
# List of GOARCH that nolibc supports, from:
# https://go.dev/doc/install/source#environment (with GOOS=linux)
#
# See nolibc supported arches in ./nolibc/arch-*.h
NOLIBC_GOARCHES := 386 amd64 arm arm64 loong64 ppc64le riscv64 s390x

ifneq (,$(filter $(GOARCH), $(NOLIBC_GOARCHES)))
# We use the flags suggested in nolibc/nolibc.h, it makes the binary very small.
CFLAGS += -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib -lgcc
else
CFLAGS += -DRUNC_USE_STDLIB
endif

runc-dmz: _dmz.c
$(CC) $(CFLAGS) -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib -lgcc -static -o $@ $^
$(CC) $(CFLAGS) -static -o $@ $^
$(STRIP) -gs $@
2 changes: 2 additions & 0 deletions libcontainer/dmz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ The current version in that folder is from Linux 6.6-rc3 tag (556fb7131e03b02836

It also support all the architectures we support in runc.

If the GOARCH we use for compiling doesn't support nolibc, it fallbacks to using the C stdlib.

[nolibc-upstream]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/include/nolibc?h=v6.6-rc3
8 changes: 6 additions & 2 deletions libcontainer/dmz/_dmz.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "xstat.h"
#include "nolibc/nolibc.h"
#ifdef RUNC_USE_STDLIB
# include <unistd.h>
#else
# include "xstat.h"
# include "nolibc/nolibc.h"
#endif

extern char **environ;

Expand Down
Loading