From 12624faa157f2a85ff86407cdba118e29a4e94c4 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 3 May 2001 06:34:13 +0000 Subject: Some more minor updates. Add in some debug stuff, and a way to print out addresses _early_ on in the process. --- ldso/ldso/boot1.c | 50 +++++++++++++++++++++++++++++++++----------------- ldso/ldso/ld-uClibc.c | 50 +++++++++++++++++++++++++++++++++----------------- ldso/ldso/ld_string.h | 21 ++++++++++++++++++++- ldso/ldso/ldso.c | 50 +++++++++++++++++++++++++++++++++----------------- ldso/ldso/string.h | 21 ++++++++++++++++++++- 5 files changed, 139 insertions(+), 53 deletions(-) diff --git a/ldso/ldso/boot1.c b/ldso/ldso/boot1.c index 729c72e53..127b9d9ff 100644 --- a/ldso/ldso/boot1.c +++ b/ldso/ldso/boot1.c @@ -170,7 +170,7 @@ void _dl_boot(unsigned int args) Elf32_auxv_t auxv_t[AT_EGID + 1]; unsigned char *malloc_buffer, *mmap_zero; int (*_dl_atexit) (void *); - int *lpnt; + unsigned long *lpnt; Elf32_Dyn *dpnt; unsigned long *hash_addr; struct r_debug *debug_addr; @@ -210,8 +210,24 @@ void _dl_boot(unsigned int args) /* Next, locate the GOT */ load_addr = auxv_t[AT_BASE].a_un.a_val; +#ifdef DL_DEBUG + SEND_STDERR("load_addr="); + SEND_STDERR(_dl_simple_ltoahex(load_addr)); + SEND_STDERR("\n"); +#endif +// __asm__("\tmovl %%ebx,%0\n\t" : "=a" (X)) GET_GOT(got); +#ifdef DL_DEBUG + SEND_STDERR("Found got="); + SEND_STDERR(_dl_simple_ltoahex((unsigned long)*got)); + SEND_STDERR("\n"); +#endif dpnt = (Elf32_Dyn *) (*got + load_addr); +#ifdef DL_DEBUG + SEND_STDERR("First Dynamic section entry="); + SEND_STDERR(_dl_simple_ltoahex((unsigned long)dpnt)); + SEND_STDERR("\n"); +#endif /* Call mmap to get a page of writable memory that can be used @@ -259,7 +275,7 @@ void _dl_boot(unsigned int args) } app_tpnt->dynamic_info[dpnt->d_tag] = dpnt->d_un.d_val; if (dpnt->d_tag == DT_DEBUG) - dpnt->d_un.d_val = (int) debug_addr; + dpnt->d_un.d_val = (unsigned long) debug_addr; if (dpnt->d_tag == DT_TEXTREL || SVR4_BUGCOMPAT) app_tpnt->dynamic_info[DT_TEXTREL] = 1; dpnt++; @@ -396,18 +412,14 @@ void _dl_boot(unsigned int args) We start with the basic executable, and then go from there. Eventually we will run across ourself, and we will need to properly deal with that as well. */ - _dl_malloc_addr = malloc_buffer; - _dl_mmap_zero = mmap_zero; -/* tpnt = _dl_malloc(sizeof(struct elf_resolve)); */ - -/* Now we have done the mandatory linking of some things. We are now - free to start using global variables, since these things have all been - fixed up by now. Still no function calls outside of this library , - since the dynamic resolver is not yet ready. */ - lpnt = (int *) (tpnt->dynamic_info[DT_PLTGOT] + load_addr); + /* Now we have done the mandatory linking of some things. We are now + free to start using global variables, since these things have all been + fixed up by now. Still no function calls outside of this library , + since the dynamic resolver is not yet ready. */ + lpnt = (unsigned long *) (tpnt->dynamic_info[DT_PLTGOT] + load_addr); INIT_GOT(lpnt, tpnt); /* OK, this was a big step, now we need to scan all of the user images @@ -471,7 +483,7 @@ void _dl_boot(unsigned int args) rpnt->dyn = _dl_loaded_modules; app_tpnt->usage_count++; app_tpnt->symbol_scope = _dl_symbol_tables; - lpnt = (int *) (app_tpnt->dynamic_info[DT_PLTGOT]); + lpnt = (unsigned long *) (app_tpnt->dynamic_info[DT_PLTGOT]); #ifdef ALLOW_ZERO_PLTGOT if (lpnt) #endif @@ -942,19 +954,23 @@ void *_dl_malloc(int size) { void *retval; - //SEND_STDERR("malloc: request for "); - //SEND_STDERR(_dl_simple_itol(size)); - //SEND_STDERR(" bytes\n"); +#ifdef DL_DEBUG + SEND_STDERR("malloc: request for "); + SEND_STDERR(_dl_simple_itoa(size)); + SEND_STDERR(" bytes\n"); +#endif if (_dl_malloc_function) return (*_dl_malloc_function) (size); if (_dl_malloc_addr - _dl_mmap_zero + size > 4096) { - //SEND_STDERR("malloc: mmapping more memory\n"); +#ifdef DL_DEBUG + SEND_STDERR("malloc: mmapping more memory\n"); +#endif _dl_mmap_zero = _dl_malloc_addr = _dl_mmap((void *) 0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (_dl_mmap_check_error(_dl_mmap_zero)) { - _dl_fdprintf(2, "%s: can't map '/dev/zero'\n", _dl_progname); + _dl_fdprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname); _dl_exit(20); } } diff --git a/ldso/ldso/ld-uClibc.c b/ldso/ldso/ld-uClibc.c index 729c72e53..127b9d9ff 100644 --- a/ldso/ldso/ld-uClibc.c +++ b/ldso/ldso/ld-uClibc.c @@ -170,7 +170,7 @@ void _dl_boot(unsigned int args) Elf32_auxv_t auxv_t[AT_EGID + 1]; unsigned char *malloc_buffer, *mmap_zero; int (*_dl_atexit) (void *); - int *lpnt; + unsigned long *lpnt; Elf32_Dyn *dpnt; unsigned long *hash_addr; struct r_debug *debug_addr; @@ -210,8 +210,24 @@ void _dl_boot(unsigned int args) /* Next, locate the GOT */ load_addr = auxv_t[AT_BASE].a_un.a_val; +#ifdef DL_DEBUG + SEND_STDERR("load_addr="); + SEND_STDERR(_dl_simple_ltoahex(load_addr)); + SEND_STDERR("\n"); +#endif +// __asm__("\tmovl %%ebx,%0\n\t" : "=a" (X)) GET_GOT(got); +#ifdef DL_DEBUG + SEND_STDERR("Found got="); + SEND_STDERR(_dl_simple_ltoahex((unsigned long)*got)); + SEND_STDERR("\n"); +#endif dpnt = (Elf32_Dyn *) (*got + load_addr); +#ifdef DL_DEBUG + SEND_STDERR("First Dynamic section entry="); + SEND_STDERR(_dl_simple_ltoahex((unsigned long)dpnt)); + SEND_STDERR("\n"); +#endif /* Call mmap to get a page of writable memory that can be used @@ -259,7 +275,7 @@ void _dl_boot(unsigned int args) } app_tpnt->dynamic_info[dpnt->d_tag] = dpnt->d_un.d_val; if (dpnt->d_tag == DT_DEBUG) - dpnt->d_un.d_val = (int) debug_addr; + dpnt->d_un.d_val = (unsigned long) debug_addr; if (dpnt->d_tag == DT_TEXTREL || SVR4_BUGCOMPAT) app_tpnt->dynamic_info[DT_TEXTREL] = 1; dpnt++; @@ -396,18 +412,14 @@ void _dl_boot(unsigned int args) We start with the basic executable, and then go from there. Eventually we will run across ourself, and we will need to properly deal with that as well. */ - _dl_malloc_addr = malloc_buffer; - _dl_mmap_zero = mmap_zero; -/* tpnt = _dl_malloc(sizeof(struct elf_resolve)); */ - -/* Now we have done the mandatory linking of some things. We are now - free to start using global variables, since these things have all been - fixed up by now. Still no function calls outside of this library , - since the dynamic resolver is not yet ready. */ - lpnt = (int *) (tpnt->dynamic_info[DT_PLTGOT] + load_addr); + /* Now we have done the mandatory linking of some things. We are now + free to start using global variables, since these things have all been + fixed up by now. Still no function calls outside of this library , + since the dynamic resolver is not yet ready. */ + lpnt = (unsigned long *) (tpnt->dynamic_info[DT_PLTGOT] + load_addr); INIT_GOT(lpnt, tpnt); /* OK, this was a big step, now we need to scan all of the user images @@ -471,7 +483,7 @@ void _dl_boot(unsigned int args) rpnt->dyn = _dl_loaded_modules; app_tpnt->usage_count++; app_tpnt->symbol_scope = _dl_symbol_tables; - lpnt = (int *) (app_tpnt->dynamic_info[DT_PLTGOT]); + lpnt = (unsigned long *) (app_tpnt->dynamic_info[DT_PLTGOT]); #ifdef ALLOW_ZERO_PLTGOT if (lpnt) #endif @@ -942,19 +954,23 @@ void *_dl_malloc(int size) { void *retval; - //SEND_STDERR("malloc: request for "); - //SEND_STDERR(_dl_simple_itol(size)); - //SEND_STDERR(" bytes\n"); +#ifdef DL_DEBUG + SEND_STDERR("malloc: request for "); + SEND_STDERR(_dl_simple_itoa(size)); + SEND_STDERR(" bytes\n"); +#endif if (_dl_malloc_function) return (*_dl_malloc_function) (size); if (_dl_malloc_addr - _dl_mmap_zero + size > 4096) { - //SEND_STDERR("malloc: mmapping more memory\n"); +#ifdef DL_DEBUG + SEND_STDERR("malloc: mmapping more memory\n"); +#endif _dl_mmap_zero = _dl_malloc_addr = _dl_mmap((void *) 0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (_dl_mmap_check_error(_dl_mmap_zero)) { - _dl_fdprintf(2, "%s: can't map '/dev/zero'\n", _dl_progname); + _dl_fdprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname); _dl_exit(20); } } diff --git a/ldso/ldso/ld_string.h b/ldso/ldso/ld_string.h index 98f2dab81..5d18bb788 100644 --- a/ldso/ldso/ld_string.h +++ b/ldso/ldso/ld_string.h @@ -111,7 +111,7 @@ extern inline void * _dl_memset(void * str,int c,size_t len) /* Early on, we can't call printf, so use this to print out * numbers using the SEND_STDERR() macro */ -static inline char *_dl_simple_itol(unsigned long i) +static inline char *_dl_simple_ltoa(unsigned long i) { /* 21 digits plus null terminator, good for 64-bit or smaller ints */ static char local[22]; @@ -124,5 +124,24 @@ static inline char *_dl_simple_itol(unsigned long i) return p + 1; } +static inline char *_dl_simple_ltoahex(unsigned long i) +{ + /* 21 digits plus null terminator, good for 64-bit or smaller ints */ + static char local[22]; + char *p = &local[21]; + *p-- = '\0'; + do { + char temp = i % 0x10; + if (temp <= 0x09) + *p-- = '0' + temp; + else + *p-- = 'a' - 0x0a + temp; + i /= 0x10; + } while (i > 0); + *p-- = 'x'; + *p-- = '0'; + return p + 1; +} + #endif diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index 729c72e53..127b9d9ff 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -170,7 +170,7 @@ void _dl_boot(unsigned int args) Elf32_auxv_t auxv_t[AT_EGID + 1]; unsigned char *malloc_buffer, *mmap_zero; int (*_dl_atexit) (void *); - int *lpnt; + unsigned long *lpnt; Elf32_Dyn *dpnt; unsigned long *hash_addr; struct r_debug *debug_addr; @@ -210,8 +210,24 @@ void _dl_boot(unsigned int args) /* Next, locate the GOT */ load_addr = auxv_t[AT_BASE].a_un.a_val; +#ifdef DL_DEBUG + SEND_STDERR("load_addr="); + SEND_STDERR(_dl_simple_ltoahex(load_addr)); + SEND_STDERR("\n"); +#endif +// __asm__("\tmovl %%ebx,%0\n\t" : "=a" (X)) GET_GOT(got); +#ifdef DL_DEBUG + SEND_STDERR("Found got="); + SEND_STDERR(_dl_simple_ltoahex((unsigned long)*got)); + SEND_STDERR("\n"); +#endif dpnt = (Elf32_Dyn *) (*got + load_addr); +#ifdef DL_DEBUG + SEND_STDERR("First Dynamic section entry="); + SEND_STDERR(_dl_simple_ltoahex((unsigned long)dpnt)); + SEND_STDERR("\n"); +#endif /* Call mmap to get a page of writable memory that can be used @@ -259,7 +275,7 @@ void _dl_boot(unsigned int args) } app_tpnt->dynamic_info[dpnt->d_tag] = dpnt->d_un.d_val; if (dpnt->d_tag == DT_DEBUG) - dpnt->d_un.d_val = (int) debug_addr; + dpnt->d_un.d_val = (unsigned long) debug_addr; if (dpnt->d_tag == DT_TEXTREL || SVR4_BUGCOMPAT) app_tpnt->dynamic_info[DT_TEXTREL] = 1; dpnt++; @@ -396,18 +412,14 @@ void _dl_boot(unsigned int args) We start with the basic executable, and then go from there. Eventually we will run across ourself, and we will need to properly deal with that as well. */ - _dl_malloc_addr = malloc_buffer; - _dl_mmap_zero = mmap_zero; -/* tpnt = _dl_malloc(sizeof(struct elf_resolve)); */ - -/* Now we have done the mandatory linking of some things. We are now - free to start using global variables, since these things have all been - fixed up by now. Still no function calls outside of this library , - since the dynamic resolver is not yet ready. */ - lpnt = (int *) (tpnt->dynamic_info[DT_PLTGOT] + load_addr); + /* Now we have done the mandatory linking of some things. We are now + free to start using global variables, since these things have all been + fixed up by now. Still no function calls outside of this library , + since the dynamic resolver is not yet ready. */ + lpnt = (unsigned long *) (tpnt->dynamic_info[DT_PLTGOT] + load_addr); INIT_GOT(lpnt, tpnt); /* OK, this was a big step, now we need to scan all of the user images @@ -471,7 +483,7 @@ void _dl_boot(unsigned int args) rpnt->dyn = _dl_loaded_modules; app_tpnt->usage_count++; app_tpnt->symbol_scope = _dl_symbol_tables; - lpnt = (int *) (app_tpnt->dynamic_info[DT_PLTGOT]); + lpnt = (unsigned long *) (app_tpnt->dynamic_info[DT_PLTGOT]); #ifdef ALLOW_ZERO_PLTGOT if (lpnt) #endif @@ -942,19 +954,23 @@ void *_dl_malloc(int size) { void *retval; - //SEND_STDERR("malloc: request for "); - //SEND_STDERR(_dl_simple_itol(size)); - //SEND_STDERR(" bytes\n"); +#ifdef DL_DEBUG + SEND_STDERR("malloc: request for "); + SEND_STDERR(_dl_simple_itoa(size)); + SEND_STDERR(" bytes\n"); +#endif if (_dl_malloc_function) return (*_dl_malloc_function) (size); if (_dl_malloc_addr - _dl_mmap_zero + size > 4096) { - //SEND_STDERR("malloc: mmapping more memory\n"); +#ifdef DL_DEBUG + SEND_STDERR("malloc: mmapping more memory\n"); +#endif _dl_mmap_zero = _dl_malloc_addr = _dl_mmap((void *) 0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (_dl_mmap_check_error(_dl_mmap_zero)) { - _dl_fdprintf(2, "%s: can't map '/dev/zero'\n", _dl_progname); + _dl_fdprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname); _dl_exit(20); } } diff --git a/ldso/ldso/string.h b/ldso/ldso/string.h index 98f2dab81..5d18bb788 100644 --- a/ldso/ldso/string.h +++ b/ldso/ldso/string.h @@ -111,7 +111,7 @@ extern inline void * _dl_memset(void * str,int c,size_t len) /* Early on, we can't call printf, so use this to print out * numbers using the SEND_STDERR() macro */ -static inline char *_dl_simple_itol(unsigned long i) +static inline char *_dl_simple_ltoa(unsigned long i) { /* 21 digits plus null terminator, good for 64-bit or smaller ints */ static char local[22]; @@ -124,5 +124,24 @@ static inline char *_dl_simple_itol(unsigned long i) return p + 1; } +static inline char *_dl_simple_ltoahex(unsigned long i) +{ + /* 21 digits plus null terminator, good for 64-bit or smaller ints */ + static char local[22]; + char *p = &local[21]; + *p-- = '\0'; + do { + char temp = i % 0x10; + if (temp <= 0x09) + *p-- = '0' + temp; + else + *p-- = 'a' - 0x0a + temp; + i /= 0x10; + } while (i > 0); + *p-- = 'x'; + *p-- = '0'; + return p + 1; +} + #endif -- cgit v1.2.3