Home | History | Annotate | Download | only in libebl
      1 /* MIPS specific symbolic name handling.
      2    Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
      3    Written by Ulrich Drepper <drepper (at) redhat.com>, 2000.
      4 
      5    This program is Open Source software; you can redistribute it and/or
      6    modify it under the terms of the Open Software License version 1.0 as
      7    published by the Open Source Initiative.
      8 
      9    You should have received a copy of the Open Software License along
     10    with this program; if not, you may obtain a copy of the Open Software
     11    License version 1.0 from http://www.opensource.org/licenses/osl.php or
     12    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
     13    3001 King Ranch Road, Ukiah, CA 95482.   */
     14 
     15 #ifdef HAVE_CONFIG_H
     16 # include <config.h>
     17 #endif
     18 
     19 #include <elf.h>
     20 #include <stddef.h>
     21 
     22 #include <libebl_mips.h>
     23 
     24 
     25 /* Return of the backend.  */
     26 const char *
     27 mips_backend_name (void)
     28 {
     29   return "mips";
     30 }
     31 
     32 
     33 /* Determine relocation type string for MIPS.  */
     34 const char *
     35 mips_reloc_type_name (int type, char *buf, size_t len)
     36 {
     37   static const char *map_table[] =
     38   {
     39     [R_MIPS_NONE] = "MIPS_NONE",
     40     [R_MIPS_16] = "MIPS_16",
     41     [R_MIPS_32] = "MIPS_32",
     42     [R_MIPS_REL32] = "MIPS_REL32",
     43     [R_MIPS_26] = "MIPS_26",
     44     [R_MIPS_HI16] = "MIPS_HI16",
     45     [R_MIPS_LO16] = "MIPS_LO16",
     46     [R_MIPS_GPREL16] = "MIPS_GPREL16",
     47     [R_MIPS_LITERAL] = "MIPS_LITERAL",
     48     [R_MIPS_GOT16] = "MIPS_GOT16",
     49     [R_MIPS_PC16] = "MIPS_PC16",
     50     [R_MIPS_CALL16] = "MIPS_CALL16",
     51     [R_MIPS_GPREL32] = "MIPS_GPREL32",
     52     [R_MIPS_SHIFT5] = "MIPS_SHIFT5",
     53     [R_MIPS_SHIFT6] = "MIPS_SHIFT6",
     54     [R_MIPS_64] = "MIPS_64",
     55     [R_MIPS_GOT_DISP] = "MIPS_GOT_DISP",
     56     [R_MIPS_GOT_PAGE] = "MIPS_GOT_PAGE",
     57     [R_MIPS_GOT_OFST] = "MIPS_GOT_OFST",
     58     [R_MIPS_GOT_HI16] = "MIPS_GOT_HI16",
     59     [R_MIPS_GOT_LO16] = "MIPS_GOT_LO16",
     60     [R_MIPS_SUB] = "MIPS_SUB",
     61     [R_MIPS_INSERT_A] = "MIPS_INSERT_A",
     62     [R_MIPS_INSERT_B] = "MIPS_INSERT_B",
     63     [R_MIPS_DELETE] = "MIPS_DELETE",
     64     [R_MIPS_HIGHER] = "MIPS_HIGHER",
     65     [R_MIPS_HIGHEST] = "MIPS_HIGHEST",
     66     [R_MIPS_CALL_HI16] = "MIPS_CALL_HI16",
     67     [R_MIPS_CALL_LO16] = "MIPS_CALL_LO16",
     68     [R_MIPS_SCN_DISP] = "MIPS_SCN_DISP",
     69     [R_MIPS_REL16] = "MIPS_REL16",
     70     [R_MIPS_ADD_IMMEDIATE] = "MIPS_ADD_IMMEDIATE",
     71     [R_MIPS_PJUMP] = "MIPS_PJUMP",
     72     [R_MIPS_RELGOT] = "MIPS_RELGOT",
     73     [R_MIPS_JALR] = "MIPS_JALR"
     74   };
     75 
     76   if (type < 0 || type >= R_MIPS_NUM)
     77     return NULL;
     78 
     79   return map_table[type];
     80 }
     81 
     82 
     83 const char *
     84 mips_segment_type_name (int type, char *buf, size_t len)
     85 {
     86   static const struct
     87   {
     88     int type;
     89     const char *str;
     90   } mips_segments[] =
     91     {
     92       { PT_MIPS_REGINFO, "MIPS_REGINFO" },
     93       { PT_MIPS_RTPROC, "MIPS_RTPROC" },
     94       { PT_MIPS_OPTIONS, "MIPS_OPTIONS" }
     95     };
     96 #define nsegments (sizeof (mips_segments) / sizeof (mips_segments[0]))
     97   size_t cnt;
     98 
     99   for (cnt = 0; cnt < nsegments; ++cnt)
    100     if (type == mips_segments[cnt].type)
    101       return mips_segments[cnt].str;
    102 
    103   /* We don't know the segment type.  */
    104   return NULL;
    105 }
    106 
    107 
    108 const char *
    109 mips_section_type_name (int type, char *buf, size_t len)
    110 {
    111   static const struct
    112   {
    113     int type;
    114     const char *str;
    115   } mips_sections[] =
    116     {
    117       { SHT_MIPS_LIBLIST, "MIPS_LIBLIST" },
    118       { SHT_MIPS_MSYM, "MIPS_MSYM" },
    119       { SHT_MIPS_CONFLICT, "MIPS_CONFLICT" },
    120       { SHT_MIPS_GPTAB, "MIPS_GPTAB" },
    121       { SHT_MIPS_UCODE, "MIPS_UCODE" },
    122       { SHT_MIPS_DEBUG, "MIPS_DEBUG" },
    123       { SHT_MIPS_REGINFO, "MIPS_REGINFO" },
    124       { SHT_MIPS_PACKAGE, "MIPS_PACKAGE" },
    125       { SHT_MIPS_PACKSYM, "MIPS_PACKSYM" },
    126       { SHT_MIPS_RELD, "MIPS_RELD" },
    127       { SHT_MIPS_IFACE, "MIPS_IFACE" },
    128       { SHT_MIPS_CONTENT, "MIPS_CONTENT" },
    129       { SHT_MIPS_OPTIONS, "MIPS_OPTIONS" },
    130       { SHT_MIPS_SHDR, "MIPS_SHDR" },
    131       { SHT_MIPS_FDESC, "MIPS_FDESC" },
    132       { SHT_MIPS_EXTSYM, "MIPS_EXTSYM" },
    133       { SHT_MIPS_DENSE, "MIPS_DENSE" },
    134       { SHT_MIPS_PDESC, "MIPS_PDESC" },
    135       { SHT_MIPS_LOCSYM, "MIPS_LOCSYM" },
    136       { SHT_MIPS_AUXSYM, "MIPS_AUXSYM" },
    137       { SHT_MIPS_OPTSYM, "MIPS_OPTSYM" },
    138       { SHT_MIPS_LOCSTR, "MIPS_LOCSTR" },
    139       { SHT_MIPS_LINE, "MIPS_LINE" },
    140       { SHT_MIPS_RFDESC, "MIPS_RFDESC" },
    141       { SHT_MIPS_DELTASYM, "MIPS_DELTASYM" },
    142       { SHT_MIPS_DELTAINST, "MIPS_DELTAINST" },
    143       { SHT_MIPS_DELTACLASS, "MIPS_DELTACLASS" },
    144       { SHT_MIPS_DWARF, "MIPS_DWARF" },
    145       { SHT_MIPS_DELTADECL, "MIPS_DELTADECL" },
    146       { SHT_MIPS_SYMBOL_LIB, "MIPS_SYMBOL_LIB" },
    147       { SHT_MIPS_EVENTS, "MIPS_EVENTS" },
    148       { SHT_MIPS_TRANSLATE, "MIPS_TRANSLATE" },
    149       { SHT_MIPS_PIXIE, "MIPS_PIXIE" },
    150       { SHT_MIPS_XLATE, "MIPS_XLATE" },
    151       { SHT_MIPS_XLATE_DEBUG, "MIPS_XLATE_DEBUG" },
    152       { SHT_MIPS_WHIRL, "MIPS_WHIRL" },
    153       { SHT_MIPS_EH_REGION, "MIPS_EH_REGION" },
    154       { SHT_MIPS_XLATE_OLD, "MIPS_XLATE_OLD" },
    155       { SHT_MIPS_PDR_EXCEPTION, "MIPS_PDR_EXCEPTION" }
    156     };
    157 #define nsections (sizeof (mips_sections) / sizeof (mips_sections[0]))
    158   size_t cnt;
    159 
    160   for (cnt = 0; cnt < nsections; ++cnt)
    161     if (type == mips_sections[cnt].type)
    162       return mips_sections[cnt].str;
    163 
    164   /* We don't know the section type.  */
    165   return NULL;
    166 }
    167 
    168 
    169 const char *
    170 mips_machine_flag_name (Elf64_Word *flags)
    171 {
    172   static const struct
    173   {
    174     unsigned int mask;
    175     unsigned int flag;
    176     const char *str;
    177   } mips_flags[] =
    178     {
    179       { EF_MIPS_NOREORDER, EF_MIPS_NOREORDER, "noreorder" },
    180       { EF_MIPS_PIC, EF_MIPS_PIC, "pic" },
    181       { EF_MIPS_CPIC, EF_MIPS_CPIC, "cpic" },
    182       { EF_MIPS_ABI2, EF_MIPS_ABI2, "abi2" },
    183       { EF_MIPS_ARCH, E_MIPS_ARCH_1, "mips1" },
    184       { EF_MIPS_ARCH, E_MIPS_ARCH_2, "mips2" },
    185       { EF_MIPS_ARCH, E_MIPS_ARCH_3, "mips3" },
    186       { EF_MIPS_ARCH, E_MIPS_ARCH_4, "mips4" },
    187       { EF_MIPS_ARCH, E_MIPS_ARCH_5, "mips5" }
    188     };
    189 #define nflags (sizeof (mips_flags) / sizeof (mips_flags[0]))
    190   size_t cnt;
    191 
    192   for (cnt = 0; cnt < nflags; ++cnt)
    193     if ((*flags & mips_flags[cnt].mask) == mips_flags[cnt].flag)
    194       {
    195 	*flags &= ~mips_flags[cnt].mask;
    196 	return mips_flags[cnt].str;
    197       }
    198 
    199   /* We don't know the flag.  */
    200   return NULL;
    201 }
    202 
    203 
    204 const char *
    205 mips_dynamic_tag_name (int64_t tag, char *buf, size_t len)
    206 {
    207   static const struct
    208   {
    209     int tag;
    210     const char *str;
    211   } mips_dtags[] =
    212     {
    213       { DT_MIPS_RLD_VERSION, "MIPS_RLD_VERSION" },
    214       { DT_MIPS_TIME_STAMP, "MIPS_TIME_STAMP" },
    215       { DT_MIPS_ICHECKSUM, "MIPS_ICHECKSUM" },
    216       { DT_MIPS_IVERSION, "MIPS_IVERSION" },
    217       { DT_MIPS_FLAGS, "MIPS_FLAGS" },
    218       { DT_MIPS_BASE_ADDRESS, "MIPS_BASE_ADDRESS" },
    219       { DT_MIPS_MSYM, "MIPS_MSYM" },
    220       { DT_MIPS_CONFLICT, "MIPS_CONFLICT" },
    221       { DT_MIPS_LIBLIST, "MIPS_LIBLIST" },
    222       { DT_MIPS_LOCAL_GOTNO, "MIPS_LOCAL_GOTNO" },
    223       { DT_MIPS_CONFLICTNO, "MIPS_CONFLICTNO" },
    224       { DT_MIPS_LIBLISTNO, "MIPS_LIBLISTNO" },
    225       { DT_MIPS_SYMTABNO, "MIPS_SYMTABNO" },
    226       { DT_MIPS_UNREFEXTNO, "MIPS_UNREFEXTNO" },
    227       { DT_MIPS_GOTSYM, "MIPS_GOTSYM" },
    228       { DT_MIPS_HIPAGENO, "MIPS_HIPAGENO" },
    229       { DT_MIPS_RLD_MAP, "MIPS_RLD_MAP" },
    230       { DT_MIPS_DELTA_CLASS, "MIPS_DELTA_CLASS" },
    231       { DT_MIPS_DELTA_CLASS_NO, "MIPS_DELTA_CLASS_NO" },
    232       { DT_MIPS_DELTA_INSTANCE, "MIPS_DELTA_INSTANCE" },
    233       { DT_MIPS_DELTA_INSTANCE_NO, "MIPS_DELTA_INSTANCE_NO" },
    234       { DT_MIPS_DELTA_RELOC, "MIPS_DELTA_RELOC" },
    235       { DT_MIPS_DELTA_RELOC_NO, "MIPS_DELTA_RELOC_NO" },
    236       { DT_MIPS_DELTA_SYM, "MIPS_DELTA_SYM" },
    237       { DT_MIPS_DELTA_SYM_NO, "MIPS_DELTA_SYM_NO" },
    238       { DT_MIPS_DELTA_CLASSSYM, "MIPS_DELTA_CLASSSYM" },
    239       { DT_MIPS_DELTA_CLASSSYM_NO, "MIPS_DELTA_CLASSSYM_NO" },
    240       { DT_MIPS_CXX_FLAGS, "MIPS_CXX_FLAGS" },
    241       { DT_MIPS_PIXIE_INIT, "MIPS_PIXIE_INIT" },
    242       { DT_MIPS_SYMBOL_LIB, "MIPS_SYMBOL_LIB" },
    243       { DT_MIPS_LOCALPAGE_GOTIDX, "MIPS_LOCALPAGE_GOTIDX" },
    244       { DT_MIPS_LOCAL_GOTIDX, "MIPS_LOCAL_GOTIDX" },
    245       { DT_MIPS_HIDDEN_GOTIDX, "MIPS_HIDDEN_GOTIDX" },
    246       { DT_MIPS_PROTECTED_GOTIDX, "MIPS_PROTECTED_GOTIDX" },
    247       { DT_MIPS_OPTIONS, "MIPS_OPTIONS" },
    248       { DT_MIPS_INTERFACE, "MIPS_INTERFACE" },
    249       { DT_MIPS_DYNSTR_ALIGN, "MIPS_DYNSTR_ALIGN" },
    250       { DT_MIPS_INTERFACE_SIZE, "MIPS_INTERFACE_SIZE" },
    251       { DT_MIPS_RLD_TEXT_RESOLVE_ADDR, "MIPS_RLD_TEXT_RESOLVE_ADDR" },
    252       { DT_MIPS_PERF_SUFFIX, "MIPS_PERF_SUFFIX" },
    253       { DT_MIPS_COMPACT_SIZE, "MIPS_COMPACT_SIZE" },
    254       { DT_MIPS_GP_VALUE, "MIPS_GP_VALUE" },
    255       { DT_MIPS_AUX_DYNAMIC, "MIPS_AUX_DYNAMIC" },
    256     };
    257 #define ndtags (sizeof (mips_dtags) / sizeof (mips_dtags[0]))
    258   size_t cnt;
    259 
    260   for (cnt = 0; cnt < ndtags; ++cnt)
    261     if (tag == mips_dtags[cnt].tag)
    262       return mips_dtags[cnt].str;
    263 
    264   /* We don't know this dynamic tag.  */
    265   return NULL;
    266 }
    267