5aefb6555731130ca4fd295960123d71f2d21fe8rie/*
5aefb6555731130ca4fd295960123d71f2d21fe8rie * CDDL HEADER START
5aefb6555731130ca4fd295960123d71f2d21fe8rie *
5aefb6555731130ca4fd295960123d71f2d21fe8rie * The contents of this file are subject to the terms of the
5aefb6555731130ca4fd295960123d71f2d21fe8rie * Common Development and Distribution License (the "License").
5aefb6555731130ca4fd295960123d71f2d21fe8rie * You may not use this file except in compliance with the License.
5aefb6555731130ca4fd295960123d71f2d21fe8rie *
5aefb6555731130ca4fd295960123d71f2d21fe8rie * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5aefb6555731130ca4fd295960123d71f2d21fe8rie * or http://www.opensolaris.org/os/licensing.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * See the License for the specific language governing permissions
5aefb6555731130ca4fd295960123d71f2d21fe8rie * and limitations under the License.
5aefb6555731130ca4fd295960123d71f2d21fe8rie *
5aefb6555731130ca4fd295960123d71f2d21fe8rie * When distributing Covered Code, include this CDDL HEADER in each
5aefb6555731130ca4fd295960123d71f2d21fe8rie * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * If applicable, add the following below this CDDL HEADER, with the
5aefb6555731130ca4fd295960123d71f2d21fe8rie * fields enclosed by brackets "[]" replaced with your own identifying
5aefb6555731130ca4fd295960123d71f2d21fe8rie * information: Portions Copyright [yyyy] [name of copyright owner]
5aefb6555731130ca4fd295960123d71f2d21fe8rie *
5aefb6555731130ca4fd295960123d71f2d21fe8rie * CDDL HEADER END
5aefb6555731130ca4fd295960123d71f2d21fe8rie */
5aefb6555731130ca4fd295960123d71f2d21fe8rie
5aefb6555731130ca4fd295960123d71f2d21fe8rie/*
7e16fca05dfbcfd32c2ebc9e4d1abdac1cd8657cAli Bahrami * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * Use is subject to license terms.
5aefb6555731130ca4fd295960123d71f2d21fe8rie */
5aefb6555731130ca4fd295960123d71f2d21fe8rie
5aefb6555731130ca4fd295960123d71f2d21fe8rie#ifndef __ELFDUMP_H
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define __ELFDUMP_H
5aefb6555731130ca4fd295960123d71f2d21fe8rie
ba2be53024c0b999e74ba9adcd7d80fec5df8c57ab#include <_machelf.h>
5aefb6555731130ca4fd295960123d71f2d21fe8rie#include <debug.h>
5aefb6555731130ca4fd295960123d71f2d21fe8rie
5aefb6555731130ca4fd295960123d71f2d21fe8rie/*
5aefb6555731130ca4fd295960123d71f2d21fe8rie * Local include file for elfdump.
5aefb6555731130ca4fd295960123d71f2d21fe8rie */
5aefb6555731130ca4fd295960123d71f2d21fe8rie#ifdef __cplusplus
5aefb6555731130ca4fd295960123d71f2d21fe8rieextern "C" {
5aefb6555731130ca4fd295960123d71f2d21fe8rie#endif
5aefb6555731130ca4fd295960123d71f2d21fe8rie
981a172d53aeb81520fcfecf6ab2615277c7bd18ab/*
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * flags: This is a bitmask that controls elfdump's operations. There
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * are three categories of flag:
981a172d53aeb81520fcfecf6ab2615277c7bd18ab *
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * SHOW - Specify categories of things in the ELF object to display.
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * CALC - Compute something based on the contents of the ELF object.
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * CTL - Control options specify general options that are not
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * specific to any specific part of the ELF object, but
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * which apply at a higher level.
981a172d53aeb81520fcfecf6ab2615277c7bd18ab *
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * To simplify masking these categories, they are assigned bit ranges
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * as follows:
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * SHOW: Bottom 24-bits
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * CALC: Upper 2 bits of most significant byte
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * CTL: Lower 6 bits of most significant byte
981a172d53aeb81520fcfecf6ab2615277c7bd18ab */
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_DYNAMIC 0x00000001
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_EHDR 0x00000002
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_INTERP 0x00000004
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_SHDR 0x00000008
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_NOTE 0x00000010
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_PHDR 0x00000020
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_RELOC 0x00000040
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_SYMBOLS 0x00000080
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_VERSIONS 0x00000100
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_HASH 0x00000200
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_GOT 0x00000400
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_SYMINFO 0x00000800
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_MOVE 0x00001000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_GROUP 0x00002000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_CAP 0x00004000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_UNWIND 0x00008000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_SHOW_SORT 0x00010000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_CTL_LONGNAME 0x01000000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_CTL_DEMANGLE 0x02000000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_CTL_FAKESHDR 0x04000000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_CTL_MATCH 0x08000000
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami#define FLG_CTL_OSABI 0x10000000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami#define FLG_CALC_CHECKSUM 0x40000000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
981a172d53aeb81520fcfecf6ab2615277c7bd18ab/* Bitmasks that isolate the parts of a flag value */
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_MASK_SHOW 0x00ffffff
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami#define FLG_MASK_CTL 0x3f000000
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami#define FLG_MASK_CALC 0xc0000000
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
981a172d53aeb81520fcfecf6ab2615277c7bd18ab/*
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * Mask that selects the show flags that do not require the ELF
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * object to have a section header array.
981a172d53aeb81520fcfecf6ab2615277c7bd18ab */
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_MASK_SHOW_NOSHDR (FLG_SHOW_EHDR | FLG_SHOW_PHDR)
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
981a172d53aeb81520fcfecf6ab2615277c7bd18ab/*
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * Masks to select the flags that require the ELF object to
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * have a section header array, within each flag type.
981a172d53aeb81520fcfecf6ab2615277c7bd18ab */
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_MASK_SHOW_SHDR (FLG_MASK_SHOW & ~FLG_MASK_SHOW_NOSHDR)
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define FLG_MASK_CALC_SHDR FLG_CALC_CHECKSUM
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
5aefb6555731130ca4fd295960123d71f2d21fe8rie
981a172d53aeb81520fcfecf6ab2615277c7bd18ab/* Size of buffer used for formatting an index into textual representation */
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define MAXNDXSIZE 10
5aefb6555731130ca4fd295960123d71f2d21fe8rie
5aefb6555731130ca4fd295960123d71f2d21fe8rietypedef struct cache {
f5a18a30a06b60eec275589214da939abbaa99d9rie Elf_Scn *c_scn;
5aefb6555731130ca4fd295960123d71f2d21fe8rie Shdr *c_shdr;
5aefb6555731130ca4fd295960123d71f2d21fe8rie Elf_Data *c_data;
5aefb6555731130ca4fd295960123d71f2d21fe8rie char *c_name;
31fdd7ca2d295948f9f1bcc2a1178c66467bca63ab int c_ndx; /* Section index */
5aefb6555731130ca4fd295960123d71f2d21fe8rie} Cache;
5aefb6555731130ca4fd295960123d71f2d21fe8rie
5aefb6555731130ca4fd295960123d71f2d21fe8rietypedef struct got_info {
5aefb6555731130ca4fd295960123d71f2d21fe8rie Word g_reltype; /* it will never happen, but */
5aefb6555731130ca4fd295960123d71f2d21fe8rie /* support mixed relocations */
5aefb6555731130ca4fd295960123d71f2d21fe8rie void *g_rel;
5aefb6555731130ca4fd295960123d71f2d21fe8rie const char *g_symname;
5aefb6555731130ca4fd295960123d71f2d21fe8rie} Got_info;
5aefb6555731130ca4fd295960123d71f2d21fe8rie
5aefb6555731130ca4fd295960123d71f2d21fe8rieextern const Cache cache_init;
5aefb6555731130ca4fd295960123d71f2d21fe8rie
5aefb6555731130ca4fd295960123d71f2d21fe8rieextern void failure(const char *, const char *);
5aefb6555731130ca4fd295960123d71f2d21fe8rieextern const char *demangle(const char *, uint_t);
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
981a172d53aeb81520fcfecf6ab2615277c7bd18ab/*
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * Flags for the match() function:
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * MATCH_F_STRICT
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * A strict match requires an explicit match to
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * a user specified match (-I, -N, -T) option. A
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * non-strict match also succeeds if the match
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * list is empty.
981a172d53aeb81520fcfecf6ab2615277c7bd18ab *
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * MATCH_F_PHDR
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * The match item is a program header. If this
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * flag is not set, the match item is a section
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * header.
981a172d53aeb81520fcfecf6ab2615277c7bd18ab *
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * MATCH_F_NAME
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * The name parameter contains valid information.
981a172d53aeb81520fcfecf6ab2615277c7bd18ab *
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * MATCH_F_NDX
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * The ndx argument contains valid information
981a172d53aeb81520fcfecf6ab2615277c7bd18ab *
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * MATCH_F_TYPE
981a172d53aeb81520fcfecf6ab2615277c7bd18ab * The type argument contains valid information
981a172d53aeb81520fcfecf6ab2615277c7bd18ab */
981a172d53aeb81520fcfecf6ab2615277c7bd18abtypedef enum {
981a172d53aeb81520fcfecf6ab2615277c7bd18ab MATCH_F_STRICT = 1,
981a172d53aeb81520fcfecf6ab2615277c7bd18ab MATCH_F_PHDR = 2,
981a172d53aeb81520fcfecf6ab2615277c7bd18ab MATCH_F_NAME = 4,
981a172d53aeb81520fcfecf6ab2615277c7bd18ab MATCH_F_NDX = 8,
981a172d53aeb81520fcfecf6ab2615277c7bd18ab MATCH_F_TYPE = 16
981a172d53aeb81520fcfecf6ab2615277c7bd18ab} match_flags_t;
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
981a172d53aeb81520fcfecf6ab2615277c7bd18ab/* It is common for calls to match() to specify all three arguments */
981a172d53aeb81520fcfecf6ab2615277c7bd18ab#define MATCH_F_ALL (MATCH_F_NAME | MATCH_F_NDX | MATCH_F_TYPE)
981a172d53aeb81520fcfecf6ab2615277c7bd18ab
981a172d53aeb81520fcfecf6ab2615277c7bd18abextern int match(match_flags_t, const char *, uint_t, uint_t);
5aefb6555731130ca4fd295960123d71f2d21fe8rie
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab/*
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab * Possible return values from corenote()
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abtypedef enum {
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab CORENOTE_R_OK = 0, /* Note data successfully displayed */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab CORENOTE_R_OK_DUMP = 1, /* Note OK, but not handled. Display Hex dump */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab CORENOTE_R_BADDATA = 2, /* Note data truncated or otherwise malformed */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab CORENOTE_R_BADARCH = 3, /* core file note code does not contain */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab /* support for given architecture */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab CORENOTE_R_BADTYPE = 4 /* Unknown note type */
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab} corenote_ret_t;
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab
5aefb6555731130ca4fd295960123d71f2d21fe8rie/*
5aefb6555731130ca4fd295960123d71f2d21fe8rie * Define various elfdump() functions into their 32-bit and 64-bit variants.
5aefb6555731130ca4fd295960123d71f2d21fe8rie */
5aefb6555731130ca4fd295960123d71f2d21fe8rie#if defined(_ELF64)
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define cap cap64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define checksum checksum64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define dynamic dynamic64
39773e466ff90ce703d7f52f3267d7e96c09c6f5ab#define fake_shdr_cache fake_shdr_cache64
39773e466ff90ce703d7f52f3267d7e96c09c6f5ab#define fake_shdr_cache_free fake_shdr_cache_free64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define got got64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define group group64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define hash hash64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define interp interp64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define move move64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define note note64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define note_entry note_entry64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define regular regular64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define reloc reloc64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define sections sections64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define string string64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define symbols symbols64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define syminfo syminfo64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define symlookup symlookup64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define unwind unwind64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define versions versions64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define version_def version_def64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define version_need version_need64
5aefb6555731130ca4fd295960123d71f2d21fe8rie#else
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define cap cap32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define checksum checksum32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define dynamic dynamic32
39773e466ff90ce703d7f52f3267d7e96c09c6f5ab#define fake_shdr_cache fake_shdr_cache32
39773e466ff90ce703d7f52f3267d7e96c09c6f5ab#define fake_shdr_cache_free fake_shdr_cache_free32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define got got32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define group group32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define hash hash32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define interp interp32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define move move32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define note note32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define note_entry note_entry32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define regular regular32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define reloc reloc32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define sections sections32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define string string32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define symbols symbols32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define syminfo syminfo32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define symlookup symlookup32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define unwind unwind32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define versions versions32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define version_def version_def32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define version_need version_need32
5aefb6555731130ca4fd295960123d71f2d21fe8rie#endif
5aefb6555731130ca4fd295960123d71f2d21fe8rie
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87abextern corenote_ret_t corenote(Half, int, Word, const char *, Word);
37915d862fc5cc87b5b702954d7d7f16a9f98e5cRichard Loweextern void dump_eh_frame(const char *, char *, uchar_t *, size_t, uint64_t,
37915d862fc5cc87b5b702954d7d7f16a9f98e5cRichard Lowe Half e_machine, uchar_t *e_ident, uint64_t gotaddr);
7e16fca05dfbcfd32c2ebc9e4d1abdac1cd8657cAli Bahramiextern void dump_hex_bytes(const void *, size_t, int, int, int);
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab
39773e466ff90ce703d7f52f3267d7e96c09c6f5abextern int fake_shdr_cache32(const char *, int, Elf *, Elf32_Ehdr *,
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab Cache **, size_t *);
39773e466ff90ce703d7f52f3267d7e96c09c6f5abextern int fake_shdr_cache64(const char *, int, Elf *, Elf64_Ehdr *,
c6c9aed4d309e3d11be652b85e3bf8bb72f20c87ab Cache **, size_t *);
39773e466ff90ce703d7f52f3267d7e96c09c6f5ab
39773e466ff90ce703d7f52f3267d7e96c09c6f5abextern void fake_shdr_cache_free32(Cache *, size_t);
39773e466ff90ce703d7f52f3267d7e96c09c6f5abextern void fake_shdr_cache_free64(Cache *, size_t);
39773e466ff90ce703d7f52f3267d7e96c09c6f5ab
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahramiextern int regular32(const char *, int, Elf *, uint_t, const char *, int,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami uchar_t);
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahramiextern int regular64(const char *, int, Elf *, uint_t, const char *, int,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami uchar_t);
5aefb6555731130ca4fd295960123d71f2d21fe8rie
5aefb6555731130ca4fd295960123d71f2d21fe8rie#ifdef __cplusplus
5aefb6555731130ca4fd295960123d71f2d21fe8rie}
5aefb6555731130ca4fd295960123d71f2d21fe8rie#endif
5aefb6555731130ca4fd295960123d71f2d21fe8rie
5aefb6555731130ca4fd295960123d71f2d21fe8rie#endif /* __ELFDUMP_H */