Skip to content

Commit 93d1617

Browse files
authored
Merge pull request #4076 from kinvolk/rata/smaller-runc-dmz
libct/dmz: Support compiling on all arches
2 parents 437725c + b6a0c48 commit 93d1617

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

libcontainer/dmz/Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
# Get CC values for cross-compilation.
1+
# Get GO, GOARCH and CC values for cross-compilation.
22
include ../../cc_platform.mk
33

4-
# We use the flags suggested in nolibc/nolibc.h, it makes the binary very small.
4+
# List of GOARCH that nolibc supports, from:
5+
# https://go.dev/doc/install/source#environment (with GOOS=linux)
6+
#
7+
# See nolibc supported arches in ./nolibc/arch-*.h
8+
NOLIBC_GOARCHES := 386 amd64 arm arm64 loong64 ppc64le riscv64 s390x
9+
10+
ifneq (,$(filter $(GOARCH), $(NOLIBC_GOARCHES)))
11+
# We use the flags suggested in nolibc/nolibc.h, it makes the binary very small.
12+
CFLAGS += -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib -lgcc
13+
else
14+
CFLAGS += -DRUNC_USE_STDLIB
15+
endif
16+
517
runc-dmz: _dmz.c
6-
$(CC) $(CFLAGS) -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib -lgcc -static -o $@ $^
18+
$(CC) $(CFLAGS) -static -o $@ $^
719
$(STRIP) -gs $@

libcontainer/dmz/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ The current version in that folder is from Linux 6.6-rc3 tag (556fb7131e03b02836
1313

1414
It also support all the architectures we support in runc.
1515

16+
If the GOARCH we use for compiling doesn't support nolibc, it fallbacks to using the C stdlib.
17+
1618
[nolibc-upstream]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/include/nolibc?h=v6.6-rc3

libcontainer/dmz/_dmz.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
#include "xstat.h"
2-
#include "nolibc/nolibc.h"
1+
#ifdef RUNC_USE_STDLIB
2+
# include <unistd.h>
3+
#else
4+
# include "xstat.h"
5+
# include "nolibc/nolibc.h"
6+
#endif
37

48
extern char **environ;
59

0 commit comments

Comments
 (0)