[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] Use ELF symbols without "32" or "64"
From: |
Pavel Roskin |
Subject: |
[PATCH 3/3] Use ELF symbols without "32" or "64" |
Date: |
Tue, 30 Jun 2009 20:35:15 -0400 |
User-agent: |
StGIT/0.14.3 |
ChangeLog:
* include/grub/elf.h: Define Elf_Sword and Elf_Xword.
* kern/i386/dl.c: Use ELF symbols without "32" or "64".
* kern/powerpc/dl.c: Likewise.
* kern/sparc64/dl.c: Likewise.
* kern/x86_64/dl.c: Likewise.
---
include/grub/elf.h | 4 ++++
kern/i386/dl.c | 34 +++++++++++++++++-----------------
kern/powerpc/dl.c | 42 +++++++++++++++++++++---------------------
kern/sparc64/dl.c | 46 +++++++++++++++++++++++-----------------------
kern/x86_64/dl.c | 6 +++---
5 files changed, 68 insertions(+), 64 deletions(-)
diff --git a/include/grub/elf.h b/include/grub/elf.h
index 49570a6..1a1ec13 100644
--- a/include/grub/elf.h
+++ b/include/grub/elf.h
@@ -2340,8 +2340,10 @@ typedef Elf32_Rel Elf_Rel;
typedef Elf32_Rela Elf_Rela;
typedef Elf32_Section Elf_Section;
typedef Elf32_Shdr Elf_Shdr;
+typedef Elf32_Sword Elf_Sword;
typedef Elf32_Sym Elf_Sym;
typedef Elf32_Word Elf_Word;
+typedef Elf32_Xword Elf_Xword;
#define ELF_ST_BIND(val) ELF32_ST_BIND(val)
#define ELF_ST_TYPE(val) ELF32_ST_TYPE(val)
@@ -2359,8 +2361,10 @@ typedef Elf64_Rel Elf_Rel;
typedef Elf64_Rela Elf_Rela;
typedef Elf64_Section Elf_Section;
typedef Elf64_Shdr Elf_Shdr;
+typedef Elf64_Sword Elf_Sword;
typedef Elf64_Sym Elf_Sym;
typedef Elf64_Word Elf_Word;
+typedef Elf64_Xword Elf_Xword;
#define ELF_ST_BIND(val) ELF64_ST_BIND (val)
#define ELF_ST_TYPE(val) ELF64_ST_TYPE (val)
diff --git a/kern/i386/dl.c b/kern/i386/dl.c
index a17f175..91121f6 100644
--- a/kern/i386/dl.c
+++ b/kern/i386/dl.c
@@ -26,7 +26,7 @@
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
- Elf32_Ehdr *e = ehdr;
+ Elf_Ehdr *e = ehdr;
/* Check the magic numbers. */
if (e->e_ident[EI_CLASS] != ELFCLASS32
@@ -41,15 +41,15 @@ grub_arch_dl_check_header (void *ehdr)
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
{
- Elf32_Ehdr *e = ehdr;
- Elf32_Shdr *s;
- Elf32_Word entsize;
+ Elf_Ehdr *e = ehdr;
+ Elf_Shdr *s;
+ Elf_Word entsize;
unsigned i;
/* Find a symbol table. */
- for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_SYMTAB)
break;
@@ -58,9 +58,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
entsize = s->sh_entsize;
- for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_REL)
{
grub_dl_segment_t seg;
@@ -72,32 +72,32 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
if (seg)
{
- Elf32_Rel *rel, *max;
+ Elf_Rel *rel, *max;
- for (rel = (Elf32_Rel *) ((char *) e + s->sh_offset),
+ for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize;
rel < max;
rel++)
{
- Elf32_Word *addr;
- Elf32_Sym *sym;
+ Elf_Word *addr;
+ Elf_Sym *sym;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
- addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset);
- sym = (Elf32_Sym *) ((char *) mod->symtab
- + entsize * ELF32_R_SYM (rel->r_info));
+ addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset);
+ sym = (Elf_Sym *) ((char *) mod->symtab
+ + entsize * ELF_R_SYM (rel->r_info));
- switch (ELF32_R_TYPE (rel->r_info))
+ switch (ELF_R_TYPE (rel->r_info))
{
case R_386_32:
*addr += sym->st_value;
break;
case R_386_PC32:
- *addr += (sym->st_value - (Elf32_Word) seg->addr
+ *addr += (sym->st_value - (Elf_Word) seg->addr
- rel->r_offset);
break;
}
diff --git a/kern/powerpc/dl.c b/kern/powerpc/dl.c
index 9b1cb14..2891b0d 100644
--- a/kern/powerpc/dl.c
+++ b/kern/powerpc/dl.c
@@ -26,7 +26,7 @@
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
- Elf32_Ehdr *e = ehdr;
+ Elf_Ehdr *e = ehdr;
/* Check the magic numbers. */
if (e->e_ident[EI_CLASS] != ELFCLASS32
@@ -42,15 +42,15 @@ grub_arch_dl_check_header (void *ehdr)
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
{
- Elf32_Ehdr *e = ehdr;
- Elf32_Shdr *s;
- Elf32_Word entsize;
+ Elf_Ehdr *e = ehdr;
+ Elf_Shdr *s;
+ Elf_Word entsize;
unsigned i;
/* Find a symbol table. */
- for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_SYMTAB)
break;
@@ -59,9 +59,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
entsize = s->sh_entsize;
- for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_RELA)
{
grub_dl_segment_t seg;
@@ -73,37 +73,37 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
if (seg)
{
- Elf32_Rela *rel, *max;
+ Elf_Rela *rel, *max;
- for (rel = (Elf32_Rela *) ((char *) e + s->sh_offset),
+ for (rel = (Elf_Rela *) ((char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize;
rel < max;
rel++)
{
- Elf32_Word *addr;
- Elf32_Sym *sym;
+ Elf_Word *addr;
+ Elf_Sym *sym;
grub_uint32_t value;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
- addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset);
- sym = (Elf32_Sym *) ((char *) mod->symtab
- + entsize * ELF32_R_SYM (rel->r_info));
+ addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset);
+ sym = (Elf_Sym *) ((char *) mod->symtab
+ + entsize * ELF_R_SYM (rel->r_info));
/* On the PPC the value does not have an explicit
addend, add it. */
value = sym->st_value + rel->r_addend;
- switch (ELF32_R_TYPE (rel->r_info))
+ switch (ELF_R_TYPE (rel->r_info))
{
case R_PPC_ADDR16_LO:
- *(Elf32_Half *) addr = value;
+ *(Elf_Half *) addr = value;
break;
case R_PPC_REL24:
{
- Elf32_Sword delta = value - (Elf32_Word) addr;
+ Elf_Sword delta = value - (Elf_Word) addr;
if (delta << 6 >> 6 != delta)
return grub_error (GRUB_ERR_BAD_MODULE, "Relocation
overflow");
@@ -112,7 +112,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
}
case R_PPC_ADDR16_HA:
- *(Elf32_Half *) addr = (value + 0x8000) >> 16;
+ *(Elf_Half *) addr = (value + 0x8000) >> 16;
break;
case R_PPC_ADDR32:
@@ -120,13 +120,13 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
break;
case R_PPC_REL32:
- *addr = value - (Elf32_Word) addr;
+ *addr = value - (Elf_Word) addr;
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"This relocation (%d) is not implemented
yet",
- ELF32_R_TYPE (rel->r_info));
+ ELF_R_TYPE (rel->r_info));
}
}
}
diff --git a/kern/sparc64/dl.c b/kern/sparc64/dl.c
index 5334896..a4d99ff 100644
--- a/kern/sparc64/dl.c
+++ b/kern/sparc64/dl.c
@@ -26,7 +26,7 @@
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
- Elf64_Ehdr *e = ehdr;
+ Elf_Ehdr *e = ehdr;
/* Check the magic numbers. */
if (e->e_ident[EI_CLASS] != ELFCLASS64
@@ -42,15 +42,15 @@ grub_arch_dl_check_header (void *ehdr)
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
{
- Elf64_Ehdr *e = ehdr;
- Elf64_Shdr *s;
- Elf64_Word entsize;
+ Elf_Ehdr *e = ehdr;
+ Elf_Shdr *s;
+ Elf_Word entsize;
unsigned i;
/* Find a symbol table. */
- for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf64_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_SYMTAB)
break;
@@ -59,9 +59,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
entsize = s->sh_entsize;
- for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf64_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_RELA)
{
grub_dl_segment_t seg;
@@ -73,27 +73,27 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
if (seg)
{
- Elf64_Rela *rel, *max;
+ Elf_Rela *rel, *max;
- for (rel = (Elf64_Rela *) ((char *) e + s->sh_offset),
+ for (rel = (Elf_Rela *) ((char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize;
rel < max;
rel++)
{
- Elf64_Word *addr;
- Elf64_Sym *sym;
- Elf64_Addr value;
+ Elf_Word *addr;
+ Elf_Sym *sym;
+ Elf_Addr value;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
- addr = (Elf64_Word *) ((char *) seg->addr + rel->r_offset);
- sym = (Elf64_Sym *) ((char *) mod->symtab
- + entsize * ELF64_R_SYM (rel->r_info));
+ addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset);
+ sym = (Elf_Sym *) ((char *) mod->symtab
+ + entsize * ELF_R_SYM (rel->r_info));
value = sym->st_value + rel->r_addend;
- switch (ELF64_R_TYPE (rel->r_info) & 0xff)
+ switch (ELF_R_TYPE (rel->r_info) & 0xff)
{
case R_SPARC_32: /* 3 V-word32 */
if (value & 0xFFFFFFFF00000000)
@@ -102,13 +102,13 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
*addr = value;
break;
case R_SPARC_WDISP30: /* 7 V-disp30 */
- if (((value - (Elf64_Addr) addr) & 0xFFFFFFFF00000000) &&
- (((value - (Elf64_Addr) addr) & 0xFFFFFFFF00000000)
+ if (((value - (Elf_Addr) addr) & 0xFFFFFFFF00000000) &&
+ (((value - (Elf_Addr) addr) & 0xFFFFFFFF00000000)
!= 0xFFFFFFFF00000000))
return grub_error (GRUB_ERR_BAD_MODULE,
"Displacement out of 30 bits range");
*addr = (*addr & 0xC0000000) |
- (((grub_int32_t) ((value - (Elf64_Addr) addr) >> 2)) &
+ (((grub_int32_t) ((value - (Elf_Addr) addr) >> 2)) &
0x3FFFFFFF);
break;
case R_SPARC_HI22: /* 9 V-imm22 */
@@ -121,18 +121,18 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
*addr = (*addr & 0xFFFFFC00) | (value & 0x3FF);
break;
case R_SPARC_64: /* 32 V-xwords64 */
- *(Elf64_Xword *) addr = value;
+ *(Elf_Xword *) addr = value;
break;
case R_SPARC_OLO10:
*addr = (*addr & ~0x1fff)
| (((value & 0x3ff) +
- (ELF64_R_TYPE (rel->r_info) >> 8))
+ (ELF_R_TYPE (rel->r_info) >> 8))
& 0x1fff);
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"This relocation (%d) is not implemented
yet",
- ELF64_R_TYPE (rel->r_info));
+ ELF_R_TYPE (rel->r_info));
}
}
}
diff --git a/kern/x86_64/dl.c b/kern/x86_64/dl.c
index 9e5de6e..73a7337 100644
--- a/kern/x86_64/dl.c
+++ b/kern/x86_64/dl.c
@@ -90,9 +90,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
addr32 = (Elf64_Word *) ((char *) seg->addr + rel->r_offset);
addr64 = (Elf64_Xword *) addr32;
sym = (Elf64_Sym *) ((char *) mod->symtab
- + entsize * ELF64_R_SYM (rel->r_info));
+ + entsize * ELF_R_SYM (rel->r_info));
- switch (ELF64_R_TYPE (rel->r_info))
+ switch (ELF_R_TYPE (rel->r_info))
{
case R_X86_64_64:
*addr64 += rel->r_addend + sym->st_value;
@@ -109,7 +109,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
break;
default:
- grub_fatal ("Unrecognized relocation: %d\n", ELF64_R_TYPE
(rel->r_info));
+ grub_fatal ("Unrecognized relocation: %d\n", ELF_R_TYPE
(rel->r_info));
}
}
}