diff --git a/Makefile b/Makefile index a8cc9de7e..e06731eec 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,10 @@ ifeq ($(ARCH),arm) PROTOUFIX := y endif +ifeq ($(ARCH),aarch64) + DEFINES := -DCONFIG_AARCH64 +endif + ifeq ($(ARCH),x86) DEFINES := -DCONFIG_X86_64 endif diff --git a/compel/src/main.c b/compel/src/main.c index 4202b1210..9be3c8b64 100644 --- a/compel/src/main.c +++ b/compel/src/main.c @@ -28,27 +28,23 @@ #define COMPEL_LDFLAGS_DEFAULT "-r -z noexecstack" typedef struct { - const char *arch; const char *cflags; -} compel_cflags_t; + const char *cflags_compat; +} flags_t; -static const compel_cflags_t compel_cflags[] = { - { - .arch = "x86", - .cflags = COMPEL_CFLAGS_PIE, - }, { - .arch = "ia32", - .cflags = COMPEL_CFLAGS_NOPIC, - }, { - .arch = "aarch64", - .cflags = COMPEL_CFLAGS_PIE, - }, { - .arch = "arm", - .cflags = COMPEL_CFLAGS_PIE, - }, { - .arch = "ppc64", - .cflags = COMPEL_CFLAGS_PIE, - }, +static const flags_t flags = { +#if defined CONFIG_X86_64 + .cflags = COMPEL_CFLAGS_PIE, + .cflags_compat = COMPEL_CFLAGS_NOPIC, +#elif defined CONFIG_AARCH64 + .cflags = COMPEL_CFLAGS_PIE, +#elif defined(CONFIG_ARMV6) || defined(CONFIG_ARMV7) + .cflags = COMPEL_CFLAGS_PIE, +#elif defined CONFIG_PPC64 + .cflags = COMPEL_CFLAGS_PIE, +#else +#error "CONFIG_ not defined, or unsupported ARCH" +#endif }; piegen_opt_t opts = {}; @@ -114,24 +110,9 @@ static void cli_log(unsigned int lvl, const char *fmt, va_list parms) } static int usage(int rc) { - int i = 0; printf( "Usage:\n" -" compel --arch=ARCH cflags\n" -" compel --arch=ARCH ldflags\n" -" ARCH := { " -); - - /* Print list of known arches */ - while (1) { - printf("%s", compel_cflags[i++].arch); - if (i == ARRAY_SIZE(compel_cflags)) - break; - printf(" | "); - } - - printf( -" }\n" +" compel [--compat] cflags | ldflags\n" " compel -f FILE -o FILE -p NAME [-l N] hgen\n" " -f, --file FILE input (parasite object) file name\n" " -o, --output FILE output (header) file name\n" @@ -145,16 +126,21 @@ static int usage(int rc) { return rc; } +static void print_cflags(bool compat) +{ + printf("%s\n", compat ? flags.cflags_compat : flags.cflags); +} + int main(int argc, char *argv[]) { - const char *current_cflags = NULL; int log_level = DEFAULT_LOGLEVEL; - int opt, idx, i; + bool compat = false; + int opt, idx; char *action; - static const char short_opts[] = "a:f:o:p:hVl:"; + static const char short_opts[] = "cf:o:p:hVl:"; static struct option long_opts[] = { - { "arch", required_argument, 0, 'a' }, + { "compat", no_argument, 0, 'c' }, { "file", required_argument, 0, 'f' }, { "output", required_argument, 0, 'o' }, { "prefix", required_argument, 0, 'p' }, @@ -170,18 +156,8 @@ int main(int argc, char *argv[]) if (opt == -1) break; switch (opt) { - case 'a': - for (i = 0; i < ARRAY_SIZE(compel_cflags); i++) { - if (!strcmp(optarg, compel_cflags[i].arch)) { - current_cflags = compel_cflags[i].cflags; - break; - } - } - if (!current_cflags) { - fprintf(stderr, "Error: unknown arch '%s'\n", - optarg); - return usage(1); - } + case 'c': + compat = true; break; case 'f': opts.input_filename = optarg; @@ -218,11 +194,7 @@ int main(int argc, char *argv[]) action = argv[optind++]; if (!strcmp(action, "cflags")) { - if (!current_cflags) { - fprintf(stderr, "Error: option --arch required\n"); - return usage(1); - } - printf("%s", current_cflags); + print_cflags(compat); return 0; } diff --git a/compel/test/infect/Makefile b/compel/test/infect/Makefile index f244755f6..ede9a474d 100644 --- a/compel/test/infect/Makefile +++ b/compel/test/infect/Makefile @@ -32,4 +32,4 @@ parasite.po: parasite.o $(COMPEL_PLUGINS)/std.built-in.o ld -r -T $(COMPEL_PACK_LDS) -o $@ $^ parasite.o: parasite.c - $(CC) $(CFLAGS) -c $(shell $(COMPEL) --arch=$(ARCH) cflags) -I$(COMPEL_IDIR) -o $@ $^ + $(CC) $(CFLAGS) -c $(shell $(COMPEL) cflags) -I$(COMPEL_IDIR) -o $@ $^ diff --git a/criu/pie/Makefile b/criu/pie/Makefile index e05bb0bbc..9ae488c89 100644 --- a/criu/pie/Makefile +++ b/criu/pie/Makefile @@ -37,7 +37,7 @@ ccflags-y += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 ccflags-y += -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=0 ifneq ($(filter-out clean mrproper,$(MAKECMDGOALS)),) - CFLAGS += $(shell $(SRC_DIR)/compel/compel-host --arch=$(ARCH) cflags) + CFLAGS += $(shell $(SRC_DIR)/compel/compel-host cflags) endif ifeq ($(SRCARCH),arm)