elfconst.c revision d29b2c4438482eb00488be49a1f5d6835f455546
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <libintl.h>
#include <libelf.h>
#include <link.h>
#include <strings.h>
#include <ctype.h>
#include <elfedit.h>
#include <_elfedit.h>
#include <sys/elf_SPARC.h>
#include <sys/elf_amd64.h>
#include <sys/auxv_386.h>
#include <sys/auxv_SPARC.h>
#include <msg.h>
/*
* This file contains support for mapping well known ELF constants
* to their numeric values. It is a layer on top of the elfedit_atoui()
* routines defined in util.c. The idea is that centralizing all the
* support for such constants will improve consistency between modules,
* allow for sharing of commonly needed items, and make the modules
* simpler.
*/
/*
* elfedit output style, with and without leading -o
*/
static elfedit_atoui_sym_t sym_outstyle[] = {
{ NULL }
};
static elfedit_atoui_sym_t sym_minus_o_outstyle[] = {
{ NULL }
};
/*
* Booleans
*/
static elfedit_atoui_sym_t sym_bool[] = {
{ MSG_ORIG(MSG_STR_FALSE), 0 },
{ MSG_ORIG(MSG_STR_OFF), 0 },
{ MSG_ORIG(MSG_STR_NO), 0 },
{ NULL }
};
/*
* ELF section indexes with support for the special index names.
*/
static elfedit_atoui_sym_t sym_shn[] = {
{ NULL }
};
/*
* ELF section types.
*/
static elfedit_atoui_sym_t sym_sht[] = {
{ NULL }
};
/*
* ELF section types.
*/
static elfedit_atoui_sym_t sym_sht_strtab[] = {
{ NULL }
};
/*
* ELF section types for symbol tables
*/
static elfedit_atoui_sym_t sym_sht_allsymtab[] = {
{ NULL }
};
/*
* ELF section types for SHT_SYMTAB
*/
static elfedit_atoui_sym_t sym_sht_symtab[] = {
{ NULL }
};
/*
* ELF section types for SHT_SYMTAB
*/
static elfedit_atoui_sym_t sym_sht_dynsym[] = {
{ NULL }
};
/*
* ELF section types for SHT_SUNW_LDYNSYM
*/
static elfedit_atoui_sym_t sym_sht_ldynsym[] = {
{ NULL }
};
/*
* ELF dynamic tag DT_ values
*/
static elfedit_atoui_sym_t sym_dt[] = {
{ NULL }
};
/*
* ELF DT_FLAGS DF_* values
*/
static elfedit_atoui_sym_t sym_df[] = {
{ NULL }
};
/*
* ELF DT_POSFLAG_1 DF_P1_* values
*/
static elfedit_atoui_sym_t sym_df_p1[] = {
{ NULL }
};
/*
* ELF DT_FLAGS_1 DF_1_* values
*/
static elfedit_atoui_sym_t sym_df_1[] = {
{ NULL }
};
/*
* ELF DT_FEATURE_1 DTF_1_* values
*/
static elfedit_atoui_sym_t sym_dtf_1[] = {
{ NULL }
};
/*
* ELF header EI_* indexes
*/
static elfedit_atoui_sym_t sym_ei[] = {
{ NULL }
};
/*
* ELF header ET_* file type values
*/
static elfedit_atoui_sym_t sym_et[] = {
{ NULL }
};
/*
* ELFCLASS
*/
static elfedit_atoui_sym_t sym_elfclass[] = {
{ NULL }
};
/*
* ELFDATA
*/
static elfedit_atoui_sym_t sym_elfdata[] = {
{ NULL }
};
/*
* ELF header EF_* flags
*/
static elfedit_atoui_sym_t sym_ef[] = {
{ NULL }
};
/*
* ELF header EV_* versions
*/
static elfedit_atoui_sym_t sym_ev[] = {
{ NULL }
};
/*
* ELF EM_* machine types
*/
static elfedit_atoui_sym_t sym_em[] = {
{ NULL }
};
#error "EM_NUM has grown"
#endif
/*
* ELF header ELFOSABI_* values (and common aliases)
*/
static elfedit_atoui_sym_t sym_elfosabi[] = {
{ NULL }
};
/*
* Program header PT_* type values
*/
static elfedit_atoui_sym_t sym_pt[] = {
{ NULL }
};
/*
* Program header PF_* flag values
*/
static elfedit_atoui_sym_t sym_pf[] = {
{ NULL }
};
/*
* Section header SHF_* flag values
*/
static elfedit_atoui_sym_t sym_shf[] = {
{ NULL }
};
/*
* ELF symbol bindings (st_info ELF_ST_BIND)
*/
static elfedit_atoui_sym_t sym_stb[] = {
{ NULL }
};
/*
* ELF symbol types (st_info ELF_ST_TYPE)
*/
static elfedit_atoui_sym_t sym_stt[] = {
{ NULL }
};
/*
* ELF symbol visibility (st_other ELF_ST_VISIBILITY)
*/
static elfedit_atoui_sym_t sym_stv[] = {
{ NULL }
};
/*
* ELF syminfo SYMINFO_BT_ special boundto values
*/
static elfedit_atoui_sym_t sym_syminfo_bt[] = {
{ NULL }
};
/*
* ELF syminfo SYMINFO_FLG_ flags
*/
static elfedit_atoui_sym_t sym_syminfo_flg[] = {
{ NULL }
};
/*
* ELF capabilities tag CA_ values
*/
static elfedit_atoui_sym_t sym_ca[] = {
{ NULL }
};
/*
* AV_386 flags used for CA_SUNW_HW_1 capabilities
*/
static elfedit_atoui_sym_t sym_av_386[] = {
{ NULL }
};
/*
* AV_SPARC flags used for CA_SUNW_HW_1 capabilities
*/
static elfedit_atoui_sym_t sym_av_sparc[] = {
{ NULL }
};
/*
* SF1_SUNW flags used for CA_SUNW_SF_1 capabilities
*/
static elfedit_atoui_sym_t sym_sf1_sunw[] = {
{ NULL }
};
/*
* Array of pointers to atoui arrays for each constant type, indexed
* by elfedit_const_t value. The number and order of entries in this
* table must agree with the definition of elfedit_const_t in elfedit.h.
*/
static elfedit_atoui_sym_t *sym_table[] = {
sym_outstyle, /* 0: ELFEDIT_CONST_OUTSTYLE */
sym_minus_o_outstyle, /* 1: ELFEDIT_CONST_OUTSTYLE_MO */
sym_bool, /* 2: ELFEDIT_CONST_BOOL */
sym_shn, /* 3: ELFEDIT_CONST_SHN */
sym_sht, /* 4: ELFEDIT_CONST_SHT */
sym_sht_strtab, /* 5: ELFEDIT_CONST_SHT_STRTAB */
sym_sht_allsymtab, /* 6: ELFEDIT_CONST_SHT_ALLSYMTAB */
sym_sht_symtab, /* 7: ELFEDIT_CONST_SHT_SYMTAB */
sym_sht_dynsym, /* 8: ELFEDIT_CONST_SHT_DYNSYM */
sym_sht_ldynsym, /* 9: ELFEDIT_CONST_SHT_LDYNSYM */
sym_dt, /* 10: ELFEDIT_CONST_DT: Dynamic tags */
sym_df, /* 11: ELFEDIT_CONST_DF: DT_FLAGS */
sym_df_p1, /* 12: ELFEDIT_CONST_DF_P1: DF_POSFLAG_1 */
sym_df_1, /* 13: ELFEDIT_CONST_DF_1: DT_FLAGS_1 */
sym_dtf_1, /* 14: ELFEDIT_CONST_DTF_1: DT_FEATURE_1 */
sym_ei, /* 15: ELFEDIT_CONST_EI: Ehdr e_ident indexes */
sym_et, /* 16: ELFEDIT_CONST_ET: Ehdr obj type */
sym_elfclass, /* 17: ELFEDIT_CONST_ELFCLASS: Ehdr class */
sym_elfdata, /* 18: ELFEDIT_CONST_ELFDATA: Ehdr endian */
sym_ef, /* 19: ELFEDIT_CONST_EF: Ehdr flags */
sym_ev, /* 20: ELFEDIT_CONST_EV: Ehdr version */
sym_em, /* 21: ELFEDIT_CONST_EM: Ehdr machine */
sym_elfosabi, /* 22: ELFEDIT_CONST_ELFOSABI: Ehdr ABI */
sym_pt, /* 23: ELFEDIT_CONST_PT: Phdr type */
sym_pf, /* 24: ELFEDIT_CONST_PF: Phdr flags */
sym_shf, /* 25: ELFEDIT_CONST_SHF: Shdr flags */
sym_stb, /* 26: ELFEDIT_CONST_STB: Sym binding */
sym_stt, /* 27: ELFEDIT_CONST_STT: Sym type */
sym_stv, /* 28: ELFEDIT_CONST_STV: Sym visibility */
sym_syminfo_bt, /* 29: ELFEDIT_CONST_SYMINFO_BT:Syminfo bndto */
sym_syminfo_flg, /* 30: ELFEDIT_CONST_SYMINFO_FLG:Syminfo flag */
sym_ca, /* 31: ELFEDIT_CONST_CA: Capabilities tags */
sym_av_386, /* 32: ELFEDIT_CONST_AV_386: X86 HW caps */
sym_av_sparc, /* 33: ELFEDIT_CONST_AV_SPARC: sparc HW caps */
sym_sf1_sunw, /* 34: ELFEDIT_CONST_SF1_SUNW: software caps */
};
/*
* Given an elfedit_const_t value, return the array of elfedit_atoui_sym_t
* entries that it represents.
*/
{
if ((const_type < 0) ||
return (sym_table[const_type]);
}
/*
* Return the elfedit_atoui_t array that corresponds to the
* CA_SUNW_HW_1 hardware capabiliies field for a given
* machine type.
*
* This routine will return NULL if there is no definition for the
* machine specified.
*/
{
switch (mach) {
case EM_386:
case EM_486:
case EM_AMD64:
return (elfedit_const_to_atoui(ELFEDIT_CONST_AV_386));
case EM_SPARC:
case EM_SPARC32PLUS:
case EM_SPARCV9:
return (elfedit_const_to_atoui(ELFEDIT_CONST_AV_SPARC));
}
/* A machine we don't know about */
return (NULL);
}