Skip to content

Commit b6a0c48

Browse files
committed
libct/dmz: Support compiling on all arches
When we added nolibc, we started using it unconditionally. But runc is currently being compiled on more arches than supported by nolibc, like MIPS. Let's compile using stdlib if the arch we are compiling on is not supported by nolibc. If compilation is broken in some arch, just removing it from the NOLIBC_GOARCHES variable should fix the compilation, as it will fallback to use the C stdlib. Signed-off-by: Rodrigo Campos <[email protected]>
1 parent ac78d13 commit b6a0c48

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)