[CRIU] [PATCH 1/8] piegen: Implement tool building, v2
Cyrill Gorcunov
gorcunov at gmail.com
Wed May 13 01:07:18 PDT 2015
On Wed, May 13, 2015 at 10:37:11AM +0300, Cyrill Gorcunov wrote:
> On Wed, May 13, 2015 at 09:22:05AM +0200, Laurent Dufour wrote:
> >
> > Hi Cyrill,
> >
> > Instead of embedding the processing C code in C code, why not creating
> > that C file and managed it under Git, and just generate the C file
> > containing the data to be processed which will be built and linked with
> > the one stored in Git?
> >
> > I found that difficult to maintain when I tried to write the ppc64 part.
>
> Hi! Yeah, I thought about it, will do.
Would attached be more convenient for you? (Pushed it into ia32 branch)
Cyrill
-------------- next part --------------
>From c6f69a567f27b2985c5351c132b6283602a19c70 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Wed, 13 May 2015 11:05:57 +0300
Subject: [PATCH] pie: piegen -- Move elf_apply_relocs into a separate template
file
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
pie/Makefile | 1 +
pie/piegen/apply.in.c | 28 ++++++++++++++++++++++++++++
pie/piegen/elf.c | 34 ++--------------------------------
pie/piegen/main.c | 7 +------
4 files changed, 32 insertions(+), 38 deletions(-)
create mode 100644 pie/piegen/apply.in.c
diff --git a/pie/Makefile b/pie/Makefile
index 49b48e6f3892..199d6c9fa841 100644
--- a/pie/Makefile
+++ b/pie/Makefile
@@ -77,6 +77,7 @@ $(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/$(PIELDS)
$(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) cat pie/piegen/apply.in.c >> $@
else
diff --git a/pie/piegen/apply.in.c b/pie/piegen/apply.in.c
new file mode 100644
index 000000000000..f5af390d5fdf
--- /dev/null
+++ b/pie/piegen/apply.in.c
@@ -0,0 +1,28 @@
+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_32)
+static __maybe_unused void elf_apply_relocs(void *mem, void *vbase, size_t size, elf_reloc_t *elf_relocs, size_t nr_relocs)
+{
+ size_t i, j;
+
+ for (i = 0, j = 0; i < nr_relocs; i++) {
+ if (elf_relocs[i].type) {
+ long *where = mem + elf_relocs[i].offset;
+ long *p = mem + size;
+
+ if (elf_relocs[i].type & 2) {
+ int *value = (int *)where;
+ int rel;
+
+ p[j] = (long)vbase + elf_relocs[i].value;
+ rel = (unsigned)((void *)&p[j] - (void *)mem) - elf_relocs[i].offset + elf_relocs[i].addend;
+
+ *value = rel;
+ j++;
+ } else
+ *where = elf_relocs[i].value + elf_relocs[i].addend + (unsigned long)vbase;
+ } else {
+ int *where = (mem + elf_relocs[i].offset);
+ *where = elf_relocs[i].value + elf_relocs[i].addend + (unsigned long)vbase;
+ }
+ }
+}
+#endif
diff --git a/pie/piegen/elf.c b/pie/piegen/elf.c
index 76cbefb52a7a..0bef9cec996b 100644
--- a/pie/piegen/elf.c
+++ b/pie/piegen/elf.c
@@ -160,8 +160,8 @@ int handle_elf(const piegen_opt_t *opts, void *mem, size_t size)
" unsigned int type;\n"
" long addend;\n"
" long value;\n"
- "} %s;\nstatic __maybe_unused %s %s[] = {\n",
- opts->type_name, opts->type_name, opts->var_name);
+ "} elf_reloc_t;\nstatic __maybe_unused elf_reloc_t %s[] = {\n",
+ opts->var_name);
pr_debug("Relocations\n------------\n");
for (i = 0; i < hdr->e_shnum; i++) {
@@ -302,36 +302,6 @@ int handle_elf(const piegen_opt_t *opts, void *mem, size_t size)
}
pr_out("};\n");
-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_32)
-pr_out(
-"static __maybe_unused void elf_apply_relocs(void *mem, void *vbase, size_t size, %s *elf_relocs, size_t nr_relocs)\n"
-"{\n"
-" size_t i, j;\n"
-"\n"
-" for (i = 0, j = 0; i < nr_relocs; i++) {\n"
-" if (elf_relocs[i].type) {\n"
-" long *where = mem + elf_relocs[i].offset;\n"
-" long *p = mem + size;\n"
-"\n"
-" if (elf_relocs[i].type & 2) {\n"
-" int *value = (int *)where;\n"
-" int rel;\n"
-"\n"
-" p[j] = (long)vbase + elf_relocs[i].value;\n"
-" rel = (unsigned)((void *)&p[j] - (void *)mem) - elf_relocs[i].offset + elf_relocs[i].addend;\n"
-"\n"
-" *value = rel;\n"
-" j++;\n"
-" } else\n"
-" *where = elf_relocs[i].value + elf_relocs[i].addend + (unsigned long)vbase;\n"
-" } else {\n"
-" int *where = (mem + elf_relocs[i].offset);\n"
-" *where = elf_relocs[i].value + elf_relocs[i].addend + (unsigned long)vbase;\n"
-" }\n"
-" }\n"
-"}\n", opts->type_name);
-#endif
-
err:
free(sec_hdrs);
return -1;
diff --git a/pie/piegen/main.c b/pie/piegen/main.c
index 45bbf24545a0..64e82497469d 100644
--- a/pie/piegen/main.c
+++ b/pie/piegen/main.c
@@ -20,7 +20,6 @@
piegen_opt_t opts = {
.input_filename = "file.o",
.stream_name = "stream",
- .type_name = "elf_reloc_t",
.prefix_name = "__",
.var_name = "elf_relocs",
.nrgotpcrel_name = "nr_gotpcrel",
@@ -59,11 +58,10 @@ int main(int argc, char *argv[])
void *mem;
int fd;
- static const char short_opts[] = "f:s:t:p:v:h";
+ static const char short_opts[] = "f:s:p:v:h";
static struct option long_opts[] = {
{ "file", required_argument, 0, 'f' },
{ "stream", required_argument, 0, 's' },
- { "type", required_argument, 0, 't' },
{ "sym-prefix", required_argument, 0, 'p' },
{ "variable", required_argument, 0, 'v' },
{ "help", required_argument, 0, 'h' },
@@ -88,9 +86,6 @@ int main(int argc, char *argv[])
case 'p':
opts.prefix_name = optarg;
break;
- case 't':
- opts.type_name = optarg;
- break;
case 'v':
opts.var_name = optarg;
break;
--
2.1.0
More information about the CRIU
mailing list