[PATCH 3/7] powerpc/vdso: separate common code in vdso_common

2016-10-25 Thread Dmitry Safonov
Impact: cleanup

I also switched usage of printk(KERNEL_,...) on pr_(...)
and used pr_fmt() macro for "vDSO{32,64}: " prefix.

Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: Andy Lutomirski 
Cc: Oleg Nesterov 
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux...@kvack.org 
Signed-off-by: Dmitry Safonov 
---
 arch/powerpc/kernel/vdso.c| 352 ++
 arch/powerpc/kernel/vdso_common.c | 221 
 2 files changed, 234 insertions(+), 339 deletions(-)
 create mode 100644 arch/powerpc/kernel/vdso_common.c

diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
index 278b9aa25a1c..8010a0d82049 100644
--- a/arch/powerpc/kernel/vdso.c
+++ b/arch/powerpc/kernel/vdso.c
@@ -51,13 +51,13 @@
 #define VDSO_ALIGNMENT (1 << 16)
 
 static unsigned int vdso32_pages;
-static void *vdso32_kbase;
 static struct page **vdso32_pagelist;
 unsigned long vdso32_sigtramp;
 unsigned long vdso32_rt_sigtramp;
 
 #ifdef CONFIG_VDSO32
 extern char vdso32_start, vdso32_end;
+static void *vdso32_kbase;
 #endif
 
 #ifdef CONFIG_PPC64
@@ -246,250 +246,16 @@ const char *arch_vma_name(struct vm_area_struct *vma)
return NULL;
 }
 
-
-
 #ifdef CONFIG_VDSO32
-static void * __init find_section32(Elf32_Ehdr *ehdr, const char *secname,
- unsigned long *size)
-{
-   Elf32_Shdr *sechdrs;
-   unsigned int i;
-   char *secnames;
-
-   /* Grab section headers and strings so we can tell who is who */
-   sechdrs = (void *)ehdr + ehdr->e_shoff;
-   secnames = (void *)ehdr + sechdrs[ehdr->e_shstrndx].sh_offset;
-
-   /* Find the section they want */
-   for (i = 1; i < ehdr->e_shnum; i++) {
-   if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) {
-   if (size)
-   *size = sechdrs[i].sh_size;
-   return (void *)ehdr + sechdrs[i].sh_offset;
-   }
-   }
-   *size = 0;
-   return NULL;
-}
-
-static Elf32_Sym * __init find_symbol32(struct lib32_elfinfo *lib,
-   const char *symname)
-{
-   unsigned int i;
-   char name[MAX_SYMNAME], *c;
-
-   for (i = 0; i < (lib->dynsymsize / sizeof(Elf32_Sym)); i++) {
-   if (lib->dynsym[i].st_name == 0)
-   continue;
-   strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
-   MAX_SYMNAME);
-   c = strchr(name, '@');
-   if (c)
-   *c = 0;
-   if (strcmp(symname, name) == 0)
-   return >dynsym[i];
-   }
-   return NULL;
-}
-
-/* Note that we assume the section is .text and the symbol is relative to
- * the library base
- */
-static unsigned long __init find_function32(struct lib32_elfinfo *lib,
-   const char *symname)
-{
-   Elf32_Sym *sym = find_symbol32(lib, symname);
-
-   if (sym == NULL) {
-   printk(KERN_WARNING "vDSO32: function %s not found !\n",
-  symname);
-   return 0;
-   }
-   return sym->st_value - VDSO32_LBASE;
-}
-
-static int __init vdso_do_func_patch32(struct lib32_elfinfo *v32,
-  const char *orig, const char *fix)
-{
-   Elf32_Sym *sym32_gen, *sym32_fix;
-
-   sym32_gen = find_symbol32(v32, orig);
-   if (sym32_gen == NULL) {
-   printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", orig);
-   return -1;
-   }
-   if (fix == NULL) {
-   sym32_gen->st_name = 0;
-   return 0;
-   }
-   sym32_fix = find_symbol32(v32, fix);
-   if (sym32_fix == NULL) {
-   printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", fix);
-   return -1;
-   }
-   sym32_gen->st_value = sym32_fix->st_value;
-   sym32_gen->st_size = sym32_fix->st_size;
-   sym32_gen->st_info = sym32_fix->st_info;
-   sym32_gen->st_other = sym32_fix->st_other;
-   sym32_gen->st_shndx = sym32_fix->st_shndx;
-
-   return 0;
-}
-#else /* !CONFIG_VDSO32 */
-static unsigned long __init find_function32(struct lib32_elfinfo *lib,
-   const char *symname)
-{
-   return 0;
-}
-
-static int __init vdso_do_func_patch32(struct lib32_elfinfo *v32,
-  const char *orig, const char *fix)
-{
-   return 0;
-}
+#include "vdso_common.c"
 #endif /* CONFIG_VDSO32 */
 
-
 #ifdef CONFIG_PPC64
-
-static void * __init find_section64(Elf64_Ehdr *ehdr, const char *secname,
- unsigned long *size)
-{
-   Elf64_Shdr *sechdrs;
-   unsigned int i;
-   char *secnames;
-
-   /* Grab section headers and strings so 

[PATCH 3/7] powerpc/vdso: separate common code in vdso_common

2016-10-25 Thread Dmitry Safonov
Impact: cleanup

I also switched usage of printk(KERNEL_,...) on pr_(...)
and used pr_fmt() macro for "vDSO{32,64}: " prefix.

Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: Andy Lutomirski 
Cc: Oleg Nesterov 
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux...@kvack.org 
Signed-off-by: Dmitry Safonov 
---
 arch/powerpc/kernel/vdso.c| 352 ++
 arch/powerpc/kernel/vdso_common.c | 221 
 2 files changed, 234 insertions(+), 339 deletions(-)
 create mode 100644 arch/powerpc/kernel/vdso_common.c

diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
index 278b9aa25a1c..8010a0d82049 100644
--- a/arch/powerpc/kernel/vdso.c
+++ b/arch/powerpc/kernel/vdso.c
@@ -51,13 +51,13 @@
 #define VDSO_ALIGNMENT (1 << 16)
 
 static unsigned int vdso32_pages;
-static void *vdso32_kbase;
 static struct page **vdso32_pagelist;
 unsigned long vdso32_sigtramp;
 unsigned long vdso32_rt_sigtramp;
 
 #ifdef CONFIG_VDSO32
 extern char vdso32_start, vdso32_end;
+static void *vdso32_kbase;
 #endif
 
 #ifdef CONFIG_PPC64
@@ -246,250 +246,16 @@ const char *arch_vma_name(struct vm_area_struct *vma)
return NULL;
 }
 
-
-
 #ifdef CONFIG_VDSO32
-static void * __init find_section32(Elf32_Ehdr *ehdr, const char *secname,
- unsigned long *size)
-{
-   Elf32_Shdr *sechdrs;
-   unsigned int i;
-   char *secnames;
-
-   /* Grab section headers and strings so we can tell who is who */
-   sechdrs = (void *)ehdr + ehdr->e_shoff;
-   secnames = (void *)ehdr + sechdrs[ehdr->e_shstrndx].sh_offset;
-
-   /* Find the section they want */
-   for (i = 1; i < ehdr->e_shnum; i++) {
-   if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) {
-   if (size)
-   *size = sechdrs[i].sh_size;
-   return (void *)ehdr + sechdrs[i].sh_offset;
-   }
-   }
-   *size = 0;
-   return NULL;
-}
-
-static Elf32_Sym * __init find_symbol32(struct lib32_elfinfo *lib,
-   const char *symname)
-{
-   unsigned int i;
-   char name[MAX_SYMNAME], *c;
-
-   for (i = 0; i < (lib->dynsymsize / sizeof(Elf32_Sym)); i++) {
-   if (lib->dynsym[i].st_name == 0)
-   continue;
-   strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
-   MAX_SYMNAME);
-   c = strchr(name, '@');
-   if (c)
-   *c = 0;
-   if (strcmp(symname, name) == 0)
-   return >dynsym[i];
-   }
-   return NULL;
-}
-
-/* Note that we assume the section is .text and the symbol is relative to
- * the library base
- */
-static unsigned long __init find_function32(struct lib32_elfinfo *lib,
-   const char *symname)
-{
-   Elf32_Sym *sym = find_symbol32(lib, symname);
-
-   if (sym == NULL) {
-   printk(KERN_WARNING "vDSO32: function %s not found !\n",
-  symname);
-   return 0;
-   }
-   return sym->st_value - VDSO32_LBASE;
-}
-
-static int __init vdso_do_func_patch32(struct lib32_elfinfo *v32,
-  const char *orig, const char *fix)
-{
-   Elf32_Sym *sym32_gen, *sym32_fix;
-
-   sym32_gen = find_symbol32(v32, orig);
-   if (sym32_gen == NULL) {
-   printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", orig);
-   return -1;
-   }
-   if (fix == NULL) {
-   sym32_gen->st_name = 0;
-   return 0;
-   }
-   sym32_fix = find_symbol32(v32, fix);
-   if (sym32_fix == NULL) {
-   printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", fix);
-   return -1;
-   }
-   sym32_gen->st_value = sym32_fix->st_value;
-   sym32_gen->st_size = sym32_fix->st_size;
-   sym32_gen->st_info = sym32_fix->st_info;
-   sym32_gen->st_other = sym32_fix->st_other;
-   sym32_gen->st_shndx = sym32_fix->st_shndx;
-
-   return 0;
-}
-#else /* !CONFIG_VDSO32 */
-static unsigned long __init find_function32(struct lib32_elfinfo *lib,
-   const char *symname)
-{
-   return 0;
-}
-
-static int __init vdso_do_func_patch32(struct lib32_elfinfo *v32,
-  const char *orig, const char *fix)
-{
-   return 0;
-}
+#include "vdso_common.c"
 #endif /* CONFIG_VDSO32 */
 
-
 #ifdef CONFIG_PPC64
-
-static void * __init find_section64(Elf64_Ehdr *ehdr, const char *secname,
- unsigned long *size)
-{
-   Elf64_Shdr *sechdrs;
-   unsigned int i;
-   char *secnames;
-
-   /* Grab section headers and strings so we can tell who is who */
-   sechdrs = (void *)ehdr + ehdr->e_shoff;
-   secnames = (void *)ehdr +