summaryrefslogtreecommitdiff
path: root/ldso
diff options
context:
space:
mode:
Diffstat (limited to 'ldso')
-rw-r--r--ldso/ldso/Makefile2
-rw-r--r--ldso/ldso/arm/elfinterp.c32
-rw-r--r--ldso/ldso/boot1.c149
-rw-r--r--ldso/ldso/dl-elf.c24
-rw-r--r--ldso/ldso/hash.h36
-rw-r--r--ldso/ldso/i386/elfinterp.c30
-rw-r--r--ldso/ldso/ld-uClibc.c149
-rw-r--r--ldso/ldso/ld_hash.h36
-rw-r--r--ldso/ldso/ld_string.h37
-rw-r--r--ldso/ldso/ldso.c149
-rw-r--r--ldso/ldso/m68k/elfinterp.c34
-rw-r--r--ldso/ldso/powerpc/elfinterp.c54
-rw-r--r--ldso/ldso/readelflib1.c24
-rw-r--r--ldso/ldso/sparc/elfinterp.c42
-rw-r--r--ldso/ldso/string.h37
-rw-r--r--ldso/ldso/vsprintf.c291
16 files changed, 570 insertions, 556 deletions
diff --git a/ldso/ldso/Makefile b/ldso/ldso/Makefile
index b0586fc30..9fa1e7c05 100644
--- a/ldso/ldso/Makefile
+++ b/ldso/ldso/Makefile
@@ -30,7 +30,7 @@ TARGET_CFLAGS += #-DDL_DEBUG #-funroll-loops
LDSO_FULLNAME=ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).so
TARGET_CFLAGS+=-fPIC -D__PIC__ -DUCLIBC_ROOT_DIR=\"$(DEVEL_PREFIX)\" -DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR); pwd)\"
-CSRC= boot1.c hash.c readelflib1.c vsprintf.c $(TARGET_ARCH)/elfinterp.c
+CSRC= boot1.c hash.c readelflib1.c $(TARGET_ARCH)/elfinterp.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
ASRC=$(shell ls $(TARGET_ARCH)/*.S)
AOBJS=$(patsubst %.S,%.o, $(ASRC))
diff --git a/ldso/ldso/arm/elfinterp.c b/ldso/ldso/arm/elfinterp.c
index 397610bd6..09b934a1a 100644
--- a/ldso/ldso/arm/elfinterp.c
+++ b/ldso/ldso/arm/elfinterp.c
@@ -81,7 +81,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
if (reloc_type != R_ARM_JUMP_SLOT) {
- _dl_fdprintf(2, "%s: Incorrect relocation type in jump relocations\n",
+ _dl_fprintf(2, "%s: Incorrect relocation type in jump relocations\n",
_dl_progname);
_dl_exit(1);
};
@@ -92,7 +92,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
got_addr = (char **) instr_addr;
#ifdef DL_DEBUG
- _dl_fdprintf(2, "Resolving symbol %s\n",
+ _dl_fprintf(2, "Resolving symbol %s\n",
strtab + symtab[symtab_index].st_name);
#endif
@@ -100,13 +100,13 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
new_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name,
tpnt->symbol_scope, (unsigned long) got_addr, tpnt, 0);
if (!new_addr) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
_dl_exit(1);
};
#ifdef DL_DEBUG
if ((unsigned long) got_addr < 0x40000000) {
- _dl_fdprintf(2, "Calling library function: %s\n",
+ _dl_fprintf(2, "Calling library function: %s\n",
strtab + symtab[symtab_index].st_name);
} else {
*got_addr = new_addr;
@@ -156,13 +156,13 @@ void _dl_parse_lazy_relocation_information(struct elf_resolve *tpnt,
*reloc_addr += (unsigned long) tpnt->loadaddr;
break;
default:
- _dl_fdprintf(2, "%s: (LAZY) can't handle reloc type ",
+ _dl_fprintf(2, "%s: (LAZY) can't handle reloc type ",
_dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf(2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf(2, "%s ", _dl_reltypes[reloc_type]);
#endif
if (symtab_index)
- _dl_fdprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
_dl_exit(1);
};
};
@@ -239,7 +239,7 @@ int _dl_parse_relocation_information(struct elf_resolve *tpnt,
* here, so all bases should be covered.
*/
if (!symbol_addr && ELF32_ST_BIND(symtab[symtab_index].st_info) == STB_GLOBAL) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
}
@@ -267,7 +267,7 @@ int _dl_parse_relocation_information(struct elf_resolve *tpnt,
topbits = newvalue & 0xfe000000;
if (topbits != 0xfe000000 && topbits != 0x00000000)
{
- _dl_fdprintf(2, "R_ARM_PC24 relocation out of range ");
+ _dl_fprintf(2, "R_ARM_PC24 relocation out of range ");
_dl_exit(1);
}
}
@@ -286,20 +286,20 @@ int _dl_parse_relocation_information(struct elf_resolve *tpnt,
case R_ARM_COPY:
#if 0
/* Do this later */
- _dl_fdprintf(2, "Doing copy for symbol ");
- if (symtab_index) _dl_fdprintf(2, strtab + symtab[symtab_index].st_name);
- _dl_fdprintf(2, "\n");
+ _dl_fprintf(2, "Doing copy for symbol ");
+ if (symtab_index) _dl_fprintf(2, strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "\n");
_dl_memcpy((void *) symtab[symtab_index].st_value,
(void *) symbol_addr, symtab[symtab_index].st_size);
#endif
break;
default:
- _dl_fdprintf(2, "%s: can't handle reloc type ", _dl_progname);
+ _dl_fprintf(2, "%s: can't handle reloc type ", _dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf(2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf(2, "%s ", _dl_reltypes[reloc_type]);
#endif
if (symtab_index)
- _dl_fdprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
_dl_exit(1);
};
@@ -360,7 +360,7 @@ int _dl_parse_copy_information(struct dyn_elf *xpnt, unsigned long rel_addr,
symtab[symtab_index].st_name, xpnt->next,
(unsigned long) reloc_addr, NULL, 1);
if (!symbol_addr) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
};
diff --git a/ldso/ldso/boot1.c b/ldso/ldso/boot1.c
index 920779dcd..2824fa4e2 100644
--- a/ldso/ldso/boot1.c
+++ b/ldso/ldso/boot1.c
@@ -121,8 +121,9 @@ char *_dl_preload = 0; /* Things to be loaded before the libs. */
#include "ld.so.h" /* Pull in the name of ld.so */
const char *_dl_progname=_dl_static_progname;
static char *_dl_not_lazy = 0;
-static char *_dl_warn = 0; /* Used by ldd */
+#ifdef DL_TRACE
static char *_dl_trace_loaded_objects = 0;
+#endif
static int (*_dl_elf_main) (int, char **, char **);
static int (*_dl_elf_init) (void);
void *(*_dl_malloc_function) (int size) = NULL;
@@ -213,7 +214,7 @@ DL_BOOT(unsigned long args)
aux_dat += 2;
}
- /* locate the ELF header. We need this done as easly as possible
+ /* locate the ELF header. We need this done as soon as possible
* (esp since SEND_STDERR() needs this on some platforms... */
load_addr = auxv_t[AT_BASE].a_un.a_val;
header = (elfhdr *) auxv_t[AT_BASE].a_un.a_ptr;
@@ -593,8 +594,9 @@ found_got:
}
}
+#ifdef DL_TRACE
_dl_trace_loaded_objects = _dl_getenv("LD_TRACE_LOADED_OBJECTS", envp);
-
+#endif
/* OK, we now have the application in the list, and we have some
basic stuff in place. Now search through the list for other shared
libraries that should be loaded, and insert them on the list in the
@@ -627,22 +629,28 @@ found_got:
{
tpnt1 = _dl_load_shared_library(_dl_secure, NULL, str);
if (!tpnt1) {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects)
- _dl_fdprintf(1, "\t%s => not found\n", str);
+ _dl_fprintf(1, "\t%s => not found\n", str);
else {
- _dl_fdprintf(2, "%s: can't load "
+#endif
+ _dl_fprintf(2, "%s: can't load "
"library '%s'\n", _dl_progname, str);
_dl_exit(15);
+#ifdef DL_TRACE
}
+#endif
} else {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects
&& !tpnt1->usage_count) {
/* this is a real hack to make ldd not print
* the library itself when run on a library. */
if (_dl_strcmp(_dl_progname, str) != 0)
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n", str, tpnt1->libname,
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n", str, tpnt1->libname,
(unsigned) tpnt1->loadaddr);
}
+#endif
rpnt->next = (struct dyn_elf *)
_dl_malloc(sizeof(struct dyn_elf));
_dl_memset(rpnt->next, 0, sizeof(*(rpnt->next)));
@@ -667,14 +675,14 @@ found_got:
if (!_dl_stat(LDSO_PRELOAD, &st)) {
if ((fd = _dl_open(LDSO_PRELOAD, O_RDONLY)) < 0) {
- _dl_fdprintf(2, "%s: can't open file '%s'\n",
+ _dl_fprintf(2, "%s: can't open file '%s'\n",
_dl_progname, LDSO_PRELOAD);
} else {
preload = (caddr_t) _dl_mmap(0, st.st_size + 1,
PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
_dl_close(fd);
if (preload == (caddr_t) - 1) {
- _dl_fdprintf(2, "%s: can't map file '%s'\n",
+ _dl_fprintf(2, "%s: can't map file '%s'\n",
_dl_progname, LDSO_PRELOAD);
} else {
char c, *cp, *cp2;
@@ -705,19 +713,25 @@ found_got:
tpnt1 = _dl_load_shared_library(0, NULL, cp2);
if (!tpnt1) {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects)
- _dl_fdprintf(1, "\t%s => not found\n", cp2);
+ _dl_fprintf(1, "\t%s => not found\n", cp2);
else {
- _dl_fdprintf(2, "%s: can't load library '%s'\n",
+#endif
+ _dl_fprintf(2, "%s: can't load library '%s'\n",
_dl_progname, cp2);
_dl_exit(15);
- }
+#ifdef DL_TRACE
+ }
+#endif
} else {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects
&& !tpnt1->usage_count) {
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n", cp2,
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n", cp2,
tpnt1->libname, (unsigned) tpnt1->loadaddr);
}
+#endif
rpnt->next = (struct dyn_elf *)
_dl_malloc(sizeof(struct dyn_elf));
_dl_memset(rpnt->next, 0,
@@ -751,10 +765,12 @@ found_got:
_dl_get_last_path_component(tpnt->libname)) == 0) {
struct elf_resolve *ttmp;
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects && !tpnt->usage_count) {
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n",
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n",
lpnt, tpnt->libname, (unsigned) tpnt->loadaddr);
}
+#endif
ttmp = _dl_loaded_modules;
while (ttmp->next)
ttmp = ttmp->next;
@@ -772,17 +788,23 @@ found_got:
continue;
}
if (!(tpnt1 = _dl_load_shared_library(0, tcurr, lpnt))) {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects)
- _dl_fdprintf(1, "\t%s => not found\n", lpnt);
+ _dl_fprintf(1, "\t%s => not found\n", lpnt);
else {
- _dl_fdprintf(2, "%s: can't load library '%s'\n",
+#endif
+ _dl_fprintf(2, "%s: can't load library '%s'\n",
_dl_progname, lpnt);
_dl_exit(16);
+#ifdef DL_TRACE
}
+#endif
} else {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects && !tpnt1->usage_count)
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n", lpnt, tpnt1->libname,
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n", lpnt, tpnt1->libname,
(unsigned) tpnt1->loadaddr);
+#endif
rpnt->next = (struct dyn_elf *)
_dl_malloc(sizeof(struct dyn_elf));
_dl_memset(rpnt->next, 0, sizeof(*(rpnt->next)));
@@ -801,11 +823,14 @@ found_got:
_dl_unmap_cache();
#endif
/* ldd uses uses this. I am not sure how you pick up the other flags */
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects) {
+ char *_dl_warn = 0;
_dl_warn = _dl_getenv("LD_WARN", envp);
if (!_dl_warn)
_dl_exit(0);
}
+#endif
/*
* If the program interpreter is not in the module chain, add it. This will
@@ -855,8 +880,10 @@ found_got:
if (_dl_symbol_tables)
goof += _dl_copy_fixups(_dl_symbol_tables);
+#ifdef DL_TRACE
if (goof || _dl_trace_loaded_objects)
_dl_exit(0);
+#endif
/* OK, at this point things are pretty much ready to run. Now we
need to touch up a few items that are required, and then
@@ -929,13 +956,13 @@ found_got:
#undef DL_DEBUG
#ifdef DL_DEBUG
else {
- _dl_fdprintf(2, tpnt->libname);
- _dl_fdprintf(2, ": ");
+ _dl_fprintf(2, tpnt->libname);
+ _dl_fprintf(2, ": ");
if (!_dl_atexit)
- _dl_fdprintf(2, "The address is atexit () is 0x0.");
+ _dl_fprintf(2, "The address is atexit () is 0x0.");
if (!tpnt->dynamic_info[DT_FINI])
- _dl_fdprintf(2, "Invalid .fini section.");
- _dl_fdprintf(2, "\n");
+ _dl_fprintf(2, "Invalid .fini section.");
+ _dl_fprintf(2, "\n");
}
#endif
#undef DL_DEBUG
@@ -970,7 +997,7 @@ int _dl_fixup(struct elf_resolve *tpnt)
goof += _dl_fixup(tpnt->next);
if (tpnt->dynamic_info[DT_REL]) {
#ifdef ELF_USES_RELOCA
- _dl_fdprintf(2, "%s: can't handle REL relocation records\n",
+ _dl_fprintf(2, "%s: can't handle REL relocation records\n",
_dl_progname);
_dl_exit(17);
#else
@@ -989,7 +1016,7 @@ int _dl_fixup(struct elf_resolve *tpnt)
goof += _dl_parse_relocation_information(tpnt,
tpnt->dynamic_info[DT_RELA], tpnt->dynamic_info[DT_RELASZ], 0);
#else
- _dl_fdprintf(2, "%s: can't handle RELA relocation records\n",
+ _dl_fprintf(2, "%s: can't handle RELA relocation records\n",
_dl_progname);
_dl_exit(18);
#endif
@@ -1028,7 +1055,7 @@ void *_dl_malloc(int size)
_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: mmap of a spare page failed!\n", _dl_progname);
+ _dl_fprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname);
_dl_exit(20);
}
}
@@ -1207,3 +1234,77 @@ void * _dl_memset(void * str,int c,size_t len)
return str;
}
+/* Minimum printf which handles only characters, %d's and %s's */
+void _dl_fprintf(int fd, const char *fmt, ...)
+{
+ int num;
+ va_list args;
+ char *start, *ptr, *string;
+ char buf[2048];
+
+ start = ptr = buf;
+
+ if (!fmt)
+ return;
+
+ if (_dl_strlen(fmt) >= (sizeof(buf)-1))
+ _dl_write(fd, "(overflow)\n", 10);
+
+ _dl_strcpy(buf, fmt);
+ va_start(args, fmt);
+
+ while(start)
+ {
+ while(*ptr != '%' && *ptr) {
+ ptr++;
+ }
+
+ if(*ptr == '%')
+ {
+ *ptr++ = '\0';
+ _dl_write(fd, start, _dl_strlen(start));
+
+ switch(*ptr++)
+ {
+ case 's':
+ string = va_arg(args, char *);
+ if (!string)
+ _dl_write(fd, "(null)", 6);
+ else
+ _dl_write(fd, string, _dl_strlen(string));
+ break;
+
+ case 'i':
+ case 'd':
+ {
+ char tmp[13];
+ num = va_arg(args, int);
+ string = _dl_simple_ltoa_inline(tmp, num);
+ _dl_write(fd, string, _dl_strlen(string));
+ break;
+ }
+ case 'x':
+ case 'X':
+ {
+ char tmp[13];
+ num = va_arg(args, int);
+ string = _dl_simple_ltoahex_inline(tmp, num);
+ _dl_write(fd, string, _dl_strlen(string));
+ break;
+ }
+ default:
+ _dl_write(fd, "(null)", 6);
+ break;
+ }
+
+ start = ptr;
+ }
+ else
+ {
+ _dl_write(fd, start, _dl_strlen(start));
+ start = NULL;
+ }
+ }
+ return;
+}
+
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c
index 4e1de140e..2276d4a9f 100644
--- a/ldso/ldso/dl-elf.c
+++ b/ldso/ldso/dl-elf.c
@@ -54,7 +54,7 @@ int _dl_map_cache(void)
if (_dl_stat(LDSO_CACHE, &st)
|| (fd = _dl_open(LDSO_CACHE, O_RDONLY)) < 0) {
- _dl_fdprintf(2, "%s: can't open cache '%s'\n", _dl_progname, LDSO_CACHE);
+ _dl_fprintf(2, "%s: can't open cache '%s'\n", _dl_progname, LDSO_CACHE);
_dl_cache_addr = (caddr_t) - 1; /* so we won't try again */
return -1;
}
@@ -63,7 +63,7 @@ int _dl_map_cache(void)
_dl_cache_addr = (caddr_t) _dl_mmap(0, _dl_cache_size, PROT_READ, MAP_SHARED, fd, 0);
_dl_close(fd);
if (_dl_cache_addr == (caddr_t) - 1) {
- _dl_fdprintf(2, "%s: can't map cache '%s'\n",
+ _dl_fprintf(2, "%s: can't map cache '%s'\n",
_dl_progname, LDSO_CACHE);
return -1;
}
@@ -77,7 +77,7 @@ int _dl_map_cache(void)
(sizeof(header_t) + header->nlibs * sizeof(libentry_t))
|| _dl_cache_addr[_dl_cache_size - 1] != '\0')
{
- _dl_fdprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname,
+ _dl_fprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname,
LDSO_CACHE);
goto fail;
}
@@ -90,7 +90,7 @@ int _dl_map_cache(void)
if (libent[i].sooffset >= strtabsize ||
libent[i].liboffset >= strtabsize)
{
- _dl_fdprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname, LDSO_CACHE);
+ _dl_fprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname, LDSO_CACHE);
goto fail;
}
}
@@ -348,7 +348,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
* NO! When we open shared libraries we may search several paths.
* it is inappropriate to generate an error here.
*/
- _dl_fdprintf(2, "%s: can't open '%s'\n", _dl_progname, libname);
+ _dl_fprintf(2, "%s: can't open '%s'\n", _dl_progname, libname);
#endif
_dl_internal_error_number = DL_ERROR_NOFILE;
return NULL;
@@ -361,7 +361,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
epnt->e_ident[2] != 'L' ||
epnt->e_ident[3] != 'F')
{
- _dl_fdprintf(2, "%s: '%s' is not an ELF file\n", _dl_progname,
+ _dl_fprintf(2, "%s: '%s' is not an ELF file\n", _dl_progname,
libname);
_dl_internal_error_number = DL_ERROR_NOTELF;
_dl_close(infile);
@@ -376,7 +376,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
{
_dl_internal_error_number =
(epnt->e_type != ET_DYN ? DL_ERROR_NOTDYN : DL_ERROR_NOTMAGIC);
- _dl_fdprintf(2, "%s: '%s' is not an ELF executable for " ELF_TARGET
+ _dl_fprintf(2, "%s: '%s' is not an ELF executable for " ELF_TARGET
"\n", _dl_progname, libname);
_dl_close(infile);
return NULL;
@@ -389,7 +389,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
if (ppnt->p_type == PT_DYNAMIC) {
if (dynamic_addr)
- _dl_fdprintf(2, "%s: '%s' has more than one dynamic section\n",
+ _dl_fprintf(2, "%s: '%s' has more than one dynamic section\n",
_dl_progname, libname);
dynamic_addr = ppnt->p_vaddr;
dynamic_size = ppnt->p_filesz;
@@ -421,7 +421,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
status = (char *) _dl_mmap((char *) (piclib ? 0 : minvma),
maxvma - minvma, PROT_NONE, flags | MAP_ANONYMOUS, -1, 0);
if (_dl_mmap_check_error(status)) {
- _dl_fdprintf(2, "%s: can't map '/dev/zero'\n", _dl_progname);
+ _dl_fprintf(2, "%s: can't map '/dev/zero'\n", _dl_progname);
_dl_internal_error_number = DL_ERROR_MMAP_FAILED;
_dl_close(infile);
return NULL;
@@ -453,7 +453,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
ppnt->p_offset & 0x7ffff000);
if (_dl_mmap_check_error(status)) {
- _dl_fdprintf(2, "%s: can't map '%s'\n",
+ _dl_fprintf(2, "%s: can't map '%s'\n",
_dl_progname, libname);
_dl_internal_error_number = DL_ERROR_MMAP_FAILED;
_dl_munmap((char *) libaddr, maxvma - minvma);
@@ -485,7 +485,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
ppnt->p_filesz, LXFLAGS(ppnt->p_flags), flags,
infile, ppnt->p_offset & 0x7ffff000);
if (_dl_mmap_check_error(status)) {
- _dl_fdprintf(2, "%s: can't map '%s'\n", _dl_progname, libname);
+ _dl_fprintf(2, "%s: can't map '%s'\n", _dl_progname, libname);
_dl_internal_error_number = DL_ERROR_MMAP_FAILED;
_dl_munmap((char *) libaddr, maxvma - minvma);
_dl_close(infile);
@@ -515,7 +515,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
if (!dynamic_addr) {
_dl_internal_error_number = DL_ERROR_NODYNAMIC;
- _dl_fdprintf(2, "%s: '%s' is missing a dynamic section\n",
+ _dl_fprintf(2, "%s: '%s' is missing a dynamic section\n",
_dl_progname, libname);
return NULL;
}
diff --git a/ldso/ldso/hash.h b/ldso/ldso/hash.h
index 1ee32672b..9cd2894f8 100644
--- a/ldso/ldso/hash.h
+++ b/ldso/ldso/hash.h
@@ -71,44 +71,8 @@ extern char * _dl_find_hash(char * name, struct dyn_elf * rpnt1,
int copyrel);
extern int _dl_linux_dynamic_link(void);
-#if defined mc68000 || defined __arm__
-/* On some arches constant strings are referenced through the GOT. */
-/* XXX Requires load_addr to be defined. */
-#define SEND_STDERR(X) \
- { const char *__s = (X); \
- if (__s < (const char *) load_addr) __s += load_addr; \
- _dl_write (2, __s, _dl_strlen_inline (__s)); \
- }
-#else
-#define SEND_STDERR(X) _dl_write(2, X, _dl_strlen_inline(X));
-#endif
-
-#define SEND_ADDRESS_STDERR(X, add_a_newline) { \
- char tmp[13], *tmp1; \
- _dl_memset_inline(tmp, 0, sizeof(tmp)); \
- tmp1=_dl_simple_ltoahex_inline( tmp, (unsigned long)(X)); \
- _dl_write(2, tmp1, _dl_strlen_inline(tmp1)); \
- if (add_a_newline) { \
- tmp[0]='\n'; \
- _dl_write(2, tmp, 1); \
- } \
-};
-
-#define SEND_NUMBER_STDERR(X, add_a_newline) { \
- char tmp[13], *tmp1; \
- _dl_memset_inline(tmp, 0, sizeof(tmp)); \
- tmp1=_dl_simple_ltoahex_inline( tmp, (unsigned long)(X)); \
- _dl_write(2, tmp1, _dl_strlen_inline(tmp1)); \
- if (add_a_newline) { \
- tmp[0]='\n'; \
- _dl_write(2, tmp, 1); \
- } \
-};
-
-extern int _dl_fdprintf(int, const char *, ...);
extern char * _dl_library_path;
extern char * _dl_not_lazy;
-extern char * _dl_strdup(const char *);
extern unsigned long _dl_elf_hash(const char * name);
static inline int _dl_symbol(char * name)
diff --git a/ldso/ldso/i386/elfinterp.c b/ldso/ldso/i386/elfinterp.c
index 0dacb1165..56b18ceb8 100644
--- a/ldso/ldso/i386/elfinterp.c
+++ b/ldso/ldso/i386/elfinterp.c
@@ -74,7 +74,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
if (reloc_type != R_386_JMP_SLOT) {
- _dl_fdprintf(2, "%s: Incorrect relocation type in jump relocations\n",
+ _dl_fprintf(2, "%s: Incorrect relocation type in jump relocations\n",
_dl_progname);
_dl_exit(1);
};
@@ -85,7 +85,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
got_addr = (char **) instr_addr;
#ifdef DEBUG
- _dl_fdprintf(2, "Resolving symbol %s\n",
+ _dl_fprintf(2, "Resolving symbol %s\n",
strtab + symtab[symtab_index].st_name);
#endif
@@ -93,14 +93,14 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
new_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name,
tpnt->symbol_scope, (unsigned long) got_addr, tpnt, 0);
if (!new_addr) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
_dl_exit(1);
};
/* #define DEBUG_LIBRARY */
#ifdef DEBUG_LIBRARY
if ((unsigned long) got_addr < 0x40000000) {
- _dl_fdprintf(2, "Calling library function: %s\n",
+ _dl_fprintf(2, "Calling library function: %s\n",
strtab + symtab[symtab_index].st_name);
} else {
*got_addr = new_addr;
@@ -150,13 +150,13 @@ void _dl_parse_lazy_relocation_information(struct elf_resolve *tpnt,
*reloc_addr += (unsigned long) tpnt->loadaddr;
break;
default:
- _dl_fdprintf(2, "%s: (LAZY) can't handle reloc type ",
+ _dl_fprintf(2, "%s: (LAZY) can't handle reloc type ",
_dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf(2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf(2, "%s ", _dl_reltypes[reloc_type]);
#endif
if (symtab_index)
- _dl_fdprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
_dl_exit(1);
};
};
@@ -209,7 +209,7 @@ int _dl_parse_relocation_information(struct elf_resolve *tpnt,
*/
if (!symbol_addr &&
ELF32_ST_BIND(symtab[symtab_index].st_info) == STB_GLOBAL) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
}
@@ -233,20 +233,20 @@ int _dl_parse_relocation_information(struct elf_resolve *tpnt,
case R_386_COPY:
#if 0
/* Do this later */
- _dl_fdprintf(2, "Doing copy for symbol ");
- if (symtab_index) _dl_fdprintf(2, strtab + symtab[symtab_index].st_name);
- _dl_fdprintf(2, "\n");
+ _dl_fprintf(2, "Doing copy for symbol ");
+ if (symtab_index) _dl_fprintf(2, strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "\n");
_dl_memcpy((void *) symtab[symtab_index].st_value,
(void *) symbol_addr, symtab[symtab_index].st_size);
#endif
break;
default:
- _dl_fdprintf(2, "%s: can't handle reloc type ", _dl_progname);
+ _dl_fprintf(2, "%s: can't handle reloc type ", _dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf(2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf(2, "%s ", _dl_reltypes[reloc_type]);
#endif
if (symtab_index)
- _dl_fdprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
_dl_exit(1);
};
@@ -307,7 +307,7 @@ int _dl_parse_copy_information(struct dyn_elf *xpnt, unsigned long rel_addr,
symtab[symtab_index].st_name, xpnt->next,
(unsigned long) reloc_addr, NULL, 1);
if (!symbol_addr) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
};
diff --git a/ldso/ldso/ld-uClibc.c b/ldso/ldso/ld-uClibc.c
index 920779dcd..2824fa4e2 100644
--- a/ldso/ldso/ld-uClibc.c
+++ b/ldso/ldso/ld-uClibc.c
@@ -121,8 +121,9 @@ char *_dl_preload = 0; /* Things to be loaded before the libs. */
#include "ld.so.h" /* Pull in the name of ld.so */
const char *_dl_progname=_dl_static_progname;
static char *_dl_not_lazy = 0;
-static char *_dl_warn = 0; /* Used by ldd */
+#ifdef DL_TRACE
static char *_dl_trace_loaded_objects = 0;
+#endif
static int (*_dl_elf_main) (int, char **, char **);
static int (*_dl_elf_init) (void);
void *(*_dl_malloc_function) (int size) = NULL;
@@ -213,7 +214,7 @@ DL_BOOT(unsigned long args)
aux_dat += 2;
}
- /* locate the ELF header. We need this done as easly as possible
+ /* locate the ELF header. We need this done as soon as possible
* (esp since SEND_STDERR() needs this on some platforms... */
load_addr = auxv_t[AT_BASE].a_un.a_val;
header = (elfhdr *) auxv_t[AT_BASE].a_un.a_ptr;
@@ -593,8 +594,9 @@ found_got:
}
}
+#ifdef DL_TRACE
_dl_trace_loaded_objects = _dl_getenv("LD_TRACE_LOADED_OBJECTS", envp);
-
+#endif
/* OK, we now have the application in the list, and we have some
basic stuff in place. Now search through the list for other shared
libraries that should be loaded, and insert them on the list in the
@@ -627,22 +629,28 @@ found_got:
{
tpnt1 = _dl_load_shared_library(_dl_secure, NULL, str);
if (!tpnt1) {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects)
- _dl_fdprintf(1, "\t%s => not found\n", str);
+ _dl_fprintf(1, "\t%s => not found\n", str);
else {
- _dl_fdprintf(2, "%s: can't load "
+#endif
+ _dl_fprintf(2, "%s: can't load "
"library '%s'\n", _dl_progname, str);
_dl_exit(15);
+#ifdef DL_TRACE
}
+#endif
} else {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects
&& !tpnt1->usage_count) {
/* this is a real hack to make ldd not print
* the library itself when run on a library. */
if (_dl_strcmp(_dl_progname, str) != 0)
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n", str, tpnt1->libname,
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n", str, tpnt1->libname,
(unsigned) tpnt1->loadaddr);
}
+#endif
rpnt->next = (struct dyn_elf *)
_dl_malloc(sizeof(struct dyn_elf));
_dl_memset(rpnt->next, 0, sizeof(*(rpnt->next)));
@@ -667,14 +675,14 @@ found_got:
if (!_dl_stat(LDSO_PRELOAD, &st)) {
if ((fd = _dl_open(LDSO_PRELOAD, O_RDONLY)) < 0) {
- _dl_fdprintf(2, "%s: can't open file '%s'\n",
+ _dl_fprintf(2, "%s: can't open file '%s'\n",
_dl_progname, LDSO_PRELOAD);
} else {
preload = (caddr_t) _dl_mmap(0, st.st_size + 1,
PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
_dl_close(fd);
if (preload == (caddr_t) - 1) {
- _dl_fdprintf(2, "%s: can't map file '%s'\n",
+ _dl_fprintf(2, "%s: can't map file '%s'\n",
_dl_progname, LDSO_PRELOAD);
} else {
char c, *cp, *cp2;
@@ -705,19 +713,25 @@ found_got:
tpnt1 = _dl_load_shared_library(0, NULL, cp2);
if (!tpnt1) {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects)
- _dl_fdprintf(1, "\t%s => not found\n", cp2);
+ _dl_fprintf(1, "\t%s => not found\n", cp2);
else {
- _dl_fdprintf(2, "%s: can't load library '%s'\n",
+#endif
+ _dl_fprintf(2, "%s: can't load library '%s'\n",
_dl_progname, cp2);
_dl_exit(15);
- }
+#ifdef DL_TRACE
+ }
+#endif
} else {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects
&& !tpnt1->usage_count) {
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n", cp2,
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n", cp2,
tpnt1->libname, (unsigned) tpnt1->loadaddr);
}
+#endif
rpnt->next = (struct dyn_elf *)
_dl_malloc(sizeof(struct dyn_elf));
_dl_memset(rpnt->next, 0,
@@ -751,10 +765,12 @@ found_got:
_dl_get_last_path_component(tpnt->libname)) == 0) {
struct elf_resolve *ttmp;
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects && !tpnt->usage_count) {
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n",
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n",
lpnt, tpnt->libname, (unsigned) tpnt->loadaddr);
}
+#endif
ttmp = _dl_loaded_modules;
while (ttmp->next)
ttmp = ttmp->next;
@@ -772,17 +788,23 @@ found_got:
continue;
}
if (!(tpnt1 = _dl_load_shared_library(0, tcurr, lpnt))) {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects)
- _dl_fdprintf(1, "\t%s => not found\n", lpnt);
+ _dl_fprintf(1, "\t%s => not found\n", lpnt);
else {
- _dl_fdprintf(2, "%s: can't load library '%s'\n",
+#endif
+ _dl_fprintf(2, "%s: can't load library '%s'\n",
_dl_progname, lpnt);
_dl_exit(16);
+#ifdef DL_TRACE
}
+#endif
} else {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects && !tpnt1->usage_count)
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n", lpnt, tpnt1->libname,
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n", lpnt, tpnt1->libname,
(unsigned) tpnt1->loadaddr);
+#endif
rpnt->next = (struct dyn_elf *)
_dl_malloc(sizeof(struct dyn_elf));
_dl_memset(rpnt->next, 0, sizeof(*(rpnt->next)));
@@ -801,11 +823,14 @@ found_got:
_dl_unmap_cache();
#endif
/* ldd uses uses this. I am not sure how you pick up the other flags */
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects) {
+ char *_dl_warn = 0;
_dl_warn = _dl_getenv("LD_WARN", envp);
if (!_dl_warn)
_dl_exit(0);
}
+#endif
/*
* If the program interpreter is not in the module chain, add it. This will
@@ -855,8 +880,10 @@ found_got:
if (_dl_symbol_tables)
goof += _dl_copy_fixups(_dl_symbol_tables);
+#ifdef DL_TRACE
if (goof || _dl_trace_loaded_objects)
_dl_exit(0);
+#endif
/* OK, at this point things are pretty much ready to run. Now we
need to touch up a few items that are required, and then
@@ -929,13 +956,13 @@ found_got:
#undef DL_DEBUG
#ifdef DL_DEBUG
else {
- _dl_fdprintf(2, tpnt->libname);
- _dl_fdprintf(2, ": ");
+ _dl_fprintf(2, tpnt->libname);
+ _dl_fprintf(2, ": ");
if (!_dl_atexit)
- _dl_fdprintf(2, "The address is atexit () is 0x0.");
+ _dl_fprintf(2, "The address is atexit () is 0x0.");
if (!tpnt->dynamic_info[DT_FINI])
- _dl_fdprintf(2, "Invalid .fini section.");
- _dl_fdprintf(2, "\n");
+ _dl_fprintf(2, "Invalid .fini section.");
+ _dl_fprintf(2, "\n");
}
#endif
#undef DL_DEBUG
@@ -970,7 +997,7 @@ int _dl_fixup(struct elf_resolve *tpnt)
goof += _dl_fixup(tpnt->next);
if (tpnt->dynamic_info[DT_REL]) {
#ifdef ELF_USES_RELOCA
- _dl_fdprintf(2, "%s: can't handle REL relocation records\n",
+ _dl_fprintf(2, "%s: can't handle REL relocation records\n",
_dl_progname);
_dl_exit(17);
#else
@@ -989,7 +1016,7 @@ int _dl_fixup(struct elf_resolve *tpnt)
goof += _dl_parse_relocation_information(tpnt,
tpnt->dynamic_info[DT_RELA], tpnt->dynamic_info[DT_RELASZ], 0);
#else
- _dl_fdprintf(2, "%s: can't handle RELA relocation records\n",
+ _dl_fprintf(2, "%s: can't handle RELA relocation records\n",
_dl_progname);
_dl_exit(18);
#endif
@@ -1028,7 +1055,7 @@ void *_dl_malloc(int size)
_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: mmap of a spare page failed!\n", _dl_progname);
+ _dl_fprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname);
_dl_exit(20);
}
}
@@ -1207,3 +1234,77 @@ void * _dl_memset(void * str,int c,size_t len)
return str;
}
+/* Minimum printf which handles only characters, %d's and %s's */
+void _dl_fprintf(int fd, const char *fmt, ...)
+{
+ int num;
+ va_list args;
+ char *start, *ptr, *string;
+ char buf[2048];
+
+ start = ptr = buf;
+
+ if (!fmt)
+ return;
+
+ if (_dl_strlen(fmt) >= (sizeof(buf)-1))
+ _dl_write(fd, "(overflow)\n", 10);
+
+ _dl_strcpy(buf, fmt);
+ va_start(args, fmt);
+
+ while(start)
+ {
+ while(*ptr != '%' && *ptr) {
+ ptr++;
+ }
+
+ if(*ptr == '%')
+ {
+ *ptr++ = '\0';
+ _dl_write(fd, start, _dl_strlen(start));
+
+ switch(*ptr++)
+ {
+ case 's':
+ string = va_arg(args, char *);
+ if (!string)
+ _dl_write(fd, "(null)", 6);
+ else
+ _dl_write(fd, string, _dl_strlen(string));
+ break;
+
+ case 'i':
+ case 'd':
+ {
+ char tmp[13];
+ num = va_arg(args, int);
+ string = _dl_simple_ltoa_inline(tmp, num);
+ _dl_write(fd, string, _dl_strlen(string));
+ break;
+ }
+ case 'x':
+ case 'X':
+ {
+ char tmp[13];
+ num = va_arg(args, int);
+ string = _dl_simple_ltoahex_inline(tmp, num);
+ _dl_write(fd, string, _dl_strlen(string));
+ break;
+ }
+ default:
+ _dl_write(fd, "(null)", 6);
+ break;
+ }
+
+ start = ptr;
+ }
+ else
+ {
+ _dl_write(fd, start, _dl_strlen(start));
+ start = NULL;
+ }
+ }
+ return;
+}
+
diff --git a/ldso/ldso/ld_hash.h b/ldso/ldso/ld_hash.h
index 1ee32672b..9cd2894f8 100644
--- a/ldso/ldso/ld_hash.h
+++ b/ldso/ldso/ld_hash.h
@@ -71,44 +71,8 @@ extern char * _dl_find_hash(char * name, struct dyn_elf * rpnt1,
int copyrel);
extern int _dl_linux_dynamic_link(void);
-#if defined mc68000 || defined __arm__
-/* On some arches constant strings are referenced through the GOT. */
-/* XXX Requires load_addr to be defined. */
-#define SEND_STDERR(X) \
- { const char *__s = (X); \
- if (__s < (const char *) load_addr) __s += load_addr; \
- _dl_write (2, __s, _dl_strlen_inline (__s)); \
- }
-#else
-#define SEND_STDERR(X) _dl_write(2, X, _dl_strlen_inline(X));
-#endif
-
-#define SEND_ADDRESS_STDERR(X, add_a_newline) { \
- char tmp[13], *tmp1; \
- _dl_memset_inline(tmp, 0, sizeof(tmp)); \
- tmp1=_dl_simple_ltoahex_inline( tmp, (unsigned long)(X)); \
- _dl_write(2, tmp1, _dl_strlen_inline(tmp1)); \
- if (add_a_newline) { \
- tmp[0]='\n'; \
- _dl_write(2, tmp, 1); \
- } \
-};
-
-#define SEND_NUMBER_STDERR(X, add_a_newline) { \
- char tmp[13], *tmp1; \
- _dl_memset_inline(tmp, 0, sizeof(tmp)); \
- tmp1=_dl_simple_ltoahex_inline( tmp, (unsigned long)(X)); \
- _dl_write(2, tmp1, _dl_strlen_inline(tmp1)); \
- if (add_a_newline) { \
- tmp[0]='\n'; \
- _dl_write(2, tmp, 1); \
- } \
-};
-
-extern int _dl_fdprintf(int, const char *, ...);
extern char * _dl_library_path;
extern char * _dl_not_lazy;
-extern char * _dl_strdup(const char *);
extern unsigned long _dl_elf_hash(const char * name);
static inline int _dl_symbol(char * name)
diff --git a/ldso/ldso/ld_string.h b/ldso/ldso/ld_string.h
index 46de5320f..caa47aa60 100644
--- a/ldso/ldso/ld_string.h
+++ b/ldso/ldso/ld_string.h
@@ -17,6 +17,7 @@ extern char *_dl_strrchr(const char *str, int c);
extern void * _dl_memcpy(void * dst, const void * src, size_t len);
extern int _dl_memcmp(const void * s1,const void * s2,size_t len);
extern void * _dl_memset(void * str,int c,size_t len);
+extern void _dl_fprintf(int, const char *, ...);
#ifndef NULL
#define NULL ((void *) 0)
@@ -200,4 +201,40 @@ static inline char *_dl_simple_ltoahex_inline(char * local, unsigned long i)
return p + 1;
}
+
+#if defined mc68000 || defined __arm__
+/* On some arches constant strings are referenced through the GOT. */
+/* XXX Requires load_addr to be defined. */
+#define SEND_STDERR(X) \
+ { const char *__s = (X); \
+ if (__s < (const char *) load_addr) __s += load_addr; \
+ _dl_write (2, __s, _dl_strlen_inline (__s)); \
+ }
+#else
+#define SEND_STDERR(X) _dl_write(2, X, _dl_strlen_inline(X));
+#endif
+
+#define SEND_ADDRESS_STDERR(X, add_a_newline) { \
+ char tmp[13], *tmp1; \
+ _dl_memset_inline(tmp, 0, sizeof(tmp)); \
+ tmp1=_dl_simple_ltoahex_inline( tmp, (unsigned long)(X)); \
+ _dl_write(2, tmp1, _dl_strlen_inline(tmp1)); \
+ if (add_a_newline) { \
+ tmp[0]='\n'; \
+ _dl_write(2, tmp, 1); \
+ } \
+};
+
+#define SEND_NUMBER_STDERR(X, add_a_newline) { \
+ char tmp[13], *tmp1; \
+ _dl_memset_inline(tmp, 0, sizeof(tmp)); \
+ tmp1=_dl_simple_ltoahex_inline( tmp, (unsigned long)(X)); \
+ _dl_write(2, tmp1, _dl_strlen_inline(tmp1)); \
+ if (add_a_newline) { \
+ tmp[0]='\n'; \
+ _dl_write(2, tmp, 1); \
+ } \
+};
+
+
#endif
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
index 920779dcd..2824fa4e2 100644
--- a/ldso/ldso/ldso.c
+++ b/ldso/ldso/ldso.c
@@ -121,8 +121,9 @@ char *_dl_preload = 0; /* Things to be loaded before the libs. */
#include "ld.so.h" /* Pull in the name of ld.so */
const char *_dl_progname=_dl_static_progname;
static char *_dl_not_lazy = 0;
-static char *_dl_warn = 0; /* Used by ldd */
+#ifdef DL_TRACE
static char *_dl_trace_loaded_objects = 0;
+#endif
static int (*_dl_elf_main) (int, char **, char **);
static int (*_dl_elf_init) (void);
void *(*_dl_malloc_function) (int size) = NULL;
@@ -213,7 +214,7 @@ DL_BOOT(unsigned long args)
aux_dat += 2;
}
- /* locate the ELF header. We need this done as easly as possible
+ /* locate the ELF header. We need this done as soon as possible
* (esp since SEND_STDERR() needs this on some platforms... */
load_addr = auxv_t[AT_BASE].a_un.a_val;
header = (elfhdr *) auxv_t[AT_BASE].a_un.a_ptr;
@@ -593,8 +594,9 @@ found_got:
}
}
+#ifdef DL_TRACE
_dl_trace_loaded_objects = _dl_getenv("LD_TRACE_LOADED_OBJECTS", envp);
-
+#endif
/* OK, we now have the application in the list, and we have some
basic stuff in place. Now search through the list for other shared
libraries that should be loaded, and insert them on the list in the
@@ -627,22 +629,28 @@ found_got:
{
tpnt1 = _dl_load_shared_library(_dl_secure, NULL, str);
if (!tpnt1) {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects)
- _dl_fdprintf(1, "\t%s => not found\n", str);
+ _dl_fprintf(1, "\t%s => not found\n", str);
else {
- _dl_fdprintf(2, "%s: can't load "
+#endif
+ _dl_fprintf(2, "%s: can't load "
"library '%s'\n", _dl_progname, str);
_dl_exit(15);
+#ifdef DL_TRACE
}
+#endif
} else {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects
&& !tpnt1->usage_count) {
/* this is a real hack to make ldd not print
* the library itself when run on a library. */
if (_dl_strcmp(_dl_progname, str) != 0)
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n", str, tpnt1->libname,
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n", str, tpnt1->libname,
(unsigned) tpnt1->loadaddr);
}
+#endif
rpnt->next = (struct dyn_elf *)
_dl_malloc(sizeof(struct dyn_elf));
_dl_memset(rpnt->next, 0, sizeof(*(rpnt->next)));
@@ -667,14 +675,14 @@ found_got:
if (!_dl_stat(LDSO_PRELOAD, &st)) {
if ((fd = _dl_open(LDSO_PRELOAD, O_RDONLY)) < 0) {
- _dl_fdprintf(2, "%s: can't open file '%s'\n",
+ _dl_fprintf(2, "%s: can't open file '%s'\n",
_dl_progname, LDSO_PRELOAD);
} else {
preload = (caddr_t) _dl_mmap(0, st.st_size + 1,
PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
_dl_close(fd);
if (preload == (caddr_t) - 1) {
- _dl_fdprintf(2, "%s: can't map file '%s'\n",
+ _dl_fprintf(2, "%s: can't map file '%s'\n",
_dl_progname, LDSO_PRELOAD);
} else {
char c, *cp, *cp2;
@@ -705,19 +713,25 @@ found_got:
tpnt1 = _dl_load_shared_library(0, NULL, cp2);
if (!tpnt1) {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects)
- _dl_fdprintf(1, "\t%s => not found\n", cp2);
+ _dl_fprintf(1, "\t%s => not found\n", cp2);
else {
- _dl_fdprintf(2, "%s: can't load library '%s'\n",
+#endif
+ _dl_fprintf(2, "%s: can't load library '%s'\n",
_dl_progname, cp2);
_dl_exit(15);
- }
+#ifdef DL_TRACE
+ }
+#endif
} else {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects
&& !tpnt1->usage_count) {
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n", cp2,
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n", cp2,
tpnt1->libname, (unsigned) tpnt1->loadaddr);
}
+#endif
rpnt->next = (struct dyn_elf *)
_dl_malloc(sizeof(struct dyn_elf));
_dl_memset(rpnt->next, 0,
@@ -751,10 +765,12 @@ found_got:
_dl_get_last_path_component(tpnt->libname)) == 0) {
struct elf_resolve *ttmp;
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects && !tpnt->usage_count) {
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n",
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n",
lpnt, tpnt->libname, (unsigned) tpnt->loadaddr);
}
+#endif
ttmp = _dl_loaded_modules;
while (ttmp->next)
ttmp = ttmp->next;
@@ -772,17 +788,23 @@ found_got:
continue;
}
if (!(tpnt1 = _dl_load_shared_library(0, tcurr, lpnt))) {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects)
- _dl_fdprintf(1, "\t%s => not found\n", lpnt);
+ _dl_fprintf(1, "\t%s => not found\n", lpnt);
else {
- _dl_fdprintf(2, "%s: can't load library '%s'\n",
+#endif
+ _dl_fprintf(2, "%s: can't load library '%s'\n",
_dl_progname, lpnt);
_dl_exit(16);
+#ifdef DL_TRACE
}
+#endif
} else {
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects && !tpnt1->usage_count)
- _dl_fdprintf(1, "\t%s => %s (0x%x)\n", lpnt, tpnt1->libname,
+ _dl_fprintf(1, "\t%s => %s (0x%x)\n", lpnt, tpnt1->libname,
(unsigned) tpnt1->loadaddr);
+#endif
rpnt->next = (struct dyn_elf *)
_dl_malloc(sizeof(struct dyn_elf));
_dl_memset(rpnt->next, 0, sizeof(*(rpnt->next)));
@@ -801,11 +823,14 @@ found_got:
_dl_unmap_cache();
#endif
/* ldd uses uses this. I am not sure how you pick up the other flags */
+#ifdef DL_TRACE
if (_dl_trace_loaded_objects) {
+ char *_dl_warn = 0;
_dl_warn = _dl_getenv("LD_WARN", envp);
if (!_dl_warn)
_dl_exit(0);
}
+#endif
/*
* If the program interpreter is not in the module chain, add it. This will
@@ -855,8 +880,10 @@ found_got:
if (_dl_symbol_tables)
goof += _dl_copy_fixups(_dl_symbol_tables);
+#ifdef DL_TRACE
if (goof || _dl_trace_loaded_objects)
_dl_exit(0);
+#endif
/* OK, at this point things are pretty much ready to run. Now we
need to touch up a few items that are required, and then
@@ -929,13 +956,13 @@ found_got:
#undef DL_DEBUG
#ifdef DL_DEBUG
else {
- _dl_fdprintf(2, tpnt->libname);
- _dl_fdprintf(2, ": ");
+ _dl_fprintf(2, tpnt->libname);
+ _dl_fprintf(2, ": ");
if (!_dl_atexit)
- _dl_fdprintf(2, "The address is atexit () is 0x0.");
+ _dl_fprintf(2, "The address is atexit () is 0x0.");
if (!tpnt->dynamic_info[DT_FINI])
- _dl_fdprintf(2, "Invalid .fini section.");
- _dl_fdprintf(2, "\n");
+ _dl_fprintf(2, "Invalid .fini section.");
+ _dl_fprintf(2, "\n");
}
#endif
#undef DL_DEBUG
@@ -970,7 +997,7 @@ int _dl_fixup(struct elf_resolve *tpnt)
goof += _dl_fixup(tpnt->next);
if (tpnt->dynamic_info[DT_REL]) {
#ifdef ELF_USES_RELOCA
- _dl_fdprintf(2, "%s: can't handle REL relocation records\n",
+ _dl_fprintf(2, "%s: can't handle REL relocation records\n",
_dl_progname);
_dl_exit(17);
#else
@@ -989,7 +1016,7 @@ int _dl_fixup(struct elf_resolve *tpnt)
goof += _dl_parse_relocation_information(tpnt,
tpnt->dynamic_info[DT_RELA], tpnt->dynamic_info[DT_RELASZ], 0);
#else
- _dl_fdprintf(2, "%s: can't handle RELA relocation records\n",
+ _dl_fprintf(2, "%s: can't handle RELA relocation records\n",
_dl_progname);
_dl_exit(18);
#endif
@@ -1028,7 +1055,7 @@ void *_dl_malloc(int size)
_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: mmap of a spare page failed!\n", _dl_progname);
+ _dl_fprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname);
_dl_exit(20);
}
}
@@ -1207,3 +1234,77 @@ void * _dl_memset(void * str,int c,size_t len)
return str;
}
+/* Minimum printf which handles only characters, %d's and %s's */
+void _dl_fprintf(int fd, const char *fmt, ...)
+{
+ int num;
+ va_list args;
+ char *start, *ptr, *string;
+ char buf[2048];
+
+ start = ptr = buf;
+
+ if (!fmt)
+ return;
+
+ if (_dl_strlen(fmt) >= (sizeof(buf)-1))
+ _dl_write(fd, "(overflow)\n", 10);
+
+ _dl_strcpy(buf, fmt);
+ va_start(args, fmt);
+
+ while(start)
+ {
+ while(*ptr != '%' && *ptr) {
+ ptr++;
+ }
+
+ if(*ptr == '%')
+ {
+ *ptr++ = '\0';
+ _dl_write(fd, start, _dl_strlen(start));
+
+ switch(*ptr++)
+ {
+ case 's':
+ string = va_arg(args, char *);
+ if (!string)
+ _dl_write(fd, "(null)", 6);
+ else
+ _dl_write(fd, string, _dl_strlen(string));
+ break;
+
+ case 'i':
+ case 'd':
+ {
+ char tmp[13];
+ num = va_arg(args, int);
+ string = _dl_simple_ltoa_inline(tmp, num);
+ _dl_write(fd, string, _dl_strlen(string));
+ break;
+ }
+ case 'x':
+ case 'X':
+ {
+ char tmp[13];
+ num = va_arg(args, int);
+ string = _dl_simple_ltoahex_inline(tmp, num);
+ _dl_write(fd, string, _dl_strlen(string));
+ break;
+ }
+ default:
+ _dl_write(fd, "(null)", 6);
+ break;
+ }
+
+ start = ptr;
+ }
+ else
+ {
+ _dl_write(fd, start, _dl_strlen(start));
+ start = NULL;
+ }
+ }
+ return;
+}
+
diff --git a/ldso/ldso/m68k/elfinterp.c b/ldso/ldso/m68k/elfinterp.c
index 2b8566d88..07a4599e9 100644
--- a/ldso/ldso/m68k/elfinterp.c
+++ b/ldso/ldso/m68k/elfinterp.c
@@ -83,7 +83,7 @@ _dl_linux_resolver (int dummy1, int dummy2,
if (reloc_type != R_68K_JMP_SLOT)
{
- _dl_fdprintf (2, "%s: incorrect relocation type in jump relocations\n",
+ _dl_fprintf (2, "%s: incorrect relocation type in jump relocations\n",
_dl_progname);
_dl_exit (1);
}
@@ -93,7 +93,7 @@ _dl_linux_resolver (int dummy1, int dummy2,
got_addr = (char **) instr_addr;
#ifdef DEBUG
- _dl_fdprintf (2, "Resolving symbol %s\n",
+ _dl_fprintf (2, "Resolving symbol %s\n",
strtab + symtab[symtab_index].st_name);
#endif
@@ -102,14 +102,14 @@ _dl_linux_resolver (int dummy1, int dummy2,
tpnt->symbol_scope, (int) got_addr, tpnt, 0);
if (!new_addr)
{
- _dl_fdprintf (2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf (2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
_dl_exit (1);
}
/* #define DEBUG_LIBRARY */
#ifdef DEBUG_LIBRARY
if ((unsigned int) got_addr < 0x40000000)
- _dl_fdprintf (2, "Calling library function: %s\n",
+ _dl_fprintf (2, "Calling library function: %s\n",
strtab + symtab[symtab_index].st_name);
else
#endif
@@ -158,13 +158,13 @@ _dl_parse_lazy_relocation_information (struct elf_resolve *tpnt,
*reloc_addr += (unsigned int) tpnt->loadaddr;
break;
default:
- _dl_fdprintf (2, "%s: (LAZY) can't handle reloc type ", _dl_progname);
+ _dl_fprintf (2, "%s: (LAZY) can't handle reloc type ", _dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf (2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf (2, "%s ", _dl_reltypes[reloc_type]);
#endif
if (symtab_index)
- _dl_fdprintf (2, "'%s'", strtab + symtab[symtab_index].st_name);
- _dl_fdprintf (2, "\n");
+ _dl_fprintf (2, "'%s'", strtab + symtab[symtab_index].st_name);
+ _dl_fprintf (2, "\n");
_dl_exit (1);
}
}
@@ -218,7 +218,7 @@ _dl_parse_relocation_information (struct elf_resolve *tpnt,
if (!symbol_addr
&& ELF32_ST_BIND (symtab[symtab_index].st_info) == STB_GLOBAL)
{
- _dl_fdprintf (2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf (2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
}
@@ -259,24 +259,24 @@ _dl_parse_relocation_information (struct elf_resolve *tpnt,
break;
case R_68K_COPY:
#if 0 /* Do this later. */
- _dl_fdprintf (2, "Doing copy");
+ _dl_fprintf (2, "Doing copy");
if (symtab_index)
- _dl_fdprintf (2, " for symbol %s",
+ _dl_fprintf (2, " for symbol %s",
strtab + symtab[symtab_index].st_name);
- _dl_fdprintf (2, "\n");
+ _dl_fprintf (2, "\n");
_dl_memcpy ((void *) symtab[symtab_index].st_value,
(void *) symbol_addr,
symtab[symtab_index].st_size);
#endif
break;
default:
- _dl_fdprintf (2, "%s: can't handle reloc type ", _dl_progname);
+ _dl_fprintf (2, "%s: can't handle reloc type ", _dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf (2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf (2, "%s ", _dl_reltypes[reloc_type]);
#endif
if (symtab_index)
- _dl_fdprintf (2, "'%s'", strtab + symtab[symtab_index].st_name);
- _dl_fdprintf (2, "\n");
+ _dl_fprintf (2, "'%s'", strtab + symtab[symtab_index].st_name);
+ _dl_fprintf (2, "\n");
_dl_exit (1);
}
@@ -337,7 +337,7 @@ _dl_parse_copy_information (struct dyn_elf *xpnt, unsigned long rel_addr,
xpnt->next, (int) reloc_addr, NULL, 1);
if (!symbol_addr)
{
- _dl_fdprintf (2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf (2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
}
diff --git a/ldso/ldso/powerpc/elfinterp.c b/ldso/ldso/powerpc/elfinterp.c
index 5fedaa267..31b97044a 100644
--- a/ldso/ldso/powerpc/elfinterp.c
+++ b/ldso/ldso/powerpc/elfinterp.c
@@ -71,16 +71,16 @@ void _dl_init_got(unsigned long *plt,struct elf_resolve *tpnt)
unsigned int rel_offset_words;
unsigned int offset;
- _dl_fdprintf(2,"init_got plt=%08lx, tpnt=%08lx\n",
+ _dl_fprintf(2,"init_got plt=%x, tpnt=%x\n",
(unsigned long)plt,(unsigned long)tpnt);
n_plt_entries = tpnt->dynamic_info[DT_PLTRELSZ] / sizeof(ELF_RELOC);
-_dl_fdprintf(2,"n_plt_entries %d\n",n_plt_entries);
+_dl_fprintf(2,"n_plt_entries %d\n",n_plt_entries);
rel_offset_words = PLT_DATA_START_WORDS(n_plt_entries);
-_dl_fdprintf(2,"rel_offset_words %08x\n",rel_offset_words);
+_dl_fprintf(2,"rel_offset_words %x\n",rel_offset_words);
data_words = (unsigned long)(plt + rel_offset_words);
-_dl_fdprintf(2,"data_words %08x\n",data_words);
+_dl_fprintf(2,"data_words %x\n",data_words);
//lpnt += PLT_INITIAL_ENTRY_WORDS;
@@ -124,7 +124,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
char **got_addr;
unsigned long instr_addr;
-_dl_fdprintf(2,"linux_resolver tpnt=%08x reloc_entry=%08x\n",tpnt,reloc_entry);
+_dl_fprintf(2,"linux_resolver tpnt=%x reloc_entry=%x\n",tpnt,reloc_entry);
rel_addr = (ELF_RELOC *) (tpnt->dynamic_info[DT_JMPREL] + tpnt->loadaddr);
this_reloc = (void *)rel_addr + reloc_entry;
@@ -136,7 +136,7 @@ _dl_fdprintf(2,"linux_resolver tpnt=%08x reloc_entry=%08x\n",tpnt,reloc_entry);
if (reloc_type != R_PPC_JMP_SLOT) {
- _dl_fdprintf(2, "%s: Incorrect relocation type [%s] in jump relocations\n",
+ _dl_fprintf(2, "%s: Incorrect relocation type [%s] in jump relocations\n",
_dl_progname,
(reloc_type<N_RELTYPES)?_dl_reltypes[reloc_type]:"unknown");
_dl_exit(1);
@@ -148,7 +148,7 @@ _dl_fdprintf(2,"linux_resolver tpnt=%08x reloc_entry=%08x\n",tpnt,reloc_entry);
got_addr = (char **) instr_addr;
#ifdef DEBUG
- _dl_fdprintf(2, "Resolving symbol %s %08x --> ",
+ _dl_fprintf(2, "Resolving symbol %s %x --> ",
strtab + symtab[symtab_index].st_name,
instr_addr);
#endif
@@ -157,18 +157,18 @@ _dl_fdprintf(2,"linux_resolver tpnt=%08x reloc_entry=%08x\n",tpnt,reloc_entry);
new_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name,
tpnt->symbol_scope, (unsigned long) got_addr, tpnt, 0);
if (!new_addr) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
_dl_exit(1);
};
#ifdef DEBUG
- _dl_fdprintf(2, "%08x\n", new_addr);
+ _dl_fprintf(2, "%x\n", new_addr);
#endif
/* #define DEBUG_LIBRARY */
#ifdef DEBUG_LIBRARY
if ((unsigned long) got_addr < 0x40000000) {
- _dl_fdprintf(2, "Calling library function: %s\n",
+ _dl_fprintf(2, "Calling library function: %s\n",
strtab + symtab[symtab_index].st_name);
} else {
*got_addr = new_addr;
@@ -193,7 +193,7 @@ void _dl_parse_lazy_relocation_information(struct elf_resolve *tpnt,
int index;
#ifdef DEBUG
-_dl_fdprintf(2,"_dl_parse_lazy_relocation_information(tpnt=%08x, rel_addr=%08x, rel_size=%08x, type=%d)\n",
+_dl_fprintf(2,"_dl_parse_lazy_relocation_information(tpnt=%x, rel_addr=%x, rel_size=%x, type=%d)\n",
tpnt,rel_addr,rel_size,type);
#endif
/* Now parse the relocation information */
@@ -219,7 +219,7 @@ _dl_fdprintf(2,"_dl_parse_lazy_relocation_information(tpnt=%08x, rel_addr=%08x,
continue;
#ifdef DEBUG
-_dl_fdprintf(2, "L %08x %-16s %-20s %08x %08x\n",
+_dl_fprintf(2, "L %x %s %s %x %x\n",
reloc_addr, _dl_reltypes[reloc_type],
symtab_index?strtab + symtab[symtab_index].st_name:"",0,0);
#endif
@@ -240,20 +240,20 @@ _dl_fdprintf(2, "L %08x %-16s %-20s %08x %08x\n",
/sizeof(unsigned long);
index /= 2;
#ifdef DEBUG
-_dl_fdprintf(2, " index %08x delta %08x\n",index,delta);
+_dl_fprintf(2, " index %x delta %x\n",index,delta);
#endif
reloc_addr[0] = OPCODE_LI(11,index*4);
reloc_addr[1] = OPCODE_B(delta);
break;
}
default:
- _dl_fdprintf(2, "%s: (LAZY) can't handle reloc type ",
+ _dl_fprintf(2, "%s: (LAZY) can't handle reloc type ",
_dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf(2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf(2, "%s ", _dl_reltypes[reloc_type]);
#endif
if (symtab_index)
- _dl_fdprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
_dl_exit(1);
};
@@ -280,7 +280,7 @@ int _dl_parse_relocation_information(struct elf_resolve *tpnt,
unsigned long *plt;
#ifdef DEBUG
-_dl_fdprintf(2,"_dl_parse_relocation_information(tpnt=%08x, rel_addr=%08x, rel_size=%08x, type=%d)\n",
+_dl_fprintf(2,"_dl_parse_relocation_information(tpnt=%x, rel_addr=%x, rel_size=%x, type=%d)\n",
tpnt,rel_addr,rel_size,type);
#endif
/* Now parse the relocation information */
@@ -319,13 +319,13 @@ _dl_fdprintf(2,"_dl_parse_relocation_information(tpnt=%08x, rel_addr=%08x, rel_s
*/
if (!symbol_addr &&
ELF32_ST_BIND(symtab[symtab_index].st_info) == STB_GLOBAL) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
}
}
#ifdef DEBUG
-_dl_fdprintf(2, " %08x %-16s %-20s %08x %08x\n",
+_dl_fprintf(2, " %x %s %s %x %x\n",
reloc_addr, _dl_reltypes[reloc_type],
symtab_index?strtab + symtab[symtab_index].st_name:"",
symbol_addr, addend);
@@ -337,7 +337,7 @@ _dl_fdprintf(2, " %08x %-16s %-20s %08x %08x\n",
{
int delta = symbol_addr - (unsigned long)reloc_addr;
if(delta<<6>>6 != delta){
- _dl_fdprintf(2,"R_PPC_REL24: Reloc out of range\n");
+ _dl_fprintf(2,"R_PPC_REL24: Reloc out of range\n");
_dl_exit(1);
}
*reloc_addr &= 0xfc000003;
@@ -381,7 +381,7 @@ _dl_fdprintf(2, " %08x %-16s %-20s %08x %08x\n",
/sizeof(unsigned long);
index /= 2;
#ifdef DEBUG
-_dl_fdprintf(2, " index %08x delta %08x\n",index,delta);
+_dl_fprintf(2, " index %x delta %x\n",index,delta);
#endif
reloc_addr[0] = OPCODE_LI(11,index*4);
reloc_addr[1] = OPCODE_B(delta);
@@ -390,12 +390,12 @@ _dl_fdprintf(2, " index %08x delta %08x\n",index,delta);
break;
}
default:
- _dl_fdprintf(2, "%s: can't handle reloc type ", _dl_progname);
+ _dl_fprintf(2, "%s: can't handle reloc type ", _dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf(2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf(2, "%s ", _dl_reltypes[reloc_type]);
#endif
if (symtab_index)
- _dl_fdprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
_dl_exit(1);
};
@@ -404,7 +404,7 @@ _dl_fdprintf(2, " index %08x delta %08x\n",index,delta);
PPC_SYNC;
PPC_ICBI(reloc_addr);
-//_dl_fdprintf(2,"reloc_addr %08x: %08x\n",reloc_addr,*reloc_addr);
+//_dl_fprintf(2,"reloc_addr %x: %x\n",reloc_addr,*reloc_addr);
};
return goof;
}
@@ -433,7 +433,7 @@ int _dl_parse_copy_information(struct dyn_elf *xpnt, unsigned long rel_addr,
struct elf_resolve *tpnt;
int symtab_index;
-_dl_fdprintf(2,"parse_copy xpnt=%08x rel_addr=%08x rel_size=%08x type=%d\n",
+_dl_fprintf(2,"parse_copy xpnt=%x rel_addr=%x rel_size=%x type=%d\n",
(int)xpnt,rel_addr,rel_size,type);
/* Now parse the relocation information */
@@ -465,7 +465,7 @@ _dl_fdprintf(2,"parse_copy xpnt=%08x rel_addr=%08x rel_size=%08x type=%d\n",
symtab[symtab_index].st_name, xpnt->next,
(unsigned long) reloc_addr, NULL, 1);
if (!symbol_addr) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
};
diff --git a/ldso/ldso/readelflib1.c b/ldso/ldso/readelflib1.c
index 4e1de140e..2276d4a9f 100644
--- a/ldso/ldso/readelflib1.c
+++ b/ldso/ldso/readelflib1.c
@@ -54,7 +54,7 @@ int _dl_map_cache(void)
if (_dl_stat(LDSO_CACHE, &st)
|| (fd = _dl_open(LDSO_CACHE, O_RDONLY)) < 0) {
- _dl_fdprintf(2, "%s: can't open cache '%s'\n", _dl_progname, LDSO_CACHE);
+ _dl_fprintf(2, "%s: can't open cache '%s'\n", _dl_progname, LDSO_CACHE);
_dl_cache_addr = (caddr_t) - 1; /* so we won't try again */
return -1;
}
@@ -63,7 +63,7 @@ int _dl_map_cache(void)
_dl_cache_addr = (caddr_t) _dl_mmap(0, _dl_cache_size, PROT_READ, MAP_SHARED, fd, 0);
_dl_close(fd);
if (_dl_cache_addr == (caddr_t) - 1) {
- _dl_fdprintf(2, "%s: can't map cache '%s'\n",
+ _dl_fprintf(2, "%s: can't map cache '%s'\n",
_dl_progname, LDSO_CACHE);
return -1;
}
@@ -77,7 +77,7 @@ int _dl_map_cache(void)
(sizeof(header_t) + header->nlibs * sizeof(libentry_t))
|| _dl_cache_addr[_dl_cache_size - 1] != '\0')
{
- _dl_fdprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname,
+ _dl_fprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname,
LDSO_CACHE);
goto fail;
}
@@ -90,7 +90,7 @@ int _dl_map_cache(void)
if (libent[i].sooffset >= strtabsize ||
libent[i].liboffset >= strtabsize)
{
- _dl_fdprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname, LDSO_CACHE);
+ _dl_fprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname, LDSO_CACHE);
goto fail;
}
}
@@ -348,7 +348,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
* NO! When we open shared libraries we may search several paths.
* it is inappropriate to generate an error here.
*/
- _dl_fdprintf(2, "%s: can't open '%s'\n", _dl_progname, libname);
+ _dl_fprintf(2, "%s: can't open '%s'\n", _dl_progname, libname);
#endif
_dl_internal_error_number = DL_ERROR_NOFILE;
return NULL;
@@ -361,7 +361,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
epnt->e_ident[2] != 'L' ||
epnt->e_ident[3] != 'F')
{
- _dl_fdprintf(2, "%s: '%s' is not an ELF file\n", _dl_progname,
+ _dl_fprintf(2, "%s: '%s' is not an ELF file\n", _dl_progname,
libname);
_dl_internal_error_number = DL_ERROR_NOTELF;
_dl_close(infile);
@@ -376,7 +376,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
{
_dl_internal_error_number =
(epnt->e_type != ET_DYN ? DL_ERROR_NOTDYN : DL_ERROR_NOTMAGIC);
- _dl_fdprintf(2, "%s: '%s' is not an ELF executable for " ELF_TARGET
+ _dl_fprintf(2, "%s: '%s' is not an ELF executable for " ELF_TARGET
"\n", _dl_progname, libname);
_dl_close(infile);
return NULL;
@@ -389,7 +389,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
if (ppnt->p_type == PT_DYNAMIC) {
if (dynamic_addr)
- _dl_fdprintf(2, "%s: '%s' has more than one dynamic section\n",
+ _dl_fprintf(2, "%s: '%s' has more than one dynamic section\n",
_dl_progname, libname);
dynamic_addr = ppnt->p_vaddr;
dynamic_size = ppnt->p_filesz;
@@ -421,7 +421,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
status = (char *) _dl_mmap((char *) (piclib ? 0 : minvma),
maxvma - minvma, PROT_NONE, flags | MAP_ANONYMOUS, -1, 0);
if (_dl_mmap_check_error(status)) {
- _dl_fdprintf(2, "%s: can't map '/dev/zero'\n", _dl_progname);
+ _dl_fprintf(2, "%s: can't map '/dev/zero'\n", _dl_progname);
_dl_internal_error_number = DL_ERROR_MMAP_FAILED;
_dl_close(infile);
return NULL;
@@ -453,7 +453,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
ppnt->p_offset & 0x7ffff000);
if (_dl_mmap_check_error(status)) {
- _dl_fdprintf(2, "%s: can't map '%s'\n",
+ _dl_fprintf(2, "%s: can't map '%s'\n",
_dl_progname, libname);
_dl_internal_error_number = DL_ERROR_MMAP_FAILED;
_dl_munmap((char *) libaddr, maxvma - minvma);
@@ -485,7 +485,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
ppnt->p_filesz, LXFLAGS(ppnt->p_flags), flags,
infile, ppnt->p_offset & 0x7ffff000);
if (_dl_mmap_check_error(status)) {
- _dl_fdprintf(2, "%s: can't map '%s'\n", _dl_progname, libname);
+ _dl_fprintf(2, "%s: can't map '%s'\n", _dl_progname, libname);
_dl_internal_error_number = DL_ERROR_MMAP_FAILED;
_dl_munmap((char *) libaddr, maxvma - minvma);
_dl_close(infile);
@@ -515,7 +515,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
if (!dynamic_addr) {
_dl_internal_error_number = DL_ERROR_NODYNAMIC;
- _dl_fdprintf(2, "%s: '%s' is missing a dynamic section\n",
+ _dl_fprintf(2, "%s: '%s' is missing a dynamic section\n",
_dl_progname, libname);
return NULL;
}
diff --git a/ldso/ldso/sparc/elfinterp.c b/ldso/ldso/sparc/elfinterp.c
index c69ef86f0..1b011abe2 100644
--- a/ldso/ldso/sparc/elfinterp.c
+++ b/ldso/ldso/sparc/elfinterp.c
@@ -82,14 +82,14 @@ unsigned int _dl_linux_resolver(unsigned int reloc_entry, unsigned int * plt)
symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr);
strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
- _dl_fdprintf(2, "tpnt = %x\n", tpnt);
- _dl_fdprintf(2, "reloc = %x\n", this_reloc);
- _dl_fdprintf(2, "symtab = %x\n", symtab);
- _dl_fdprintf(2, "strtab = %x\n", strtab);
+ _dl_fprintf(2, "tpnt = %x\n", tpnt);
+ _dl_fprintf(2, "reloc = %x\n", this_reloc);
+ _dl_fprintf(2, "symtab = %x\n", symtab);
+ _dl_fprintf(2, "strtab = %x\n", strtab);
if (reloc_type != R_SPARC_JMP_SLOT) {
- _dl_fdprintf(2, "%s: incorrect relocation type in jump relocations (%d)\n",
+ _dl_fprintf(2, "%s: incorrect relocation type in jump relocations (%d)\n",
_dl_progname, reloc_type);
_dl_exit(30);
};
@@ -98,10 +98,10 @@ unsigned int _dl_linux_resolver(unsigned int reloc_entry, unsigned int * plt)
instr_addr = ((int)this_reloc->r_offset + (int)tpnt->loadaddr);
got_addr = (char **) instr_addr;
- _dl_fdprintf(2, "symtab_index %d\n", symtab_index);
+ _dl_fprintf(2, "symtab_index %d\n", symtab_index);
#ifdef DEBUG
- _dl_fdprintf(2, "Resolving symbol %s\n",
+ _dl_fprintf(2, "Resolving symbol %s\n",
strtab + symtab[symtab_index].st_name);
#endif
@@ -109,14 +109,14 @@ unsigned int _dl_linux_resolver(unsigned int reloc_entry, unsigned int * plt)
new_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name,
tpnt->symbol_scope, (int) got_addr, tpnt, 0);
if(!new_addr) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
_dl_exit(31);
};
/* #define DEBUG_LIBRARY */
#ifdef DEBUG_LIBRARY
if((unsigned int) got_addr < 0x40000000) {
- _dl_fdprintf(2, "Calling library function: %s\n",
+ _dl_fprintf(2, "Calling library function: %s\n",
strtab + symtab[symtab_index].st_name);
} else {
got_addr[1] = (char *) (0x03000000 | (((unsigned int) new_addr >> 10) & 0x3fffff));
@@ -126,7 +126,7 @@ unsigned int _dl_linux_resolver(unsigned int reloc_entry, unsigned int * plt)
got_addr[1] = (char *) (0x03000000 | (((unsigned int) new_addr >> 10) & 0x3fffff));
got_addr[2] = (char *) (0x81c06000 | ((unsigned int) new_addr & 0x3ff));
#endif
- _dl_fdprintf(2, "Address = %x\n",new_addr);
+ _dl_fprintf(2, "Address = %x\n",new_addr);
_dl_exit(32);
return (unsigned int) new_addr;
@@ -166,11 +166,11 @@ void _dl_parse_lazy_relocation_information(struct elf_resolve * tpnt, int rel_ad
case R_SPARC_JMP_SLOT:
break;
default:
- _dl_fdprintf(2, "%s: (LAZY) can't handle reloc type ", _dl_progname);
+ _dl_fprintf(2, "%s: (LAZY) can't handle reloc type ", _dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf(2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf(2, "%s ", _dl_reltypes[reloc_type]);
#endif
- if(symtab_index) _dl_fdprintf(2, "'%s'\n",
+ if(symtab_index) _dl_fprintf(2, "'%s'\n",
strtab + symtab[symtab_index].st_name);
_dl_exit(33);
};
@@ -216,7 +216,7 @@ int _dl_parse_relocation_information(struct elf_resolve * tpnt, int rel_addr,
if(!symbol_addr &&
ELF32_ST_BIND(symtab [symtab_index].st_info) == STB_GLOBAL) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
};
@@ -260,21 +260,21 @@ int _dl_parse_relocation_information(struct elf_resolve * tpnt, int rel_addr,
break;
case R_SPARC_COPY:
#if 0 /* This one is done later */
- _dl_fdprintf(2, "Doing copy for symbol ");
- if(symtab_index) _dl_fdprintf(2, strtab + symtab[symtab_index].st_name);
- _dl_fdprintf(2, "\n");
+ _dl_fprintf(2, "Doing copy for symbol ");
+ if(symtab_index) _dl_fprintf(2, strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "\n");
_dl_memcpy((void *) symtab[symtab_index].st_value,
(void *) symbol_addr,
symtab[symtab_index].st_size);
#endif
break;
default:
- _dl_fdprintf(2, "%s: can't handle reloc type ", _dl_progname);
+ _dl_fprintf(2, "%s: can't handle reloc type ", _dl_progname);
#ifdef VERBOSE_DLINKER
- _dl_fdprintf(2, "%s ", _dl_reltypes[reloc_type]);
+ _dl_fprintf(2, "%s ", _dl_reltypes[reloc_type]);
#endif
if (symtab_index)
- _dl_fdprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
+ _dl_fprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
_dl_exit(34);
};
@@ -331,7 +331,7 @@ int _dl_parse_copy_information(struct dyn_elf * xpnt, int rel_addr,
_dl_find_hash(strtab + symtab[symtab_index].st_name,
xpnt->next, (int) reloc_addr, NULL, 1);
if(!symbol_addr) {
- _dl_fdprintf(2, "%s: can't resolve symbol '%s'\n",
+ _dl_fprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, strtab + symtab[symtab_index].st_name);
goof++;
};
diff --git a/ldso/ldso/string.h b/ldso/ldso/string.h
index 46de5320f..caa47aa60 100644
--- a/ldso/ldso/string.h
+++ b/ldso/ldso/string.h
@@ -17,6 +17,7 @@ extern char *_dl_strrchr(const char *str, int c);
extern void * _dl_memcpy(void * dst, const void * src, size_t len);
extern int _dl_memcmp(const void * s1,const void * s2,size_t len);
extern void * _dl_memset(void * str,int c,size_t len);
+extern void _dl_fprintf(int, const char *, ...);
#ifndef NULL
#define NULL ((void *) 0)
@@ -200,4 +201,40 @@ static inline char *_dl_simple_ltoahex_inline(char * local, unsigned long i)
return p + 1;
}
+
+#if defined mc68000 || defined __arm__
+/* On some arches constant strings are referenced through the GOT. */
+/* XXX Requires load_addr to be defined. */
+#define SEND_STDERR(X) \
+ { const char *__s = (X); \
+ if (__s < (const char *) load_addr) __s += load_addr; \
+ _dl_write (2, __s, _dl_strlen_inline (__s)); \
+ }
+#else
+#define SEND_STDERR(X) _dl_write(2, X, _dl_strlen_inline(X));
+#endif
+
+#define SEND_ADDRESS_STDERR(X, add_a_newline) { \
+ char tmp[13], *tmp1; \
+ _dl_memset_inline(tmp, 0, sizeof(tmp)); \
+ tmp1=_dl_simple_ltoahex_inline( tmp, (unsigned long)(X)); \
+ _dl_write(2, tmp1, _dl_strlen_inline(tmp1)); \
+ if (add_a_newline) { \
+ tmp[0]='\n'; \
+ _dl_write(2, tmp, 1); \
+ } \
+};
+
+#define SEND_NUMBER_STDERR(X, add_a_newline) { \
+ char tmp[13], *tmp1; \
+ _dl_memset_inline(tmp, 0, sizeof(tmp)); \
+ tmp1=_dl_simple_ltoahex_inline( tmp, (unsigned long)(X)); \
+ _dl_write(2, tmp1, _dl_strlen_inline(tmp1)); \
+ if (add_a_newline) { \
+ tmp[0]='\n'; \
+ _dl_write(2, tmp, 1); \
+ } \
+};
+
+
#endif
diff --git a/ldso/ldso/vsprintf.c b/ldso/ldso/vsprintf.c
deleted file mode 100644
index 959c24080..000000000
--- a/ldso/ldso/vsprintf.c
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * vsprintf.c
- *
- * Copyright (C) 1991-1996 Linus Torvalds
- */
-
-/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
-/*
- * Wirzenius wrote this portably, Torvalds fucked it up :-)
- */
-
-#include <stdarg.h>
-#include "string.h"
-#include "hash.h"
-#include "syscall.h"
-
-/* we use this so that we can do without the ctype library */
-#define is_digit(c) ((c) >= '0' && (c) <= '9')
-
-static int skip_atoi(const char **s)
-{
- int i=0;
-
- while (is_digit(**s))
- i = i*10 + *((*s)++) - '0';
- return i;
-}
-
-#define ZEROPAD 1 /* pad with zero */
-#define SIGN 2 /* unsigned/signed long */
-#define PLUS 4 /* show plus */
-#define SPACE 8 /* space if plus */
-#define LEFT 16 /* left justified */
-#define SPECIAL 32 /* 0x */
-#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
-
-#ifndef __sparc__
-#define do_div(n,base) ({ \
-int __res; \
-__res = ((unsigned long) n) % (unsigned) base; \
-n = ((unsigned long) n) / (unsigned) base; \
-__res; })
-#else
-#define do_div(n,base) _dl_div ((n)/(base))
-#define do_div(n,base) ({ \
-int __res; \
-__res = _dl_urem(((unsigned long) n),(unsigned) base); \
-n = _dl_udiv(((unsigned long) n),(unsigned) base); \
-__res; })
-#endif
-
-#define ADD_CHAR(s,n,c) ( ((n) > 1) ? *(s)++ = (c), (n)-- : (c) )
-
-static char * number(char * str, int *bufsize, long num, int base, int size, int precision
- ,int type)
-{
- char c,sign,tmp[66];
- const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
- int i;
-
- if (type & LARGE)
- digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- if (type & LEFT)
- type &= ~ZEROPAD;
- if (base < 2 || base > 36)
- return 0;
- c = (type & ZEROPAD) ? '0' : ' ';
- sign = 0;
- if (type & SIGN) {
- if (num < 0) {
- sign = '-';
- num = -num;
- size--;
- } else if (type & PLUS) {
- sign = '+';
- size--;
- } else if (type & SPACE) {
- sign = ' ';
- size--;
- }
- }
- if (type & SPECIAL) {
- if (base == 16)
- size -= 2;
- else if (base == 8)
- size--;
- }
- i = 0;
- if (num == 0)
- tmp[i++]='0';
- else while (num != 0)
- tmp[i++] = digits[do_div(num,base)];
- if (i > precision)
- precision = i;
- size -= precision;
- if (!(type&(ZEROPAD+LEFT)))
- while(size-->0)
- ADD_CHAR(str, *bufsize, ' ');
- if (sign)
- ADD_CHAR(str, *bufsize, sign);
- if (type & SPECIAL) {
- if (base==8)
- ADD_CHAR(str, *bufsize, '0');
- else if (base==16) {
- ADD_CHAR(str, *bufsize, '0');
- ADD_CHAR(str, *bufsize, digits[33]);
- }
- }
- if (!(type & LEFT))
- while (size-- > 0)
- ADD_CHAR(str, *bufsize, c);
- while (i < precision--)
- ADD_CHAR(str, *bufsize, '0');
- while (i-- > 0)
- ADD_CHAR(str, *bufsize, tmp[i]);
- while (size-- > 0)
- ADD_CHAR(str, *bufsize, ' ');
- return str;
-}
-
-int _dl_fdprintf(int fd, const char *fmt, ...)
-{
- int len;
- unsigned long num;
- int i, base;
- char * str;
- const char *s;
-
- int flags; /* flags to number() */
-
- int field_width; /* width of output field */
- int precision; /* min. # of digits for integers; max
- number of chars for from string */
- int qualifier; /* 'h', 'l', or 'L' for integer fields */
-
- int bufsize;
- char buf[2048];
- va_list(args);
-
- va_start(args, fmt);
-
- for (str=buf, bufsize=sizeof buf ; *fmt ; ++fmt) {
- if (*fmt != '%') {
- ADD_CHAR(str, bufsize, *fmt);
- continue;
- }
-
- /* process flags */
- flags = 0;
- repeat:
- ++fmt; /* this also skips first '%' */
- switch (*fmt) {
- case '-': flags |= LEFT; goto repeat;
- case '+': flags |= PLUS; goto repeat;
- case ' ': flags |= SPACE; goto repeat;
- case '#': flags |= SPECIAL; goto repeat;
- case '0': flags |= ZEROPAD; goto repeat;
- }
-
- /* get field width */
- field_width = -1;
- if (is_digit(*fmt))
- field_width = skip_atoi(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- field_width = va_arg(args, int);
- if (field_width < 0) {
- field_width = -field_width;
- flags |= LEFT;
- }
- }
-
- /* get the precision */
- precision = -1;
- if (*fmt == '.') {
- ++fmt;
- if (is_digit(*fmt))
- precision = skip_atoi(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- precision = va_arg(args, int);
- }
- if (precision < 0)
- precision = 0;
- }
-
- /* get the conversion qualifier */
- qualifier = -1;
- if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
- qualifier = *fmt;
- ++fmt;
- }
-
- /* default base */
- base = 10;
-
- switch (*fmt) {
- case 'c':
- if (!(flags & LEFT))
- while (--field_width > 0)
- ADD_CHAR(str, bufsize, ' ');
- ADD_CHAR(str, bufsize, (unsigned char) va_arg(args, int));
- while (--field_width > 0)
- ADD_CHAR(str, bufsize, ' ');
- continue;
-
- case 's':
- s = va_arg(args, char *);
- if (!s)
- s = "<NULL>";
-
- len = _dl_strlen(s);
-
- if (!(flags & LEFT))
- while (len < field_width--)
- ADD_CHAR(str, bufsize, ' ');
- for (i = 0; i < len; ++i)
- ADD_CHAR(str, bufsize, *s++);
- while (len < field_width--)
- ADD_CHAR(str, bufsize, ' ');
- continue;
-
- case 'p':
- if (field_width == -1) {
- field_width = 2*sizeof(void *);
- flags |= ZEROPAD;
- }
- str = number(str, &bufsize,
- (unsigned long) va_arg(args, void *), 16,
- field_width, precision, flags);
- continue;
-
-
- case 'n':
- if (qualifier == 'l') {
- long * ip = va_arg(args, long *);
- *ip = (str - buf);
- } else {
- int * ip = va_arg(args, int *);
- *ip = (str - buf);
- }
- continue;
-
- /* integer number formats - set up the flags and "break" */
- case 'o':
- base = 8;
- break;
-
- case 'X':
- flags |= LARGE;
- case 'x':
- base = 16;
- break;
-
- case 'd':
- case 'i':
- flags |= SIGN;
- case 'u':
- break;
-
- default:
- if (*fmt != '%')
- ADD_CHAR(str, bufsize, '%');
- if (*fmt)
- ADD_CHAR(str, bufsize, *fmt);
- else
- --fmt;
- continue;
- }
- if (qualifier == 'l')
- num = va_arg(args, unsigned long);
-#ifndef __powerpc__
- else if (qualifier == 'h')
- if (flags & SIGN)
- num = va_arg(args, short);
- else
- num = va_arg(args, unsigned short);
-#endif
- else if (flags & SIGN)
- num = va_arg(args, int);
- else
- num = va_arg(args, unsigned int);
- str = number(str, &bufsize, num, base, field_width, precision, flags);
- }
- *str = '\0';
- _dl_write(fd, buf, str-buf);
- return str-buf;
-}
-