Commit dbc2edb8 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Andrei Vagin

compel: piegen -- Introduce actions

Here we introduce actions:

 - "piegen" to generate blobs, which is used
    by criu already;

 - "cflags" and "ldflags" to print out options
   needed for compiler and linker when building
   compel compatible objects.

We rather moved old "main" function body into
piegen helper function and implement the rest
of actions since they are one-liners.

Note the usage uses new "compel" brand, but it's
safe because we don't export anything yet.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent ec973560
......@@ -78,7 +78,7 @@ $(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/lib.a $(obj)/$(PIELDS)
$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(obj)/$(PIELDS) criu/pie/piegen
$(call msg-gen, $@)
$(Q) criu/pie/piegen/piegen -f $< -v $(call target-name,$@)_relocs -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob -o $@ $(piegen_stdout)
$(Q) criu/pie/piegen/piegen piegen -f $< -v $(call target-name,$@)_relocs -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob -o $@ $(piegen_stdout)
else
......
......@@ -70,17 +70,53 @@ static int handle_elf(void *mem, size_t size)
return -1;
}
/*
* That;s the tool to generate patches object files.
*/
int main(int argc, char *argv[])
static int piegen(void)
{
const char *current_cflags = NULL;
struct stat st;
int opt, idx, i;
void *mem;
int fd;
fd = open(opts.input_filename, O_RDONLY);
if (fd < 0) {
pr_perror("Can't open file %s", opts.input_filename);
goto err;
}
if (fstat(fd, &st)) {
pr_perror("Can't stat file %s", opts.input_filename);
goto err;
}
fout = fopen(opts.output_filename, "w");
if (fout == NULL) {
pr_perror("Can't open %s", opts.output_filename);
goto err;
}
mem = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE, fd, 0);
if (mem == MAP_FAILED) {
pr_perror("Can't mmap file %s", opts.input_filename);
goto err;
}
if (handle_elf(mem, st.st_size)) {
fclose(fout);
unlink(opts.output_filename);
goto err;
}
err:
fclose(fout);
printf("%s generated successfully.\n", opts.output_filename);
return 0;
}
int main(int argc, char *argv[])
{
const char *current_cflags = NULL;
int opt, idx, i;
char *action;
typedef struct {
const char *arch;
const char *cflags;
......@@ -161,47 +197,39 @@ int main(int argc, char *argv[])
opts.nrgotpcrel_name = optarg;
break;
case 'h':
default:
goto usage;
default:
break;
}
}
if (!opts.input_filename)
if (optind >= argc)
goto usage;
fd = open(opts.input_filename, O_RDONLY);
if (fd < 0) {
pr_perror("Can't open file %s", opts.input_filename);
goto err;
}
action = argv[optind++];
if (fstat(fd, &st)) {
pr_perror("Can't stat file %s", opts.input_filename);
goto err;
if (!strcmp(action, "cflags")) {
if (!current_cflags)
goto usage;
printf("%s", current_cflags);
return 0;
}
fout = fopen(opts.output_filename, "w");
if (fout == NULL) {
pr_perror("Can't open %s", opts.output_filename);
goto err;
if (!strcmp(action, "ldflags")) {
printf("%s", compel_ldflags);
return 0;
}
mem = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE, fd, 0);
if (mem == MAP_FAILED) {
pr_perror("Can't mmap file %s", opts.input_filename);
goto err;
if (!strcmp(action, "piegen")) {
if (!opts.input_filename)
goto usage;
return piegen();
}
if (handle_elf(mem, st.st_size)) {
fclose(fout);
unlink(opts.output_filename);
goto err;
}
fclose(fout);
printf("%s generated successfully.\n", opts.output_filename);
return 0;
usage:
fprintf(stderr, "Usage: %s -f filename\n", argv[0]);
err:
printf("Usage:\n");
printf(" compel --arch=(x86|ia32|aarch64|arm|ppc64) cflags\n");
printf(" compel --arch=(x86|ia32|aarch64|arm|ppc64) ldflags\n");
printf(" compel -f filename piegen\n");
return 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment