elfconst.c revision ba2be53024c0b999e74ba9adcd7d80fec5df8c57
d29b2c4438482eb00488be49a1f5d6835f455546ab * CDDL HEADER START
d29b2c4438482eb00488be49a1f5d6835f455546ab * The contents of this file are subject to the terms of the
d29b2c4438482eb00488be49a1f5d6835f455546ab * Common Development and Distribution License (the "License").
d29b2c4438482eb00488be49a1f5d6835f455546ab * You may not use this file except in compliance with the License.
d29b2c4438482eb00488be49a1f5d6835f455546ab * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d29b2c4438482eb00488be49a1f5d6835f455546ab * See the License for the specific language governing permissions
d29b2c4438482eb00488be49a1f5d6835f455546ab * and limitations under the License.
d29b2c4438482eb00488be49a1f5d6835f455546ab * When distributing Covered Code, include this CDDL HEADER in each
d29b2c4438482eb00488be49a1f5d6835f455546ab * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d29b2c4438482eb00488be49a1f5d6835f455546ab * If applicable, add the following below this CDDL HEADER, with the
d29b2c4438482eb00488be49a1f5d6835f455546ab * fields enclosed by brackets "[]" replaced with your own identifying
d29b2c4438482eb00488be49a1f5d6835f455546ab * information: Portions Copyright [yyyy] [name of copyright owner]
d29b2c4438482eb00488be49a1f5d6835f455546ab * CDDL HEADER END
cce0e03bb2d07f0fe27cabb93acae9c23655859fab * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
d29b2c4438482eb00488be49a1f5d6835f455546ab * Use is subject to license terms.
d29b2c4438482eb00488be49a1f5d6835f455546ab#pragma ident "%Z%%M% %I% %E% SMI"
d29b2c4438482eb00488be49a1f5d6835f455546ab#include <_elfedit.h>
d29b2c4438482eb00488be49a1f5d6835f455546ab * This file contains support for mapping well known ELF constants
d29b2c4438482eb00488be49a1f5d6835f455546ab * to their numeric values. It is a layer on top of the elfedit_atoui()
d29b2c4438482eb00488be49a1f5d6835f455546ab * routines defined in util.c. The idea is that centralizing all the
d29b2c4438482eb00488be49a1f5d6835f455546ab * support for such constants will improve consistency between modules,
d29b2c4438482eb00488be49a1f5d6835f455546ab * allow for sharing of commonly needed items, and make the modules
d29b2c4438482eb00488be49a1f5d6835f455546ab * simpler.
d29b2c4438482eb00488be49a1f5d6835f455546ab * elfedit output style, with and without leading -o
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_STR_MINUS_O_DEFAULT), ELFEDIT_OUTSTYLE_DEFAULT },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_STR_MINUS_O_SIMPLE), ELFEDIT_OUTSTYLE_SIMPLE },
d29b2c4438482eb00488be49a1f5d6835f455546ab * Booleans
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF section indexes with support for the special index names.
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHN_AMD64_LCOMMON_ALT1), SHN_AMD64_LCOMMON },
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF section types.
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_PREINIT_ARRAY_ALT1), SHT_PREINIT_ARRAY },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SYMTAB_SHNDX_ALT1), SHT_SYMTAB_SHNDX },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_SYMSORT_ALT1), SHT_SUNW_symsort },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_TLSSORT_ALT1), SHT_SUNW_tlssort },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_LDYNSYM_ALT1), SHT_SUNW_LDYNSYM },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_SIGNATURE), SHT_SUNW_SIGNATURE },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_SIGNATURE_ALT1), SHT_SUNW_SIGNATURE },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_ANNOTATE_ALT1), SHT_SUNW_ANNOTATE },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_DEBUGSTR_ALT1), SHT_SUNW_DEBUGSTR },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_SYMINFO_ALT1), SHT_SUNW_syminfo },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_VERNEED_ALT1), SHT_SUNW_verneed },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SPARC_GOTDATA_ALT1), SHT_SPARC_GOTDATA },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_AMD64_UNWIND_ALT1), SHT_AMD64_UNWIND },
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF section types.
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF section types for symbol tables
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_LDYNSYM_ALT1), SHT_SUNW_LDYNSYM },
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF section types for SHT_SYMTAB
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF section types for SHT_SYMTAB
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF section types for SHT_SUNW_LDYNSYM
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHT_SUNW_LDYNSYM_ALT1), SHT_SUNW_LDYNSYM },
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF dynamic tag DT_ values
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_DT_PREINIT_ARRAY_ALT1), DT_PREINIT_ARRAY },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_DT_PREINIT_ARRAYSZ), DT_PREINIT_ARRAYSZ },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_DT_PREINIT_ARRAYSZ_ALT1), DT_PREINIT_ARRAYSZ },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_DT_SUNW_AUXILIARY_ALT1), DT_SUNW_AUXILIARY },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_DT_SUNW_SYMSORTSZ_ALT1), DT_SUNW_SYMSORTSZ },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_DT_SUNW_TLSSORTSZ_ALT1), DT_SUNW_TLSSORTSZ },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_DT_SPARC_REGISTER_ALT1), DT_SPARC_REGISTER },
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF DT_FLAGS DF_* values
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF DT_POSFLAG_1 DF_P1_* values
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF DT_FLAGS_1 DF_1_* values
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF DT_FEATURE_1 DTF_1_* values
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF header EI_* indexes
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF header ET_* file type values
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELFCLASS
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF header EF_* flags
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_EF_SPARC_SUN_US1_ALT1), EF_SPARC_SUN_US1 },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_EF_SPARC_SUN_US3_ALT1), EF_SPARC_SUN_US3 },
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF header EV_* versions
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF EM_* machine types
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF header ELFOSABI_* values (and common aliases)
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_ELFOSABI_SOLARIS_ALT1), ELFOSABI_SOLARIS },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_ELFOSABI_FREEBSD_ALT1), ELFOSABI_FREEBSD },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_ELFOSABI_MODESTO_ALT1), ELFOSABI_MODESTO },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_ELFOSABI_OPENBSD_ALT1), ELFOSABI_OPENBSD },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_ELFOSABI_OPENVMS_ALT1), ELFOSABI_OPENVMS },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_ELFOSABI_STANDALONE), ELFOSABI_STANDALONE },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_ELFOSABI_STANDALONE_ALT1), ELFOSABI_STANDALONE },
d29b2c4438482eb00488be49a1f5d6835f455546ab * Program header PT_* type values
d29b2c4438482eb00488be49a1f5d6835f455546ab * Program header PF_* flag values
d29b2c4438482eb00488be49a1f5d6835f455546ab * Section header SHF_* flag values
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHF_OS_NONCONFORMING), SHF_OS_NONCONFORMING },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SHF_OS_NONCONFORMING_ALT1), SHF_OS_NONCONFORMING },
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF symbol bindings (st_info ELF_ST_BIND)
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF symbol types (st_info ELF_ST_TYPE)
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF symbol visibility (st_other ELF_ST_VISIBILITY)
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF syminfo SYMINFO_BT_ special boundto values
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_BT_PARENT_ALT1), SYMINFO_BT_PARENT },
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF syminfo SYMINFO_FLG_ flags
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_FLG_DIRECT), SYMINFO_FLG_DIRECT },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_FLG_DIRECT_ALT1), SYMINFO_FLG_DIRECT },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_FLG_COPY_ALT1), SYMINFO_FLG_COPY },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_FLG_LAZYLOAD), SYMINFO_FLG_LAZYLOAD },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_FLG_LAZYLOAD_ALT1), SYMINFO_FLG_LAZYLOAD },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_FLG_DIRECTBIND), SYMINFO_FLG_DIRECTBIND },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_FLG_DIRECTBIND_ALT1), SYMINFO_FLG_DIRECTBIND },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_FLG_NOEXTDIRECT), SYMINFO_FLG_NOEXTDIRECT },
d29b2c4438482eb00488be49a1f5d6835f455546ab { MSG_ORIG(MSG_SYMINFO_FLG_NOEXTDIRECT_ALT1), SYMINFO_FLG_NOEXTDIRECT },
d29b2c4438482eb00488be49a1f5d6835f455546ab * ELF capabilities tag CA_ values
d29b2c4438482eb00488be49a1f5d6835f455546ab * AV_386 flags used for CA_SUNW_HW_1 capabilities
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * The space for this is reserved at compile time, but the values are
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * filled in at runtime on demand from the usr/src/common/elfcap code.
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * Note that we need two slots for every capability, one for the full
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * string, and another for the informal lowercase version.
99f63845ee65f89a523460ce4b6b0603a06eceb7abstatic elfedit_atoui_sym_t sym_av_386[(2 * ELFCAP_NUM_HW1_386) + 1];
d29b2c4438482eb00488be49a1f5d6835f455546ab * AV_SPARC flags used for CA_SUNW_HW_1 capabilities
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * The space for this is reserved at compile time, but the values are
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * filled in at runtime on demand from the usr/src/common/elfcap code.
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * Note that we need two slots for every capability, one for the full
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * string, and another for the informal lowercase version.
99f63845ee65f89a523460ce4b6b0603a06eceb7abstatic elfedit_atoui_sym_t sym_av_sparc[(2 * ELFCAP_NUM_HW1_SPARC) + 1];
d29b2c4438482eb00488be49a1f5d6835f455546ab * SF1_SUNW flags used for CA_SUNW_SF_1 capabilities
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * The space for this is reserved at compile time, but the values are
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * filled in at runtime on demand from the usr/src/common/elfcap code.
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * Note that we need two slots for every capability, one for the full
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * string, and another for the informal lowercase version.
99f63845ee65f89a523460ce4b6b0603a06eceb7abstatic elfedit_atoui_sym_t sym_sf1_sunw[(2 * ELFCAP_NUM_SF1) + 1];
d29b2c4438482eb00488be49a1f5d6835f455546ab * Array of pointers to atoui arrays for each constant type, indexed
d29b2c4438482eb00488be49a1f5d6835f455546ab * by elfedit_const_t value. The number and order of entries in this
d29b2c4438482eb00488be49a1f5d6835f455546ab * table must agree with the definition of elfedit_const_t in elfedit.h.
d29b2c4438482eb00488be49a1f5d6835f455546ab sym_elfclass, /* 17: ELFEDIT_CONST_ELFCLASS: Ehdr class */
d29b2c4438482eb00488be49a1f5d6835f455546ab sym_elfdata, /* 18: ELFEDIT_CONST_ELFDATA: Ehdr endian */
d29b2c4438482eb00488be49a1f5d6835f455546ab sym_syminfo_bt, /* 29: ELFEDIT_CONST_SYMINFO_BT:Syminfo bndto */
d29b2c4438482eb00488be49a1f5d6835f455546ab sym_syminfo_flg, /* 30: ELFEDIT_CONST_SYMINFO_FLG:Syminfo flag */
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * Fill in the specified hardware/software capability array
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * const_type - Index of constant item being filled
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * arr - elfedit_atoui_sym_t array to be filled
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * desc - Array of capability descriptors from elfcap
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * cnt - # of capability descriptors.
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * arr is expected to have [(2 * cnt) + 1] elements, all zero filled.
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * For each descriptor, 2 array elements are filled in. The first one
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * has the full name, and the second has the lowecase informal version.
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * The final element of arr is left as NULL, to serve as termination.
99f63845ee65f89a523460ce4b6b0603a06eceb7abstatic void
99f63845ee65f89a523460ce4b6b0603a06eceb7ab elfedit_atoui_sym_t *arr, const elfcap_desc_t *desc, size_t cnt)
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * Ignore "placeholder" items. These represent
99f63845ee65f89a523460ce4b6b0603a06eceb7ab * unallocated holes in the capability bits.
d29b2c4438482eb00488be49a1f5d6835f455546ab * Given an elfedit_const_t value, return the array of elfedit_atoui_sym_t
d29b2c4438482eb00488be49a1f5d6835f455546ab * entries that it represents.
d29b2c4438482eb00488be49a1f5d6835f455546ab if ((const_type < 0) ||
d29b2c4438482eb00488be49a1f5d6835f455546ab (const_type >= (sizeof (sym_table) / sizeof (sym_table[0]))))
d29b2c4438482eb00488be49a1f5d6835f455546ab elfedit_msg(ELFEDIT_MSG_ERR, MSG_INTL(MSG_ERR_BADCONST));
99f63845ee65f89a523460ce4b6b0603a06eceb7ab /* Fill capability constant array on demand? */
d29b2c4438482eb00488be49a1f5d6835f455546ab * Return the elfedit_atoui_t array that corresponds to the
d29b2c4438482eb00488be49a1f5d6835f455546ab * CA_SUNW_HW_1 hardware capabiliies field for a given
d29b2c4438482eb00488be49a1f5d6835f455546ab * machine type.
d29b2c4438482eb00488be49a1f5d6835f455546ab * This routine will return NULL if there is no definition for the
d29b2c4438482eb00488be49a1f5d6835f455546ab * machine specified.
d29b2c4438482eb00488be49a1f5d6835f455546ab switch (mach) {
d29b2c4438482eb00488be49a1f5d6835f455546ab /* A machine we don't know about */