base: avoid use of deprecated base/printf.h

Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.

While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).

To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.

Issue #1987
This commit is contained in:
Norman Feske
2016-07-13 19:07:09 +02:00
committed by Christian Helmuth
parent a5d3aa8373
commit 17c79a9e23
699 changed files with 5156 additions and 5865 deletions

View File

@ -33,8 +33,8 @@ void Linker::dump_link_map(Object *o)
if (o->is_binary())
continue;
Genode::printf(" " EFMT " .. " EFMT ": %s\n",
o->link_map()->addr, o->link_map()->addr + o->size() - 1,
o->name());
Genode::log(" ", Genode::Hex(o->link_map()->addr),
" .. ", Genode::Hex(o->link_map()->addr + o->size() - 1),
": ", o->name());
}
}

View File

@ -34,7 +34,7 @@ Linker::Dependency::~Dependency()
if (obj->unload()) {
if (verbose_loading)
PDBG("Destroy: %s\n", obj->name());
Genode::log("Destroy: ", obj->name());
destroy(Genode::env()->heap(), obj);
}

View File

@ -47,7 +47,7 @@ extern "C" int dl_iterate_phdr(int (*callback) (Phdr_info *info, Genode::size_t
info.phnum = e->file()->phdr.count;
if (verbose_exception)
PDBG("%s reloc " EFMT, e->name(), e->reloc_base());
Genode::log(e->name(), " reloc ", Genode::Hex(e->reloc_base()));
if ((err = callback(&info, sizeof(Phdr_info), data)))
break;

View File

@ -161,12 +161,12 @@ struct Linker::Elf_file : File
bool check_compat(Elf::Ehdr const *ehdr)
{
if (memcmp(ehdr, ELFMAG, SELFMAG) != 0) {
PERR("LD: binary is not an ELF");
Genode::error("LD: binary is not an ELF");
return false;
}
if (ehdr->e_ident[EI_CLASS] != ELFCLASS) {
PERR("LD: support for 32/64-bit objects only");
Genode::error("LD: support for 32/64-bit objects only");
return false;
}
@ -215,7 +215,7 @@ struct Linker::Elf_file : File
continue;
if (ph->p_align & (0x1000 - 1)) {
PERR("LD: Unsupported alignment %p", (void *)ph->p_align);
Genode::error("LD: Unsupported alignment ", (void *)ph->p_align);
throw Incompatible();
}
@ -244,8 +244,9 @@ struct Linker::Elf_file : File
reloc_base = (start == reloc_base) ? 0 : reloc_base;
if (verbose_loading)
PDBG("reloc_base: " EFMT " start: " EFMT " end: " EFMT,
reloc_base, start, reloc_base + start + size);
Genode::log("LD: reloc_base: ", Genode::Hex(reloc_base),
" start: ", Genode::Hex(start),
" end: ", Genode::Hex(reloc_base + start + size));
for (unsigned i = 0; i < p.count; i++) {
Elf::Phdr *ph = &p.phdr[i];
@ -257,7 +258,7 @@ struct Linker::Elf_file : File
load_segment_rw(*ph, i);
else {
PERR("LD: Non-RW/RX segment");
Genode::error("LD: Non-RW/RX segment");
throw Invalid_file();
}
}
@ -321,7 +322,8 @@ struct Linker::Elf_file : File
File const *Linker::load(char const *path, bool load)
{
if (verbose_loading)
PDBG("loading: %s (PHDRS only: %s)", path, load ? "no" : "yes");
Genode::log("LD loading: ", path, " "
"(PHDRS only: ", load ? "no" : "yes", ")");
Elf_file *file = new (env()->heap()) Elf_file(Linker::file(path), load);
return file;

View File

@ -14,7 +14,8 @@
#ifndef _INCLUDE__DEBUG_H_
#define _INCLUDE__DEBUG_H_
#include <base/printf.h>
#include <util/string.h>
#include <base/log.h>
#include <elf.h>
constexpr bool verbose_link_map = false;
@ -127,8 +128,9 @@ struct Linker::Link_map
return;
for (Link_map *m = first; m; m = m->next)
PINF("MAP: addr: " EFMT " dynamic: %p %s m: %p p: %p n: %p",
m->addr, m->dynamic, m->path, m, m->prev, m->next);
Genode::log("MAP: addr: ", Genode::Hex(m->addr),
" dynamic: ", m->dynamic, " ", Genode::Cstring(m->path),
" m: ", m, " p: ", m->prev, " n: ", m->next);
}
};

View File

@ -185,7 +185,7 @@ struct Linker::Dynamic
Reloc_plt(obj, pltrel_type, pltrel, pltrel_size);
break;
default:
PERR("LD: Invalid PLT relocation %u", pltrel_type);
Genode::error("LD: Invalid PLT relocation ", (int)pltrel_type);
throw Incompatible();
}
}

View File

@ -68,7 +68,7 @@ struct Linker::Init : Genode::List<Object>
/* relocate */
for (; obj; obj = obj->next_init()) {
if (verbose_relocation)
PDBG("Relocate %s", obj->name());
Genode::log("Relocate ", obj->name());
obj->relocate();
}
@ -94,7 +94,7 @@ struct Linker::Init : Genode::List<Object>
if (obj->dynamic()->init_function) {
if (verbose_relocation)
PDBG("%s init func %p", obj->name(), obj->dynamic()->init_function);
Genode::log(obj->name(), " init func ", obj->dynamic()->init_function);
obj->dynamic()->init_function();
}

View File

@ -34,7 +34,7 @@ constexpr bool verbose_exception = false;
constexpr bool verbose_shared = false;
constexpr bool verbose_loading = false;
extern Elf::Addr etext;
extern Elf::Addr etext;
/**
* Forward declartions and helpers

View File

@ -48,7 +48,7 @@ struct Linker::Plt_got
Plt_got(Dependency const *dep, Elf::Addr *pltgot)
{
if (verbose_relocation)
PDBG("OBJ: %s (%p)", dep->obj->name(), dep);
Genode::log("OBJ: ", dep->obj->name(), " (", dep, ")");
pltgot[1] = (Elf::Addr) dep; /* ELF object */
pltgot[2] = (Elf::Addr) &_jmp_slot; /* Linker entry */
@ -66,7 +66,7 @@ struct Linker::Reloc_plt_generic
Elf::Rel const *start, unsigned long size)
{
if (type != TYPE) {
PERR("LD: Unsupported PLT relocation type: %u", type);
Genode::error("LD: Unsupported PLT relocation type: ", (int)type);
throw Incompatible();
}
@ -75,7 +75,7 @@ struct Linker::Reloc_plt_generic
for (; rel < end; rel++) {
if (rel->type() != JMPSLOT) {
PERR("LD: Unsupported PLT relocation %u", rel->type());
Genode::error("LD: Unsupported PLT relocation ", (int)rel->type());
throw Incompatible();
}
@ -102,7 +102,8 @@ class Linker::Reloc_non_plt_generic
void _copy(REL const *rel, Elf::Addr *addr)
{
if (!_dep->obj->is_binary()) {
PERR("LD: Copy relocation in DSO (%s at %p)", _dep->obj->name(), addr);
Genode::error("LD: copy relocation in DSO "
"(", _dep->obj->name(), " at ", addr, ")");
throw Incompatible();
}
@ -111,7 +112,7 @@ class Linker::Reloc_non_plt_generic
/* search symbol in other objects, do not return undefined symbols */
if (!(sym = lookup_symbol(rel->sym(), _dep, &reloc_base, false, true))) {
PWRN("LD: Symbol not found");
Genode::warning("LD: symbol not found");
return;
}
@ -119,8 +120,9 @@ class Linker::Reloc_non_plt_generic
Genode::memcpy(addr, (void *)src, sym->st_size);
if (verbose_relocation)
PDBG("Copy relocation: " EFMT " -> %p (0x" EFMT " bytes) val: " EFMT "\n",
src, addr, sym->st_size, sym->st_value);
Genode::log("Copy relocation: ", Genode::Hex(src),
" -> ", addr, " (", Genode::Hex(sym->st_size), " bytes)"
" val: ", Genode::Hex(sym->st_value));
}
public:
@ -143,7 +145,7 @@ class Linker::Reloc_jmpslot_generic
Elf::Size const index)
{
if (type != TYPE) {
PERR("LD: Unsupported JMP relocation type: %u", type);
Genode::error("LD: unsupported JMP relocation type: ", (int)type);
throw Incompatible();
}
@ -152,7 +154,7 @@ class Linker::Reloc_jmpslot_generic
Elf::Addr reloc_base;
if (!(sym = lookup_symbol(rel->sym(), dep, &reloc_base))) {
PWRN("LD: Symbol not found");
Genode::warning("LD: symbol not found");
return;
}
@ -162,8 +164,9 @@ class Linker::Reloc_jmpslot_generic
if (verbose_relocation) {
PDBG("jmp: rbase " EFMT " s: %p sval: " EFMT, reloc_base, sym, sym->st_value);
PDBG("jmp_slot at %p -> " EFMT, _addr, *_addr);
Genode::log("jmp: rbase ", Genode::Hex(reloc_base),
" s: ", sym, " sval: ", Genode::Hex(sym->st_value));
Genode::log("jmp_slot at ", _addr, " -> ", *_addr);
}
}

View File

@ -13,7 +13,7 @@
/* Genode includes */
#include <base/component.h>
#include <base/printf.h>
#include <base/log.h>
#include <base/attached_rom_dataspace.h>
#include <util/list.h>
#include <util/string.h>
@ -86,7 +86,7 @@ struct Linker::Elf_object : Object, Genode::Fifo<Elf_object>::Element
return;
if (verbose_loading)
PDBG("destroy: %s", name());
Genode::log("LD: destroy ELF object: ", name());
/* remove from link map */
Debug::state_change(Debug::DELETE, &map);
@ -288,13 +288,13 @@ Elf::Addr Ld::jmp_slot(Dependency const *dep, Elf::Size index)
Genode::Lock::Guard guard(Elf_object::lock());
if (verbose_relocation)
PDBG("SLOT %p " EFMT, dep->obj, index);
Genode::log("LD: SLOT ", dep->obj, " ", Genode::Hex(index));
try {
Reloc_jmpslot slot(dep, dep->obj->dynamic()->pltrel_type,
dep->obj->dynamic()->pltrel, index);
return slot.target_addr();
} catch (...) { PERR("LD: Jump slot relocation failed. FATAL!"); }
} catch (...) { Genode::error("LD: jump slot relocation failed. FATAL!"); }
return 0;
}
@ -405,7 +405,7 @@ Object *Linker::load(char const *path, Dependency *dep, unsigned flags)
for (Object *e = Elf_object::obj_list()->head(); e; e = e->next_obj()) {
if (verbose_loading)
PDBG("LOAD: %s == %s", Linker::file(path), e->name());
Genode::log("LOAD: ", Linker::file(path), " == ", e->name());
if (!Genode::strcmp(Linker::file(path), e->name())) {
e->load();
@ -432,7 +432,7 @@ Elf::Sym const *Linker::lookup_symbol(unsigned sym_index, Dependency const *dep,
Elf::Sym const *symbol = e->symbol(sym_index);
if (!symbol) {
PWRN("LD: Unkown symbol index %x", sym_index);
Genode::warning("LD: unknown symbol index ", Genode::Hex(sym_index));
return 0;
}
@ -465,7 +465,9 @@ Elf::Sym const *Linker::lookup_symbol(char const *name, Dependency const *dep,
if ((symbol = elf->lookup_symbol(name, hash)) && (symbol->st_value || undef)) {
if (dep->root && verbose_lookup)
PINF("Lookup %s obj_src %s st %p info %x weak: %u", name, elf->name(), symbol, symbol->st_info, symbol->weak());
Genode::log("LD: lookup ", name, " obj_src ", elf->name(),
" st ", symbol, " info ", Genode::Hex(symbol->st_info),
" weak: ", symbol->weak());
if (!undef && symbol->st_shndx == SHN_UNDEF)
continue;
@ -487,13 +489,13 @@ Elf::Sym const *Linker::lookup_symbol(char const *name, Dependency const *dep,
if (binary && dep != binary->dep.head()) {
return lookup_symbol(name, binary->dep.head(), base, undef, other);
} else {
PERR("Could not lookup symbol \"%s\"", name);
Genode::error("LD: could not lookup symbol \"", name, "\"");
throw Not_found();
}
}
if (dep->root && verbose_lookup)
PDBG("Return %p", weak_symbol);
Genode::log("LD: return ", weak_symbol);
if (!weak_symbol)
throw Not_found();
@ -563,17 +565,18 @@ void Component::construct(Genode::Env &env)
try {
binary = new(Genode::env()->heap()) Binary();
} catch (...) {
PERR("LD: Failed to load program");
throw Failed_to_load_program();
Genode::error("LD: failed to load program");
throw Failed_to_load_program();
}
/* print loaded object information */
try {
if (verbose) {
PINF(" %lx .. %lx: stack area",
Genode::Thread::stack_area_virtual_base(),
Genode::Thread::stack_area_virtual_base() +
Genode::Thread::stack_area_virtual_size() - 1);
using namespace Genode;
log(" ", Hex(Thread::stack_area_virtual_base()),
" .. ", Hex(Thread::stack_area_virtual_base() +
Thread::stack_area_virtual_size() - 1),
": stack area");
dump_link_map(Elf_object::obj_list()->head());
}
} catch (...) { }

View File

@ -55,7 +55,7 @@ Genode::Shared_object::Shared_object(char const *file, unsigned flags)
using namespace Linker;
if (verbose_shared)
PDBG("open '%s'", file ? file : "binary");
Genode::log("LD: open '", file ? file : "binary", "'");
try {
Genode::Lock::Guard guard(shared_object_lock());
@ -80,7 +80,7 @@ void *Genode::Shared_object::_lookup(const char *name) const
using namespace Linker;
if (verbose_shared)
PDBG("lookup '%s'", name);
Genode::log("LD: shared object lookup '", name, "'");
try {
Genode::Lock::Guard guard(Object::lock());
@ -105,7 +105,7 @@ Genode::Shared_object::~Shared_object()
using namespace Linker;
if (verbose_shared)
PDBG("close");
Genode::log("LD: close shared object");
Genode::Lock::Guard guard(shared_object_lock());
destroy(Genode::env()->heap(), to_root(_handle));
@ -117,13 +117,14 @@ Genode::Address_info::Address_info(Genode::addr_t address)
using namespace Genode;
if (verbose_shared)
PDBG("request: %lx", address);
Genode::log("LD: address-info request: ", Genode::Hex(address));
Linker::Object *e = find_obj(address);
e->info(address, *this);
if (verbose_shared)
PDBG("Found: obj: %s sym: %s addr: %lx", path, name, addr);
Genode::log("LD: found address info: obj: ", path, " sym: ", name,
" addr: ", Genode::Hex(addr));
}

View File

@ -81,7 +81,7 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
Reloc_non_plt(Dependency const *dep, Elf::Rela const *, unsigned long)
: Reloc_non_plt_generic(dep)
{
PERR("LD: DT_RELA not supported");
Genode::error("LD: DT_RELA not supported");
throw Incompatible();
}
@ -105,7 +105,7 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
case R_RELATIVE: _relative(addr); break;
default:
if (_dep->root) {
PWRN("LD: Unkown relocation %u", rel->type());
Genode::warning("LD: Unkown relocation ", (int)rel->type());
throw Incompatible();
}
break;

View File

@ -68,8 +68,9 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
*addr = reloc_base + sym->st_value + (addend ? rel->addend : 0);
if (verbose_reloc(_dep))
PDBG("GLOB DAT %p -> %llx r %llx v %llx", addr, *addr, reloc_base,
sym->st_value);
Genode::log("LD: GLOB DAT ", addr, " -> ", Genode::Hex(*addr),
" r ", Genode::Hex(reloc_base),
" v ", Genode::Hex(sym->st_value));
}
public:
@ -83,7 +84,7 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
Elf::Addr *addr = (Elf::Addr *)(_dep->obj->reloc_base() + rel->offset);
if (verbose_reloc(_dep))
PDBG("reloc: %p type: %u", rel, rel->type());
Genode::log("LD: reloc: ", rel, " type: ", (int)rel->type());
switch(rel->type()) {
case R_JMPSLOT: _glob_dat_64(rel, addr, false); break;
@ -92,7 +93,7 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
default:
if (!_dep->obj->is_linker()) {
PWRN("LD: Unkown relocation %u", rel->type());
Genode::warning("LD: unkown relocation ", (int)rel->type());
throw Incompatible();
}
break;
@ -103,7 +104,7 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
Reloc_non_plt(Dependency const *dep, Elf::Rel const *, unsigned long, bool)
: Reloc_non_plt_generic(dep)
{
PERR("LD: DT_REL not supported");
Genode::error("LD: DT_REL not supported");
throw Incompatible();
}
};

View File

@ -61,7 +61,7 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
Reloc_non_plt(Dependency const *dep, Elf::Rela const *, unsigned long)
: Reloc_non_plt_generic(dep)
{
PERR("LD: DT_RELA not supported");
Genode::error("LD: DT_RELA not supported");
throw Incompatible();
}
@ -85,7 +85,7 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
case R_RELATIVE: _relative(rel, addr); break;
default:
if (_dep->root) {
PWRN("LD: Unkown relocation %u", rel->type());
Genode::warning("LD: Unkown relocation ", (int)rel->type());
throw Incompatible();
}
break;

View File

@ -62,8 +62,8 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
*addr = reloc_base + sym->st_value + (addend ? rel->addend : 0);
if (verbose_reloc(_dep))
PDBG("GLOB DAT %p -> %llx r %llx v %llx", addr, *addr, reloc_base,
sym->st_value);
Genode::log("GLOB DAT ", addr, " -> ", *addr,
" r ", reloc_base, " v ", sym->st_value);
}
public:
@ -84,7 +84,7 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
default:
if (!_dep->obj->is_linker()) {
PWRN("LD: Unkown relocation %u", rel->type());
Genode::warning("LD: Unkown relocation ", (int)rel->type());
throw Incompatible();
}
break;
@ -95,7 +95,7 @@ class Linker::Reloc_non_plt : public Reloc_non_plt_generic
Reloc_non_plt(Dependency const *dep, Elf::Rel const *, unsigned long, bool)
: Reloc_non_plt_generic(dep)
{
PERR("LD: DT_REL not supported");
Genode::error("LD: DT_REL not supported");
throw Incompatible();
}
};

View File

@ -17,7 +17,7 @@
* under the terms of the GNU General Public License version 2.
*/
#include <base/printf.h>
#include <base/log.h>
/*
* from gcc/config/arm/unwind-arm.h
@ -31,7 +31,7 @@ typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
extern "C" _Unwind_Ptr __attribute__((weak)) dl_unwind_find_exidx(_Unwind_Ptr pc, int *pcount);
extern "C" _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int *pcount)
{
PERR("Ops called");
Genode::error("dl_unwind_find_exidx called");
return 0;
}