Commit 8c98ede3 authored by Laurent Dufour's avatar Laurent Dufour Committed by Pavel Emelyanov

piegen: separates generated output from debug

Introduce a new -o argument to piegen to specify generate file name.
Send the debug stream to stdout and force it to /dev/null in the makefile
if V=1 is not specify.
Signed-off-by: 's avatarLaurent Dufour <ldufour@linux.vnet.ibm.com>
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent e8e13d7f
......@@ -77,13 +77,17 @@ $(obj)/$(PIELDS): $(obj)/pie-reloc.lds.S.in
endif
endif
ifeq ($(strip $(V)),)
piegen_stdout = >/dev/null
endif
$(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/$(PIELDS)
$(E) " GEN " $@
$(Q) $(LD) $(ldflags-y) -T $(obj)/$(PIELDS) -o $@ $<
$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(obj)/$(PIELDS) pie/piegen
$(E) " GEN " $@
$(Q) pie/piegen/piegen -f $< -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob > $@
$(Q) pie/piegen/piegen -f $< -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob -o $@ $(piegen_stdout)
else
......
......@@ -25,6 +25,8 @@ piegen_opt_t opts = {
.nrgotpcrel_name = "nr_gotpcrel",
};
FILE *fout;
static int handle_elf(const piegen_opt_t *opts, void *mem, size_t size)
{
#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
......@@ -73,9 +75,10 @@ int main(int argc, char *argv[])
void *mem;
int fd;
static const char short_opts[] = "f:s:p:v:h";
static const char short_opts[] = "f:o:s:p:v:h";
static struct option long_opts[] = {
{ "file", required_argument, 0, 'f' },
{ "output", required_argument, 0, 'o' },
{ "stream", required_argument, 0, 's' },
{ "sym-prefix", required_argument, 0, 'p' },
{ "variable", required_argument, 0, 'v' },
......@@ -95,6 +98,9 @@ int main(int argc, char *argv[])
case 'f':
opts.input_filename = optarg;
break;
case 'o':
opts.output_filename = optarg;
break;
case 's':
opts.stream_name = optarg;
break;
......@@ -121,17 +127,28 @@ int main(int argc, char *argv[])
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(&opts, mem, st.st_size))
if (handle_elf(&opts, mem, st.st_size)) {
fclose(fout);
unlink(opts.output_filename);
goto err;
return 1;
}
fclose(fout);
printf("%s generated successfully.\n", opts.output_filename);
return 0;
usage:
printf("Usage: %s -f filename\n", argv[0]);
fprintf(stderr, "Usage: %s -f filename\n", argv[0]);
err:
return 0;
return 1;
}
......@@ -6,6 +6,7 @@
typedef struct {
char *input_filename;
char *output_filename;
char *stream_name;
char *prefix_name;
char *var_name;
......@@ -13,6 +14,7 @@ typedef struct {
} piegen_opt_t;
extern piegen_opt_t opts;
extern FILE *fout;
#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
extern int handle_elf_x86_32(const piegen_opt_t *opts, void *mem, size_t size);
......@@ -23,13 +25,9 @@ extern int handle_elf_x86_64(const piegen_opt_t *opts, void *mem, size_t size);
extern int handle_elf_ppc64(const piegen_opt_t *opts, void *mem, size_t size);
#endif
#define pr_out(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
#define pr_out(fmt, ...) fprintf(fout, fmt, ##__VA_ARGS__)
#if 0
# define pr_debug(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#else
# define pr_debug(fmt, ...)
#endif
#define pr_debug(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
#define pr_err(fmt, ...) fprintf(stderr, "Error (%s:%d): "fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#define pr_perror(fmt, ...) fprintf(stderr, "Error (%s:%d): "fmt "%m\n", __FILE__, __LINE__, ##__VA_ARGS__)
......
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