1998-03-07 19:24:35 +00:00
|
|
|
/*-
|
|
|
|
* Copyright 1996-1998 John D. Polstra.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 00:22:10 +00:00
|
|
|
* $FreeBSD$
|
1998-03-07 19:24:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for printing debugging messages.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "debug.h"
|
2003-06-19 03:55:38 +00:00
|
|
|
#include "rtld.h"
|
2011-08-24 20:05:13 +00:00
|
|
|
#include "rtld_printf.h"
|
2003-06-19 03:55:38 +00:00
|
|
|
|
|
|
|
static const char rel_header[] =
|
|
|
|
" symbol name r_info r_offset st_value st_size address value\n"
|
|
|
|
" ------------------------------------------------------------------------------\n";
|
2003-06-19 16:09:18 +00:00
|
|
|
static const char rel_format[] = " %-25s %6lx %08lx %08lx %7d %10p %08lx\n";
|
1998-03-07 19:24:35 +00:00
|
|
|
|
|
|
|
int debug = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
debug_printf(const char *format, ...)
|
|
|
|
{
|
|
|
|
if (debug) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_vfdprintf(STDERR_FILENO, format, ap);
|
|
|
|
rtld_fdputchar(STDERR_FILENO, '\n');
|
1998-03-07 19:24:35 +00:00
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
2003-06-19 03:55:38 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
dump_relocations (Obj_Entry *obj0)
|
|
|
|
{
|
|
|
|
Obj_Entry *obj;
|
|
|
|
|
2016-01-20 07:21:33 +00:00
|
|
|
for (obj = globallist_curr(obj0); obj != NULL;
|
|
|
|
obj = globallist_next(obj)) {
|
2003-06-19 03:55:38 +00:00
|
|
|
dump_obj_relocations(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dump_obj_relocations (Obj_Entry *obj)
|
|
|
|
{
|
|
|
|
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_printf("Object \"%s\", relocbase %p\n", obj->path, obj->relocbase);
|
2003-06-19 03:55:38 +00:00
|
|
|
|
|
|
|
if (obj->relsize) {
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_printf("Non-PLT Relocations: %ld\n",
|
2003-06-19 03:55:38 +00:00
|
|
|
(obj->relsize / sizeof(Elf_Rel)));
|
|
|
|
dump_Elf_Rel(obj, obj->rel, obj->relsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj->relasize) {
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_printf("Non-PLT Relocations with Addend: %ld\n",
|
2003-06-19 03:55:38 +00:00
|
|
|
(obj->relasize / sizeof(Elf_Rela)));
|
|
|
|
dump_Elf_Rela(obj, obj->rela, obj->relasize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj->pltrelsize) {
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_printf("PLT Relocations: %ld\n",
|
2003-06-19 03:55:38 +00:00
|
|
|
(obj->pltrelsize / sizeof(Elf_Rel)));
|
|
|
|
dump_Elf_Rel(obj, obj->pltrel, obj->pltrelsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj->pltrelasize) {
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_printf("PLT Relocations with Addend: %ld\n",
|
2003-06-19 03:55:38 +00:00
|
|
|
(obj->pltrelasize / sizeof(Elf_Rela)));
|
|
|
|
dump_Elf_Rela(obj, obj->pltrela, obj->pltrelasize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dump_Elf_Rel (Obj_Entry *obj, const Elf_Rel *rel0, u_long relsize)
|
|
|
|
{
|
|
|
|
const Elf_Rel *rel;
|
|
|
|
const Elf_Rel *rellim;
|
|
|
|
const Elf_Sym *sym;
|
|
|
|
Elf_Addr *dstaddr;
|
|
|
|
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_putstr(rel_header);
|
2003-06-19 16:09:18 +00:00
|
|
|
rellim = (const Elf_Rel *)((const char *)rel0 + relsize);
|
2003-06-19 03:55:38 +00:00
|
|
|
for (rel = rel0; rel < rellim; rel++) {
|
|
|
|
dstaddr = (Elf_Addr *)(obj->relocbase + rel->r_offset);
|
|
|
|
sym = obj->symtab + ELF_R_SYM(rel->r_info);
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_printf(rel_format,
|
2003-06-19 03:55:38 +00:00
|
|
|
obj->strtab + sym->st_name,
|
2003-06-19 16:09:18 +00:00
|
|
|
(u_long)rel->r_info, (u_long)rel->r_offset,
|
|
|
|
(u_long)sym->st_value, (int)sym->st_size,
|
|
|
|
dstaddr, (u_long)*dstaddr);
|
2003-06-19 03:55:38 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dump_Elf_Rela (Obj_Entry *obj, const Elf_Rela *rela0, u_long relasize)
|
|
|
|
{
|
|
|
|
const Elf_Rela *rela;
|
|
|
|
const Elf_Rela *relalim;
|
|
|
|
const Elf_Sym *sym;
|
|
|
|
Elf_Addr *dstaddr;
|
|
|
|
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_putstr(rel_header);
|
2003-06-19 16:09:18 +00:00
|
|
|
relalim = (const Elf_Rela *)((const char *)rela0 + relasize);
|
2003-06-19 03:55:38 +00:00
|
|
|
for (rela = rela0; rela < relalim; rela++) {
|
|
|
|
dstaddr = (Elf_Addr *)(obj->relocbase + rela->r_offset);
|
|
|
|
sym = obj->symtab + ELF_R_SYM(rela->r_info);
|
2011-08-24 20:05:13 +00:00
|
|
|
rtld_printf(rel_format,
|
2003-06-19 03:55:38 +00:00
|
|
|
obj->strtab + sym->st_name,
|
2003-06-19 16:09:18 +00:00
|
|
|
(u_long)rela->r_info, (u_long)rela->r_offset,
|
|
|
|
(u_long)sym->st_value, (int)sym->st_size,
|
|
|
|
dstaddr, (u_long)*dstaddr);
|
2003-06-19 03:55:38 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|