Import ELF Tool Chain snapshot at revision 3475

From http://svn.code.sf.net/p/elftoolchain/code/
This commit is contained in:
Ed Maste 2016-05-19 20:06:56 +00:00
parent 7c9f2b63d3
commit a7f03fcfe7
68 changed files with 2189 additions and 1454 deletions

View File

@ -40,7 +40,7 @@
#include "uthash.h"
#include "_elftc.h"
ELFTC_VCSID("$Id: addr2line.c 3273 2015-12-11 21:38:57Z kaiwang27 $");
ELFTC_VCSID("$Id: addr2line.c 3446 2016-05-03 01:31:17Z emaste $");
struct Func {
char *name;
@ -284,7 +284,7 @@ collect_func(Dwarf_Debug dbg, Dwarf_Die die, struct Func *parent, struct CU *cu)
&de) == DW_DLV_OK)
goto add_func;
/* Skip if no name assoicated with this DIE. */
/* Skip if no name associated with this DIE. */
goto cont_search;
add_func:

View File

@ -44,7 +44,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: brandelf.c 3354 2016-01-18 21:50:15Z jkoshy $");
ELFTC_VCSID("$Id: brandelf.c 3440 2016-04-07 14:51:47Z emaste $");
static int elftype(const char *);
static const char *iselftype(int);
@ -62,6 +62,7 @@ static struct ELFtypes elftypes[] = {
{ "AIX", ELFOSABI_AIX },
{ "ARM", ELFOSABI_ARM },
{ "AROS", ELFOSABI_AROS },
{ "CloudABI", ELFOSABI_CLOUDABI },
{ "FreeBSD", ELFOSABI_FREEBSD },
{ "GNU", ELFOSABI_GNU },
{ "HP/UX", ELFOSABI_HPUX},

View File

@ -23,11 +23,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: _elftc.h 3244 2015-08-31 19:53:08Z emaste $
* $Id: _elftc.h 3446 2016-05-03 01:31:17Z emaste $
*/
/**
** Miscellanous definitions needed by multiple components.
** Miscellaneous definitions needed by multiple components.
**/
#ifndef _ELFTC_H

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: elfdefinitions.h 3392 2016-02-05 19:51:22Z emaste $
* $Id: elfdefinitions.h 3455 2016-05-09 13:47:29Z emaste $
*/
/*
@ -184,6 +184,10 @@ _ELF_DEFINE_DT(DT_ADDRRNGLO, 0x6FFFFE00UL, \
"start of range using the d_ptr field") \
_ELF_DEFINE_DT(DT_GNU_HASH, 0x6FFFFEF5UL, \
"GNU style hash tables") \
_ELF_DEFINE_DT(DT_TLSDESC_PLT, 0x6FFFFEF6UL, \
"location of PLT entry for TLS descriptor resolver calls") \
_ELF_DEFINE_DT(DT_TLSDESC_GOT, 0x6FFFFEF7UL, \
"location of GOT entry used by TLS descriptor resolver PLT entry") \
_ELF_DEFINE_DT(DT_GNU_CONFLICT, 0x6FFFFEF8UL, \
"address of conflict section") \
_ELF_DEFINE_DT(DT_GNU_LIBLIST, 0x6FFFFEF9UL, \
@ -269,7 +273,7 @@ _ELF_DEFINE_DT(DT_MIPS_DELTA_RELOC, 0x7000001BUL, \
_ELF_DEFINE_DT(DT_MIPS_DELTA_RELOC_NO, 0x7000001CUL, \
"number of entries in DT_MIPS_DELTA_RELOC") \
_ELF_DEFINE_DT(DT_MIPS_DELTA_SYM, 0x7000001DUL, \
"Delta symbols refered by Delta relocations") \
"Delta symbols referred by Delta relocations") \
_ELF_DEFINE_DT(DT_MIPS_DELTA_SYM_NO, 0x7000001EUL, \
"number of entries in DT_MIPS_DELTA_SYM") \
_ELF_DEFINE_DT(DT_MIPS_DELTA_CLASSSYM, 0x70000020UL, \
@ -540,6 +544,7 @@ _ELF_DEFINE_EABI(ELFOSABI_NSK, 14, \
_ELF_DEFINE_EABI(ELFOSABI_AROS, 15, "Amiga Research OS") \
_ELF_DEFINE_EABI(ELFOSABI_FENIXOS, 16, \
"The FenixOS highly scalable multi-core OS") \
_ELF_DEFINE_EABI(ELFOSABI_CLOUDABI, 17, "Nuxi CloudABI") \
_ELF_DEFINE_EABI(ELFOSABI_ARM_AEABI, 64, \
"ARM specific symbol versioning extensions") \
_ELF_DEFINE_EABI(ELFOSABI_ARM, 97, "ARM ABI") \
@ -1193,7 +1198,7 @@ _ELF_DEFINE_SHT(SHT_MIPS_ABIFLAGS, 0x7000002AUL, \
"ABI flags") \
_ELF_DEFINE_SHT(SHT_SPARC_GOTDATA, 0x70000000UL, \
"SPARC-specific data") \
_ELF_DEFINE_SHT(SHT_AMD64_UNWIND, 0x70000001UL, \
_ELF_DEFINE_SHT(SHT_X86_64_UNWIND, 0x70000001UL, \
"unwind tables for the AMD64") \
_ELF_DEFINE_SHT(SHT_ORDERED, 0x7FFFFFFFUL, \
"sort entries in the section") \
@ -1212,6 +1217,7 @@ enum {
};
/* Aliases for section types. */
#define SHT_AMD64_UNWIND SHT_X86_64_UNWIND
#define SHT_GNU_verdef SHT_SUNW_verdef
#define SHT_GNU_verneed SHT_SUNW_verneed
#define SHT_GNU_versym SHT_SUNW_versym
@ -1255,6 +1261,7 @@ _ELF_DEFINE_STT(STT_FILE, 4, "source file") \
_ELF_DEFINE_STT(STT_COMMON, 5, "uninitialized common block") \
_ELF_DEFINE_STT(STT_TLS, 6, "thread local storage") \
_ELF_DEFINE_STT(STT_LOOS, 10, "start of OS-specific types") \
_ELF_DEFINE_STT(STT_GNU_IFUNC, 10, "indirect function") \
_ELF_DEFINE_STT(STT_HIOS, 12, "end of OS-specific types") \
_ELF_DEFINE_STT(STT_LOPROC, 13, \
"start of processor-specific types") \
@ -1402,10 +1409,37 @@ _ELF_DEFINE_RELOC(R_386_RELATIVE, 8) \
_ELF_DEFINE_RELOC(R_386_GOTOFF, 9) \
_ELF_DEFINE_RELOC(R_386_GOTPC, 10) \
_ELF_DEFINE_RELOC(R_386_32PLT, 11) \
_ELF_DEFINE_RELOC(R_386_TLS_TPOFF, 14) \
_ELF_DEFINE_RELOC(R_386_TLS_IE, 15) \
_ELF_DEFINE_RELOC(R_386_TLS_GOTIE, 16) \
_ELF_DEFINE_RELOC(R_386_TLS_LE, 17) \
_ELF_DEFINE_RELOC(R_386_TLS_GD, 18) \
_ELF_DEFINE_RELOC(R_386_TLS_LDM, 19) \
_ELF_DEFINE_RELOC(R_386_16, 20) \
_ELF_DEFINE_RELOC(R_386_PC16, 21) \
_ELF_DEFINE_RELOC(R_386_8, 22) \
_ELF_DEFINE_RELOC(R_386_PC8, 23)
_ELF_DEFINE_RELOC(R_386_PC8, 23) \
_ELF_DEFINE_RELOC(R_386_TLS_GD_32, 24) \
_ELF_DEFINE_RELOC(R_386_TLS_GD_PUSH, 25) \
_ELF_DEFINE_RELOC(R_386_TLS_GD_CALL, 26) \
_ELF_DEFINE_RELOC(R_386_TLS_GD_POP, 27) \
_ELF_DEFINE_RELOC(R_386_TLS_LDM_32, 28) \
_ELF_DEFINE_RELOC(R_386_TLS_LDM_PUSH, 29) \
_ELF_DEFINE_RELOC(R_386_TLS_LDM_CALL, 30) \
_ELF_DEFINE_RELOC(R_386_TLS_LDM_POP, 31) \
_ELF_DEFINE_RELOC(R_386_TLS_LDO_32, 32) \
_ELF_DEFINE_RELOC(R_386_TLS_IE_32, 33) \
_ELF_DEFINE_RELOC(R_386_TLS_LE_32, 34) \
_ELF_DEFINE_RELOC(R_386_TLS_DTPMOD32, 35) \
_ELF_DEFINE_RELOC(R_386_TLS_DTPOFF32, 36) \
_ELF_DEFINE_RELOC(R_386_TLS_TPOFF32, 37) \
_ELF_DEFINE_RELOC(R_386_SIZE32, 38) \
_ELF_DEFINE_RELOC(R_386_TLS_GOTDESC, 39) \
_ELF_DEFINE_RELOC(R_386_TLS_DESC_CALL, 40) \
_ELF_DEFINE_RELOC(R_386_TLS_DESC, 41) \
_ELF_DEFINE_RELOC(R_386_IRELATIVE, 42) \
_ELF_DEFINE_RELOC(R_386_GOT32X, 43)
/*
*/
@ -1795,11 +1829,18 @@ _ELF_DEFINE_RELOC(R_MIPS_GOT16, 9) \
_ELF_DEFINE_RELOC(R_MIPS_PC16, 10) \
_ELF_DEFINE_RELOC(R_MIPS_CALL16, 11) \
_ELF_DEFINE_RELOC(R_MIPS_GPREL32, 12) \
_ELF_DEFINE_RELOC(R_MIPS_SHIFT5, 16) \
_ELF_DEFINE_RELOC(R_MIPS_SHIFT6, 17) \
_ELF_DEFINE_RELOC(R_MIPS_64, 18) \
_ELF_DEFINE_RELOC(R_MIPS_GOTHI16, 21) \
_ELF_DEFINE_RELOC(R_MIPS_GOTLO16, 22) \
_ELF_DEFINE_RELOC(R_MIPS_GOT_DISP, 19) \
_ELF_DEFINE_RELOC(R_MIPS_GOT_PAGE, 20) \
_ELF_DEFINE_RELOC(R_MIPS_GOT_OFST, 21) \
_ELF_DEFINE_RELOC(R_MIPS_GOT_HI16, 22) \
_ELF_DEFINE_RELOC(R_MIPS_GOT_LO16, 23) \
_ELF_DEFINE_RELOC(R_MIPS_SUB, 24) \
_ELF_DEFINE_RELOC(R_MIPS_CALLHI16, 30) \
_ELF_DEFINE_RELOC(R_MIPS_CALLLO16, 31) \
_ELF_DEFINE_RELOC(R_MIPS_JALR, 37) \
_ELF_DEFINE_RELOC(R_MIPS_TLS_DTPMOD32, 38) \
_ELF_DEFINE_RELOC(R_MIPS_TLS_DTPREL32, 39) \
_ELF_DEFINE_RELOC(R_MIPS_TLS_DTPMOD64, 40) \
@ -2095,6 +2136,7 @@ _ELF_DEFINE_RELOC(R_SPARC_PC_HM10, 38) \
_ELF_DEFINE_RELOC(R_SPARC_PC_LM22, 39) \
_ELF_DEFINE_RELOC(R_SPARC_WDISP16, 40) \
_ELF_DEFINE_RELOC(R_SPARC_WDISP19, 41) \
_ELF_DEFINE_RELOC(R_SPARC_GLOB_JMP, 42) \
_ELF_DEFINE_RELOC(R_SPARC_7, 43) \
_ELF_DEFINE_RELOC(R_SPARC_5, 44) \
_ELF_DEFINE_RELOC(R_SPARC_6, 45) \
@ -2108,6 +2150,30 @@ _ELF_DEFINE_RELOC(R_SPARC_L44, 52) \
_ELF_DEFINE_RELOC(R_SPARC_REGISTER, 53) \
_ELF_DEFINE_RELOC(R_SPARC_UA64, 54) \
_ELF_DEFINE_RELOC(R_SPARC_UA16, 55) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_GD_HI22, 56) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_GD_LO10, 57) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_GD_ADD, 58) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_GD_CALL, 59) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_LDM_HI22, 60) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_LDM_LO10, 61) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_LDM_ADD, 62) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_LDM_CALL, 63) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_LDO_HIX22, 64) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_LDO_LOX10, 65) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_LDO_ADD, 66) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_HI22, 67) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_LO10, 68) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_LD, 69) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_LDX, 70) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_ADD, 71) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_LE_HIX22, 72) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_LE_LOX10, 73) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_DTPMOD32, 74) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_DTPMOD64, 75) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_DTPOFF32, 76) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_DTPOFF64, 77) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_TPOFF32, 78) \
_ELF_DEFINE_RELOC(R_SPARC_TLS_TPOFF64, 79) \
_ELF_DEFINE_RELOC(R_SPARC_GOTDATA_HIX22, 80) \
_ELF_DEFINE_RELOC(R_SPARC_GOTDATA_LOX10, 81) \
_ELF_DEFINE_RELOC(R_SPARC_GOTDATA_OP_HIX22, 82) \
@ -2153,7 +2219,10 @@ _ELF_DEFINE_RELOC(R_X86_64_SIZE64, 33) \
_ELF_DEFINE_RELOC(R_X86_64_GOTPC32_TLSDESC, 34) \
_ELF_DEFINE_RELOC(R_X86_64_TLSDESC_CALL, 35) \
_ELF_DEFINE_RELOC(R_X86_64_TLSDESC, 36) \
_ELF_DEFINE_RELOC(R_X86_64_IRELATIVE, 37)
_ELF_DEFINE_RELOC(R_X86_64_IRELATIVE, 37) \
_ELF_DEFINE_RELOC(R_X86_64_RELATIVE64, 38) \
_ELF_DEFINE_RELOC(R_X86_64_GOTPCRELX, 41) \
_ELF_DEFINE_RELOC(R_X86_64_REX_GOTPCRELX, 42)
#define _ELF_DEFINE_RELOCATIONS() \
_ELF_DEFINE_386_RELOCATIONS() \
@ -2424,7 +2493,7 @@ _ELF_DEFINE_ODK(ODK_HWOR, 8, "hardware OR patch applied") \
_ELF_DEFINE_ODK(ODK_GP_GROUP, 9, \
"GP group to use for text/data sections") \
_ELF_DEFINE_ODK(ODK_IDENT, 10, "ID information") \
_ELF_DEFINE_ODK(ODK_PAGESIZE, 11, "page size infomation")
_ELF_DEFINE_ODK(ODK_PAGESIZE, 11, "page size information")
#undef _ELF_DEFINE_ODK
#define _ELF_DEFINE_ODK(N, V, DESCR) N = V ,

View File

@ -35,7 +35,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: cxxfilt.c 3356 2016-01-22 22:31:38Z jkoshy $");
ELFTC_VCSID("$Id: cxxfilt.c 3454 2016-05-07 17:11:05Z kaiwang27 $");
#define STRBUFSZ 8192
@ -112,35 +112,18 @@ find_format(const char *fstr)
}
static char *
demangle(char *name, int strict, size_t *pos)
demangle(char *name)
{
static char dem[STRBUFSZ];
char nb[STRBUFSZ];
size_t p, t;
if (stripus && *name == '_') {
strncpy(nb, name + 1, sizeof(nb) - 1);
t = 1;
} else {
strncpy(nb, name, sizeof(nb) - 1);
t = 0;
}
nb[sizeof(nb) - 1] = '\0';
if (stripus && *name == '_')
name++;
p = strlen(nb);
if (p == 0)
return NULL;
if (strlen(name) == 0)
return (NULL);
while (elftc_demangle(nb, dem, sizeof(dem), (unsigned) format) < 0) {
if (!strict && p > 1) {
nb[--p] = '\0';
continue;
} else
return (NULL);
}
if (pos != NULL)
*pos = t ? p + 1 : p;
if (elftc_demangle(name, dem, sizeof(dem), (unsigned) format) < 0)
return (NULL);
return (dem);
}
@ -149,7 +132,7 @@ int
main(int argc, char **argv)
{
char *dem, buf[STRBUFSZ];
size_t i, p, s;
size_t p;
int c, n, opt;
while ((opt = getopt_long(argc, argv, "_nps:V", longopts, NULL)) !=
@ -184,8 +167,8 @@ main(int argc, char **argv)
if (*argv != NULL) {
for (n = 0; n < argc; n++) {
if ((dem = demangle(argv[n], 1, NULL)) == NULL)
fprintf(stderr, "Failed: %s\n", argv[n]);
if ((dem = demangle(argv[n])) == NULL)
printf("%s\n", argv[n]);
else
printf("%s\n", dem);
}
@ -193,23 +176,18 @@ main(int argc, char **argv)
p = 0;
for (;;) {
c = fgetc(stdin);
if (c == EOF || !isprint(c) || strchr(" \t\n", c)) {
if (c == EOF || !(isalnum(c) || strchr(".$_", c))) {
if (p > 0) {
buf[p] = '\0';
if ((dem = demangle(buf, 0, &s)) ==
NULL)
if ((dem = demangle(buf)) == NULL)
printf("%s", buf);
else {
else
printf("%s", dem);
for (i = s; i < p; i++)
putchar(buf[i]);
}
p = 0;
}
if (c == EOF)
break;
if (isprint(c) || strchr(" \t\n", c))
putchar(c);
putchar(c);
} else {
if ((size_t) p >= sizeof(buf) - 1)
warnx("buffer overflowed");

View File

@ -36,7 +36,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: ascii.c 3177 2015-03-30 18:19:41Z emaste $");
ELFTC_VCSID("$Id: ascii.c 3446 2016-05-03 01:31:17Z emaste $");
static void append_data(struct section *s, const void *buf, size_t sz);
static char hex_digit(uint8_t n);
@ -187,7 +187,7 @@ create_srec(struct elfcopy *ecp, int ifd, int ofd, const char *ofn)
if (elferr != 0)
warnx("elf_nextscn failed: %s", elf_errmsg(elferr));
/* Generate S{7,8,9} end of block recrod. */
/* Generate S{7,8,9} end of block record. */
if (gelf_getehdr(e, &eh) == NULL)
errx(EXIT_FAILURE, "gelf_getehdr() failed: %s",
elf_errmsg(-1));

View File

@ -26,6 +26,7 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <ctype.h>
#include <err.h>
#include <gelf.h>
#include <stdio.h>
@ -35,7 +36,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: binary.c 3270 2015-12-11 18:48:56Z emaste $");
ELFTC_VCSID("$Id: binary.c 3445 2016-04-20 19:08:30Z emaste $");
/*
* Convert ELF object to `binary'. Sections with SHF_ALLOC flag set
@ -213,9 +214,9 @@ create_elf_from_binary(struct elfcopy *ecp, int ifd, const char *ifn)
if ((sym_basename = strdup(ifn)) == NULL)
err(1, "strdup");
p = sym_basename;
while ((p = strchr(p, '.')) != NULL)
*p++ = '_';
for (p = sym_basename; *p != '\0'; p++)
if (!isalnum(*p))
*p = '_';
#define _GEN_SYMNAME(S) do { \
snprintf(name, sizeof(name), "%s%s%s", "_binary_", sym_basename, S); \
} while (0)

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: elfcopy.1 3381 2016-01-30 19:39:47Z jkoshy $
.\" $Id: elfcopy.1 3426 2016-03-05 13:32:28Z emaste $
.\"
.Dd January 29, 2016
.Dd March 5, 2016
.Os
.Dt ELFCOPY 1
.Sh NAME
@ -67,7 +67,10 @@
.Op Fl -change-section-vma Ar section Ns {+|-|=} Ns Ar val
.Op Fl -extract-dwo
.Op Fl -gap-fill Ns = Ns Ar val
.Op Fl -globalize-symbol Ns = Ns ar symbolname
.Op Fl -globalize-symbols Ns = Ns Ar filename
.Op Fl -localize-hidden
.Op Fl -localize-symbols Ns = Ns Ar filename
.Op Fl -no-adjust-warnings | Fl -no-change-warnings
.Op Fl -only-keep-debug
.Op Fl -pad-to Ns = Ns Ar address
@ -239,9 +242,21 @@ Copy only .dwo debug sections to the output file.
Fill the gaps between sections with the byte value specified by
the argument
.Ar val .
.It Fl -globalize-symbol Ns = Ns Ar symbolname
Make the symbol named by argument
.Ar symbolname
global, so that it is visible outside of the file in which it is defined.
.It Fl -globalize-symbols Ns = Ns Ar filename
Make each symbol listed in the file specified by
.Ar filename
global.
.It Fl -localize-hidden
Make all hidden symbols local to the output file.
This includes symbols with internal visiblity.
.It Fl -localize-symbols Ns = Ns Ar filename
Make each symbol listed in the file specified by
.Ar filename
local to the output file.
.It Fl -no-adjust-warnings | Fl -no-change-warnings
Do not issue a warning if the section specified by the options
.Fl -change-section-address ,

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: elfcopy.h 3310 2016-01-10 09:10:54Z kaiwang27 $
* $Id: elfcopy.h 3446 2016-05-03 01:31:17Z emaste $
*/
#include <sys/queue.h>
@ -139,7 +139,8 @@ struct section {
/* Internal data structure for segments. */
struct segment {
uint64_t addr; /* load addr */
uint64_t vaddr; /* virtual addr (VMA) */
uint64_t paddr; /* physical addr (LMA) */
uint64_t off; /* file offset */
uint64_t fsz; /* file size */
uint64_t msz; /* memory size */
@ -177,7 +178,7 @@ struct elfcopy {
Elftc_Bfd_Target_Flavor otf; /* flavour of output object */
const char *otgt; /* output target name */
int oec; /* elfclass of output object */
unsigned char oed; /* endianess of output object */
unsigned char oed; /* endianness of output object */
int oem; /* EM_XXX of output object */
int abi; /* OSABI of output object */
Elf *ein; /* ELF descriptor of input object */
@ -237,7 +238,7 @@ struct elfcopy {
uint64_t *secndx; /* section index map. */
uint64_t *symndx; /* symbol index map. */
unsigned char *v_rel; /* symbols needed by relocation. */
unsigned char *v_grp; /* symbols refered by section group. */
unsigned char *v_grp; /* symbols referred by section group. */
unsigned char *v_secsym; /* sections with section symbol. */
STAILQ_HEAD(, segment) v_seg; /* list of segments. */
STAILQ_HEAD(, sec_action) v_sac;/* list of section operations. */

View File

@ -39,7 +39,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: main.c 3399 2016-02-12 18:07:56Z emaste $");
ELFTC_VCSID("$Id: main.c 3446 2016-05-03 01:31:17Z emaste $");
enum options
{
@ -209,6 +209,7 @@ static struct {
{"openbsd", ELFOSABI_OPENBSD},
{"openvms", ELFOSABI_OPENVMS},
{"nsk", ELFOSABI_NSK},
{"cloudabi", ELFOSABI_CLOUDABI},
{"arm", ELFOSABI_ARM},
{"standalone", ELFOSABI_STANDALONE},
{NULL, 0}
@ -235,7 +236,7 @@ static void strip_main(struct elfcopy *ecp, int argc, char **argv);
static void strip_usage(void);
/*
* An ELF object usually has a sturcture described by the
* An ELF object usually has a structure described by the
* diagram below.
* _____________
* | |
@ -641,6 +642,18 @@ create_file(struct elfcopy *ecp, const char *src, const char *dst)
* ELF object before processing.
*/
if (ecp->itf != ETF_ELF) {
/*
* If the output object is not an ELF file, choose an arbitrary
* ELF format for the intermediate file. srec, ihex and binary
* formats are independent of class, endianness and machine
* type so these choices do not affect the output.
*/
if (ecp->otf != ETF_ELF) {
if (ecp->oec == ELFCLASSNONE)
ecp->oec = ELFCLASS64;
if (ecp->oed == ELFDATANONE)
ecp->oed = ELFDATA2LSB;
}
create_tempfile(&elftemp, &efd);
if ((ecp->eout = elf_begin(efd, ELF_C_WRITE, NULL)) == NULL)
errx(EXIT_FAILURE, "elf_begin() failed: %s",
@ -1434,7 +1447,7 @@ Usage: %s [options] infile [outfile]\n\
sections.\n\
--only-keep-debug Copy only debugging information.\n\
--output-target=FORMAT Use the specified format for the output.\n\
--pad-to=ADDRESS Pad the output object upto the given address.\n\
--pad-to=ADDRESS Pad the output object up to the given address.\n\
--prefix-alloc-sections=STRING\n\
Prefix the section names of all the allocated\n\
sections with STRING.\n\

View File

@ -34,7 +34,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: sections.c 3346 2016-01-17 20:09:15Z kaiwang27 $");
ELFTC_VCSID("$Id: sections.c 3443 2016-04-15 18:57:54Z kaiwang27 $");
static void add_gnu_debuglink(struct elfcopy *ecp);
static uint32_t calc_crc32(const char *p, size_t len, uint32_t crc);
@ -343,7 +343,7 @@ create_scn(struct elfcopy *ecp)
GElf_Shdr ish;
size_t indx;
uint64_t oldndx, newndx;
int elferr, sec_flags;
int elferr, sec_flags, reorder;
/*
* Insert a pseudo section that contains the ELF header
@ -367,6 +367,7 @@ create_scn(struct elfcopy *ecp)
errx(EXIT_FAILURE, "elf_getshstrndx failed: %s",
elf_errmsg(-1));
reorder = 0;
is = NULL;
while ((is = elf_nextscn(ecp->ein, is)) != NULL) {
if (gelf_getshdr(is, &ish) == NULL)
@ -482,8 +483,20 @@ create_scn(struct elfcopy *ecp)
/* create section header based on input object. */
if (strcmp(name, ".symtab") != 0 &&
strcmp(name, ".strtab") != 0 &&
strcmp(name, ".shstrtab") != 0)
strcmp(name, ".shstrtab") != 0) {
copy_shdr(ecp, s, NULL, 0, sec_flags);
/*
* elfcopy puts .symtab, .strtab and .shstrtab
* sections in the end of the output object.
* If the input objects have more sections
* after any of these 3 sections, the section
* table will be reordered. section symbols
* should be regenerated for relocations.
*/
if (reorder)
ecp->flags &= ~SYMTAB_INTACT;
} else
reorder = 1;
if (strcmp(name, ".symtab") == 0) {
ecp->flags |= SYMTAB_EXIST;
@ -1519,6 +1532,9 @@ add_gnu_debuglink(struct elfcopy *ecp)
err(EXIT_FAILURE, "strdup failed");
if (stat(ecp->debuglink, &sb) == -1)
err(EXIT_FAILURE, "stat failed");
if (sb.st_size == 0)
errx(EXIT_FAILURE, "empty debug link target %s",
ecp->debuglink);
if ((buf = malloc(sb.st_size)) == NULL)
err(EXIT_FAILURE, "malloc failed");
if ((fp = fopen(ecp->debuglink, "r")) == NULL)

View File

@ -34,7 +34,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: segments.c 3397 2016-02-12 14:35:19Z emaste $");
ELFTC_VCSID("$Id: segments.c 3449 2016-05-03 13:59:29Z emaste $");
static void insert_to_inseg_list(struct segment *seg, struct section *sec);
@ -72,12 +72,12 @@ add_to_inseg_list(struct elfcopy *ecp, struct section *s)
*/
loadable = 0;
STAILQ_FOREACH(seg, &ecp->v_seg, seg_list) {
if (s->off < seg->off || (s->vma < seg->addr && !s->pseudo))
if (s->off < seg->off || (s->vma < seg->vaddr && !s->pseudo))
continue;
if (s->off + s->sz > seg->off + seg->fsz &&
s->type != SHT_NOBITS)
continue;
if (s->vma + s->sz > seg->addr + seg->msz)
if (s->vma + s->sz > seg->vaddr + seg->msz)
continue;
insert_to_inseg_list(seg, s);
@ -85,7 +85,12 @@ add_to_inseg_list(struct elfcopy *ecp, struct section *s)
s->seg = seg;
else if (seg->type == PT_TLS)
s->seg_tls = seg;
s->lma = seg->addr + (s->off - seg->off);
if (s->pseudo)
s->vma = seg->vaddr + (s->off - seg->off);
if (seg->paddr > 0)
s->lma = seg->paddr + (s->off - seg->off);
else
s->lma = 0;
loadable = 1;
}
@ -98,7 +103,7 @@ adjust_addr(struct elfcopy *ecp)
struct section *s, *s0;
struct segment *seg;
struct sec_action *sac;
uint64_t dl, lma, start, end;
uint64_t dl, vma, lma, start, end;
int found, i;
/*
@ -110,59 +115,52 @@ adjust_addr(struct elfcopy *ecp)
if (!s->loadable)
continue;
/* Apply global VMA adjustment. */
if (ecp->change_addr != 0)
s->vma += ecp->change_addr;
/* Apply global LMA adjustment. */
if (ecp->change_addr != 0 && s->seg != NULL)
if (ecp->change_addr != 0 && s->seg != NULL &&
s->seg->paddr > 0)
s->lma += ecp->change_addr;
if (!s->pseudo) {
/* Apply global VMA adjustment. */
if (ecp->change_addr != 0)
s->vma += ecp->change_addr;
/* Apply section VMA adjustment. */
sac = lookup_sec_act(ecp, s->name, 0);
if (sac == NULL)
continue;
if (sac->setvma)
s->vma = sac->vma;
if (sac->vma_adjust != 0)
s->vma += sac->vma_adjust;
}
}
/*
* Apply sections LMA change in the second iteration.
* Apply sections VMA change in the second iteration.
*/
TAILQ_FOREACH(s, &ecp->v_sec, sec_list) {
/*
* Only loadable section that's inside a segment can have
* LMA adjusted.
*/
if (!s->loadable || s->seg == NULL)
if (!s->loadable)
continue;
/*
* Check if there is a LMA change request for this
* Check if there is a VMA change request for this
* section.
*/
sac = lookup_sec_act(ecp, s->name, 0);
if (sac == NULL)
continue;
if (!sac->setlma && sac->lma_adjust == 0)
continue;
lma = s->lma;
if (sac->setlma)
lma = sac->lma;
if (sac->lma_adjust != 0)
lma += sac->lma_adjust;
if (lma == s->lma)
vma = s->vma;
if (sac->setvma)
vma = sac->vma;
if (sac->vma_adjust != 0)
vma += sac->vma_adjust;
if (vma == s->vma)
continue;
/*
* Check if the LMA change is viable.
* No need to make segment adjustment if the section doesn't
* belong to any segment.
*/
if (s->seg == NULL) {
s->vma = vma;
continue;
}
/*
* Check if the VMA change is viable.
*
* 1. Check if the new LMA is properly aligned accroding to
* 1. Check if the new VMA is properly aligned accroding to
* section alignment.
*
* 2. Compute the new extent of segment that contains this
@ -170,37 +168,36 @@ adjust_addr(struct elfcopy *ecp)
* segments.
*/
#ifdef DEBUG
printf("LMA for section %s: %#jx\n", s->name, lma);
printf("VMA for section %s: %#jx\n", s->name, vma);
#endif
if (lma % s->align != 0)
errx(EXIT_FAILURE, "The load address %#jx for "
if (vma % s->align != 0)
errx(EXIT_FAILURE, "The VMA %#jx for "
"section %s is not aligned to %ju",
(uintmax_t) lma, s->name, (uintmax_t) s->align);
(uintmax_t) vma, s->name, (uintmax_t) s->align);
if (lma < s->lma) {
if (vma < s->vma) {
/* Move section to lower address. */
if (lma < s->lma - s->seg->addr)
if (vma < s->vma - s->seg->vaddr)
errx(EXIT_FAILURE, "Not enough space to move "
"section %s load address to %#jx", s->name,
(uintmax_t) lma);
start = lma - (s->lma - s->seg->addr);
"section %s VMA to %#jx", s->name,
(uintmax_t) vma);
start = vma - (s->vma - s->seg->vaddr);
if (s == s->seg->v_sec[s->seg->nsec - 1])
end = start + s->seg->msz;
else
end = s->seg->addr + s->seg->msz;
end = s->seg->vaddr + s->seg->msz;
} else {
/* Move section to upper address. */
if (s == s->seg->v_sec[0])
start = lma;
start = vma;
else
start = s->seg->addr;
end = lma + (s->seg->addr + s->seg->msz - s->lma);
start = s->seg->vaddr;
end = vma + (s->seg->vaddr + s->seg->msz - s->vma);
if (end < start)
errx(EXIT_FAILURE, "Not enough space to move "
"section %s load address to %#jx", s->name,
(uintmax_t) lma);
"section %s VMA to %#jx", s->name,
(uintmax_t) vma);
}
#ifdef DEBUG
@ -211,34 +208,34 @@ adjust_addr(struct elfcopy *ecp)
STAILQ_FOREACH(seg, &ecp->v_seg, seg_list) {
if (seg == s->seg || seg->type != PT_LOAD)
continue;
if (start > seg->addr + seg->msz)
if (start > seg->vaddr + seg->msz)
continue;
if (end < seg->addr)
if (end < seg->vaddr)
continue;
errx(EXIT_FAILURE, "The extent of segment containing "
"section %s overlaps with segment(%#jx,%#jx)",
s->name, (uintmax_t) seg->addr,
(uintmax_t) (seg->addr + seg->msz));
s->name, (uintmax_t) seg->vaddr,
(uintmax_t) (seg->vaddr + seg->msz));
}
/*
* Update section LMA and file offset.
* Update section VMA and file offset.
*/
if (lma < s->lma) {
if (vma < s->vma) {
/*
* To move a section to lower load address, we decrease
* the load addresses of the section and all the
* sections that are before it, and we increase the
* file offsets of all the sections that are after it.
* To move a section to lower VMA, we decrease
* the VMA of the section and all the sections that
* are before it, and we increase the file offsets
* of all the sections that are after it.
*/
dl = s->lma - lma;
dl = s->vma - vma;
for (i = 0; i < s->seg->nsec; i++) {
s0 = s->seg->v_sec[i];
s0->lma -= dl;
s0->vma -= dl;
#ifdef DEBUG
printf("section %s LMA set to %#jx\n",
s0->name, (uintmax_t) s0->lma);
printf("section %s VMA set to %#jx\n",
s0->name, (uintmax_t) s0->vma);
#endif
if (s0 == s)
break;
@ -253,13 +250,13 @@ adjust_addr(struct elfcopy *ecp)
}
} else {
/*
* To move a section to upper load address, we increase
* the load addresses of the section and all the
* sections that are after it, and we increase the
* their file offsets too unless the section in question
* To move a section to upper VMA, we increase
* the VMA of the section and all the sections that
* are after it, and we increase the their file
* offsets too unless the section in question
* is the first in its containing segment.
*/
dl = lma - s->lma;
dl = vma - s->vma;
for (i = 0; i < s->seg->nsec; i++)
if (s->seg->v_sec[i] == s)
break;
@ -269,9 +266,9 @@ adjust_addr(struct elfcopy *ecp)
s->name);
for (; i < s->seg->nsec; i++) {
s0 = s->seg->v_sec[i];
s0->lma += dl;
s0->vma += dl;
#ifdef DEBUG
printf("section %s LMA set to %#jx\n",
printf("section %s VMA set to %#jx\n",
s0->name, (uintmax_t) s0->lma);
#endif
if (s != s->seg->v_sec[0]) {
@ -292,9 +289,8 @@ adjust_addr(struct elfcopy *ecp)
if (ecp->pad_to != 0) {
/*
* Find the section with highest load address.
* Find the section with highest VMA.
*/
s = NULL;
STAILQ_FOREACH(seg, &ecp->v_seg, seg_list) {
if (seg->type != PT_LOAD)
@ -308,26 +304,113 @@ adjust_addr(struct elfcopy *ecp)
s = seg->v_sec[i];
else {
s0 = seg->v_sec[i];
if (s0->lma > s->lma)
if (s0->vma > s->vma)
s = s0;
}
}
if (s == NULL)
goto issue_warn;
goto adjust_lma;
/* No need to pad if the pad_to address is lower. */
if (ecp->pad_to <= s->lma + s->sz)
goto issue_warn;
if (ecp->pad_to <= s->vma + s->sz)
goto adjust_lma;
s->pad_sz = ecp->pad_to - (s->lma + s->sz);
s->pad_sz = ecp->pad_to - (s->vma + s->sz);
#ifdef DEBUG
printf("pad section %s load to address %#jx by %#jx\n", s->name,
printf("pad section %s VMA to address %#jx by %#jx\n", s->name,
(uintmax_t) ecp->pad_to, (uintmax_t) s->pad_sz);
#endif
}
issue_warn:
adjust_lma:
/*
* Apply sections LMA change in the third iteration.
*/
TAILQ_FOREACH(s, &ecp->v_sec, sec_list) {
/*
* Only loadable section that's inside a segment can have
* LMA adjusted. Also, if LMA of the containing segment is
* set to 0, it probably means we should ignore the LMA.
*/
if (!s->loadable || s->seg == NULL || s->seg->paddr == 0)
continue;
/*
* Check if there is a LMA change request for this
* section.
*/
sac = lookup_sec_act(ecp, s->name, 0);
if (sac == NULL)
continue;
if (!sac->setlma && sac->lma_adjust == 0)
continue;
lma = s->lma;
if (sac->setlma)
lma = sac->lma;
if (sac->lma_adjust != 0)
lma += sac->lma_adjust;
if (lma == s->lma)
continue;
#ifdef DEBUG
printf("LMA for section %s: %#jx\n", s->name, lma);
#endif
/* Check alignment. */
if (lma % s->align != 0)
errx(EXIT_FAILURE, "The LMA %#jx for "
"section %s is not aligned to %ju",
(uintmax_t) lma, s->name, (uintmax_t) s->align);
/*
* Update section LMA.
*/
if (lma < s->lma) {
/*
* To move a section to lower LMA, we decrease
* the LMA of the section and all the sections that
* are before it.
*/
dl = s->lma - lma;
for (i = 0; i < s->seg->nsec; i++) {
s0 = s->seg->v_sec[i];
s0->lma -= dl;
#ifdef DEBUG
printf("section %s LMA set to %#jx\n",
s0->name, (uintmax_t) s0->lma);
#endif
if (s0 == s)
break;
}
} else {
/*
* To move a section to upper LMA, we increase
* the LMA of the section and all the sections that
* are after it.
*/
dl = lma - s->lma;
for (i = 0; i < s->seg->nsec; i++)
if (s->seg->v_sec[i] == s)
break;
if (i >= s->seg->nsec)
errx(EXIT_FAILURE, "Internal: section `%s' not"
" found in its containing segement",
s->name);
for (; i < s->seg->nsec; i++) {
s0 = s->seg->v_sec[i];
s0->lma += dl;
#ifdef DEBUG
printf("section %s LMA set to %#jx\n",
s0->name, (uintmax_t) s0->lma);
#endif
}
}
}
/*
* Issue a warning if there are VMA/LMA adjust requests for
@ -385,8 +468,7 @@ setup_phdr(struct elfcopy *ecp)
{
struct segment *seg;
GElf_Phdr iphdr;
size_t iphnum;
int i;
size_t iphnum, i;
if (elf_getphnum(ecp->ein, &iphnum) == 0)
errx(EXIT_FAILURE, "elf_getphnum failed: %s",
@ -402,13 +484,14 @@ setup_phdr(struct elfcopy *ecp)
return;
}
for (i = 0; (size_t)i < iphnum; i++) {
for (i = 0; i < iphnum; i++) {
if (gelf_getphdr(ecp->ein, i, &iphdr) != &iphdr)
errx(EXIT_FAILURE, "gelf_getphdr failed: %s",
elf_errmsg(-1));
if ((seg = calloc(1, sizeof(*seg))) == NULL)
err(EXIT_FAILURE, "calloc failed");
seg->addr = iphdr.p_vaddr;
seg->vaddr = iphdr.p_vaddr;
seg->paddr = iphdr.p_paddr;
seg->off = iphdr.p_offset;
seg->fsz = iphdr.p_filesz;
seg->msz = iphdr.p_memsz;
@ -429,20 +512,30 @@ copy_phdr(struct elfcopy *ecp)
if (seg->type == PT_PHDR) {
if (!TAILQ_EMPTY(&ecp->v_sec)) {
s = TAILQ_FIRST(&ecp->v_sec);
if (s->pseudo)
seg->addr = s->lma +
if (s->pseudo) {
seg->vaddr = s->vma +
gelf_fsize(ecp->eout, ELF_T_EHDR,
1, EV_CURRENT);
seg->paddr = s->lma +
gelf_fsize(ecp->eout, ELF_T_EHDR,
1, EV_CURRENT);
}
}
seg->fsz = seg->msz = gelf_fsize(ecp->eout, ELF_T_PHDR,
ecp->ophnum, EV_CURRENT);
continue;
}
if (seg->nsec > 0) {
s = seg->v_sec[0];
seg->vaddr = s->vma;
seg->paddr = s->lma;
}
seg->fsz = seg->msz = 0;
for (i = 0; i < seg->nsec; i++) {
s = seg->v_sec[i];
seg->msz = s->vma + s->sz - seg->addr;
seg->msz = s->vma + s->sz - seg->vaddr;
if (s->type != SHT_NOBITS)
seg->fsz = s->off + s->sz - seg->off;
}
@ -481,8 +574,8 @@ copy_phdr(struct elfcopy *ecp)
elf_errmsg(-1));
ophdr.p_type = iphdr.p_type;
ophdr.p_vaddr = seg->addr;
ophdr.p_paddr = seg->addr;
ophdr.p_vaddr = seg->vaddr;
ophdr.p_paddr = seg->paddr;
ophdr.p_flags = iphdr.p_flags;
ophdr.p_align = iphdr.p_align;
ophdr.p_offset = seg->off;

View File

@ -34,7 +34,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: symbols.c 3376 2016-01-26 18:41:39Z emaste $");
ELFTC_VCSID("$Id: symbols.c 3446 2016-05-03 01:31:17Z emaste $");
/* Symbol table buffer structure. */
struct symbuf {
@ -162,7 +162,7 @@ is_needed_symbol(struct elfcopy *ecp, int i, GElf_Sym *s)
if (BIT_ISSET(ecp->v_rel, i))
return (1);
/* Symbols refered by COMDAT sections are needed. */
/* Symbols referred by COMDAT sections are needed. */
if (BIT_ISSET(ecp->v_grp, i))
return (1);
@ -252,7 +252,7 @@ is_remove_symbol(struct elfcopy *ecp, size_t sc, int i, GElf_Sym *s,
}
/*
* Mark symbols refered by relocation entries.
* Mark symbols referred by relocation entries.
*/
static void
mark_reloc_symbols(struct elfcopy *ecp, size_t sc)
@ -1159,7 +1159,7 @@ lookup_symop_list(struct elfcopy *ecp, const char *name, unsigned int op)
if ((s->op & op) == 0)
continue;
if (name == NULL || !strcmp(name, s->name))
return (s);
return (s);
if ((ecp->flags & WILDCARD) == 0)
continue;

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: findtextrel.c 3359 2016-01-24 17:06:20Z jkoshy $");
ELFTC_VCSID("$Id: findtextrel.c 3461 2016-05-10 18:00:05Z emaste $");
static struct option longopts[] = {
{"help", no_argument, NULL, 'H'},
@ -74,6 +74,10 @@ find_symbol(const char *fn, Elf *e, Elf_Data *d, GElf_Shdr *sh, uintmax_t off)
GElf_Sym sym;
int i, len;
if (sh->sh_entsize == 0) {
warnx("invalid sh_entsize");
return (NULL);
}
len = (int) (d->d_size / sh->sh_entsize);
for (i = 0; i < len; i++) {
if (gelf_getsym(d, i, &sym) != &sym) {
@ -240,6 +244,10 @@ examine_reloc(const char *fn, Elf *e, Elf_Data *d, GElf_Shdr *sh, GElf_Phdr *ph,
int i, j, len;
GElf_Rel rel;
if (sh->sh_entsize == 0) {
warnx("invalid sh_entsize");
return;
}
len = (int) (d->d_size / sh->sh_entsize);
for (i = 0; i < len; i++) {
if (sh->sh_type == SHT_REL) {

View File

@ -1,4 +1,4 @@
# $Id: Makefile 3385 2016-01-31 14:26:26Z jkoshy $
# $Id: Makefile 3407 2016-02-14 17:47:23Z jkoshy $
TOP= ..
@ -45,8 +45,6 @@ LDADD= -lelftc -ldwarf -lelf
CFLAGS+= -I. -I${.CURDIR}
YFLAGS= -d
NOMAN=
.SUFFIXES: .ld .c
.ld.c:
awk -f ld_script.awk ${.ALLSRC} > ${.TARGET}

View File

@ -35,7 +35,7 @@
#include "ld_utils.h"
#include "amd64.h"
ELFTC_VCSID("$Id: amd64.c 3390 2016-02-05 16:15:58Z emaste $");
ELFTC_VCSID("$Id: amd64.c 3419 2016-02-19 20:07:15Z emaste $");
static void _create_plt_reloc(struct ld *ld, struct ld_symbol *lsb,
uint64_t offset);
@ -59,7 +59,6 @@ static void _adjust_reloc(struct ld *ld, struct ld_input_section *is,
struct ld_reloc_entry *lre, struct ld_symbol *lsb, uint8_t *buf);
static void _process_reloc(struct ld *ld, struct ld_input_section *is,
struct ld_reloc_entry *lre, struct ld_symbol *lsb, uint8_t *buf);
static const char *_reloc2str(uint64_t r);
static void _reserve_got_entry(struct ld *ld, struct ld_symbol *lsb, int num);
static void _reserve_gotplt_entry(struct ld *ld, struct ld_symbol *lsb);
static void _reserve_plt_entry(struct ld *ld, struct ld_symbol *lsb);
@ -102,42 +101,6 @@ _get_common_page_size(struct ld *ld)
return (0x1000);
}
static const char *
_reloc2str(uint64_t r)
{
static char s[32];
switch (r) {
case 0: return "R_X86_64_NONE";
case 1: return "R_X86_64_64";
case 2: return "R_X86_64_PC32";
case 3: return "R_X86_64_GOT32";
case 4: return "R_X86_64_PLT32";
case 5: return "R_X86_64_COPY";
case 6: return "R_X86_64_GLOB_DAT";
case 7: return "R_X86_64_JUMP_SLOT";
case 8: return "R_X86_64_RELATIVE";
case 9: return "R_X86_64_GOTPCREL";
case 10: return "R_X86_64_32";
case 11: return "R_X86_64_32S";
case 12: return "R_X86_64_16";
case 13: return "R_X86_64_PC16";
case 14: return "R_X86_64_8";
case 15: return "R_X86_64_PC8";
case 16: return "R_X86_64_DTPMOD64";
case 17: return "R_X86_64_DTPOFF64";
case 18: return "R_X86_64_TPOFF64";
case 19: return "R_X86_64_TLSGD";
case 20: return "R_X86_64_TLSLD";
case 21: return "R_X86_64_DTPOFF32";
case 22: return "R_X86_64_GOTTPOFF";
case 23: return "R_X86_64_TPOFF32";
default:
snprintf(s, sizeof(s), "<unkown: %ju>", (uintmax_t) r);
return (s);
}
}
static int
_is_absolute_reloc(uint64_t r)
{
@ -169,10 +132,12 @@ _warn_pic(struct ld *ld, struct ld_reloc_entry *lre)
if (lsb->lsb_bind != STB_LOCAL)
ld_warn(ld, "relocation %s against `%s' can not be used"
" by runtime linker; recompile with -fPIC",
_reloc2str(lre->lre_type), lsb->lsb_name);
elftc_reloc_type_str(EM_X86_64,
lre->lre_type), lsb->lsb_name);
else
ld_warn(ld, "relocation %s can not be used by runtime linker;"
" recompile with -fPIC", _reloc2str(lre->lre_type));
" recompile with -fPIC", elftc_reloc_type_str(EM_X86_64,
lre->lre_type));
}
static struct ld_input_section *
@ -1009,7 +974,7 @@ _process_reloc(struct ld *ld, struct ld_input_section *is,
default:
ld_warn(ld, "Relocation %s not supported",
_reloc2str(lre->lre_type));
elftc_reloc_type_str(EM_X86_64, lre->lre_type));
break;
}
}

View File

@ -34,7 +34,7 @@
#include "ld_utils.h"
#include "i386.h"
ELFTC_VCSID("$Id: i386.c 3391 2016-02-05 19:43:01Z emaste $");
ELFTC_VCSID("$Id: i386.c 3419 2016-02-19 20:07:15Z emaste $");
static void _create_plt_reloc(struct ld *ld, struct ld_symbol *lsb,
uint64_t offset);
@ -55,7 +55,6 @@ static uint64_t _get_max_page_size(struct ld *ld);
static uint64_t _get_common_page_size(struct ld *ld);
static void _process_reloc(struct ld *ld, struct ld_input_section *is,
struct ld_reloc_entry *lre, struct ld_symbol *lsb, uint8_t *buf);
static const char *_reloc2str(uint64_t r);
static void _reserve_got_entry(struct ld *ld, struct ld_symbol *lsb, int num);
static void _reserve_gotplt_entry(struct ld *ld, struct ld_symbol *lsb);
static void _reserve_plt_entry(struct ld *ld, struct ld_symbol *lsb);
@ -80,50 +79,6 @@ _get_common_page_size(struct ld *ld)
return (0x1000);
}
static const char *
_reloc2str(uint64_t r)
{
static char s[32];
switch (r) {
case 0: return "R_386_NONE";
case 1: return "R_386_32";
case 2: return "R_386_PC32";
case 3: return "R_386_GOT32";
case 4: return "R_386_PLT32";
case 5: return "R_386_COPY";
case 6: return "R_386_GLOB_DAT";
case 7: return "R_386_JUMP_SLOT";
case 8: return "R_386_RELATIVE";
case 9: return "R_386_GOTOFF";
case 10: return "R_386_GOTPC";
case 14: return "R_386_TLS_TPOFF";
case 15: return "R_386_TLS_IE";
case 16: return "R_386_TLS_GOTI";
case 17: return "R_386_TLS_LE";
case 18: return "R_386_TLS_GD";
case 19: return "R_386_TLS_LDM";
case 24: return "R_386_TLS_GD_32";
case 25: return "R_386_TLS_GD_PUSH";
case 26: return "R_386_TLS_GD_CALL";
case 27: return "R_386_TLS_GD_POP";
case 28: return "R_386_TLS_LDM_32";
case 29: return "R_386_TLS_LDM_PUSH";
case 30: return "R_386_TLS_LDM_CALL";
case 31: return "R_386_TLS_LDM_POP";
case 32: return "R_386_TLS_LDO_32";
case 33: return "R_386_TLS_IE_32";
case 34: return "R_386_TLS_LE_32";
case 35: return "R_386_TLS_DTPMOD32";
case 36: return "R_386_TLS_DTPOFF32";
case 37: return "R_386_TLS_TPOFF32";
default:
snprintf(s, sizeof(s), "<unkown: %ju>", (uintmax_t) r);
return (s);
}
}
static int
_is_absolute_reloc(uint64_t r)
{
@ -154,10 +109,11 @@ _warn_pic(struct ld *ld, struct ld_reloc_entry *lre)
if (lsb->lsb_bind != STB_LOCAL)
ld_warn(ld, "relocation %s against `%s' can not be used"
" by runtime linker; recompile with -fPIC",
_reloc2str(lre->lre_type), lsb->lsb_name);
elftc_reloc_type_str(EM_386, lre->lre_type), lsb->lsb_name);
else
ld_warn(ld, "relocation %s can not be used by runtime linker;"
" recompile with -fPIC", _reloc2str(lre->lre_type));
" recompile with -fPIC",
elftc_reloc_type_str(EM_386, lre->lre_type));
}
static struct ld_input_section *

478
ld/ld.1 Normal file
View File

@ -0,0 +1,478 @@
.\" Copyright (c) 2016 Joseph Koshy. 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 and contributors ``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 or
.\" contributors 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.
.\"
.\" $Id$
.\"
.Dd February 14, 2016
.Os
.Dt LD 1
.Sh NAME
.Nm ld
.Nd link editor
.Sh SYNOPSIS
.Nm
.Op Fl \&(
.Op Fl \&)
.Op Fl Bdynamic
.Op Fl Bshareable
.Op Fl Bstatic
.Op Fl I Ar file | Fl -dynamic-linker= Ns Ar file
.Op Fl L Ar dir | Fl -library-path= Ns Ar dir
.Op Fl M | Fl -print-map
.Op Fl T Ar script-file | Fl -script= Ns Ar script-file
.Op Fl V | Fl v | Fl -version
.Op Fl a Ar linkmode
.Op Fl b Ar input-format | Fl -format= Ns Ar input-format
.Op Fl call_shared
.Op Fl d | Fl dc | Fl dp
.Op Fl dn
.Op Fl dy
.Op Fl e Ar symbol | Fl -entry= Ns Ar symbol
.Op Fl h Ar name | Fl soname= Ns Ar name
.Op Fl l Ar library | Fl -library= Ns Ar library
.Op Fl o Ar output-file | Fl -output= Ns Ar output-file
.Op Fl q | Fl -emit-relocs
.Op Fl r | Fl -relocatable
.Op Fl u Ar name | Fl -undefined= Ns Ar name
.Op Fl z Ar keyword
.Op Fl -as-needed
.Op Fl -eh-frame-hdr
.Op Fl -end-group
.Op Fl -gc-sections
.Op Fl -no-as-needed
.Op Fl -no-define-common
.Op Fl -no-gc-sections
.Op Fl -no-print-gc-sections
.Op Fl -no-whole-archive
.Op Fl -oformat= Ns Ar format
.Op Fl -pic-executable | Fl pie
.Op Fl -print-gc-sections
.Op Fl -rpath= Ns Ar dirs
.Op Fl -rpath-link= Ns Ar dirs
.Op Fl -start-group
.Op Fl shared
.Op Fl static
.Op Fl -version-script= Ns Ar script
.Op Fl -whole-archive
.Ar
.Sh DESCRIPTION
The
.Nm
utility combines ELF objects and
.Xr ar 1
archives containing ELF objects into an executable or a partially
relocated object.
.Pp
The
.Nm
utility processes options and files in the order presented on the
command line.
Unlike most
.Ux
utilities, options and file names may be interspersed.
Options seen on the command line will generally apply to subsequent
files, or till overridden by another option.
.Sh OPTIONS
.Pp
The
.Nm
utility supports the following options:
.Bl -tag -width indent
.It Xo
.Fl \&(
.Ar archives Ns ...
.Fl \&)
.Xc
Start a group of archives that are to be searched repeatedly until no new
undefined references are created.
This option is used when there are circular references between one or
more archives in the archive group.
.Pp
The files named by the arguments
.Ar archives
are expected to be archive files.
.Pp
Each use of the
.Fl \&(
option starts a new archive group that is ended by a matching
.Fl \&)
option.
.It Fl Bdynamic
Choose dynamic libraries for the libraries specified by subsequent
.Fl l
options.
.It Fl Bshareable
Create a shared library.
.It Fl Bstatic
Choose static libraries for the libraries specified by subsequent
.Fl l
options.
.It Fl I Ar file | Fl -dynamic-linker= Ns Ar file
Set the name of the dynamic linker when generating ELF executables.
.It Fl L Ar dir | Fl -library-path= Ns Ar dir
Add directory
.Ar dir
to the list of paths that
.Nm
will search for archive libraries.
This option may be specified multiple times.
User supplied directories are searched in the order specified on
the command line.
.It Fl M | Fl -print-map
Print a link map to standard output.
.It Fl T Ar script-file | Fl -script= Ns Ar script-file
Use the file name by argument
.Ar script-file
as the linker script instead of the default.
.It Fl V | Fl v | Fl version
Print a version identifier for
.Nm
and exit.
.It Fl a Ar linkmode
Select linking mode.
The value of the argument
.Ar linkmode
should be one of the following literals:
.Bl -tag -width ".Li default" -compact
.It Cm default
Equivalent to specifying
.Fl Bdynamic .
.It Cm archive
Equivalent to specifying
.Fl Bstatic .
.It Cm shared
Equivalent to specifying
.Fl Bdynamic .
.El
.It Fl b Ar input-format | Fl -format Ar input-format
Set the input format to that specified by argument
.Ar input-format .
The legal values for the argument
.Ar input-format
are those supported by
.Xr elftc_bfd_find_target 3 .
.It Fl d | Fl dc | Fl dp
Assign space for common symbols even if generating a relocatable object.
.It Fl dn
Equivalent to specifying option
.Fl Bstatic .
.It Fl dy
Equivalent to specifying option
.Fl Bdynamic .
.It Fl e Ar entry | Fl -entry Ar entry
Set execution to start at the symbol named by the argument
.Ar entry .
The argument should be the name of a symbol.
.It Fl h Ar name | Fl soname Ar name
Set the
.Li DT_SONAME
field in the object to that specified by the argument
.Ar name .
.It Fl l Ar name | Fl -library= Ns Ar name
Add the archive library or shared library named by argument
.Ar name
to the set of files to link.
This file is looked for in the list of directories specified by prior
.Fl L
options on the command line.
.It Fl o Ar output-file | Fl -output= Ns Ar output-file
Use the file specified by argument
.Ar output-file
for the output, instead of the default file name of
.Sq a.out .
.It Fl q | Fl -emit-relocs
Preserve relocation information in executables, for use by post-link
analysis tools.
.It Fl r | Fl -relocatable
Generate a relocatable output file that can be used as input for subsequent
linker runs.
.It Fl u Ar name | Fl -undefined= Ns Ar name
Add the symbol specified by argument
.Ar name
to the output file as an undefined symbol.
This option may be specified multiple times.
.It Fl z Ar keyword
Recognized keywords include:
.Bl -tag -width ".Li defaultextract" -compact
.It Cm execstack
Require the object to use an executable stack.
.It Cm noexecstack
Do not require the object to use an executable stack.
.El
.It Fl -as-needed
Add
.Li DT_NEEDED
tags for only those shared libraries that satisfy non-weak
unresolved references from object files or other dynamic libraries
seen so far on the command line.
.It Fl call_shared
Equivalent to specifying option
.Fl Bdynamic .
.It Fl -eh-frame-hdr
Create a
.Dq ".eh_frame_hdr"
section, and a
.Li PT_GNU_EH_FRAME
segment header, containing exception handling information.
.It Fl -end-group
Equivalent to specifying option
.Fl \&) .
.It Fl -gc-sections
Garbage collect unused input sections.
.It Fl -no-as-needed
Insert
.Li DT_NEEDED
tags for all shared libraries seen henceforth on the command line,
irrespective of whether the shared library is needed to resolve an
undefined symbol or not.
This behavior is the default.
.It Fl -no-define-common
Do not assign addresses to common symbols.
.It Fl -no-gc-sections
Do not garbage collect input sections that contain unreferenced
symbols.
.It Fl -no-print-gc-sections
Do not print the list of sections removed when the
.Fl -gc-sections
directive is active.
.It Fl -no-whole-archive
Only include objects in an archive that satisfy an unresolved reference
in the link.
This behavior is the default.
.It Fl non_shared
Equivalent to specifying option
.Fl Bstatic .
.It Fl -oformat= Ns Ar format
Set the desired output format to that specified by the argument
.Ar format .
Supported values for argument
.Ar format
are those understood by
.Xr elftc_bfd_find_target 3 .
.It Fl -pic-executable | Fl pie
Create a position-independent executable.
.It Fl -print-gc-sections
Print the list of sections removed when the
.Fl -gc-sections
directive is active.
The output is printed to stderr.
.It Fl -rpath= Ns Ar dirs
Add the colon-separated list of directories named by the argument
.Ar dirs
to the runtime library search path and to the link-time search
path.
.It Fl -rpath-link= Ns Ar dirs
Add the directories specified by the colon-separated list of directories
in argument
.Ar dirs
to the link-time search path for libraries.
The directories specified by this option are searched before those
specified by
.Fl -rpath
options.
.It Fl shared
Equivalent to specifying option
.Fl Bshareable .
.It Fl -start-group
Equivalent to specifying option
.Fl \&( .
.It Fl static
Equivalent to specifying option
.Fl Bstatic .
.It Fl -version-script= Ns Ar script-file
Use the version script in the file named by argument
.Ar script-file .
.It Fl -whole-archive
Include the entire contents of every archive file encountered on the
command line after this option in the link.
.El
.Sh DIAGNOSTICS
.Ex -std
.Sh SEE ALSO
.Xr ar 1 ,
.Xr ranlib 1 ,
.Xr archive 3 ,
.Xr elf 3 ,
.Xr elftc_bfd_find_target 3 ,
.Xr dwarf 3
.Sh IMPLEMENTATION NOTES
The
.Nm
utility differs from its GNU equivalent in the following:
.Bl -bullet
.It
The
.Nm
utility currently supports a limited range of output formats.
.It
The
.Fl e
and
.Fl -entry
options only accept a symbol name as an argument, and not a numeric
address.
.It
The
.Fl l
option only searches files in the directories specified by
prior
.Fl L
options.
.It
The
.Fl T | Fl -script
option does not search for script files in the directories specified
by prior
.Fl L
options.
.It
The
.Fl -rpath
option accepts a colon-separated list of directories instead of
single directory.
.El
.Pp
The following options are recognized, but are currently unimplemented:
.Fl Bgroup ,
.Fl Bsymbolic ,
.Fl Bsymbolic_functions ,
.Fl E ,
.Fl EB ,
.Fl EL ,
.Fl F ,
.Fl Map ,
.Fl N ,
.Fl O ,
.Fl Qy ,
.Fl R ,
.Fl S ,
.Fl Tbss ,
.Fl Tdata ,
.Fl Ttext ,
.Fl X ,
.Fl Y ,
.Fl Ur ,
.Fl c ,
.Fl f ,
.Fl g ,
.Fl i ,
.Fl m ,
.Fl n ,
.Fl s ,
.Fl t ,
.Fl x ,
.Fl y ,
.Fl -accept-unknown-input-arch ,
.Fl -allow-multiple-definition ,
.Fl -allow-shlib-undefined ,
.Fl -assert ,
.Fl -auxiliary ,
.Fl -build-id ,
.Fl -check-sections ,
.Fl -cref ,
.Fl -defsym ,
.Fl -demangle ,
.Fl -disable-new-dtags ,
.Fl -discard-all ,
.Fl -discard-locals ,
.Fl -error-unresolved-symbols ,
.Fl -export-dynamic ,
.Fl -emulation ,
.Fl -enable-new-dtags ,
.Fl -fatal-warnings ,
.Fl -filter ,
.Fl -fini ,
.Fl -hash-style ,
.Fl -help ,
.Fl -init ,
.Fl -just-symbols ,
.Fl -mri-script ,
.Fl -nmagic ,
.Fl nostdlib ,
.Fl -no-accept-unknown-input-arch ,
.Fl -no-allow-shlib-undefined ,
.Fl -no-assert ,
.Fl -no-check-sections ,
.Fl -no-demangle ,
.Fl -no-keep-memory ,
.Fl -no-omagic ,
.Fl -no-undefined ,
.Fl -no-undefined-version ,
.Fl -no-warn-mismatch ,
.Fl -omagic ,
.Fl -qmagic ,
.Fl -relax ,
.Fl -retain-symbols-file ,
.Fl -runpath ,
.Fl -section-start ,
.Fl -sort-common ,
.Fl -split-by-file ,
.Fl -split-by-reloc ,
.Fl -stats ,
.Fl -strip-all ,
.Fl -strip-debug ,
.Fl -trace ,
.Fl -trace_symbol ,
.Fl -traditional-format ,
.Fl -unique ,
.Fl -unresolved-symbols ,
.Fl -verbose ,
.Fl -warn-common ,
.Fl -warn-constructors ,
.Fl -warn-multiple-gp ,
.Fl -warn-once ,
.Fl -warn-section-align ,
.Fl -warn-shared-textrel ,
.Fl -warn-unresolved-symbols ,
.Fl -wrap .
.Pp
The following keywords are recognized by the
.Fl z
option, but are currently unimplemented:
.Cm allextract ,
.Cm defaultextract ,
.Cm defs ,
.Cm ignore ,
.Cm initfirst ,
.Cm lazyload ,
.Cm muldefs ,
.Cm nodefaultlib ,
.Cm nodefs ,
.Cm nodelete ,
.Cm nodlopen ,
.Cm nolazyload ,
.Cm now ,
.Cm origin ,
.Cm record ,
.Cm systemlibrary ,
.Cm weakextract .
.Sh HISTORY
A
.Nm
command first appeared in AT&T UNIX Version 1.
.Pp
The Elftoolchain implementation of
.Nm
was written by
.An Kai Wang Aq Mt kaiwang27@gmail.com .

View File

@ -32,7 +32,7 @@
#include "ld_options.h"
#include "ld_output.h"
ELFTC_VCSID("$Id: ld_options.c 2926 2013-03-17 22:53:54Z kaiwang27 $");
ELFTC_VCSID("$Id: ld_options.c 3406 2016-02-14 17:45:43Z jkoshy $");
/*
* Support routines for parsing command line options.
@ -94,7 +94,7 @@ static struct ld_option ld_opts[] = {
{"no-define-common", KEY_NO_DEFINE_COMMON, ANY_DASH, NO_ARG},
{"no-demangle", KEY_NO_DEMANGLE, ANY_DASH, OPT_ARG},
{"no-gc-sections", KEY_NO_GC_SECTIONS, ANY_DASH, NO_ARG},
{"no-keep-memorg", KEY_NO_KEEP_MEMORY, ANY_DASH, NO_ARG},
{"no-keep-memory", KEY_NO_KEEP_MEMORY, ANY_DASH, NO_ARG},
{"no-omagic", KEY_NO_OMAGIC, ANY_DASH, NO_ARG},
{"no-print-gc-sections", KEY_NO_PRINT_GC_SECTIONS, ANY_DASH, NO_ARG},
{"no-undefined", KEY_Z_DEFS, ANY_DASH, NO_ARG},
@ -118,7 +118,7 @@ static struct ld_option ld_opts[] = {
{"runpath", KEY_RUNPATH, ANY_DASH, REQ_ARG},
{"script", 'T', ANY_DASH, REQ_ARG},
{"section-start", KEY_SECTION_START, ANY_DASH, REQ_ARG},
{"shared", KEY_SHARED, ANY_DASH, NO_ARG},
{"shared", KEY_SHARED, ONE_DASH, NO_ARG},
{"soname", 'h', ONE_DASH, REQ_ARG},
{"sort-common", KEY_SORT_COMMON, ANY_DASH, NO_ARG},
{"split-by-file", KEY_SPLIT_BY_FILE, ANY_DASH, REQ_ARG},
@ -134,8 +134,8 @@ static struct ld_option ld_opts[] = {
{"undefined", 'u', ANY_DASH, REQ_ARG},
{"unique", KEY_UNIQUE, ANY_DASH, OPT_ARG},
{"unresolved-symbols", KEY_UNRESOLVED_SYMBOLS, ANY_DASH, REQ_ARG},
{"verbose" , 'v', ANY_DASH, NO_ARG},
{"version", KEY_VERSION, ANY_DASH, NO_ARG},
{"verbose" , KEY_VERBOSE, ANY_DASH, NO_ARG},
{"version", 'V', ANY_DASH, NO_ARG},
{"version-script", KEY_VERSION_SCRIPT, ANY_DASH, REQ_ARG},
{"warn-common", KEY_WARN_COMMON, ANY_DASH, NO_ARG},
{"warn-constructors", KEY_WARN_CONSTRUCTORS, ANY_DASH, NO_ARG},
@ -144,7 +144,7 @@ static struct ld_option ld_opts[] = {
{"warn-section-align", KEY_WARN_SECTION_ALIGN, ANY_DASH, NO_ARG},
{"warn-shared-textrel", KEY_WARN_SHARED_TEXTREL, ANY_DASH, NO_ARG},
{"warn-unresolved-symbols", KEY_WARN_UNRESOLVE_SYM, ANY_DASH, NO_ARG},
{"whole_archive", KEY_WHOLE_ARCHIVE, ANY_DASH, NO_ARG},
{"whole-archive", KEY_WHOLE_ARCHIVE, ANY_DASH, NO_ARG},
{"wrap", KEY_WRAP, ANY_DASH, REQ_ARG},
{"EB", KEY_EB, ONE_DASH, NO_ARG},
{"EL", KEY_EL, ONE_DASH, NO_ARG},

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: ld_options.h 2894 2013-01-15 23:05:24Z kaiwang27 $
* $Id: ld_options.h 3405 2016-02-14 10:56:34Z jkoshy $
*/
enum ld_dash {
@ -103,7 +103,7 @@ enum ld_key {
KEY_UNRESOLVED_SYMBOLS,
KEY_UNIQUE,
KEY_UR,
KEY_VERSION,
KEY_VERBOSE,
KEY_VERSION_SCRIPT,
KEY_WARN_COMMON,
KEY_WARN_CONSTRUCTORS,

View File

@ -27,7 +27,7 @@
#include "_libdwarf.h"
ELFTC_VCSID("$Id: libdwarf_abbrev.c 3136 2014-12-24 16:04:38Z kaiwang27 $");
ELFTC_VCSID("$Id: libdwarf_abbrev.c 3420 2016-02-27 02:14:05Z emaste $");
int
_dwarf_abbrev_add(Dwarf_CU cu, uint64_t entry, uint64_t tag, uint8_t children,
@ -115,9 +115,7 @@ _dwarf_abbrev_parse(Dwarf_Debug dbg, Dwarf_CU cu, Dwarf_Unsigned *offset,
assert(abp != NULL);
ds = _dwarf_find_section(dbg, ".debug_abbrev");
assert(ds != NULL);
if (*offset >= ds->ds_size)
if (ds == NULL || *offset >= ds->ds_size)
return (DW_DLE_NO_ENTRY);
aboff = *offset;

View File

@ -26,7 +26,7 @@
#include "_libdwarf.h"
ELFTC_VCSID("$Id: libdwarf_elf_init.c 3161 2015-02-15 21:43:36Z emaste $");
ELFTC_VCSID("$Id: libdwarf_elf_init.c 3475 2016-05-18 18:11:26Z emaste $");
static const char *debug_name[] = {
".debug_abbrev",
@ -50,46 +50,81 @@ static const char *debug_name[] = {
};
static void
_dwarf_elf_write_reloc(Dwarf_Debug dbg, Elf_Data *symtab_data, int endian,
void *buf, uint64_t offset, GElf_Xword r_info, GElf_Sxword r_addend)
{
GElf_Sym sym;
int size;
if (gelf_getsym(symtab_data, GELF_R_SYM(r_info), &sym) == NULL)
return;
if ((size = _dwarf_get_reloc_size(dbg, GELF_R_TYPE(r_info))) == 0)
return; /* Unknown or non-absolute relocation. */
if (endian == ELFDATA2MSB)
_dwarf_write_msb(buf, &offset, sym.st_value + r_addend, size);
else
_dwarf_write_lsb(buf, &offset, sym.st_value + r_addend, size);
}
static void
_dwarf_elf_apply_rel_reloc(Dwarf_Debug dbg, void *buf, Elf_Data *rel_data,
Elf_Data *symtab_data, int endian)
_dwarf_elf_apply_rel_reloc(Dwarf_Debug dbg, void *buf, uint64_t bufsize,
Elf_Data *rel_data, Elf_Data *symtab_data, int endian)
{
Dwarf_Unsigned type;
GElf_Rel rel;
int j;
GElf_Sym sym;
size_t symndx;
uint64_t offset;
uint64_t addend;
int size, j;
j = 0;
while (gelf_getrel(rel_data, j++, &rel) != NULL)
_dwarf_elf_write_reloc(dbg, symtab_data, endian, buf,
rel.r_offset, rel.r_info, 0);
while (gelf_getrel(rel_data, j++, &rel) != NULL) {
symndx = GELF_R_SYM(rel.r_info);
type = GELF_R_TYPE(rel.r_info);
if (gelf_getsym(symtab_data, symndx, &sym) == NULL)
continue;
size = _dwarf_get_reloc_size(dbg, type);
if (size == 0)
continue; /* Unknown or non-absolute relocation. */
offset = rel.r_offset;
if (offset + size >= bufsize)
continue;
if (endian == ELFDATA2MSB)
addend = _dwarf_read_msb(buf, &offset, size);
else
addend = _dwarf_read_lsb(buf, &offset, size);
offset = rel.r_offset;
if (endian == ELFDATA2MSB)
_dwarf_write_msb(buf, &offset, sym.st_value + addend,
size);
else
_dwarf_write_lsb(buf, &offset, sym.st_value + addend,
size);
}
}
static void
_dwarf_elf_apply_rela_reloc(Dwarf_Debug dbg, void *buf, Elf_Data *rel_data,
Elf_Data *symtab_data, int endian)
_dwarf_elf_apply_rela_reloc(Dwarf_Debug dbg, void *buf, uint64_t bufsize,
Elf_Data *rel_data, Elf_Data *symtab_data, int endian)
{
Dwarf_Unsigned type;
GElf_Rela rela;
int j;
GElf_Sym sym;
size_t symndx;
uint64_t offset;
int size, j;
j = 0;
while (gelf_getrela(rel_data, j++, &rela) != NULL)
_dwarf_elf_write_reloc(dbg, symtab_data, endian, buf,
rela.r_offset, rela.r_info, rela.r_addend);
while (gelf_getrela(rel_data, j++, &rela) != NULL) {
symndx = GELF_R_SYM(rela.r_info);
type = GELF_R_TYPE(rela.r_info);
if (gelf_getsym(symtab_data, symndx, &sym) == NULL)
continue;
offset = rela.r_offset;
size = _dwarf_get_reloc_size(dbg, type);
if (size == 0)
continue; /* Unknown or non-absolute relocation. */
if (offset + size >= bufsize)
continue;
if (endian == ELFDATA2MSB)
_dwarf_write_msb(buf, &offset,
sym.st_value + rela.r_addend, size);
else
_dwarf_write_lsb(buf, &offset,
sym.st_value + rela.r_addend, size);
}
}
static int
@ -141,10 +176,12 @@ _dwarf_elf_relocate(Dwarf_Debug dbg, Elf *elf, Dwarf_Elf_Data *ed, size_t shndx,
memcpy(ed->ed_alloc, ed->ed_data->d_buf,
ed->ed_data->d_size);
if (sh.sh_type == SHT_REL)
_dwarf_elf_apply_rel_reloc(dbg, ed->ed_alloc,
_dwarf_elf_apply_rel_reloc(dbg,
ed->ed_alloc, ed->ed_data->d_size,
rel, symtab_data, eh.e_ident[EI_DATA]);
else
_dwarf_elf_apply_rela_reloc(dbg, ed->ed_alloc,
_dwarf_elf_apply_rela_reloc(dbg,
ed->ed_alloc, ed->ed_data->d_size,
rel, symtab_data, eh.e_ident[EI_DATA]);
return (DW_DLE_NONE);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: _libelf_config.h 3396 2016-02-10 21:50:05Z emaste $
* $Id: _libelf_config.h 3400 2016-02-12 18:38:49Z emaste $
*/
#if defined(__APPLE__) || defined(__DragonFly__)
@ -99,9 +99,9 @@
#elif defined(__riscv64)
#define LIBELF_ARCH EM_RISCV
#define LIBELF_BYTEORDER ELFDATA2LSB
#define LIBELF_CLASS ELFCLASS64
#define LIBELF_ARCH EM_RISCV
#define LIBELF_BYTEORDER ELFDATA2LSB
#define LIBELF_CLASS ELFCLASS64
#elif defined(__sparc__)

View File

@ -32,7 +32,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: elf_data.c 3258 2015-11-20 18:59:43Z emaste $");
ELFTC_VCSID("$Id: elf_data.c 3466 2016-05-11 18:35:44Z emaste $");
Elf_Data *
elf_getdata(Elf_Scn *s, Elf_Data *ed)
@ -94,7 +94,7 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST ||
elftype > ELF_T_LAST || (sh_type != SHT_NOBITS &&
sh_offset + sh_size > (uint64_t) e->e_rawsize)) {
(sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset))) {
LIBELF_SET_ERROR(SECTION, 0);
return (NULL);
}
@ -254,7 +254,7 @@ elf_rawdata(Elf_Scn *s, Elf_Data *ed)
}
if (sh_type != SHT_NOBITS &&
sh_offset + sh_size > (uint64_t) e->e_rawsize) {
(sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset)) {
LIBELF_SET_ERROR(SECTION, 0);
return (NULL);
}

View File

@ -33,7 +33,7 @@
#include "_libelf.h"
#include "_libelf_ar.h"
ELFTC_VCSID("$Id: libelf_ar.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: libelf_ar.c 3446 2016-05-03 01:31:17Z emaste $");
#define LIBELF_NALLOC_SIZE 16
@ -64,7 +64,7 @@ ELFTC_VCSID("$Id: libelf_ar.c 3174 2015-03-27 17:13:41Z emaste $");
* table where the actual file name of the object starts. Strings in
* the string table are padded to start on even addresses.
*
* In the BSD format, file names can be upto 16 characters. File
* In the BSD format, file names can be up to 16 characters. File
* names shorter than 16 characters are padded to 16 characters using
* (ASCII) space characters. File names with embedded spaces and file
* names longer than 16 characters are stored immediately after the

View File

@ -30,7 +30,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_convert.m4 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: libelf_convert.m4 3429 2016-03-12 04:12:39Z emaste $");
/* WARNING: GENERATED FROM __file__. */
@ -1019,6 +1019,7 @@ _libelf_cvt_NOTE_tof(unsigned char *dst, size_t dsz, unsigned char *src,
WRITE_WORD(dst, type);
src += sizeof(Elf_Note);
count -= sizeof(Elf_Note);
if (count < sz)
sz = count;

View File

@ -1,4 +1,4 @@
# $Id: Makefile 3292 2016-01-06 21:46:32Z jkoshy $
# $Id: Makefile 3418 2016-02-19 20:04:42Z emaste $
TOP= ${.CURDIR}/..
@ -7,6 +7,7 @@ LIB= elftc
SRCS= elftc_bfdtarget.c \
elftc_copyfile.c \
elftc_demangle.c \
elftc_reloc_type_str.c \
elftc_set_timestamps.c \
elftc_string_table.c \
elftc_version.c \
@ -34,6 +35,7 @@ MAN= elftc.3 \
elftc_bfd_find_target.3 \
elftc_copyfile.3 \
elftc_demangle.3 \
elftc_reloc_type_str.3 \
elftc_set_timestamps.3 \
elftc_string_table_create.3 \
elftc_version.3

View File

@ -0,0 +1,72 @@
.\" Copyright (c) 2016 The FreeBSD Foundation. All rights reserved.
.\"
.\" This documentation was written by Ed Maste under sponsorship of
.\" the FreeBSD Foundation.
.\"
.\" 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 and contributors ``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 or contributors 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.
.\"
.\" $Id$
.\"
.Dd February 19, 2016
.Os
.Dt ELFTC_RELOC_TYPE_STR 3
.Sh NAME
.Nm elftc_reloc_type_str
.Nd return the type name for an ELF relocation
.Sh LIBRARY
.Lb libelftc
.Sh SYNOPSIS
.In libelftc.h
.Ft const char *
.Fo elftc_reloc_type_str
.Fa "unsigned int mach"
.Fa "unsigned int type"
.Fc
.Sh DESCRIPTION
Function
.Fn elftc_reloc_type_str
returns the name for specified relocation type.
.Pp
Argument
.Ar mach
specifies the machine (architecture) type.
Argument
.Ar type
specifies the relocation value.
.Sh RETURN VALUE
Function
.Fn elftc_program_version
returns a pointer to a string constant, or to an internal character buffer
if the relocation type is unknown.
.Sh EXAMPLES
To print ARM relocation type 7, use:
.Bd -literal -offset indent
#include <sys/types.h>
#include <libelftc.h>
#include <stdio.h>
(void) printf("%s\en", elftc_reloc_type_str(EM_ARM, 7));
.Ed
.Sh ERRORS
Function
.Fn elftc_reloc_type_str
always succeeds.

View File

@ -0,0 +1,684 @@
/*-
* Copyright (c) 2009-2015 Kai Wang
* Copyright (c) 2016 The FreeBSD Foundation
* All rights reserved.
*
* Portions of this software were developed by Ed Maste under sponsorship
* of the FreeBSD Foundation.
*
* 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*/
#include <libelftc.h>
#include <stdio.h>
const char *
elftc_reloc_type_str(unsigned int mach, unsigned int type)
{
static char s_type[32];
switch(mach) {
case EM_386:
case EM_IAMCU:
switch(type) {
case 0: return "R_386_NONE";
case 1: return "R_386_32";
case 2: return "R_386_PC32";
case 3: return "R_386_GOT32";
case 4: return "R_386_PLT32";
case 5: return "R_386_COPY";
case 6: return "R_386_GLOB_DAT";
case 7: return "R_386_JUMP_SLOT";
case 8: return "R_386_RELATIVE";
case 9: return "R_386_GOTOFF";
case 10: return "R_386_GOTPC";
case 11: return "R_386_32PLT"; /* Not in psabi */
case 14: return "R_386_TLS_TPOFF";
case 15: return "R_386_TLS_IE";
case 16: return "R_386_TLS_GOTIE";
case 17: return "R_386_TLS_LE";
case 18: return "R_386_TLS_GD";
case 19: return "R_386_TLS_LDM";
case 20: return "R_386_16";
case 21: return "R_386_PC16";
case 22: return "R_386_8";
case 23: return "R_386_PC8";
case 24: return "R_386_TLS_GD_32";
case 25: return "R_386_TLS_GD_PUSH";
case 26: return "R_386_TLS_GD_CALL";
case 27: return "R_386_TLS_GD_POP";
case 28: return "R_386_TLS_LDM_32";
case 29: return "R_386_TLS_LDM_PUSH";
case 30: return "R_386_TLS_LDM_CALL";
case 31: return "R_386_TLS_LDM_POP";
case 32: return "R_386_TLS_LDO_32";
case 33: return "R_386_TLS_IE_32";
case 34: return "R_386_TLS_LE_32";
case 35: return "R_386_TLS_DTPMOD32";
case 36: return "R_386_TLS_DTPOFF32";
case 37: return "R_386_TLS_TPOFF32";
case 38: return "R_386_SIZE32";
case 39: return "R_386_TLS_GOTDESC";
case 40: return "R_386_TLS_DESC_CALL";
case 41: return "R_386_TLS_DESC";
case 42: return "R_386_IRELATIVE";
case 43: return "R_386_GOT32X";
}
break;
case EM_AARCH64:
switch(type) {
case 0: return "R_AARCH64_NONE";
case 257: return "R_AARCH64_ABS64";
case 258: return "R_AARCH64_ABS32";
case 259: return "R_AARCH64_ABS16";
case 260: return "R_AARCH64_PREL64";
case 261: return "R_AARCH64_PREL32";
case 262: return "R_AARCH64_PREL16";
case 263: return "R_AARCH64_MOVW_UABS_G0";
case 264: return "R_AARCH64_MOVW_UABS_G0_NC";
case 265: return "R_AARCH64_MOVW_UABS_G1";
case 266: return "R_AARCH64_MOVW_UABS_G1_NC";
case 267: return "R_AARCH64_MOVW_UABS_G2";
case 268: return "R_AARCH64_MOVW_UABS_G2_NC";
case 269: return "R_AARCH64_MOVW_UABS_G3";
case 270: return "R_AARCH64_MOVW_SABS_G0";
case 271: return "R_AARCH64_MOVW_SABS_G1";
case 272: return "R_AARCH64_MOVW_SABS_G2";
case 273: return "R_AARCH64_LD_PREL_LO19";
case 274: return "R_AARCH64_ADR_PREL_LO21";
case 275: return "R_AARCH64_ADR_PREL_PG_HI21";
case 276: return "R_AARCH64_ADR_PREL_PG_HI21_NC";
case 277: return "R_AARCH64_ADD_ABS_LO12_NC";
case 278: return "R_AARCH64_LDST8_ABS_LO12_NC";
case 279: return "R_AARCH64_TSTBR14";
case 280: return "R_AARCH64_CONDBR19";
case 282: return "R_AARCH64_JUMP26";
case 283: return "R_AARCH64_CALL26";
case 284: return "R_AARCH64_LDST16_ABS_LO12_NC";
case 285: return "R_AARCH64_LDST32_ABS_LO12_NC";
case 286: return "R_AARCH64_LDST64_ABS_LO12_NC";
case 287: return "R_AARCH64_MOVW_PREL_G0";
case 288: return "R_AARCH64_MOVW_PREL_G0_NC";
case 289: return "R_AARCH64_MOVW_PREL_G1";
case 290: return "R_AARCH64_MOVW_PREL_G1_NC";
case 291: return "R_AARCH64_MOVW_PREL_G2";
case 292: return "R_AARCH64_MOVW_PREL_G2_NC";
case 293: return "R_AARCH64_MOVW_PREL_G3";
case 299: return "R_AARCH64_LDST128_ABS_LO12_NC";
case 300: return "R_AARCH64_MOVW_GOTOFF_G0";
case 301: return "R_AARCH64_MOVW_GOTOFF_G0_NC";
case 302: return "R_AARCH64_MOVW_GOTOFF_G1";
case 303: return "R_AARCH64_MOVW_GOTOFF_G1_NC";
case 304: return "R_AARCH64_MOVW_GOTOFF_G2";
case 305: return "R_AARCH64_MOVW_GOTOFF_G2_NC";
case 306: return "R_AARCH64_MOVW_GOTOFF_G3";
case 307: return "R_AARCH64_GOTREL64";
case 308: return "R_AARCH64_GOTREL32";
case 309: return "R_AARCH64_GOT_LD_PREL19";
case 310: return "R_AARCH64_LD64_GOTOFF_LO15";
case 311: return "R_AARCH64_ADR_GOT_PAGE";
case 312: return "R_AARCH64_LD64_GOT_LO12_NC";
case 313: return "R_AARCH64_LD64_GOTPAGE_LO15";
case 560: return "R_AARCH64_TLSDESC_LD_PREL19";
case 561: return "R_AARCH64_TLSDESC_ADR_PREL21";
case 562: return "R_AARCH64_TLSDESC_ADR_PAGE21";
case 563: return "R_AARCH64_TLSDESC_LD64_LO12";
case 564: return "R_AARCH64_TLSDESC_ADD_LO12";
case 565: return "R_AARCH64_TLSDESC_OFF_G1";
case 566: return "R_AARCH64_TLSDESC_OFF_G0_NC";
case 567: return "R_AARCH64_TLSDESC_LDR";
case 568: return "R_AARCH64_TLSDESC_ADD";
case 569: return "R_AARCH64_TLSDESC_CALL";
case 1024: return "R_AARCH64_COPY";
case 1025: return "R_AARCH64_GLOB_DAT";
case 1026: return "R_AARCH64_JUMP_SLOT";
case 1027: return "R_AARCH64_RELATIVE";
case 1028: return "R_AARCH64_TLS_DTPREL64";
case 1029: return "R_AARCH64_TLS_DTPMOD64";
case 1030: return "R_AARCH64_TLS_TPREL64";
case 1031: return "R_AARCH64_TLSDESC";
case 1032: return "R_AARCH64_IRELATIVE";
}
break;
case EM_ARM:
switch(type) {
case 0: return "R_ARM_NONE";
case 1: return "R_ARM_PC24"; /* Deprecated */
case 2: return "R_ARM_ABS32";
case 3: return "R_ARM_REL32";
case 4: return "R_ARM_LDR_PC_G0"; /* Also R_ARM_PC13 */
case 5: return "R_ARM_ABS16";
case 6: return "R_ARM_ABS12";
case 7: return "R_ARM_THM_ABS5";
case 8: return "R_ARM_ABS8";
case 9: return "R_ARM_SBREL32";
case 10: return "R_ARM_THM_CALL"; /* Also R_ARM_THM_PC22 */
case 11: return "R_ARM_THM_PC8";
case 12: return "R_ARM_BREL_ADJ"; /* Also R_ARM_AMP_VCALL9 */
case 13: return "R_ARM_TLS_DESC"; /* Also R_ARM_SWI24 */
case 14: return "R_ARM_THM_SWI8"; /* Obsolete */
case 15: return "R_ARM_XPC25"; /* Obsolete */
case 16: return "R_ARM_THM_XPC22"; /* Obsolete */
case 17: return "R_ARM_TLS_DTPMOD32";
case 18: return "R_ARM_TLS_DTPOFF32";
case 19: return "R_ARM_TLS_TPOFF32";
case 20: return "R_ARM_COPY";
case 21: return "R_ARM_GLOB_DAT";
case 22: return "R_ARM_JUMP_SLOT";
case 23: return "R_ARM_RELATIVE";
case 24: return "R_ARM_GOTOFF32"; /* Also R_ARM_GOTOFF */
case 25: return "R_ARM_BASE_PREL"; /* GNU R_ARM_GOTPC */
case 26: return "R_ARM_GOT_BREL"; /* GNU R_ARM_GOT32 */
case 27: return "R_ARM_PLT32"; /* Deprecated */
case 28: return "R_ARM_CALL";
case 29: return "R_ARM_JUMP24";
case 30: return "R_ARM_THM_JUMP24";
case 31: return "R_ARM_BASE_ABS";
case 32: return "R_ARM_ALU_PCREL_7_0"; /* Obsolete */
case 33: return "R_ARM_ALU_PCREL_15_8"; /* Obsolete */
case 34: return "R_ARM_ALU_PCREL_23_15"; /* Obsolete */
case 35: return "R_ARM_LDR_SBREL_11_0_NC"; /* Deprecated */
case 36: return "R_ARM_ALU_SBREL_19_12_NC"; /* Deprecated */
case 37: return "R_ARM_ALU_SBREL_27_20_CK"; /* Deprecated */
case 38: return "R_ARM_TARGET1";
case 39: return "R_ARM_SBREL31"; /* Deprecated. */
case 40: return "R_ARM_V4BX";
case 41: return "R_ARM_TARGET2";
case 42: return "R_ARM_PREL31";
case 43: return "R_ARM_MOVW_ABS_NC";
case 44: return "R_ARM_MOVT_ABS";
case 45: return "R_ARM_MOVW_PREL_NC";
case 46: return "R_ARM_MOVT_PREL";
case 47: return "R_ARM_THM_MOVW_ABS_NC";
case 48: return "R_ARM_THM_MOVT_ABS";
case 49: return "R_ARM_THM_MOVW_PREL_NC";
case 50: return "R_ARM_THM_MOVT_PREL";
case 51: return "R_ARM_THM_JUMP19";
case 52: return "R_ARM_THM_JUMP6";
case 53: return "R_ARM_THM_ALU_PREL_11_0";
case 54: return "R_ARM_THM_PC12";
case 55: return "R_ARM_ABS32_NOI";
case 56: return "R_ARM_REL32_NOI";
case 57: return "R_ARM_ALU_PC_G0_NC";
case 58: return "R_ARM_ALU_PC_G0";
case 59: return "R_ARM_ALU_PC_G1_NC";
case 60: return "R_ARM_ALU_PC_G1";
case 61: return "R_ARM_ALU_PC_G2";
case 62: return "R_ARM_LDR_PC_G1";
case 63: return "R_ARM_LDR_PC_G2";
case 64: return "R_ARM_LDRS_PC_G0";
case 65: return "R_ARM_LDRS_PC_G1";
case 66: return "R_ARM_LDRS_PC_G2";
case 67: return "R_ARM_LDC_PC_G0";
case 68: return "R_ARM_LDC_PC_G1";
case 69: return "R_ARM_LDC_PC_G2";
case 70: return "R_ARM_ALU_SB_G0_NC";
case 71: return "R_ARM_ALU_SB_G0";
case 72: return "R_ARM_ALU_SB_G1_NC";
case 73: return "R_ARM_ALU_SB_G1";
case 74: return "R_ARM_ALU_SB_G2";
case 75: return "R_ARM_LDR_SB_G0";
case 76: return "R_ARM_LDR_SB_G1";
case 77: return "R_ARM_LDR_SB_G2";
case 78: return "R_ARM_LDRS_SB_G0";
case 79: return "R_ARM_LDRS_SB_G1";
case 80: return "R_ARM_LDRS_SB_G2";
case 81: return "R_ARM_LDC_SB_G0";
case 82: return "R_ARM_LDC_SB_G1";
case 83: return "R_ARM_LDC_SB_G2";
case 84: return "R_ARM_MOVW_BREL_NC";
case 85: return "R_ARM_MOVT_BREL";
case 86: return "R_ARM_MOVW_BREL";
case 87: return "R_ARM_THM_MOVW_BREL_NC";
case 88: return "R_ARM_THM_MOVT_BREL";
case 89: return "R_ARM_THM_MOVW_BREL";
case 90: return "R_ARM_TLS_GOTDESC";
case 91: return "R_ARM_TLS_CALL";
case 92: return "R_ARM_TLS_DESCSEQ";
case 93: return "R_ARM_THM_TLS_CALL";
case 94: return "R_ARM_PLT32_ABS";
case 95: return "R_ARM_GOT_ABS";
case 96: return "R_ARM_GOT_PREL";
case 97: return "R_ARM_GOT_BREL12";
case 98: return "R_ARM_GOTOFF12";
case 99: return "R_ARM_GOTRELAX";
case 100: return "R_ARM_GNU_VTENTRY";
case 101: return "R_ARM_GNU_VTINHERIT";
case 102: return "R_ARM_THM_JUMP11"; /* Also R_ARM_THM_PC11 */
case 103: return "R_ARM_THM_JUMP8"; /* Also R_ARM_THM_PC9 */
case 104: return "R_ARM_TLS_GD32";
case 105: return "R_ARM_TLS_LDM32";
case 106: return "R_ARM_TLS_LDO32";
case 107: return "R_ARM_TLS_IE32";
case 108: return "R_ARM_TLS_LE32";
case 109: return "R_ARM_TLS_LDO12";
case 110: return "R_ARM_TLS_LE12";
case 111: return "R_ARM_TLS_IE12GP";
/* 112-127 R_ARM_PRIVATE_<n> */
case 128: return "R_ARM_ME_TOO"; /* Obsolete */
case 129: return "R_ARM_THM_TLS_DESCSEQ16";
case 130: return "R_ARM_THM_TLS_DESCSEQ32";
case 131: return "R_ARM_THM_GOT_BREL12";
case 132: return "R_ARM_THM_ALU_ABS_G0_NC";
case 133: return "R_ARM_THM_ALU_ABS_G1_NC";
case 134: return "R_ARM_THM_ALU_ABS_G2_NC";
case 135: return "R_ARM_THM_ALU_ABS_G3";
/* 136-159 Reserved for future allocation. */
case 160: return "R_ARM_IRELATIVE";
/* 161-255 Reserved for future allocation. */
case 249: return "R_ARM_RXPC25";
case 250: return "R_ARM_RSBREL32";
case 251: return "R_ARM_THM_RPC22";
case 252: return "R_ARM_RREL32";
case 253: return "R_ARM_RABS32";
case 254: return "R_ARM_RPC24";
case 255: return "R_ARM_RBASE";
}
break;
case EM_IA_64:
switch(type) {
case 0: return "R_IA_64_NONE";
case 33: return "R_IA_64_IMM14";
case 34: return "R_IA_64_IMM22";
case 35: return "R_IA_64_IMM64";
case 36: return "R_IA_64_DIR32MSB";
case 37: return "R_IA_64_DIR32LSB";
case 38: return "R_IA_64_DIR64MSB";
case 39: return "R_IA_64_DIR64LSB";
case 42: return "R_IA_64_GPREL22";
case 43: return "R_IA_64_GPREL64I";
case 44: return "R_IA_64_GPREL32MSB";
case 45: return "R_IA_64_GPREL32LSB";
case 46: return "R_IA_64_GPREL64MSB";
case 47: return "R_IA_64_GPREL64LSB";
case 50: return "R_IA_64_LTOFF22";
case 51: return "R_IA_64_LTOFF64I";
case 58: return "R_IA_64_PLTOFF22";
case 59: return "R_IA_64_PLTOFF64I";
case 62: return "R_IA_64_PLTOFF64MSB";
case 63: return "R_IA_64_PLTOFF64LSB";
case 67: return "R_IA_64_FPTR64I";
case 68: return "R_IA_64_FPTR32MSB";
case 69: return "R_IA_64_FPTR32LSB";
case 70: return "R_IA_64_FPTR64MSB";
case 71: return "R_IA_64_FPTR64LSB";
case 72: return "R_IA_64_PCREL60B";
case 73: return "R_IA_64_PCREL21B";
case 74: return "R_IA_64_PCREL21M";
case 75: return "R_IA_64_PCREL21F";
case 76: return "R_IA_64_PCREL32MSB";
case 77: return "R_IA_64_PCREL32LSB";
case 78: return "R_IA_64_PCREL64MSB";
case 79: return "R_IA_64_PCREL64LSB";
case 82: return "R_IA_64_LTOFF_FPTR22";
case 83: return "R_IA_64_LTOFF_FPTR64I";
case 84: return "R_IA_64_LTOFF_FPTR32MSB";
case 85: return "R_IA_64_LTOFF_FPTR32LSB";
case 86: return "R_IA_64_LTOFF_FPTR64MSB";
case 87: return "R_IA_64_LTOFF_FPTR64LSB";
case 92: return "R_IA_64_SEGREL32MSB";
case 93: return "R_IA_64_SEGREL32LSB";
case 94: return "R_IA_64_SEGREL64MSB";
case 95: return "R_IA_64_SEGREL64LSB";
case 100: return "R_IA_64_SECREL32MSB";
case 101: return "R_IA_64_SECREL32LSB";
case 102: return "R_IA_64_SECREL64MSB";
case 103: return "R_IA_64_SECREL64LSB";
case 108: return "R_IA_64_REL32MSB";
case 109: return "R_IA_64_REL32LSB";
case 110: return "R_IA_64_REL64MSB";
case 111: return "R_IA_64_REL64LSB";
case 116: return "R_IA_64_LTV32MSB";
case 117: return "R_IA_64_LTV32LSB";
case 118: return "R_IA_64_LTV64MSB";
case 119: return "R_IA_64_LTV64LSB";
case 121: return "R_IA_64_PCREL21BI";
case 122: return "R_IA_64_PCREL22";
case 123: return "R_IA_64_PCREL64I";
case 128: return "R_IA_64_IPLTMSB";
case 129: return "R_IA_64_IPLTLSB";
case 133: return "R_IA_64_SUB";
case 134: return "R_IA_64_LTOFF22X";
case 135: return "R_IA_64_LDXMOV";
case 145: return "R_IA_64_TPREL14";
case 146: return "R_IA_64_TPREL22";
case 147: return "R_IA_64_TPREL64I";
case 150: return "R_IA_64_TPREL64MSB";
case 151: return "R_IA_64_TPREL64LSB";
case 154: return "R_IA_64_LTOFF_TPREL22";
case 166: return "R_IA_64_DTPMOD64MSB";
case 167: return "R_IA_64_DTPMOD64LSB";
case 170: return "R_IA_64_LTOFF_DTPMOD22";
case 177: return "R_IA_64_DTPREL14";
case 178: return "R_IA_64_DTPREL22";
case 179: return "R_IA_64_DTPREL64I";
case 180: return "R_IA_64_DTPREL32MSB";
case 181: return "R_IA_64_DTPREL32LSB";
case 182: return "R_IA_64_DTPREL64MSB";
case 183: return "R_IA_64_DTPREL64LSB";
case 186: return "R_IA_64_LTOFF_DTPREL22";
}
break;
case EM_MIPS:
switch(type) {
case 0: return "R_MIPS_NONE";
case 1: return "R_MIPS_16";
case 2: return "R_MIPS_32";
case 3: return "R_MIPS_REL32";
case 4: return "R_MIPS_26";
case 5: return "R_MIPS_HI16";
case 6: return "R_MIPS_LO16";
case 7: return "R_MIPS_GPREL16";
case 8: return "R_MIPS_LITERAL";
case 9: return "R_MIPS_GOT16";
case 10: return "R_MIPS_PC16";
case 11: return "R_MIPS_CALL16";
case 12: return "R_MIPS_GPREL32";
case 16: return "R_MIPS_SHIFT5";
case 17: return "R_MIPS_SHIFT6";
case 18: return "R_MIPS_64";
case 19: return "R_MIPS_GOT_DISP";
case 20: return "R_MIPS_GOT_PAGE";
case 21: return "R_MIPS_GOT_OFST";
case 22: return "R_MIPS_GOT_HI16";
case 23: return "R_MIPS_GOT_LO16";
case 24: return "R_MIPS_SUB";
case 30: return "R_MIPS_CALLHI16";
case 31: return "R_MIPS_CALLLO16";
case 37: return "R_MIPS_JALR";
case 38: return "R_MIPS_TLS_DTPMOD32";
case 39: return "R_MIPS_TLS_DTPREL32";
case 40: return "R_MIPS_TLS_DTPMOD64";
case 41: return "R_MIPS_TLS_DTPREL64";
case 42: return "R_MIPS_TLS_GD";
case 43: return "R_MIPS_TLS_LDM";
case 44: return "R_MIPS_TLS_DTPREL_HI16";
case 45: return "R_MIPS_TLS_DTPREL_LO16";
case 46: return "R_MIPS_TLS_GOTTPREL";
case 47: return "R_MIPS_TLS_TPREL32";
case 48: return "R_MIPS_TLS_TPREL64";
case 49: return "R_MIPS_TLS_TPREL_HI16";
case 50: return "R_MIPS_TLS_TPREL_LO16";
}
break;
case EM_PPC:
switch(type) {
case 0: return "R_PPC_NONE";
case 1: return "R_PPC_ADDR32";
case 2: return "R_PPC_ADDR24";
case 3: return "R_PPC_ADDR16";
case 4: return "R_PPC_ADDR16_LO";
case 5: return "R_PPC_ADDR16_HI";
case 6: return "R_PPC_ADDR16_HA";
case 7: return "R_PPC_ADDR14";
case 8: return "R_PPC_ADDR14_BRTAKEN";
case 9: return "R_PPC_ADDR14_BRNTAKEN";
case 10: return "R_PPC_REL24";
case 11: return "R_PPC_REL14";
case 12: return "R_PPC_REL14_BRTAKEN";
case 13: return "R_PPC_REL14_BRNTAKEN";
case 14: return "R_PPC_GOT16";
case 15: return "R_PPC_GOT16_LO";
case 16: return "R_PPC_GOT16_HI";
case 17: return "R_PPC_GOT16_HA";
case 18: return "R_PPC_PLTREL24";
case 19: return "R_PPC_COPY";
case 20: return "R_PPC_GLOB_DAT";
case 21: return "R_PPC_JMP_SLOT";
case 22: return "R_PPC_RELATIVE";
case 23: return "R_PPC_LOCAL24PC";
case 24: return "R_PPC_UADDR32";
case 25: return "R_PPC_UADDR16";
case 26: return "R_PPC_REL32";
case 27: return "R_PPC_PLT32";
case 28: return "R_PPC_PLTREL32";
case 29: return "R_PPC_PLT16_LO";
case 30: return "R_PPC_PLT16_HI";
case 31: return "R_PPC_PLT16_HA";
case 32: return "R_PPC_SDAREL16";
case 33: return "R_PPC_SECTOFF";
case 34: return "R_PPC_SECTOFF_LO";
case 35: return "R_PPC_SECTOFF_HI";
case 36: return "R_PPC_SECTOFF_HA";
case 67: return "R_PPC_TLS";
case 68: return "R_PPC_DTPMOD32";
case 69: return "R_PPC_TPREL16";
case 70: return "R_PPC_TPREL16_LO";
case 71: return "R_PPC_TPREL16_HI";
case 72: return "R_PPC_TPREL16_HA";
case 73: return "R_PPC_TPREL32";
case 74: return "R_PPC_DTPREL16";
case 75: return "R_PPC_DTPREL16_LO";
case 76: return "R_PPC_DTPREL16_HI";
case 77: return "R_PPC_DTPREL16_HA";
case 78: return "R_PPC_DTPREL32";
case 79: return "R_PPC_GOT_TLSGD16";
case 80: return "R_PPC_GOT_TLSGD16_LO";
case 81: return "R_PPC_GOT_TLSGD16_HI";
case 82: return "R_PPC_GOT_TLSGD16_HA";
case 83: return "R_PPC_GOT_TLSLD16";
case 84: return "R_PPC_GOT_TLSLD16_LO";
case 85: return "R_PPC_GOT_TLSLD16_HI";
case 86: return "R_PPC_GOT_TLSLD16_HA";
case 87: return "R_PPC_GOT_TPREL16";
case 88: return "R_PPC_GOT_TPREL16_LO";
case 89: return "R_PPC_GOT_TPREL16_HI";
case 90: return "R_PPC_GOT_TPREL16_HA";
case 101: return "R_PPC_EMB_NADDR32";
case 102: return "R_PPC_EMB_NADDR16";
case 103: return "R_PPC_EMB_NADDR16_LO";
case 104: return "R_PPC_EMB_NADDR16_HI";
case 105: return "R_PPC_EMB_NADDR16_HA";
case 106: return "R_PPC_EMB_SDAI16";
case 107: return "R_PPC_EMB_SDA2I16";
case 108: return "R_PPC_EMB_SDA2REL";
case 109: return "R_PPC_EMB_SDA21";
case 110: return "R_PPC_EMB_MRKREF";
case 111: return "R_PPC_EMB_RELSEC16";
case 112: return "R_PPC_EMB_RELST_LO";
case 113: return "R_PPC_EMB_RELST_HI";
case 114: return "R_PPC_EMB_RELST_HA";
case 115: return "R_PPC_EMB_BIT_FLD";
case 116: return "R_PPC_EMB_RELSDA";
}
break;
case EM_RISCV:
switch(type) {
case 0: return "R_RISCV_NONE";
case 1: return "R_RISCV_32";
case 2: return "R_RISCV_64";
case 3: return "R_RISCV_RELATIVE";
case 4: return "R_RISCV_COPY";
case 5: return "R_RISCV_JUMP_SLOT";
case 6: return "R_RISCV_TLS_DTPMOD32";
case 7: return "R_RISCV_TLS_DTPMOD64";
case 8: return "R_RISCV_TLS_DTPREL32";
case 9: return "R_RISCV_TLS_DTPREL64";
case 10: return "R_RISCV_TLS_TPREL32";
case 11: return "R_RISCV_TLS_TPREL64";
case 16: return "R_RISCV_BRANCH";
case 17: return "R_RISCV_JAL";
case 18: return "R_RISCV_CALL";
case 19: return "R_RISCV_CALL_PLT";
case 20: return "R_RISCV_GOT_HI20";
case 21: return "R_RISCV_TLS_GOT_HI20";
case 22: return "R_RISCV_TLS_GD_HI20";
case 23: return "R_RISCV_PCREL_HI20";
case 24: return "R_RISCV_PCREL_LO12_I";
case 25: return "R_RISCV_PCREL_LO12_S";
case 26: return "R_RISCV_HI20";
case 27: return "R_RISCV_LO12_I";
case 28: return "R_RISCV_LO12_S";
case 29: return "R_RISCV_TPREL_HI20";
case 30: return "R_RISCV_TPREL_LO12_I";
case 31: return "R_RISCV_TPREL_LO12_S";
case 32: return "R_RISCV_TPREL_ADD";
case 33: return "R_RISCV_ADD8";
case 34: return "R_RISCV_ADD16";
case 35: return "R_RISCV_ADD32";
case 36: return "R_RISCV_ADD64";
case 37: return "R_RISCV_SUB8";
case 38: return "R_RISCV_SUB16";
case 39: return "R_RISCV_SUB32";
case 40: return "R_RISCV_SUB64";
case 41: return "R_RISCV_GNU_VTINHERIT";
case 42: return "R_RISCV_GNU_VTENTRY";
case 43: return "R_RISCV_ALIGN";
case 44: return "R_RISCV_RVC_BRANCH";
case 45: return "R_RISCV_RVC_JUMP";
}
break;
case EM_SPARC:
case EM_SPARCV9:
switch(type) {
case 0: return "R_SPARC_NONE";
case 1: return "R_SPARC_8";
case 2: return "R_SPARC_16";
case 3: return "R_SPARC_32";
case 4: return "R_SPARC_DISP8";
case 5: return "R_SPARC_DISP16";
case 6: return "R_SPARC_DISP32";
case 7: return "R_SPARC_WDISP30";
case 8: return "R_SPARC_WDISP22";
case 9: return "R_SPARC_HI22";
case 10: return "R_SPARC_22";
case 11: return "R_SPARC_13";
case 12: return "R_SPARC_LO10";
case 13: return "R_SPARC_GOT10";
case 14: return "R_SPARC_GOT13";
case 15: return "R_SPARC_GOT22";
case 16: return "R_SPARC_PC10";
case 17: return "R_SPARC_PC22";
case 18: return "R_SPARC_WPLT30";
case 19: return "R_SPARC_COPY";
case 20: return "R_SPARC_GLOB_DAT";
case 21: return "R_SPARC_JMP_SLOT";
case 22: return "R_SPARC_RELATIVE";
case 23: return "R_SPARC_UA32";
case 24: return "R_SPARC_PLT32";
case 25: return "R_SPARC_HIPLT22";
case 26: return "R_SPARC_LOPLT10";
case 27: return "R_SPARC_PCPLT32";
case 28: return "R_SPARC_PCPLT22";
case 29: return "R_SPARC_PCPLT10";
case 30: return "R_SPARC_10";
case 31: return "R_SPARC_11";
case 32: return "R_SPARC_64";
case 33: return "R_SPARC_OLO10";
case 34: return "R_SPARC_HH22";
case 35: return "R_SPARC_HM10";
case 36: return "R_SPARC_LM22";
case 37: return "R_SPARC_PC_HH22";
case 38: return "R_SPARC_PC_HM10";
case 39: return "R_SPARC_PC_LM22";
case 40: return "R_SPARC_WDISP16";
case 41: return "R_SPARC_WDISP19";
case 42: return "R_SPARC_GLOB_JMP";
case 43: return "R_SPARC_7";
case 44: return "R_SPARC_5";
case 45: return "R_SPARC_6";
case 46: return "R_SPARC_DISP64";
case 47: return "R_SPARC_PLT64";
case 48: return "R_SPARC_HIX22";
case 49: return "R_SPARC_LOX10";
case 50: return "R_SPARC_H44";
case 51: return "R_SPARC_M44";
case 52: return "R_SPARC_L44";
case 53: return "R_SPARC_REGISTER";
case 54: return "R_SPARC_UA64";
case 55: return "R_SPARC_UA16";
case 56: return "R_SPARC_TLS_GD_HI22";
case 57: return "R_SPARC_TLS_GD_LO10";
case 58: return "R_SPARC_TLS_GD_ADD";
case 59: return "R_SPARC_TLS_GD_CALL";
case 60: return "R_SPARC_TLS_LDM_HI22";
case 61: return "R_SPARC_TLS_LDM_LO10";
case 62: return "R_SPARC_TLS_LDM_ADD";
case 63: return "R_SPARC_TLS_LDM_CALL";
case 64: return "R_SPARC_TLS_LDO_HIX22";
case 65: return "R_SPARC_TLS_LDO_LOX10";
case 66: return "R_SPARC_TLS_LDO_ADD";
case 67: return "R_SPARC_TLS_IE_HI22";
case 68: return "R_SPARC_TLS_IE_LO10";
case 69: return "R_SPARC_TLS_IE_LD";
case 70: return "R_SPARC_TLS_IE_LDX";
case 71: return "R_SPARC_TLS_IE_ADD";
case 72: return "R_SPARC_TLS_LE_HIX22";
case 73: return "R_SPARC_TLS_LE_LOX10";
case 74: return "R_SPARC_TLS_DTPMOD32";
case 75: return "R_SPARC_TLS_DTPMOD64";
case 76: return "R_SPARC_TLS_DTPOFF32";
case 77: return "R_SPARC_TLS_DTPOFF64";
case 78: return "R_SPARC_TLS_TPOFF32";
case 79: return "R_SPARC_TLS_TPOFF64";
}
break;
case EM_X86_64:
switch(type) {
case 0: return "R_X86_64_NONE";
case 1: return "R_X86_64_64";
case 2: return "R_X86_64_PC32";
case 3: return "R_X86_64_GOT32";
case 4: return "R_X86_64_PLT32";
case 5: return "R_X86_64_COPY";
case 6: return "R_X86_64_GLOB_DAT";
case 7: return "R_X86_64_JUMP_SLOT";
case 8: return "R_X86_64_RELATIVE";
case 9: return "R_X86_64_GOTPCREL";
case 10: return "R_X86_64_32";
case 11: return "R_X86_64_32S";
case 12: return "R_X86_64_16";
case 13: return "R_X86_64_PC16";
case 14: return "R_X86_64_8";
case 15: return "R_X86_64_PC8";
case 16: return "R_X86_64_DTPMOD64";
case 17: return "R_X86_64_DTPOFF64";
case 18: return "R_X86_64_TPOFF64";
case 19: return "R_X86_64_TLSGD";
case 20: return "R_X86_64_TLSLD";
case 21: return "R_X86_64_DTPOFF32";
case 22: return "R_X86_64_GOTTPOFF";
case 23: return "R_X86_64_TPOFF32";
case 24: return "R_X86_64_PC64";
case 25: return "R_X86_64_GOTOFF64";
case 26: return "R_X86_64_GOTPC32";
case 27: return "R_X86_64_GOT64";
case 28: return "R_X86_64_GOTPCREL64";
case 29: return "R_X86_64_GOTPC64";
case 30: return "R_X86_64_GOTPLT64";
case 31: return "R_X86_64_PLTOFF64";
case 32: return "R_X86_64_SIZE32";
case 33: return "R_X86_64_SIZE64";
case 34: return "R_X86_64_GOTPC32_TLSDESC";
case 35: return "R_X86_64_TLSDESC_CALL";
case 36: return "R_X86_64_TLSDESC";
case 37: return "R_X86_64_IRELATIVE";
case 38: return "R_X86_64_RELATIVE64";
case 41: return "R_X86_64_GOTPCRELX";
case 42: return "R_X86_64_REX_GOTPCRELX";
}
break;
}
snprintf(s_type, sizeof(s_type), "<unknown: %#x>", type);
return (s_type);
}

View File

@ -24,7 +24,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: users/kaiwang27/elftc/libelftc.h 392 2009-05-31 19:17:46Z kaiwang27 $
* $Id: libelftc.h 3309 2016-01-10 09:10:51Z kaiwang27 $
* $Id: libelftc.h 3418 2016-02-19 20:04:42Z emaste $
*/
#ifndef _LIBELFTC_H_
@ -75,6 +75,7 @@ unsigned int elftc_bfd_target_machine(Elftc_Bfd_Target *_tgt);
int elftc_copyfile(int _srcfd, int _dstfd);
int elftc_demangle(const char *_mangledname, char *_buffer,
size_t _bufsize, unsigned int _flags);
const char *elftc_reloc_type_str(unsigned int mach, unsigned int type);
int elftc_set_timestamps(const char *_filename, struct stat *_sb);
Elftc_String_Table *elftc_string_table_create(int _hint);
void elftc_string_table_destroy(Elftc_String_Table *_table);

View File

@ -37,7 +37,7 @@
#include "_libelftc.h"
ELFTC_VCSID("$Id: libelftc_dem_arm.c 2065 2011-10-26 15:24:47Z jkoshy $");
ELFTC_VCSID("$Id: libelftc_dem_arm.c 3447 2016-05-03 13:32:23Z emaste $");
/**
* @file cpp_demangle_arm.c
@ -1171,8 +1171,8 @@ read_type(struct demangle_data *d)
break;
default :
break;
};
};
}
}
if (ELFTC_ISDIGIT(*d->p))
return (read_class(d));

View File

@ -37,7 +37,7 @@
#include "_libelftc.h"
ELFTC_VCSID("$Id: libelftc_dem_gnu2.c 2065 2011-10-26 15:24:47Z jkoshy $");
ELFTC_VCSID("$Id: libelftc_dem_gnu2.c 3447 2016-05-03 13:32:23Z emaste $");
/**
* @file cpp_demangle_gnu2.c
@ -135,7 +135,7 @@ cpp_demangle_gnu2(const char *org)
case ENCODE_OP_TI :
case ENCODE_OP_VT :
goto flat;
};
}
if (*d.p == 'F')
++d.p;
@ -315,7 +315,7 @@ is_cpp_mangled_gnu2(const char *org)
rtn |= true;
break;
};
}
}
}
@ -1308,8 +1308,8 @@ read_type(struct demangle_data *d)
break;
default :
break;
};
};
}
}
if (ELFTC_ISDIGIT(*d->p))
return (read_class(d));

View File

@ -36,7 +36,7 @@
#include "_libelftc.h"
ELFTC_VCSID("$Id: libelftc_dem_gnu3.c 3291 2016-01-04 02:36:38Z emaste $");
ELFTC_VCSID("$Id: libelftc_dem_gnu3.c 3447 2016-05-03 13:32:23Z emaste $");
/**
* @file cpp_demangle.c
@ -553,7 +553,7 @@ cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata,
free(buf);
++e_idx;
break;
};
}
--idx;
}
@ -714,7 +714,7 @@ cpp_demangle_read_expr_primary(struct cpp_demangle_data *ddata)
return (cpp_demangle_push_str(ddata, "true", 4));
default:
return (0);
};
}
case 'd':
++ddata->cur;
@ -764,7 +764,7 @@ cpp_demangle_read_expr_primary(struct cpp_demangle_data *ddata)
default:
return (0);
};
}
}
static int
@ -1039,14 +1039,14 @@ cpp_demangle_read_expression(struct cpp_demangle_data *ddata)
/* operator sizeof */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "sizeof", 6));
};
}
switch (*ddata->cur) {
case 'L':
return (cpp_demangle_read_expr_primary(ddata));
case 'T':
return (cpp_demangle_read_tmpl_param(ddata));
};
}
return (0);
}
@ -1421,7 +1421,7 @@ cpp_demangle_read_encoding(struct cpp_demangle_data *ddata)
if (*ddata->cur == '\0')
return (0);
break;
};
}
return (cpp_demangle_read_name(ddata));
}
@ -1493,7 +1493,7 @@ cpp_demangle_read_name(struct cpp_demangle_data *ddata)
return (cpp_demangle_read_nested_name(ddata));
case 'Z':
return (cpp_demangle_read_local_name(ddata));
};
}
if (!vector_str_init(&v))
return (0);
@ -1594,7 +1594,7 @@ cpp_demangle_read_nested_name(struct cpp_demangle_data *ddata)
case 'K':
ddata->mem_cst = true;
break;
};
}
++ddata->cur;
}
@ -1622,7 +1622,7 @@ cpp_demangle_read_nested_name(struct cpp_demangle_data *ddata)
default:
if (!cpp_demangle_read_uqname(ddata))
goto clean;
};
}
if ((subst_str = vector_str_substr(output, p_idx,
output->size - 1, &subst_str_len)) == NULL)
@ -1947,7 +1947,7 @@ cpp_demangle_read_subst(struct cpp_demangle_data *ddata)
case SIMPLE_HASH('S', 't'):
/* std:: */
return (cpp_demangle_read_subst_std(ddata));
};
}
if (*(++ddata->cur) == '\0')
return (0);
@ -2095,7 +2095,7 @@ cpp_demangle_read_tmpl_arg(struct cpp_demangle_data *ddata)
return (cpp_demangle_read_expr_primary(ddata));
case 'X':
return (cpp_demangle_read_expression(ddata));
};
}
return (cpp_demangle_read_type(ddata, 0));
}
@ -2576,7 +2576,7 @@ cpp_demangle_read_type(struct cpp_demangle_data *ddata, int delimit)
goto clean;
++ddata->cur;
goto rtn;
};
}
if (!cpp_demangle_read_name(ddata))
goto clean;
@ -3040,7 +3040,7 @@ cpp_demangle_read_uqname(struct cpp_demangle_data *ddata)
return (0);
ddata->cur += 2;
return (1);
};
}
/* vendor extened operator */
if (*ddata->cur == 'v' && ELFTC_ISDIGIT(*(ddata->cur + 1))) {
@ -3086,7 +3086,7 @@ cpp_demangle_read_uqname(struct cpp_demangle_data *ddata)
return (0);
ddata->cur +=2;
return (1);
};
}
/* source name */
if (ELFTC_ISDIGIT(*ddata->cur) != 0)
@ -3449,7 +3449,7 @@ hex_to_dec(char c)
return (15);
default:
return (-1);
};
}
}
/**

View File

@ -3,7 +3,7 @@
# This script generates a project-wide version identifier for use by
# the `elftc_version()' API.
#
# $Id: make-toolchain-version 3299 2016-01-09 19:58:46Z jkoshy $
# $Id: make-toolchain-version 3414 2016-02-16 22:55:28Z jkoshy $
#
# Defaults.
@ -64,19 +64,25 @@ done
curdir=`pwd`
cd ${top} || usage "ERROR: Cannot change directory to \"${top}\"."
if [ -d .svn -o -d ../.svn ]; then # FreeBSD and SF.Net sources.
versionstring=" svn:"$(svnversion)
elif [ -d CVS ]; then # NetBSD.
if [ -d CVS ]; then # Look for CVS (NetBSD).
versionstring=" cvs:unknown"
else # DragonFlyBSD.
versionstring=" git:"$(git describe --all --dirty --long 2> /dev/null)
# Cannot determine an in-tree version number.
if [ $? -ne 0 ]; then
versionstring=""
else # Try git (DragonFlyBSD).
gitversion="$(git describe --all --dirty --long 2> /dev/null)"
if [ -n "${gitversion}" ]; then
versionstring=" git:${gitversion}"
else # Assume an SVN checkout (SourceForge or FreeBSD).
svnversion="$(svnversion)"
if [ -n "${svnversion}" ]; then
versionstring=" svn:$(svnversion)"
fi
fi
fi
if [ -z "${versionstring}" ]; then
echo "ERROR: cannot determine a revision number." 1>&2
exit 1
fi
cd ${curdir} || usage "Cannot change back to ${curdir}."
#

View File

@ -33,7 +33,7 @@
#include "_libpe.h"
ELFTC_VCSID("$Id: libpe_section.c 3312 2016-01-10 09:23:51Z kaiwang27 $");
ELFTC_VCSID("$Id: libpe_section.c 3446 2016-05-03 01:31:17Z emaste $");
PE_Scn *
libpe_alloc_scn(PE *pe)
@ -486,7 +486,7 @@ libpe_write_sections(PE *pe, off_t off)
/*
* Padding between sections. (padding always written
* in case the the section headers or sections are
* moved or shrinked.)
* moved or shrunk.)
*/
assert(off <= sh->sh_rawptr);
if (off < sh->sh_rawptr)

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: pe.h 3312 2016-01-10 09:23:51Z kaiwang27 $
* $Id: pe.h 3441 2016-04-07 15:04:20Z emaste $
*/
#ifndef _PE_H_
@ -88,6 +88,9 @@ typedef struct _PE_RichHdr {
#define IMAGE_FILE_MACHINE_POWERPC 0x1f0 /* Power PC LE */
#define IMAGE_FILE_MACHINE_POWERPCFP 0x1f1 /* Power PC floating point */
#define IMAGE_FILE_MACHINE_R4000 0x166 /* MIPS R4000 LE */
#define IMAGE_FILE_MACHINE_RISCV32 0x5032 /* RISC-V 32-bit */
#define IMAGE_FILE_MACHINE_RISCV64 0x5064 /* RISC-V 64-bit */
#define IMAGE_FILE_MACHINE_RISCV128 0x5128 /* RISC-V 128-bit */
#define IMAGE_FILE_MACHINE_SH3 0x1a2 /* Hitachi SH3 */
#define IMAGE_FILE_MACHINE_SH3DSP 0x1a3 /* Hitachi SH3 DSP */
#define IMAGE_FILE_MACHINE_SH4 0x1a6 /* Hitachi SH4 */

View File

@ -48,7 +48,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: nm.c 3179 2015-03-31 19:38:56Z emaste $");
ELFTC_VCSID("$Id: nm.c 3472 2016-05-17 20:11:16Z emaste $");
/* symbol information list */
STAILQ_HEAD(sym_head, sym_entry);
@ -790,7 +790,8 @@ is_sec_debug(const char *shname)
};
const char **p;
assert(shname != NULL && "shname is NULL");
if (shname == NULL)
return (false);
for (p = dbg_sec; *p; p++) {
if (!strncmp(shname, *p, strlen(*p)))
@ -1716,7 +1717,7 @@ sym_elem_print_all_sysv(char type, const char *sec, const GElf_Sym *sym,
case STT_NOTYPE:
default:
printf("%18s|", "NOTYPE");
};
}
if (sym->st_size != 0)
nm_opts.size_print_fn(sym);
@ -1945,7 +1946,7 @@ sym_list_print_each(struct sym_entry *ep, struct sym_print_data *p,
return;
sec = p->s_table[ep->sym->st_shndx];
break;
};
}
nm_opts.elem_print_fn(type, sec, ep->sym, ep->name);

View File

@ -47,7 +47,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: readelf.c 3395 2016-02-10 16:29:44Z emaste $");
ELFTC_VCSID("$Id: readelf.c 3469 2016-05-15 23:16:09Z emaste $");
/*
* readelf(1) options.
@ -337,7 +337,6 @@ static const char *option_kind(uint8_t kind);
static const char *phdr_type(unsigned int ptype);
static const char *ppc_abi_fp(uint64_t fp);
static const char *ppc_abi_vector(uint64_t vec);
static const char *r_type(unsigned int mach, unsigned int type);
static void readelf_usage(int status);
static void readelf_version(void);
static void search_loclist_at(struct readelf *re, Dwarf_Die die,
@ -348,7 +347,8 @@ static void set_cu_context(struct readelf *re, Dwarf_Half psize,
Dwarf_Half osize, Dwarf_Half ver);
static const char *st_bind(unsigned int sbind);
static const char *st_shndx(unsigned int shndx);
static const char *st_type(unsigned int mach, unsigned int stype);
static const char *st_type(unsigned int mach, unsigned int os,
unsigned int stype);
static const char *st_vis(unsigned int svis);
static const char *top_tag(unsigned int tag);
static void unload_sections(struct readelf *re);
@ -430,6 +430,7 @@ elf_osabi(unsigned int abi)
case ELFOSABI_OPENBSD: return "OpenBSD";
case ELFOSABI_OPENVMS: return "OpenVMS";
case ELFOSABI_NSK: return "NSK";
case ELFOSABI_CLOUDABI: return "CloudABI";
case ELFOSABI_ARM: return "ARM";
case ELFOSABI_STANDALONE: return "StandAlone";
default:
@ -651,7 +652,7 @@ section_type(unsigned int mach, unsigned int stype)
switch (mach) {
case EM_X86_64:
switch (stype) {
case SHT_AMD64_UNWIND: return "AMD64_UNWIND";
case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
default:
break;
}
@ -921,6 +922,8 @@ dt_type(unsigned int mach, unsigned int dtype)
case DT_SYMINSZ: return "SYMINSZ";
case DT_SYMINENT: return "SYMINENT";
case DT_GNU_HASH: return "GNU_HASH";
case DT_TLSDESC_PLT: return "DT_TLSDESC_PLT";
case DT_TLSDESC_GOT: return "DT_TLSDESC_GOT";
case DT_GNU_CONFLICT: return "GNU_CONFLICT";
case DT_GNU_LIBLIST: return "GNU_LIBLIST";
case DT_CONFIG: return "CONFIG";
@ -972,7 +975,7 @@ st_bind(unsigned int sbind)
}
static const char *
st_type(unsigned int mach, unsigned int stype)
st_type(unsigned int mach, unsigned int os, unsigned int stype)
{
static char s_stype[32];
@ -985,10 +988,13 @@ st_type(unsigned int mach, unsigned int stype)
case STT_COMMON: return "COMMON";
case STT_TLS: return "TLS";
default:
if (stype >= STT_LOOS && stype <= STT_HIOS)
if (stype >= STT_LOOS && stype <= STT_HIOS) {
if ((os == ELFOSABI_GNU || os == ELFOSABI_FREEBSD) &&
stype == STT_GNU_IFUNC)
return "IFUNC";
snprintf(s_stype, sizeof(s_stype), "OS+%#x",
stype - STT_LOOS);
else if (stype >= STT_LOPROC && stype <= STT_HIPROC) {
} else if (stype >= STT_LOPROC && stype <= STT_HIPROC) {
if (mach == EM_SPARCV9 && stype == STT_SPARC_REGISTER)
return "REGISTER";
snprintf(s_stype, sizeof(s_stype), "PROC+%#x",
@ -1050,556 +1056,10 @@ static struct {
{"OS NONCONF", 'O', SHF_OS_NONCONFORMING},
{"GROUP", 'G', SHF_GROUP},
{"TLS", 'T', SHF_TLS},
{"COMPRESSED", 'C', SHF_COMPRESSED},
{NULL, 0, 0}
};
static const char *
r_type(unsigned int mach, unsigned int type)
{
static char s_type[32];
switch(mach) {
case EM_386:
case EM_IAMCU:
switch(type) {
case 0: return "R_386_NONE";
case 1: return "R_386_32";
case 2: return "R_386_PC32";
case 3: return "R_386_GOT32";
case 4: return "R_386_PLT32";
case 5: return "R_386_COPY";
case 6: return "R_386_GLOB_DAT";
case 7: return "R_386_JUMP_SLOT";
case 8: return "R_386_RELATIVE";
case 9: return "R_386_GOTOFF";
case 10: return "R_386_GOTPC";
case 14: return "R_386_TLS_TPOFF";
case 15: return "R_386_TLS_IE";
case 16: return "R_386_TLS_GOTIE";
case 17: return "R_386_TLS_LE";
case 18: return "R_386_TLS_GD";
case 19: return "R_386_TLS_LDM";
case 24: return "R_386_TLS_GD_32";
case 25: return "R_386_TLS_GD_PUSH";
case 26: return "R_386_TLS_GD_CALL";
case 27: return "R_386_TLS_GD_POP";
case 28: return "R_386_TLS_LDM_32";
case 29: return "R_386_TLS_LDM_PUSH";
case 30: return "R_386_TLS_LDM_CALL";
case 31: return "R_386_TLS_LDM_POP";
case 32: return "R_386_TLS_LDO_32";
case 33: return "R_386_TLS_IE_32";
case 34: return "R_386_TLS_LE_32";
case 35: return "R_386_TLS_DTPMOD32";
case 36: return "R_386_TLS_DTPOFF32";
case 37: return "R_386_TLS_TPOFF32";
}
break;
case EM_AARCH64:
switch(type) {
case 0: return "R_AARCH64_NONE";
case 257: return "R_AARCH64_ABS64";
case 258: return "R_AARCH64_ABS32";
case 259: return "R_AARCH64_ABS16";
case 260: return "R_AARCH64_PREL64";
case 261: return "R_AARCH64_PREL32";
case 262: return "R_AARCH64_PREL16";
case 263: return "R_AARCH64_MOVW_UABS_G0";
case 264: return "R_AARCH64_MOVW_UABS_G0_NC";
case 265: return "R_AARCH64_MOVW_UABS_G1";
case 266: return "R_AARCH64_MOVW_UABS_G1_NC";
case 267: return "R_AARCH64_MOVW_UABS_G2";
case 268: return "R_AARCH64_MOVW_UABS_G2_NC";
case 269: return "R_AARCH64_MOVW_UABS_G3";
case 270: return "R_AARCH64_MOVW_SABS_G0";
case 271: return "R_AARCH64_MOVW_SABS_G1";
case 272: return "R_AARCH64_MOVW_SABS_G2";
case 273: return "R_AARCH64_LD_PREL_LO19";
case 274: return "R_AARCH64_ADR_PREL_LO21";
case 275: return "R_AARCH64_ADR_PREL_PG_HI21";
case 276: return "R_AARCH64_ADR_PREL_PG_HI21_NC";
case 277: return "R_AARCH64_ADD_ABS_LO12_NC";
case 278: return "R_AARCH64_LDST8_ABS_LO12_NC";
case 279: return "R_AARCH64_TSTBR14";
case 280: return "R_AARCH64_CONDBR19";
case 282: return "R_AARCH64_JUMP26";
case 283: return "R_AARCH64_CALL26";
case 284: return "R_AARCH64_LDST16_ABS_LO12_NC";
case 285: return "R_AARCH64_LDST32_ABS_LO12_NC";
case 286: return "R_AARCH64_LDST64_ABS_LO12_NC";
case 287: return "R_AARCH64_MOVW_PREL_G0";
case 288: return "R_AARCH64_MOVW_PREL_G0_NC";
case 289: return "R_AARCH64_MOVW_PREL_G1";
case 290: return "R_AARCH64_MOVW_PREL_G1_NC";
case 291: return "R_AARCH64_MOVW_PREL_G2";
case 292: return "R_AARCH64_MOVW_PREL_G2_NC";
case 293: return "R_AARCH64_MOVW_PREL_G3";
case 299: return "R_AARCH64_LDST128_ABS_LO12_NC";
case 300: return "R_AARCH64_MOVW_GOTOFF_G0";
case 301: return "R_AARCH64_MOVW_GOTOFF_G0_NC";
case 302: return "R_AARCH64_MOVW_GOTOFF_G1";
case 303: return "R_AARCH64_MOVW_GOTOFF_G1_NC";
case 304: return "R_AARCH64_MOVW_GOTOFF_G2";
case 305: return "R_AARCH64_MOVW_GOTOFF_G2_NC";
case 306: return "R_AARCH64_MOVW_GOTOFF_G3";
case 307: return "R_AARCH64_GOTREL64";
case 308: return "R_AARCH64_GOTREL32";
case 309: return "R_AARCH64_GOT_LD_PREL19";
case 310: return "R_AARCH64_LD64_GOTOFF_LO15";
case 311: return "R_AARCH64_ADR_GOT_PAGE";
case 312: return "R_AARCH64_LD64_GOT_LO12_NC";
case 313: return "R_AARCH64_LD64_GOTPAGE_LO15";
case 560: return "R_AARCH64_TLSDESC_LD_PREL19";
case 561: return "R_AARCH64_TLSDESC_ADR_PREL21";
case 562: return "R_AARCH64_TLSDESC_ADR_PAGE21";
case 563: return "R_AARCH64_TLSDESC_LD64_LO12";
case 564: return "R_AARCH64_TLSDESC_ADD_LO12";
case 565: return "R_AARCH64_TLSDESC_OFF_G1";
case 566: return "R_AARCH64_TLSDESC_OFF_G0_NC";
case 567: return "R_AARCH64_TLSDESC_LDR";
case 568: return "R_AARCH64_TLSDESC_ADD";
case 569: return "R_AARCH64_TLSDESC_CALL";
case 1024: return "R_AARCH64_COPY";
case 1025: return "R_AARCH64_GLOB_DAT";
case 1026: return "R_AARCH64_JUMP_SLOT";
case 1027: return "R_AARCH64_RELATIVE";
case 1028: return "R_AARCH64_TLS_DTPREL64";
case 1029: return "R_AARCH64_TLS_DTPMOD64";
case 1030: return "R_AARCH64_TLS_TPREL64";
case 1031: return "R_AARCH64_TLSDESC";
case 1032: return "R_AARCH64_IRELATIVE";
}
break;
case EM_ARM:
switch(type) {
case 0: return "R_ARM_NONE";
case 1: return "R_ARM_PC24";
case 2: return "R_ARM_ABS32";
case 3: return "R_ARM_REL32";
case 4: return "R_ARM_PC13";
case 5: return "R_ARM_ABS16";
case 6: return "R_ARM_ABS12";
case 7: return "R_ARM_THM_ABS5";
case 8: return "R_ARM_ABS8";
case 9: return "R_ARM_SBREL32";
case 10: return "R_ARM_THM_PC22";
case 11: return "R_ARM_THM_PC8";
case 12: return "R_ARM_AMP_VCALL9";
case 13: return "R_ARM_TLS_DESC";
/* Obsolete R_ARM_SWI24 is also 13 */
case 14: return "R_ARM_THM_SWI8";
case 15: return "R_ARM_XPC25";
case 16: return "R_ARM_THM_XPC22";
case 17: return "R_ARM_TLS_DTPMOD32";
case 18: return "R_ARM_TLS_DTPOFF32";
case 19: return "R_ARM_TLS_TPOFF32";
case 20: return "R_ARM_COPY";
case 21: return "R_ARM_GLOB_DAT";
case 22: return "R_ARM_JUMP_SLOT";
case 23: return "R_ARM_RELATIVE";
case 24: return "R_ARM_GOTOFF";
case 25: return "R_ARM_GOTPC";
case 26: return "R_ARM_GOT32";
case 27: return "R_ARM_PLT32";
case 28: return "R_ARM_CALL";
case 29: return "R_ARM_JUMP24";
case 30: return "R_ARM_THM_JUMP24";
case 31: return "R_ARM_BASE_ABS";
case 38: return "R_ARM_TARGET1";
case 40: return "R_ARM_V4BX";
case 42: return "R_ARM_PREL31";
case 43: return "R_ARM_MOVW_ABS_NC";
case 44: return "R_ARM_MOVT_ABS";
case 45: return "R_ARM_MOVW_PREL_NC";
case 46: return "R_ARM_MOVT_PREL";
case 100: return "R_ARM_GNU_VTENTRY";
case 101: return "R_ARM_GNU_VTINHERIT";
case 250: return "R_ARM_RSBREL32";
case 251: return "R_ARM_THM_RPC22";
case 252: return "R_ARM_RREL32";
case 253: return "R_ARM_RABS32";
case 254: return "R_ARM_RPC24";
case 255: return "R_ARM_RBASE";
}
break;
case EM_IA_64:
switch(type) {
case 0: return "R_IA_64_NONE";
case 33: return "R_IA_64_IMM14";
case 34: return "R_IA_64_IMM22";
case 35: return "R_IA_64_IMM64";
case 36: return "R_IA_64_DIR32MSB";
case 37: return "R_IA_64_DIR32LSB";
case 38: return "R_IA_64_DIR64MSB";
case 39: return "R_IA_64_DIR64LSB";
case 42: return "R_IA_64_GPREL22";
case 43: return "R_IA_64_GPREL64I";
case 44: return "R_IA_64_GPREL32MSB";
case 45: return "R_IA_64_GPREL32LSB";
case 46: return "R_IA_64_GPREL64MSB";
case 47: return "R_IA_64_GPREL64LSB";
case 50: return "R_IA_64_LTOFF22";
case 51: return "R_IA_64_LTOFF64I";
case 58: return "R_IA_64_PLTOFF22";
case 59: return "R_IA_64_PLTOFF64I";
case 62: return "R_IA_64_PLTOFF64MSB";
case 63: return "R_IA_64_PLTOFF64LSB";
case 67: return "R_IA_64_FPTR64I";
case 68: return "R_IA_64_FPTR32MSB";
case 69: return "R_IA_64_FPTR32LSB";
case 70: return "R_IA_64_FPTR64MSB";
case 71: return "R_IA_64_FPTR64LSB";
case 72: return "R_IA_64_PCREL60B";
case 73: return "R_IA_64_PCREL21B";
case 74: return "R_IA_64_PCREL21M";
case 75: return "R_IA_64_PCREL21F";
case 76: return "R_IA_64_PCREL32MSB";
case 77: return "R_IA_64_PCREL32LSB";
case 78: return "R_IA_64_PCREL64MSB";
case 79: return "R_IA_64_PCREL64LSB";
case 82: return "R_IA_64_LTOFF_FPTR22";
case 83: return "R_IA_64_LTOFF_FPTR64I";
case 84: return "R_IA_64_LTOFF_FPTR32MSB";
case 85: return "R_IA_64_LTOFF_FPTR32LSB";
case 86: return "R_IA_64_LTOFF_FPTR64MSB";
case 87: return "R_IA_64_LTOFF_FPTR64LSB";
case 92: return "R_IA_64_SEGREL32MSB";
case 93: return "R_IA_64_SEGREL32LSB";
case 94: return "R_IA_64_SEGREL64MSB";
case 95: return "R_IA_64_SEGREL64LSB";
case 100: return "R_IA_64_SECREL32MSB";
case 101: return "R_IA_64_SECREL32LSB";
case 102: return "R_IA_64_SECREL64MSB";
case 103: return "R_IA_64_SECREL64LSB";
case 108: return "R_IA_64_REL32MSB";
case 109: return "R_IA_64_REL32LSB";
case 110: return "R_IA_64_REL64MSB";
case 111: return "R_IA_64_REL64LSB";
case 116: return "R_IA_64_LTV32MSB";
case 117: return "R_IA_64_LTV32LSB";
case 118: return "R_IA_64_LTV64MSB";
case 119: return "R_IA_64_LTV64LSB";
case 121: return "R_IA_64_PCREL21BI";
case 122: return "R_IA_64_PCREL22";
case 123: return "R_IA_64_PCREL64I";
case 128: return "R_IA_64_IPLTMSB";
case 129: return "R_IA_64_IPLTLSB";
case 133: return "R_IA_64_SUB";
case 134: return "R_IA_64_LTOFF22X";
case 135: return "R_IA_64_LDXMOV";
case 145: return "R_IA_64_TPREL14";
case 146: return "R_IA_64_TPREL22";
case 147: return "R_IA_64_TPREL64I";
case 150: return "R_IA_64_TPREL64MSB";
case 151: return "R_IA_64_TPREL64LSB";
case 154: return "R_IA_64_LTOFF_TPREL22";
case 166: return "R_IA_64_DTPMOD64MSB";
case 167: return "R_IA_64_DTPMOD64LSB";
case 170: return "R_IA_64_LTOFF_DTPMOD22";
case 177: return "R_IA_64_DTPREL14";
case 178: return "R_IA_64_DTPREL22";
case 179: return "R_IA_64_DTPREL64I";
case 180: return "R_IA_64_DTPREL32MSB";
case 181: return "R_IA_64_DTPREL32LSB";
case 182: return "R_IA_64_DTPREL64MSB";
case 183: return "R_IA_64_DTPREL64LSB";
case 186: return "R_IA_64_LTOFF_DTPREL22";
}
break;
case EM_MIPS:
switch(type) {
case 0: return "R_MIPS_NONE";
case 1: return "R_MIPS_16";
case 2: return "R_MIPS_32";
case 3: return "R_MIPS_REL32";
case 4: return "R_MIPS_26";
case 5: return "R_MIPS_HI16";
case 6: return "R_MIPS_LO16";
case 7: return "R_MIPS_GPREL16";
case 8: return "R_MIPS_LITERAL";
case 9: return "R_MIPS_GOT16";
case 10: return "R_MIPS_PC16";
case 11: return "R_MIPS_CALL16";
case 12: return "R_MIPS_GPREL32";
case 21: return "R_MIPS_GOTHI16";
case 22: return "R_MIPS_GOTLO16";
case 30: return "R_MIPS_CALLHI16";
case 31: return "R_MIPS_CALLLO16";
case 38: return "R_MIPS_TLS_DTPMOD32";
case 39: return "R_MIPS_TLS_DTPREL32";
case 40: return "R_MIPS_TLS_DTPMOD64";
case 41: return "R_MIPS_TLS_DTPREL64";
case 42: return "R_MIPS_TLS_GD";
case 43: return "R_MIPS_TLS_LDM";
case 44: return "R_MIPS_TLS_DTPREL_HI16";
case 45: return "R_MIPS_TLS_DTPREL_LO16";
case 46: return "R_MIPS_TLS_GOTTPREL";
case 47: return "R_MIPS_TLS_TPREL32";
case 48: return "R_MIPS_TLS_TPREL64";
case 49: return "R_MIPS_TLS_TPREL_HI16";
case 50: return "R_MIPS_TLS_TPREL_LO16";
}
break;
case EM_PPC:
switch(type) {
case 0: return "R_PPC_NONE";
case 1: return "R_PPC_ADDR32";
case 2: return "R_PPC_ADDR24";
case 3: return "R_PPC_ADDR16";
case 4: return "R_PPC_ADDR16_LO";
case 5: return "R_PPC_ADDR16_HI";
case 6: return "R_PPC_ADDR16_HA";
case 7: return "R_PPC_ADDR14";
case 8: return "R_PPC_ADDR14_BRTAKEN";
case 9: return "R_PPC_ADDR14_BRNTAKEN";
case 10: return "R_PPC_REL24";
case 11: return "R_PPC_REL14";
case 12: return "R_PPC_REL14_BRTAKEN";
case 13: return "R_PPC_REL14_BRNTAKEN";
case 14: return "R_PPC_GOT16";
case 15: return "R_PPC_GOT16_LO";
case 16: return "R_PPC_GOT16_HI";
case 17: return "R_PPC_GOT16_HA";
case 18: return "R_PPC_PLTREL24";
case 19: return "R_PPC_COPY";
case 20: return "R_PPC_GLOB_DAT";
case 21: return "R_PPC_JMP_SLOT";
case 22: return "R_PPC_RELATIVE";
case 23: return "R_PPC_LOCAL24PC";
case 24: return "R_PPC_UADDR32";
case 25: return "R_PPC_UADDR16";
case 26: return "R_PPC_REL32";
case 27: return "R_PPC_PLT32";
case 28: return "R_PPC_PLTREL32";
case 29: return "R_PPC_PLT16_LO";
case 30: return "R_PPC_PLT16_HI";
case 31: return "R_PPC_PLT16_HA";
case 32: return "R_PPC_SDAREL16";
case 33: return "R_PPC_SECTOFF";
case 34: return "R_PPC_SECTOFF_LO";
case 35: return "R_PPC_SECTOFF_HI";
case 36: return "R_PPC_SECTOFF_HA";
case 67: return "R_PPC_TLS";
case 68: return "R_PPC_DTPMOD32";
case 69: return "R_PPC_TPREL16";
case 70: return "R_PPC_TPREL16_LO";
case 71: return "R_PPC_TPREL16_HI";
case 72: return "R_PPC_TPREL16_HA";
case 73: return "R_PPC_TPREL32";
case 74: return "R_PPC_DTPREL16";
case 75: return "R_PPC_DTPREL16_LO";
case 76: return "R_PPC_DTPREL16_HI";
case 77: return "R_PPC_DTPREL16_HA";
case 78: return "R_PPC_DTPREL32";
case 79: return "R_PPC_GOT_TLSGD16";
case 80: return "R_PPC_GOT_TLSGD16_LO";
case 81: return "R_PPC_GOT_TLSGD16_HI";
case 82: return "R_PPC_GOT_TLSGD16_HA";
case 83: return "R_PPC_GOT_TLSLD16";
case 84: return "R_PPC_GOT_TLSLD16_LO";
case 85: return "R_PPC_GOT_TLSLD16_HI";
case 86: return "R_PPC_GOT_TLSLD16_HA";
case 87: return "R_PPC_GOT_TPREL16";
case 88: return "R_PPC_GOT_TPREL16_LO";
case 89: return "R_PPC_GOT_TPREL16_HI";
case 90: return "R_PPC_GOT_TPREL16_HA";
case 101: return "R_PPC_EMB_NADDR32";
case 102: return "R_PPC_EMB_NADDR16";
case 103: return "R_PPC_EMB_NADDR16_LO";
case 104: return "R_PPC_EMB_NADDR16_HI";
case 105: return "R_PPC_EMB_NADDR16_HA";
case 106: return "R_PPC_EMB_SDAI16";
case 107: return "R_PPC_EMB_SDA2I16";
case 108: return "R_PPC_EMB_SDA2REL";
case 109: return "R_PPC_EMB_SDA21";
case 110: return "R_PPC_EMB_MRKREF";
case 111: return "R_PPC_EMB_RELSEC16";
case 112: return "R_PPC_EMB_RELST_LO";
case 113: return "R_PPC_EMB_RELST_HI";
case 114: return "R_PPC_EMB_RELST_HA";
case 115: return "R_PPC_EMB_BIT_FLD";
case 116: return "R_PPC_EMB_RELSDA";
}
break;
case EM_RISCV:
switch(type) {
case 0: return "R_RISCV_NONE";
case 1: return "R_RISCV_32";
case 2: return "R_RISCV_64";
case 3: return "R_RISCV_RELATIVE";
case 4: return "R_RISCV_COPY";
case 5: return "R_RISCV_JUMP_SLOT";
case 6: return "R_RISCV_TLS_DTPMOD32";
case 7: return "R_RISCV_TLS_DTPMOD64";
case 8: return "R_RISCV_TLS_DTPREL32";
case 9: return "R_RISCV_TLS_DTPREL64";
case 10: return "R_RISCV_TLS_TPREL32";
case 11: return "R_RISCV_TLS_TPREL64";
case 16: return "R_RISCV_BRANCH";
case 17: return "R_RISCV_JAL";
case 18: return "R_RISCV_CALL";
case 19: return "R_RISCV_CALL_PLT";
case 20: return "R_RISCV_GOT_HI20";
case 21: return "R_RISCV_TLS_GOT_HI20";
case 22: return "R_RISCV_TLS_GD_HI20";
case 23: return "R_RISCV_PCREL_HI20";
case 24: return "R_RISCV_PCREL_LO12_I";
case 25: return "R_RISCV_PCREL_LO12_S";
case 26: return "R_RISCV_HI20";
case 27: return "R_RISCV_LO12_I";
case 28: return "R_RISCV_LO12_S";
case 29: return "R_RISCV_TPREL_HI20";
case 30: return "R_RISCV_TPREL_LO12_I";
case 31: return "R_RISCV_TPREL_LO12_S";
case 32: return "R_RISCV_TPREL_ADD";
case 33: return "R_RISCV_ADD8";
case 34: return "R_RISCV_ADD16";
case 35: return "R_RISCV_ADD32";
case 36: return "R_RISCV_ADD64";
case 37: return "R_RISCV_SUB8";
case 38: return "R_RISCV_SUB16";
case 39: return "R_RISCV_SUB32";
case 40: return "R_RISCV_SUB64";
case 41: return "R_RISCV_GNU_VTINHERIT";
case 42: return "R_RISCV_GNU_VTENTRY";
case 43: return "R_RISCV_ALIGN";
case 44: return "R_RISCV_RVC_BRANCH";
case 45: return "R_RISCV_RVC_JUMP";
}
break;
case EM_SPARC:
case EM_SPARCV9:
switch(type) {
case 0: return "R_SPARC_NONE";
case 1: return "R_SPARC_8";
case 2: return "R_SPARC_16";
case 3: return "R_SPARC_32";
case 4: return "R_SPARC_DISP8";
case 5: return "R_SPARC_DISP16";
case 6: return "R_SPARC_DISP32";
case 7: return "R_SPARC_WDISP30";
case 8: return "R_SPARC_WDISP22";
case 9: return "R_SPARC_HI22";
case 10: return "R_SPARC_22";
case 11: return "R_SPARC_13";
case 12: return "R_SPARC_LO10";
case 13: return "R_SPARC_GOT10";
case 14: return "R_SPARC_GOT13";
case 15: return "R_SPARC_GOT22";
case 16: return "R_SPARC_PC10";
case 17: return "R_SPARC_PC22";
case 18: return "R_SPARC_WPLT30";
case 19: return "R_SPARC_COPY";
case 20: return "R_SPARC_GLOB_DAT";
case 21: return "R_SPARC_JMP_SLOT";
case 22: return "R_SPARC_RELATIVE";
case 23: return "R_SPARC_UA32";
case 24: return "R_SPARC_PLT32";
case 25: return "R_SPARC_HIPLT22";
case 26: return "R_SPARC_LOPLT10";
case 27: return "R_SPARC_PCPLT32";
case 28: return "R_SPARC_PCPLT22";
case 29: return "R_SPARC_PCPLT10";
case 30: return "R_SPARC_10";
case 31: return "R_SPARC_11";
case 32: return "R_SPARC_64";
case 33: return "R_SPARC_OLO10";
case 34: return "R_SPARC_HH22";
case 35: return "R_SPARC_HM10";
case 36: return "R_SPARC_LM22";
case 37: return "R_SPARC_PC_HH22";
case 38: return "R_SPARC_PC_HM10";
case 39: return "R_SPARC_PC_LM22";
case 40: return "R_SPARC_WDISP16";
case 41: return "R_SPARC_WDISP19";
case 42: return "R_SPARC_GLOB_JMP";
case 43: return "R_SPARC_7";
case 44: return "R_SPARC_5";
case 45: return "R_SPARC_6";
case 46: return "R_SPARC_DISP64";
case 47: return "R_SPARC_PLT64";
case 48: return "R_SPARC_HIX22";
case 49: return "R_SPARC_LOX10";
case 50: return "R_SPARC_H44";
case 51: return "R_SPARC_M44";
case 52: return "R_SPARC_L44";
case 53: return "R_SPARC_REGISTER";
case 54: return "R_SPARC_UA64";
case 55: return "R_SPARC_UA16";
case 56: return "R_SPARC_TLS_GD_HI22";
case 57: return "R_SPARC_TLS_GD_LO10";
case 58: return "R_SPARC_TLS_GD_ADD";
case 59: return "R_SPARC_TLS_GD_CALL";
case 60: return "R_SPARC_TLS_LDM_HI22";
case 61: return "R_SPARC_TLS_LDM_LO10";
case 62: return "R_SPARC_TLS_LDM_ADD";
case 63: return "R_SPARC_TLS_LDM_CALL";
case 64: return "R_SPARC_TLS_LDO_HIX22";
case 65: return "R_SPARC_TLS_LDO_LOX10";
case 66: return "R_SPARC_TLS_LDO_ADD";
case 67: return "R_SPARC_TLS_IE_HI22";
case 68: return "R_SPARC_TLS_IE_LO10";
case 69: return "R_SPARC_TLS_IE_LD";
case 70: return "R_SPARC_TLS_IE_LDX";
case 71: return "R_SPARC_TLS_IE_ADD";
case 72: return "R_SPARC_TLS_LE_HIX22";
case 73: return "R_SPARC_TLS_LE_LOX10";
case 74: return "R_SPARC_TLS_DTPMOD32";
case 75: return "R_SPARC_TLS_DTPMOD64";
case 76: return "R_SPARC_TLS_DTPOFF32";
case 77: return "R_SPARC_TLS_DTPOFF64";
case 78: return "R_SPARC_TLS_TPOFF32";
case 79: return "R_SPARC_TLS_TPOFF64";
}
break;
case EM_X86_64:
switch(type) {
case 0: return "R_X86_64_NONE";
case 1: return "R_X86_64_64";
case 2: return "R_X86_64_PC32";
case 3: return "R_X86_64_GOT32";
case 4: return "R_X86_64_PLT32";
case 5: return "R_X86_64_COPY";
case 6: return "R_X86_64_GLOB_DAT";
case 7: return "R_X86_64_JUMP_SLOT";
case 8: return "R_X86_64_RELATIVE";
case 9: return "R_X86_64_GOTPCREL";
case 10: return "R_X86_64_32";
case 11: return "R_X86_64_32S";
case 12: return "R_X86_64_16";
case 13: return "R_X86_64_PC16";
case 14: return "R_X86_64_8";
case 15: return "R_X86_64_PC8";
case 16: return "R_X86_64_DTPMOD64";
case 17: return "R_X86_64_DTPOFF64";
case 18: return "R_X86_64_TPOFF64";
case 19: return "R_X86_64_TLSGD";
case 20: return "R_X86_64_TLSLD";
case 21: return "R_X86_64_DTPOFF32";
case 22: return "R_X86_64_GOTTPOFF";
case 23: return "R_X86_64_TPOFF32";
case 24: return "R_X86_64_PC64";
case 25: return "R_X86_64_GOTOFF64";
case 26: return "R_X86_64_GOTPC32";
case 27: return "R_X86_64_GOT64";
case 28: return "R_X86_64_GOTPCREL64";
case 29: return "R_X86_64_GOTPC64";
case 30: return "R_X86_64_GOTPLT64";
case 31: return "R_X86_64_PLTOFF64";
case 32: return "R_X86_64_SIZE32";
case 33: return "R_X86_64_SIZE64";
case 34: return "R_X86_64_GOTPC32_TLSDESC";
case 35: return "R_X86_64_TLSDESC_CALL";
case 36: return "R_X86_64_TLSDESC";
case 37: return "R_X86_64_IRELATIVE";
}
break;
}
snprintf(s_type, sizeof(s_type), "<unknown: %#x>", type);
return (s_type);
}
static const char *
note_type(const char *name, unsigned int et, unsigned int nt)
{
@ -3303,11 +2763,11 @@ dump_rel(struct readelf *re, struct section *s, Elf_Data *d)
#define REL_HDR "r_offset", "r_info", "r_type", "st_value", "st_name"
#define REL_CT32 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \
r_type(re->ehdr.e_machine, ELF32_R_TYPE(r.r_info)), \
(uintmax_t)symval, symname
elftc_reloc_type_str(re->ehdr.e_machine, \
ELF32_R_TYPE(r.r_info)), (uintmax_t)symval, symname
#define REL_CT64 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \
r_type(re->ehdr.e_machine, ELF64_R_TYPE(r.r_info)), \
(uintmax_t)symval, symname
elftc_reloc_type_str(re->ehdr.e_machine, \
ELF64_R_TYPE(r.r_info)), (uintmax_t)symval, symname
printf("\nRelocation section (%s):\n", s->name);
if (re->ec == ELFCLASS32)
@ -3360,11 +2820,11 @@ dump_rela(struct readelf *re, struct section *s, Elf_Data *d)
#define RELA_HDR "r_offset", "r_info", "r_type", "st_value", \
"st_name + r_addend"
#define RELA_CT32 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \
r_type(re->ehdr.e_machine, ELF32_R_TYPE(r.r_info)), \
(uintmax_t)symval, symname
elftc_reloc_type_str(re->ehdr.e_machine, \
ELF32_R_TYPE(r.r_info)), (uintmax_t)symval, symname
#define RELA_CT64 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \
r_type(re->ehdr.e_machine, ELF64_R_TYPE(r.r_info)), \
(uintmax_t)symval, symname
elftc_reloc_type_str(re->ehdr.e_machine, \
ELF64_R_TYPE(r.r_info)), (uintmax_t)symval, symname
printf("\nRelocation section with addend (%s):\n", s->name);
if (re->ec == ELFCLASS32)
@ -3471,7 +2931,7 @@ dump_symtab(struct readelf *re, int i)
printf(" %16.16jx", (uintmax_t) sym.st_value);
printf(" %5ju", (uintmax_t) sym.st_size);
printf(" %-7s", st_type(re->ehdr.e_machine,
GELF_ST_TYPE(sym.st_info)));
re->ehdr.e_ident[EI_OSABI], GELF_ST_TYPE(sym.st_info)));
printf(" %-6s", st_bind(GELF_ST_BIND(sym.st_info)));
printf(" %-8s", st_vis(GELF_ST_VISIBILITY(sym.st_other)));
printf(" %3s", st_shndx(sym.st_shndx));
@ -3722,6 +3182,10 @@ dump_gnu_hash(struct readelf *re, struct section *s)
ds = &re->sl[s->link];
if (!get_ent_count(ds, &dynsymcount))
return;
if (symndx >= (uint32_t)dynsymcount) {
warnx("Malformed .gnu.hash section (symndx out of range)");
return;
}
nchain = dynsymcount - symndx;
if (d->d_size != 4 * sizeof(uint32_t) + maskwords *
(re->ec == ELFCLASS32 ? sizeof(uint32_t) : sizeof(uint64_t)) +
@ -3787,7 +3251,7 @@ dump_notes(struct readelf *re)
const char *rawfile;
GElf_Phdr phdr;
Elf_Data *d;
size_t phnum;
size_t filesize, phnum;
int i, elferr;
if (re->ehdr.e_type == ET_CORE) {
@ -3801,7 +3265,7 @@ dump_notes(struct readelf *re)
}
if (phnum == 0)
return;
if ((rawfile = elf_rawfile(re->elf, NULL)) == NULL) {
if ((rawfile = elf_rawfile(re->elf, &filesize)) == NULL) {
warnx("elf_rawfile failed: %s", elf_errmsg(-1));
return;
}
@ -3811,9 +3275,15 @@ dump_notes(struct readelf *re)
elf_errmsg(-1));
continue;
}
if (phdr.p_type == PT_NOTE)
if (phdr.p_type == PT_NOTE) {
if (phdr.p_offset >= filesize ||
phdr.p_filesz > filesize - phdr.p_offset) {
warnx("invalid PHDR offset");
continue;
}
dump_notes_content(re, rawfile + phdr.p_offset,
phdr.p_filesz, phdr.p_offset);
}
}
} else {
@ -6803,9 +6273,12 @@ get_symbol_name(struct readelf *re, int symtab, int i)
if (gelf_getsym(data, i, &sym) != &sym)
return ("");
/* Return section name for STT_SECTION symbol. */
if (GELF_ST_TYPE(sym.st_info) == STT_SECTION &&
re->sl[sym.st_shndx].name != NULL)
return (re->sl[sym.st_shndx].name);
if (GELF_ST_TYPE(sym.st_info) == STT_SECTION) {
if (sym.st_shndx < re->shnum &&
re->sl[sym.st_shndx].name != NULL)
return (re->sl[sym.st_shndx].name);
return ("");
}
if (s->link >= re->shnum ||
(name = elf_strptr(re->elf, s->link, sym.st_name)) == NULL)
return ("");

View File

@ -38,7 +38,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: size.c 3242 2015-08-07 12:47:11Z emaste $");
ELFTC_VCSID("$Id: size.c 3458 2016-05-09 15:01:25Z emaste $");
#define BUF_SIZE 1024
#define ELF_ALIGN(val,x) (((val)+(x)-1) & ~((x)-1))
@ -262,7 +262,7 @@ static void
handle_core_note(Elf *elf, GElf_Ehdr *elfhdr, GElf_Phdr *phdr,
char **cmd_line)
{
size_t max_size;
size_t max_size, segment_end;
uint64_t raw_size;
GElf_Off offset;
static pid_t pid;
@ -276,7 +276,13 @@ handle_core_note(Elf *elf, GElf_Ehdr *elfhdr, GElf_Phdr *phdr,
data = elf_rawfile(elf, &max_size);
offset = phdr->p_offset;
while (data != NULL && offset < phdr->p_offset + phdr->p_filesz) {
if (offset >= max_size || phdr->p_filesz > max_size - offset) {
warnx("invalid PHDR offset");
return;
}
segment_end = phdr->p_offset + phdr->p_filesz;
while (data != NULL && offset + sizeof(Elf32_Nhdr) < segment_end) {
nhdr = (Elf32_Nhdr *)(uintptr_t)((char*)data + offset);
memset(&nhdr_l, 0, sizeof(Elf32_Nhdr));
if (!xlatetom(elf, elfhdr, &nhdr->n_type, &nhdr_l.n_type,
@ -287,6 +293,13 @@ handle_core_note(Elf *elf, GElf_Ehdr *elfhdr, GElf_Phdr *phdr,
ELF_T_WORD, sizeof(Elf32_Word)))
break;
if (offset + sizeof(Elf32_Nhdr) +
ELF_ALIGN(nhdr_l.n_namesz, 4) +
ELF_ALIGN(nhdr_l.n_descsz, 4) >= segment_end) {
warnx("invalid note header");
return;
}
name = (char *)((char *)nhdr + sizeof(Elf32_Nhdr));
switch (nhdr_l.n_type) {
case NT_PRSTATUS: {
@ -424,8 +437,8 @@ handle_core_note(Elf *elf, GElf_Ehdr *elfhdr, GElf_Phdr *phdr,
}
/*
* Handles program headers except for PT_NOTE, when sysv output stlye is
* choosen, prints out the segment name and length. For berkely output
* Handles program headers except for PT_NOTE, when sysv output style is
* chosen, prints out the segment name and length. For berkely output
* style only PT_LOAD segments are handled, and text,
* data, bss size is calculated for them.
*/
@ -596,7 +609,7 @@ handle_elf(char const *name)
elf_cmd = elf_next(elf);
(void) elf_end(elf);
warnx("%s: File format not recognized",
arhdr->ar_name);
arhdr != NULL ? arhdr->ar_name : name);
continue;
}
/* Core dumps are handled separately */
@ -735,7 +748,7 @@ berkeley_calc(GElf_Shdr *shdr)
static void
berkeley_totals(void)
{
long unsigned int grand_total;
uint64_t grand_total;
grand_total = text_size_total + data_size_total + bss_size_total;
tbl_append();

View File

@ -46,7 +46,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: strings.c 3360 2016-01-24 18:34:06Z jkoshy $");
ELFTC_VCSID("$Id: strings.c 3446 2016-05-03 01:31:17Z emaste $");
enum return_code {
RETURN_OK,
@ -258,7 +258,7 @@ handle_elf(const char *name, int fd)
int rc;
rc = RETURN_OK;
/* If entire file is choosen, treat it as a binary file */
/* If entire file is chosen, treat it as a binary file */
if (entire_file)
return (handle_binary(name, fd));

6
test/cxxfilt/Makefile Normal file
View File

@ -0,0 +1,6 @@
# $Id$
TOP= ../..
SUBDIR= ts
.include "${TOP}/mk/elftoolchain.tetbase.mk"

11
test/cxxfilt/tet_scen Normal file
View File

@ -0,0 +1,11 @@
# $Id$
all
"Starting Test Suite"
^misc
"Complete Test Suite"
misc
"Starting noarg Test"
/ts/misc/tc
"Complete noarg Test"

5
test/cxxfilt/tetexec.cfg Normal file
View File

@ -0,0 +1,5 @@
# elfdump Test Suite.
#
# $Id$
TET_OUTPUT_CAPTURE=False

7
test/cxxfilt/ts/Makefile Normal file
View File

@ -0,0 +1,7 @@
# $Id$
TOP= ../../..
SUBDIR+= misc
.include "${TOP}/mk/elftoolchain.subdir.mk"

49
test/cxxfilt/ts/common/func.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/sh
#
# $Id$
tpstart() # write test purpose banner and initialise variables
{
tet_infoline "$*"
FAIL=N
}
tpresult() # give test purpose result
{
# $1 is result code to give if FAIL=N (default PASS)
if [ $FAIL = N ]; then
tet_result ${1-PASS}
else
tet_result FAIL
fi
}
check_rlt() # execute command (saving output) and check exit code
{
# $1 is command, $2 is expected exit code (0 or "N" for non-zero)
RLT=`$1`
CODE=$?
if [ $2 = 0 -a $CODE -ne 0 ]; then
tet_infoline "Command ($1) gave exit code $CODE, expected 0"
FAIL=Y
elif [ $2 != 0 -a $CODE -eq 0 ]; then
tet_infoline "Command ($1) gave exit code $CODE, expected non-zero"
FAIL=Y
fi
# $3 is expected result.
if [ "$RLT" != "$3" ]; then
tet_infoline "Command ($1) gave wrong result:"
tet_infoline "$RLT"
tet_infoline "expected:"
tet_infoline "$3"
FAIL=Y
fi
}
run()
{
tpstart "Running test '$1'"
check_rlt "$TET_SUITE_ROOT/../../cxxfilt/c++filt $1" 0 "$2"
tpresult
}

33
test/cxxfilt/ts/common/gen.awk Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/awk -f
#
# $Id$
BEGIN {
FS = "\""
tp = 0
print "#!/bin/sh\n"
}
{
sub(/#.*/, "");
if (NF >= 5) {
tp++
printf("tp%d()\n{\n run \"%s\" \"%s\"\n}\n\n", tp, $2, $4);
}
}
END {
print "tet_startup=\"\""
print "tet_cleanup=\"\"\n"
printf("%s", "iclist=\"");
for (i = 1; i <= tp; i++) {
printf("ic%d", i);
if (i != tp)
printf(" ");
}
printf("\"\n\n");
for (i = 1; i <= tp; i++)
printf("ic%d=\"tp%d\"\n", i, i);
print "\n. $TET_SUITE_ROOT/ts/common/func.sh";
print ". $TET_ROOT/lib/xpg3sh/tcm.sh";
}

View File

@ -0,0 +1,15 @@
# $Id$
TCLIST?= tclist
.PHONY: all
all: tc
tc: ${TCLIST}
${.CURDIR}/../common/gen.awk ${.ALLSRC} > ${.TARGET}
chmod +x ${.TARGET}
clean:
rm -rf tc

View File

@ -0,0 +1,5 @@
# $Id$
TOP= ../../../..
.include "../common/ts.mk"

View File

@ -0,0 +1,15 @@
# simple function
"_Z1f", "f"
"_Z1fi", "f(int)"
"_Z1fic", "f(int, char)"
# namespace
"_ZN12elftoolchainE", "elftoolchain"
"_ZN11elftoolchainE", "_ZN11elftoolchainE"
"_ZN12elftoolchain", "_ZN12elftoolchain"
"_ZN12elftoolchain3foo3barE", "elftoolchain::foo::bar"
"_ZN12elftoolchain3foo3barEi", "elftoolchain::foo::bar(int)"
"_ZN12elftoolchain3foo3barEic", "elftoolchain::foo::bar(int, char)"

View File

@ -19,6 +19,6 @@ Program Header[2]:
Program Header[3]:
p_vaddr: 0x1610c p_flags: [ PF_R ]
p_paddr: 0x1610c p_type: [ PT_NULL ]
p_paddr: 0x1610c p_type: [ PT_GNU_EH_FRAME ]
p_filesz: 0x8 p_memsz: 0x8
p_offset: 0x1610c p_align: 0x4

View File

@ -32,7 +32,7 @@ entry: 2
p_align: 8
entry: 3
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 90380
p_vaddr: 0x1610c
p_paddr: 0x1610c

View File

@ -49,7 +49,7 @@ entry: 2
p_align: 8
entry: 3
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 90380
p_vaddr: 0x1610c
p_paddr: 0x1610c

View File

@ -32,7 +32,7 @@ entry: 2
p_align: 8
entry: 3
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 90380
p_vaddr: 0x1610c
p_paddr: 0x1610c

View File

@ -32,7 +32,7 @@ entry: 2
p_align: 8
entry: 3
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 90380
p_vaddr: 0x1610c
p_paddr: 0x1610c

View File

@ -19,12 +19,12 @@ Program Header[2]:
Program Header[3]:
p_vaddr: 0xb10 p_flags: [ PF_R ]
p_paddr: 0xb10 p_type: [ PT_NULL ]
p_paddr: 0xb10 p_type: [ PT_GNU_EH_FRAME ]
p_filesz: 0x3c p_memsz: 0x3c
p_offset: 0xb10 p_align: 0x4
Program Header[4]:
p_vaddr: 0 p_flags: [ PF_W|PF_R ]
p_paddr: 0 p_type: [ PT_LOAD ]
p_paddr: 0 p_type: [ PT_GNU_STACK ]
p_filesz: 0 p_memsz: 0
p_offset: 0 p_align: 0x8

View File

@ -32,7 +32,7 @@ entry: 2
p_align: 8
entry: 3
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 2832
p_vaddr: 0xb10
p_paddr: 0xb10
@ -42,7 +42,7 @@ entry: 3
p_align: 4
entry: 4
p_type: PT_LOAD
p_type: PT_GNU_STACK
p_offset: 0
p_vaddr: 0
p_paddr: 0

View File

@ -49,7 +49,7 @@ entry: 2
p_align: 8
entry: 3
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 2832
p_vaddr: 0xb10
p_paddr: 0xb10
@ -59,7 +59,7 @@ entry: 3
p_align: 4
entry: 4
p_type: PT_LOAD
p_type: PT_GNU_STACK
p_offset: 0
p_vaddr: 0
p_paddr: 0

View File

@ -32,7 +32,7 @@ entry: 2
p_align: 8
entry: 3
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 2832
p_vaddr: 0xb10
p_paddr: 0xb10
@ -42,7 +42,7 @@ entry: 3
p_align: 4
entry: 4
p_type: PT_LOAD
p_type: PT_GNU_STACK
p_offset: 0
p_vaddr: 0
p_paddr: 0

View File

@ -32,7 +32,7 @@ entry: 2
p_align: 8
entry: 3
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 2832
p_vaddr: 0xb10
p_paddr: 0xb10
@ -42,7 +42,7 @@ entry: 3
p_align: 4
entry: 4
p_type: PT_LOAD
p_type: PT_GNU_STACK
p_offset: 0
p_vaddr: 0
p_paddr: 0

View File

@ -47,6 +47,6 @@ Program Header[5]:
Program Header[6]:
p_vaddr: 0x40613c p_flags: [ PF_R ]
p_paddr: 0x40613c p_type: [ PT_NULL ]
p_paddr: 0x40613c p_type: [ PT_GNU_EH_FRAME ]
p_filesz: 0x8 p_memsz: 0x8
p_offset: 0x613c p_align: 0x4

View File

@ -62,7 +62,7 @@ entry: 5
p_align: 4
entry: 6
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 24892
p_vaddr: 0x40613c
p_paddr: 0x40613c

View File

@ -79,7 +79,7 @@ entry: 5
p_align: 4
entry: 6
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 24892
p_vaddr: 0x40613c
p_paddr: 0x40613c

View File

@ -79,7 +79,7 @@ entry: 5
p_align: 4
entry: 6
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 24892
p_vaddr: 0x40613c
p_paddr: 0x40613c

View File

@ -79,7 +79,7 @@ entry: 5
p_align: 4
entry: 6
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 24892
p_vaddr: 0x40613c
p_paddr: 0x40613c

View File

@ -62,7 +62,7 @@ entry: 5
p_align: 4
entry: 6
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 24892
p_vaddr: 0x40613c
p_paddr: 0x40613c

View File

@ -62,7 +62,7 @@ entry: 5
p_align: 4
entry: 6
p_type: PT_NULL
p_type: PT_GNU_EH_FRAME
p_offset: 24892
p_vaddr: 0x40613c
p_paddr: 0x40613c

View File

@ -5,4 +5,4 @@ Note Section: .note.ABI-tag
namesz 0x8:
FreeBSD
descsz 0x4:
desc[0] ffffffac ffffffb2 0a 00
desc[0] ac b2 0a 00