diff options
author | kib <kib@FreeBSD.org> | 2011-08-24 20:05:13 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2011-08-24 20:05:13 +0000 |
commit | 6a7906318730de9b42a49050eb3f9fa3b476812b (patch) | |
tree | cbf9abe0c68b62c518886f500059522babc1525d /libexec/rtld-elf/debug.c | |
parent | a3d2844ed5203016f1e0148e2a87c759bbf01954 (diff) | |
download | FreeBSD-src-6a7906318730de9b42a49050eb3f9fa3b476812b.zip FreeBSD-src-6a7906318730de9b42a49050eb3f9fa3b476812b.tar.gz |
Rtld links with the specially built pic static libc library to get some
C runtime services, like printf(). Unfortunately, the multithread-safeness
measures in the libc do not work in rtld environment.
Rip the kernel printf() implementation and use it in the rtld instead of
libc version. This printf does not require any shared global data and thus
is mt-safe. Systematically use rtld_printf() and related functions, remove
the calls to err(3).
Note that stdio is still pulled from libc due to libmap implementaion using
fopen(). This is safe but unoptimal, and can be changed later.
Reported and tested by: pgj
Diagnosed and reviewed by: kan (previous version)
Approved by: re (bz)
Diffstat (limited to 'libexec/rtld-elf/debug.c')
-rw-r--r-- | libexec/rtld-elf/debug.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/libexec/rtld-elf/debug.c b/libexec/rtld-elf/debug.c index 3b7611c..8f8311c 100644 --- a/libexec/rtld-elf/debug.c +++ b/libexec/rtld-elf/debug.c @@ -34,6 +34,7 @@ #include "debug.h" #include "rtld.h" +#include "rtld_printf.h" static const char rel_header[] = " symbol name r_info r_offset st_value st_size address value\n" @@ -49,9 +50,8 @@ debug_printf(const char *format, ...) va_list ap; va_start(ap, format); - fflush(stdout); - vfprintf(stderr, format, ap); - putc('\n', stderr); + rtld_vfdprintf(STDERR_FILENO, format, ap); + rtld_fdputchar(STDERR_FILENO, '\n'); va_end(ap); } @@ -71,28 +71,28 @@ void dump_obj_relocations (Obj_Entry *obj) { - printf("Object \"%s\", relocbase %p\n", obj->path, obj->relocbase); + rtld_printf("Object \"%s\", relocbase %p\n", obj->path, obj->relocbase); if (obj->relsize) { - printf("Non-PLT Relocations: %ld\n", + rtld_printf("Non-PLT Relocations: %ld\n", (obj->relsize / sizeof(Elf_Rel))); dump_Elf_Rel(obj, obj->rel, obj->relsize); } if (obj->relasize) { - printf("Non-PLT Relocations with Addend: %ld\n", + rtld_printf("Non-PLT Relocations with Addend: %ld\n", (obj->relasize / sizeof(Elf_Rela))); dump_Elf_Rela(obj, obj->rela, obj->relasize); } if (obj->pltrelsize) { - printf("PLT Relocations: %ld\n", + rtld_printf("PLT Relocations: %ld\n", (obj->pltrelsize / sizeof(Elf_Rel))); dump_Elf_Rel(obj, obj->pltrel, obj->pltrelsize); } if (obj->pltrelasize) { - printf("PLT Relocations with Addend: %ld\n", + rtld_printf("PLT Relocations with Addend: %ld\n", (obj->pltrelasize / sizeof(Elf_Rela))); dump_Elf_Rela(obj, obj->pltrela, obj->pltrelasize); } @@ -106,12 +106,12 @@ dump_Elf_Rel (Obj_Entry *obj, const Elf_Rel *rel0, u_long relsize) const Elf_Sym *sym; Elf_Addr *dstaddr; - printf("%s", rel_header); + rtld_putstr(rel_header); rellim = (const Elf_Rel *)((const char *)rel0 + relsize); for (rel = rel0; rel < rellim; rel++) { dstaddr = (Elf_Addr *)(obj->relocbase + rel->r_offset); sym = obj->symtab + ELF_R_SYM(rel->r_info); - printf(rel_format, + rtld_printf(rel_format, obj->strtab + sym->st_name, (u_long)rel->r_info, (u_long)rel->r_offset, (u_long)sym->st_value, (int)sym->st_size, @@ -128,12 +128,12 @@ dump_Elf_Rela (Obj_Entry *obj, const Elf_Rela *rela0, u_long relasize) const Elf_Sym *sym; Elf_Addr *dstaddr; - printf("%s", rel_header); + rtld_putstr(rel_header); relalim = (const Elf_Rela *)((const char *)rela0 + relasize); for (rela = rela0; rela < relalim; rela++) { dstaddr = (Elf_Addr *)(obj->relocbase + rela->r_offset); sym = obj->symtab + ELF_R_SYM(rela->r_info); - printf(rel_format, + rtld_printf(rel_format, obj->strtab + sym->st_name, (u_long)rela->r_info, (u_long)rela->r_offset, (u_long)sym->st_value, (int)sym->st_size, |