[uClibc] [PATHC] first attempt to support 64bit ELF
Atsushi Nemoto
anemo at mba.ocn.ne.jp
Mon Oct 13 14:31:17 UTC 2003
This fairly large patch is to support 64bit ELF. This includes:
* replace Elf32_xxx with ElfW(xxx)
* replace ELF32_xxx with ELFW(xxx)
* use Elf_Symndx for hash data types (bucket/chain)
* use "unsigned long" cast to convert a pointer to integer.
* use "long int" for "%d", "%x" in _dl_dprintf() if _WORDSIZE > 32
* use ELFCLASS64 if __ELF_NATIVE_CLASS == 64
This should have no effect for 32bit platforms but will help
implementing ldso on 64bit platforms. This is a patch against current
CVS.
diff -ur uClibc-cvs/include/link.h uClibc/include/link.h
--- uClibc-cvs/include/link.h Thu Sep 27 14:21:09 2001
+++ uClibc/include/link.h Mon Oct 13 22:39:36 2003
@@ -32,6 +32,10 @@
#define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
#define _ElfW_1(e,w,t) e##w##t
+#define ELFW(type) _ELFW (ELF, __ELF_NATIVE_CLASS, type)
+#define _ELFW(e,w,t) _ELFW_1 (e, w, _##t)
+#define _ELFW_1(e,w,t) e##w##t
+
#include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
/* Rendezvous structure used by the run-time dynamic linker to communicate
diff -ur uClibc-cvs/ldso/include/ld_hash.h uClibc/ldso/include/ld_hash.h
--- uClibc-cvs/ldso/include/ld_hash.h Tue Aug 19 22:11:05 2003
+++ uClibc/ldso/include/ld_hash.h Mon Oct 13 22:39:36 2003
@@ -26,18 +26,18 @@
struct dyn_elf * symbol_scope;
unsigned short usage_count;
unsigned short int init_flag;
- unsigned int nbucket;
- unsigned long * elf_buckets;
+ Elf_Symndx nbucket;
+ Elf_Symndx * elf_buckets;
/*
* These are only used with ELF style shared libraries
*/
- unsigned long nchain;
- unsigned long * chains;
+ Elf_Symndx nchain;
+ Elf_Symndx * chains;
unsigned long dynamic_info[24];
unsigned long dynamic_size;
unsigned long n_phent;
- Elf32_Phdr * ppnt;
+ ElfW(Phdr) * ppnt;
#if defined(__mips__)
/* Needed for MIPS relocation */
diff -ur uClibc-cvs/ldso/include/ld_syscall.h uClibc/ldso/include/ld_syscall.h
--- uClibc-cvs/ldso/include/ld_syscall.h Tue Aug 19 15:05:30 2003
+++ uClibc/ldso/include/ld_syscall.h Mon Oct 13 22:39:36 2003
@@ -78,7 +78,7 @@
#define _dl_MAX_ERRNO 4096
#endif
#define _dl_mmap_check_error(__res) \
- (((int)__res) < 0 && ((int)__res) >= -_dl_MAX_ERRNO)
+ (((long)__res) < 0 && ((long)__res) >= -_dl_MAX_ERRNO)
#ifndef MAP_ANONYMOUS
#ifdef __sparc__
#define MAP_ANONYMOUS 0x20
diff -ur uClibc-cvs/ldso/ldso/hash.c uClibc/ldso/ldso/hash.c
--- uClibc-cvs/ldso/ldso/hash.c Sun Aug 24 20:45:41 2003
+++ uClibc/ldso/ldso/hash.c Mon Oct 13 22:39:36 2003
@@ -102,7 +102,7 @@
char *loadaddr, unsigned long *dynamic_info, unsigned long dynamic_addr,
unsigned long dynamic_size)
{
- unsigned long *hash_addr;
+ Elf_Symndx *hash_addr;
struct elf_resolve *tpnt;
int i;
@@ -128,7 +128,7 @@
tpnt->libtype = loaded_file;
if (dynamic_info[DT_HASH] != 0) {
- hash_addr = (unsigned long *) (intptr_t)(dynamic_info[DT_HASH] + loadaddr);
+ hash_addr = (Elf_Symndx *) (intptr_t)(dynamic_info[DT_HASH] + loadaddr);
tpnt->nbucket = *hash_addr++;
tpnt->nchain = *hash_addr++;
tpnt->elf_buckets = hash_addr;
@@ -140,7 +140,7 @@
tpnt->dynamic_info[i] = dynamic_info[i];
#ifdef __mips__
{
- Elf32_Dyn *dpnt = (Elf32_Dyn *) dynamic_addr;
+ ElfW(Dyn) *dpnt = (ElfW(Dyn) *) dynamic_addr;
while(dpnt->d_tag) {
if (dpnt->d_tag == DT_MIPS_GOTSYM)
@@ -170,7 +170,7 @@
char *pnt;
int pass;
char *strtab;
- Elf32_Sym *symtab;
+ ElfW(Sym) *symtab;
unsigned long elf_hash_number, hn;
char *weak_result;
struct elf_resolve *first_def;
@@ -245,7 +245,7 @@
* Avoid calling .urem here.
*/
do_rem(hn, elf_hash_number, tpnt->nbucket);
- symtab = (Elf32_Sym *) (intptr_t) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr);
+ symtab = (ElfW(Sym) *) (intptr_t) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr);
strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
/*
* This crap is required because the first instance of a
@@ -262,9 +262,9 @@
if (_dl_strcmp(pnt, name) == 0 &&
symtab[si].st_value != 0)
{
- if ((ELF32_ST_TYPE(symtab[si].st_info) == STT_FUNC ||
- ELF32_ST_TYPE(symtab[si].st_info) == STT_NOTYPE ||
- ELF32_ST_TYPE(symtab[si].st_info) == STT_OBJECT) &&
+ if ((ELFW(ST_TYPE)(symtab[si].st_info) == STT_FUNC ||
+ ELFW(ST_TYPE)(symtab[si].st_info) == STT_NOTYPE ||
+ ELFW(ST_TYPE)(symtab[si].st_info) == STT_OBJECT) &&
symtab[si].st_shndx != SHN_UNDEF) {
/* Here we make sure that we find a module where the symbol is
@@ -279,10 +279,10 @@
continue;
}
- switch (ELF32_ST_BIND(symtab[si].st_info)) {
+ switch (ELFW(ST_BIND)(symtab[si].st_info)) {
case STB_GLOBAL:
if (tpnt->libtype != elf_executable &&
- ELF32_ST_TYPE(symtab[si].st_info)
+ ELFW(ST_TYPE)(symtab[si].st_info)
== STT_NOTYPE)
{ /* nakao */
data_result = (char *)tpnt->loadaddr +
@@ -311,7 +311,7 @@
if (resolver != caller_type &&
NULL==f_tpnt && /*trick: don't handle R_??_JMP_SLOT reloc type*/
tpnt->libtype == elf_executable &&
- ELF32_ST_TYPE(symtab[si].st_info) == STT_FUNC &&
+ ELFW(ST_TYPE)(symtab[si].st_info) == STT_FUNC &&
symtab[si].st_shndx == SHN_UNDEF)
{
return (char*)symtab[si].st_value;
diff -ur uClibc-cvs/ldso/ldso/ldso.c uClibc/ldso/ldso/ldso.c
--- uClibc-cvs/ldso/ldso/ldso.c Tue Oct 7 23:22:01 2003
+++ uClibc/ldso/ldso/ldso.c Mon Oct 13 22:39:36 2003
@@ -149,7 +149,7 @@
void _dl_debug_state(void);
char *_dl_get_last_path_component(char *path);
static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *app_tpnt,
- unsigned long load_addr, unsigned long *hash_addr, Elf32_auxv_t auxvt[AT_EGID + 1],
+ unsigned long load_addr, Elf_Symndx *hash_addr, ElfW(auxv_t) auxvt[AT_EGID + 1],
char **envp, struct r_debug *debug_addr);
#include "boot1_arch.h"
@@ -200,10 +200,10 @@
ElfW(Ehdr) *header;
struct elf_resolve *tpnt;
struct elf_resolve *app_tpnt;
- Elf32_auxv_t auxvt[AT_EGID + 1];
+ ElfW(auxv_t) auxvt[AT_EGID + 1];
unsigned char *malloc_buffer, *mmap_zero;
- Elf32_Dyn *dpnt;
- unsigned long *hash_addr;
+ ElfW(Dyn) *dpnt;
+ Elf_Symndx *hash_addr;
struct r_debug *debug_addr = NULL;
int indx;
int status;
@@ -237,10 +237,10 @@
* the Auxiliary Vector Table. Read out the elements of the auxvt,
* sort and store them in auxvt for later use. */
while (*aux_dat) {
- Elf32_auxv_t *auxv_entry = (Elf32_auxv_t *) aux_dat;
+ ElfW(auxv_t) *auxv_entry = (ElfW(auxv_t) *) aux_dat;
if (auxv_entry->a_type <= AT_EGID) {
- _dl_memcpy(&(auxvt[auxv_entry->a_type]), auxv_entry, sizeof(Elf32_auxv_t));
+ _dl_memcpy(&(auxvt[auxv_entry->a_type]), auxv_entry, sizeof(ElfW(auxv_t)));
}
aux_dat += 2;
}
@@ -251,7 +251,12 @@
header = (ElfW(Ehdr) *) auxvt[AT_BASE].a_un.a_ptr;
/* Check the ELF header to make sure everything looks ok. */
- if (!header || header->e_ident[EI_CLASS] != ELFCLASS32 ||
+ if (!header ||
+#if __ELF_NATIVE_CLASS == 64
+ header->e_ident[EI_CLASS] != ELFCLASS64 ||
+#else
+ header->e_ident[EI_CLASS] != ELFCLASS32 ||
+#endif
header->e_ident[EI_VERSION] != EV_CURRENT
#if !defined(__powerpc__) && !defined(__mips__) && !defined(__sh__)
|| _dl_strncmp((void *) header, ELFMAGIC, SELFMAG) != 0
@@ -302,15 +307,15 @@
/* Do things the slow way in C */
{
unsigned long tx_reloc;
- Elf32_Dyn *dynamic = NULL;
- Elf32_Shdr *shdr;
- Elf32_Phdr *pt_load;
+ ElfW(Dyn) *dynamic = NULL;
+ ElfW(Shdr) *shdr;
+ ElfW(Phdr) *pt_load;
#ifdef __SUPPORT_LD_DEBUG_EARLY__
SEND_STDERR("Finding the GOT using C code to read the ELF file\n");
#endif
/* Find where the dynamic linking information section is hiding */
- shdr = (Elf32_Shdr *) (header->e_shoff + (char *) header);
+ shdr = (ElfW(Shdr) *) (header->e_shoff + (char *) header);
for (indx = header->e_shnum; --indx >= 0; ++shdr) {
if (shdr->sh_type == SHT_DYNAMIC) {
goto found_dynamic;
@@ -320,10 +325,10 @@
_dl_exit(0);
found_dynamic:
- dynamic = (Elf32_Dyn *) (shdr->sh_offset + (char *) header);
+ dynamic = (ElfW(Dyn) *) (shdr->sh_offset + (char *) header);
/* Find where PT_LOAD is hiding */
- pt_load = (Elf32_Phdr *) (header->e_phoff + (char *) header);
+ pt_load = (ElfW(Phdr) *) (header->e_phoff + (char *) header);
for (indx = header->e_phnum; --indx >= 0; ++pt_load) {
if (pt_load->p_type == PT_LOAD) {
goto found_pt_load;
@@ -350,7 +355,7 @@
#endif
/* Now, finally, fix up the location of the dynamic stuff */
- dpnt = (Elf32_Dyn *) (*got + load_addr);
+ dpnt = (ElfW(Dyn) *) (*got + load_addr);
#ifdef __SUPPORT_LD_DEBUG_EARLY__
SEND_STDERR("First Dynamic section entry=");
SEND_ADDRESS_STDERR(dpnt, 1);
@@ -407,7 +412,7 @@
ppnt = (ElfW(Phdr) *) auxvt[AT_PHDR].a_un.a_ptr;
for (i = 0; i < auxvt[AT_PHNUM].a_un.a_val; i++, ppnt++)
if (ppnt->p_type == PT_DYNAMIC) {
- dpnt = (Elf32_Dyn *) ppnt->p_vaddr;
+ dpnt = (ElfW(Dyn) *) ppnt->p_vaddr;
while (dpnt->d_tag) {
#if defined(__mips__)
if (dpnt->d_tag == DT_MIPS_GOTSYM)
@@ -456,7 +461,7 @@
/* Get some more of the information that we will need to dynamicly link
this module to itself */
- hash_addr = (unsigned long *) (tpnt->dynamic_info[DT_HASH] + load_addr);
+ hash_addr = (Elf_Symndx *) (tpnt->dynamic_info[DT_HASH] + load_addr);
tpnt->nbucket = *hash_addr++;
tpnt->nchain = *hash_addr++;
tpnt->elf_buckets = hash_addr;
@@ -482,7 +487,7 @@
/* First cover the shared library/dynamic linker. */
if (tpnt->dynamic_info[DT_TEXTREL]) {
header = (ElfW(Ehdr) *) auxvt[AT_BASE].a_un.a_ptr;
- ppnt = (ElfW(Phdr) *) ((int)auxvt[AT_BASE].a_un.a_ptr +
+ ppnt = (ElfW(Phdr) *) ((long)auxvt[AT_BASE].a_un.a_ptr +
header->e_phoff);
for (i = 0; i < header->e_phnum; i++, ppnt++) {
if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W)) {
@@ -553,13 +558,13 @@
rpnt = (ELF_RELOC *) (rel_addr + load_addr);
for (i = 0; i < rel_size; i += sizeof(ELF_RELOC), rpnt++) {
reloc_addr = (unsigned long *) (load_addr + (unsigned long) rpnt->r_offset);
- symtab_index = ELF32_R_SYM(rpnt->r_info);
+ symtab_index = ELFW(R_SYM)(rpnt->r_info);
symbol_addr = 0;
if (symtab_index) {
char *strtab;
- Elf32_Sym *symtab;
+ ElfW(Sym) *symtab;
- symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + load_addr);
+ symtab = (ElfW(Sym) *) (tpnt->dynamic_info[DT_SYMTAB] + load_addr);
strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + load_addr);
/* We only do a partial dynamic linking right now. The user
@@ -649,7 +654,7 @@
#endif
static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *app_tpnt,
- unsigned long load_addr, unsigned long *hash_addr, Elf32_auxv_t auxvt[AT_EGID + 1],
+ unsigned long load_addr, Elf_Symndx *hash_addr, ElfW(auxv_t) auxvt[AT_EGID + 1],
char **envp, struct r_debug *debug_addr)
{
ElfW(Phdr) *ppnt;
@@ -1032,8 +1037,8 @@
for (tcurr = _dl_loaded_modules; tcurr; tcurr = tcurr->next)
{
- Elf32_Dyn *dpnt;
- for (dpnt = (Elf32_Dyn *) tcurr->dynamic_addr; dpnt->d_tag; dpnt++)
+ ElfW(Dyn) *dpnt;
+ for (dpnt = (ElfW(Dyn) *) tcurr->dynamic_addr; dpnt->d_tag; dpnt++)
{
if (dpnt->d_tag == DT_NEEDED)
{
diff -ur uClibc-cvs/ldso/ldso/readelflib1.c uClibc/ldso/ldso/readelflib1.c
--- uClibc-cvs/ldso/ldso/readelflib1.c Thu Oct 9 23:12:35 2003
+++ uClibc/ldso/ldso/readelflib1.c Mon Oct 13 22:39:36 2003
@@ -398,7 +398,7 @@
ElfW(Ehdr) *epnt;
unsigned long dynamic_addr = 0;
unsigned long dynamic_size = 0;
- Elf32_Dyn *dpnt;
+ ElfW(Dyn) *dpnt;
struct elf_resolve *tpnt;
ElfW(Phdr) *ppnt;
char *status;
@@ -618,16 +618,16 @@
return NULL;
}
- dpnt = (Elf32_Dyn *) dynamic_addr;
+ dpnt = (ElfW(Dyn) *) dynamic_addr;
- dynamic_size = dynamic_size / sizeof(Elf32_Dyn);
+ dynamic_size = dynamic_size / sizeof(ElfW(Dyn));
_dl_memset(dynamic_info, 0, sizeof(dynamic_info));
#if defined(__mips__)
{
int indx = 1;
- Elf32_Dyn *dpnt = (Elf32_Dyn *) dynamic_addr;
+ ElfW(Dyn) *dpnt = (ElfW(Dyn) *) dynamic_addr;
while(dpnt->d_tag) {
dpnt++;
@@ -703,7 +703,7 @@
if (lpnt) {
lpnt = (unsigned long *) (dynamic_info[DT_PLTGOT] +
- ((int) libaddr));
+ libaddr);
INIT_GOT(lpnt, tpnt);
};
@@ -764,7 +764,11 @@
/* Minimal printf which handles only %s, %d, and %x */
void _dl_dprintf(int fd, const char *fmt, ...)
{
+#if __WORDSIZE > 32
+ long int num;
+#else
int num;
+#endif
va_list args;
char *start, *ptr, *string;
char buf[2048];
@@ -803,7 +807,11 @@
case 'd':
{
char tmp[22];
+#if __WORDSIZE > 32
+ num = va_arg(args, long int);
+#else
num = va_arg(args, int);
+#endif
string = _dl_simple_ltoa(tmp, num);
_dl_write(fd, string, _dl_strlen(string));
@@ -813,7 +821,11 @@
case 'X':
{
char tmp[22];
+#if __WORDSIZE > 32
+ num = va_arg(args, long int);
+#else
num = va_arg(args, int);
+#endif
string = _dl_simple_ltoahex(tmp, num);
_dl_write(fd, string, _dl_strlen(string));
diff -ur uClibc-cvs/ldso/libdl/dlib.c uClibc/ldso/libdl/dlib.c
--- uClibc-cvs/ldso/libdl/dlib.c Thu Oct 9 23:12:35 2003
+++ uClibc/ldso/libdl/dlib.c Mon Oct 13 22:39:36 2003
@@ -28,7 +28,11 @@
_dl_exit(1);
}
+#if __WORDSIZE > 32
+static long __attribute__ ((unused)) foobar1 = (long) foobar; /* Use as pointer */
+#else
static int __attribute__ ((unused)) foobar1 = (int) foobar; /* Use as pointer */
+#endif
extern void _dl_dprintf(int, const char *, ...) __attribute__ ((__weak__, __alias__ ("foobar")));
extern char *_dl_find_hash(const char *, struct dyn_elf *, struct elf_resolve *, enum caller_type)
__attribute__ ((__weak__, __alias__ ("foobar")));
@@ -212,9 +216,9 @@
for (tcurr = tpnt; tcurr; tcurr = tcurr->next)
{
- Elf32_Dyn *dpnt;
+ ElfW(Dyn) *dpnt;
char *lpntstr;
- for (dpnt = (Elf32_Dyn *) tcurr->dynamic_addr; dpnt->d_tag; dpnt++) {
+ for (dpnt = (ElfW(Dyn) *) tcurr->dynamic_addr; dpnt->d_tag; dpnt++) {
if (dpnt->d_tag == DT_NEEDED) {
char *name;
@@ -565,22 +569,22 @@
/* First start with a complete list of all of the loaded files. */
for (tpnt = _dl_loaded_modules; tpnt; tpnt = tpnt->next) {
_dl_dprintf(2, "\t%x %x %x %s %d %s\n",
- (unsigned) tpnt->loadaddr, (unsigned) tpnt,
- (unsigned) tpnt->symbol_scope,
+ (unsigned long) tpnt->loadaddr, (unsigned long) tpnt,
+ (unsigned long) tpnt->symbol_scope,
type[tpnt->libtype],
tpnt->usage_count, tpnt->libname);
}
/* Next dump the module list for the application itself */
_dl_dprintf(2, "\nModules for application (%x):\n",
- (unsigned) _dl_symbol_tables);
+ (unsigned long) _dl_symbol_tables);
for (rpnt = _dl_symbol_tables; rpnt; rpnt = rpnt->next)
- _dl_dprintf(2, "\t%x %s\n", (unsigned) rpnt->dyn, rpnt->dyn->libname);
+ _dl_dprintf(2, "\t%x %s\n", (unsigned long) rpnt->dyn, rpnt->dyn->libname);
for (hpnt = _dl_handles; hpnt; hpnt = hpnt->next_handle) {
- _dl_dprintf(2, "Modules for handle %x\n", (unsigned) hpnt);
+ _dl_dprintf(2, "Modules for handle %x\n", (unsigned long) hpnt);
for (rpnt = hpnt; rpnt; rpnt = rpnt->next)
- _dl_dprintf(2, "\t%x %s\n", (unsigned) rpnt->dyn,
+ _dl_dprintf(2, "\t%x %s\n", (unsigned long) rpnt->dyn,
rpnt->dyn->libname);
}
}
@@ -625,14 +629,14 @@
{
char *strtab;
- Elf32_Sym *symtab;
+ ElfW(Sym) *symtab;
int hn, si;
int sf;
int sn = 0;
ElfW(Addr) sa;
sa = 0;
- symtab = (Elf32_Sym *) (pelf->dynamic_info[DT_SYMTAB] + pelf->loadaddr);
+ symtab = (ElfW(Sym) *) (pelf->dynamic_info[DT_SYMTAB] + pelf->loadaddr);
strtab = (char *) (pelf->dynamic_info[DT_STRTAB] + pelf->loadaddr);
sf = 0;
diff -ur uClibc-cvs/ldso/util/ldd.c uClibc/ldso/util/ldd.c
--- uClibc-cvs/ldso/util/ldd.c Mon Oct 13 20:18:55 2003
+++ uClibc/ldso/util/ldd.c Mon Oct 13 22:39:36 2003
@@ -41,11 +41,7 @@
#include <sys/wait.h>
#include "bswap.h"
-#if defined (sun)
#include "link.h"
-#else
-#include "elf.h"
-#endif
#ifdef DMALLOC
#include <dmalloc.h>
@@ -135,11 +131,11 @@
-Elf32_Shdr * elf_find_section_type( int key, Elf32_Ehdr *ehdr)
+ElfW(Shdr) * elf_find_section_type( int key, ElfW(Ehdr) *ehdr)
{
int j;
- Elf32_Shdr *shdr;
- shdr = (Elf32_Shdr *)(ehdr->e_shoff + (char *)ehdr);
+ ElfW(Shdr) *shdr;
+ shdr = (ElfW(Shdr) *)(ehdr->e_shoff + (char *)ehdr);
for (j = ehdr->e_shnum; --j>=0; ++shdr) {
if (key==(int)byteswap32_to_host(shdr->sh_type)) {
return shdr;
@@ -148,10 +144,10 @@
return NULL;
}
-Elf32_Phdr * elf_find_phdr_type( int type, Elf32_Ehdr *ehdr)
+ElfW(Phdr) * elf_find_phdr_type( int type, ElfW(Ehdr) *ehdr)
{
int j;
- Elf32_Phdr *phdr = (Elf32_Phdr *)(ehdr->e_phoff + (char *)ehdr);
+ ElfW(Phdr) *phdr = (ElfW(Phdr) *)(ehdr->e_phoff + (char *)ehdr);
for (j = ehdr->e_phnum; --j>=0; ++phdr) {
if (type==(int)byteswap32_to_host(phdr->p_type)) {
return phdr;
@@ -161,10 +157,10 @@
}
/* Returns value if return_val==1, ptr otherwise */
-void * elf_find_dynamic(int const key, Elf32_Dyn *dynp,
- Elf32_Ehdr *ehdr, int return_val)
+void * elf_find_dynamic(int const key, ElfW(Dyn) *dynp,
+ ElfW(Ehdr) *ehdr, int return_val)
{
- Elf32_Phdr *pt_text = elf_find_phdr_type(PT_LOAD, ehdr);
+ ElfW(Phdr) *pt_text = elf_find_phdr_type(PT_LOAD, ehdr);
unsigned tx_reloc = byteswap32_to_host(pt_text->p_vaddr) - byteswap32_to_host(pt_text->p_offset);
for (; DT_NULL!=byteswap32_to_host(dynp->d_tag); ++dynp) {
if (key == (int)byteswap32_to_host(dynp->d_tag)) {
@@ -177,10 +173,10 @@
return NULL;
}
-int check_elf_header(Elf32_Ehdr *const ehdr)
+int check_elf_header(ElfW(Ehdr) *const ehdr)
{
if (! ehdr || strncmp((void *)ehdr, ELFMAG, SELFMAG) != 0 ||
- ehdr->e_ident[EI_CLASS] != ELFCLASS32 ||
+ ehdr->e_ident[EI_CLASS] != ELFCLASSM ||
ehdr->e_ident[EI_VERSION] != EV_CURRENT)
{
return 1;
@@ -258,7 +254,7 @@
*result = '\0';
}
-void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_suid, struct library *lib)
+void locate_library_file(ElfW(Ehdr)* ehdr, ElfW(Dyn)* dynamic, int is_suid, struct library *lib)
{
char *buf;
char *path;
@@ -338,7 +334,7 @@
}
}
-static int add_library(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_setuid, char *s)
+static int add_library(ElfW(Ehdr)* ehdr, ElfW(Dyn)* dynamic, int is_setuid, char *s)
{
char *tmp, *tmp1, *tmp2;
struct library *cur, *newlib=lib_list;
@@ -399,9 +395,9 @@
}
-static void find_needed_libraries(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int is_setuid)
+static void find_needed_libraries(ElfW(Ehdr)* ehdr, ElfW(Dyn)* dynamic, char *strtab, int is_setuid)
{
- Elf32_Dyn *dyns;
+ ElfW(Dyn) *dyns;
for (dyns=dynamic; byteswap32_to_host(dyns->d_tag)!=DT_NULL; ++dyns) {
if (DT_NEEDED == byteswap32_to_host(dyns->d_tag)) {
@@ -411,9 +407,9 @@
}
}
-static struct library * find_elf_interpreter(Elf32_Ehdr* ehdr)
+static struct library * find_elf_interpreter(ElfW(Ehdr)* ehdr)
{
- Elf32_Phdr *phdr;
+ ElfW(Phdr) *phdr;
if (interpreter_already_found==1)
return NULL;
@@ -480,9 +476,9 @@
FILE *thefile;
struct stat statbuf;
char *dynstr=NULL;
- Elf32_Ehdr *ehdr = NULL;
- Elf32_Shdr *dynsec = NULL;
- Elf32_Dyn *dynamic = NULL;
+ ElfW(Ehdr) *ehdr = NULL;
+ ElfW(Shdr) *dynsec = NULL;
+ ElfW(Dyn) *dynamic = NULL;
struct library *interp;
if (filename == not_found)
@@ -501,14 +497,14 @@
return -1;
}
- if ((size_t)statbuf.st_size < sizeof(Elf32_Ehdr))
+ if ((size_t)statbuf.st_size < sizeof(ElfW(Ehdr)))
goto foo;
if (!S_ISREG(statbuf.st_mode))
goto foo;
/* mmap the file to make reading stuff from it effortless */
- ehdr = (Elf32_Ehdr *)mmap(0, statbuf.st_size,
+ ehdr = (ElfW(Ehdr) *)mmap(0, statbuf.st_size,
PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(thefile), 0);
foo:
@@ -573,7 +569,7 @@
dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr);
if (dynsec) {
- dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr);
+ dynamic = (ElfW(Dyn)*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr);
dynstr = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0);
find_needed_libraries(ehdr, dynamic, dynstr, is_suid);
}
diff -ur uClibc-cvs/ldso/util/readelf.c uClibc/ldso/util/readelf.c
--- uClibc-cvs/ldso/util/readelf.c Fri Mar 7 21:39:51 2003
+++ uClibc/ldso/util/readelf.c Mon Oct 13 23:14:16 2003
@@ -38,7 +38,7 @@
#include <sys/types.h>
#include "bswap.h"
-#include "elf.h"
+#include "link.h"
int byteswap;
@@ -51,10 +51,10 @@
}
}
-Elf32_Shdr * elf_find_section_type( int key, Elf32_Ehdr *ehdr)
+ElfW(Shdr) * elf_find_section_type( int key, ElfW(Ehdr) *ehdr)
{
int j;
- Elf32_Shdr *shdr = (Elf32_Shdr *)(ehdr->e_shoff + (char *)ehdr);
+ ElfW(Shdr) *shdr = (ElfW(Shdr) *)(ehdr->e_shoff + (char *)ehdr);
for (j = ehdr->e_shnum; --j>=0; ++shdr) {
if (key==(int)byteswap32_to_host(shdr->sh_type)) {
return shdr;
@@ -63,10 +63,10 @@
return NULL;
}
-Elf32_Phdr * elf_find_phdr_type( int type, Elf32_Ehdr *ehdr)
+ElfW(Phdr) * elf_find_phdr_type( int type, ElfW(Ehdr) *ehdr)
{
int j;
- Elf32_Phdr *phdr = (Elf32_Phdr *)(ehdr->e_phoff + (char *)ehdr);
+ ElfW(Phdr) *phdr = (ElfW(Phdr) *)(ehdr->e_phoff + (char *)ehdr);
for (j = ehdr->e_phnum; --j>=0; ++phdr) {
if (type==(int)byteswap32_to_host(phdr->p_type)) {
return phdr;
@@ -76,10 +76,10 @@
}
/* Returns value if return_val==1, ptr otherwise */
-void * elf_find_dynamic(int const key, Elf32_Dyn *dynp,
- Elf32_Ehdr *ehdr, int return_val)
+void * elf_find_dynamic(int const key, ElfW(Dyn) *dynp,
+ ElfW(Ehdr) *ehdr, int return_val)
{
- Elf32_Phdr *pt_text = elf_find_phdr_type(PT_LOAD, ehdr);
+ ElfW(Phdr) *pt_text = elf_find_phdr_type(PT_LOAD, ehdr);
unsigned tx_reloc = byteswap32_to_host(pt_text->p_vaddr) - byteswap32_to_host(pt_text->p_offset);
for (; DT_NULL!=byteswap32_to_host(dynp->d_tag); ++dynp) {
if (key == (int)byteswap32_to_host(dynp->d_tag)) {
@@ -92,10 +92,14 @@
return NULL;
}
-int check_elf_header(Elf32_Ehdr *const ehdr)
+int check_elf_header(ElfW(Ehdr) *const ehdr)
{
if (! ehdr || strncmp((void *)ehdr, ELFMAG, SELFMAG) != 0 ||
+#if __ELF_NATIVE_CLASS == 64
+ ehdr->e_ident[EI_CLASS] != ELFCLASS64 ||
+#else
ehdr->e_ident[EI_CLASS] != ELFCLASS32 ||
+#endif
ehdr->e_ident[EI_VERSION] != EV_CURRENT)
{
return 1;
@@ -142,7 +146,7 @@
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
#define ELFOSABI_ARM 97 /* ARM */
-static void describe_elf_hdr(Elf32_Ehdr* ehdr)
+static void describe_elf_hdr(ElfW(Ehdr)* ehdr)
{
char *tmp, *tmp1;
@@ -275,9 +279,9 @@
printf( "ABI Version:\t%d\n", ehdr->e_ident[EI_ABIVERSION]);
}
-static void list_needed_libraries(Elf32_Dyn* dynamic, char *strtab)
+static void list_needed_libraries(ElfW(Dyn)* dynamic, char *strtab)
{
- Elf32_Dyn *dyns;
+ ElfW(Dyn) *dyns;
printf("Dependancies:\n");
for (dyns=dynamic; byteswap32_to_host(dyns->d_tag)!=DT_NULL; ++dyns) {
@@ -287,9 +291,9 @@
}
}
-static void describe_elf_interpreter(Elf32_Ehdr* ehdr)
+static void describe_elf_interpreter(ElfW(Ehdr)* ehdr)
{
- Elf32_Phdr *phdr;
+ ElfW(Phdr) *phdr;
phdr = elf_find_phdr_type(PT_INTERP, ehdr);
if (phdr) {
printf("Interpreter:\t%s\n", (char*)ehdr + byteswap32_to_host(phdr->p_offset));
@@ -303,9 +307,9 @@
char *thefilename = argv[1];
FILE *thefile;
struct stat statbuf;
- Elf32_Ehdr *ehdr = 0;
- Elf32_Shdr *dynsec;
- Elf32_Dyn *dynamic;
+ ElfW(Ehdr) *ehdr = 0;
+ ElfW(Shdr) *dynsec;
+ ElfW(Dyn) *dynamic;
if (argc < 2 || !thefilename) {
fprintf(stderr, "No filename specified.\n");
@@ -320,11 +324,11 @@
exit(EXIT_FAILURE);
}
- if ((size_t)statbuf.st_size < sizeof(Elf32_Ehdr))
+ if ((size_t)statbuf.st_size < sizeof(ElfW(Ehdr)))
goto foo;
/* mmap the file to make reading stuff from it effortless */
- ehdr = (Elf32_Ehdr *)mmap(0, statbuf.st_size,
+ ehdr = (ElfW(Ehdr) *)mmap(0, statbuf.st_size,
PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(thefile), 0);
foo:
@@ -338,7 +342,7 @@
dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr);
if (dynsec) {
- dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr);
+ dynamic = (ElfW(Dyn)*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr);
dynstr = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0);
list_needed_libraries(dynamic, dynstr);
}
---
Atsushi Nemoto
More information about the uClibc
mailing list