Home | History | Annotate | Download | only in libebl
      1 /* Generate ELF backend handle.
      2    Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007,2008 Red Hat, Inc.
      3    This file is part of Red Hat elfutils.
      4 
      5    Red Hat elfutils is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by the
      7    Free Software Foundation; version 2 of the License.
      8 
      9    Red Hat elfutils is distributed in the hope that it will be useful, but
     10    WITHOUT ANY WARRANTY; without even the implied warranty of
     11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12    General Public License for more details.
     13 
     14    You should have received a copy of the GNU General Public License along
     15    with Red Hat elfutils; if not, write to the Free Software Foundation,
     16    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
     17 
     18    In addition, as a special exception, Red Hat, Inc. gives You the
     19    additional right to link the code of Red Hat elfutils with code licensed
     20    under any Open Source Initiative certified open source license
     21    (http://www.opensource.org/licenses/index.php) which requires the
     22    distribution of source code with any binary distribution and to
     23    distribute linked combinations of the two.  Non-GPL Code permitted under
     24    this exception must only link to the code of Red Hat elfutils through
     25    those well defined interfaces identified in the file named EXCEPTION
     26    found in the source code files (the "Approved Interfaces").  The files
     27    of Non-GPL Code may instantiate templates or use macros or inline
     28    functions from the Approved Interfaces without causing the resulting
     29    work to be covered by the GNU General Public License.  Only Red Hat,
     30    Inc. may make changes or additions to the list of Approved Interfaces.
     31    Red Hat's grant of this exception is conditioned upon your not adding
     32    any new exceptions.  If you wish to add a new Approved Interface or
     33    exception, please contact Red Hat.  You must obey the GNU General Public
     34    License in all respects for all of the Red Hat elfutils code and other
     35    code used in conjunction with Red Hat elfutils except the Non-GPL Code
     36    covered by this exception.  If you modify this file, you may extend this
     37    exception to your version of the file, but you are not obligated to do
     38    so.  If you do not wish to provide this exception without modification,
     39    you must delete this exception statement from your version and license
     40    this file solely under the GPL without exception.
     41 
     42    Red Hat elfutils is an included package of the Open Invention Network.
     43    An included package of the Open Invention Network is a package for which
     44    Open Invention Network licensees cross-license their patents.  No patent
     45    license is granted, either expressly or impliedly, by designation as an
     46    included package.  Should you wish to participate in the Open Invention
     47    Network licensing program, please visit www.openinventionnetwork.com
     48    <http://www.openinventionnetwork.com>.  */
     49 
     50 #ifdef HAVE_CONFIG_H
     51 # include <config.h>
     52 #endif
     53 
     54 #include <assert.h>
     55 #include <dlfcn.h>
     56 #include <error.h>
     57 #include <libelfP.h>
     58 #include <dwarf.h>
     59 #include <stdlib.h>
     60 #include <string.h>
     61 #include <stdio.h>
     62 
     63 #include <libeblP.h>
     64 
     65 
     66 /* This table should contain the complete list of architectures as far
     67    as the ELF specification is concerned.  */
     68 /* XXX When things are stable replace the string pointers with char
     69    arrays to avoid relocations.  */
     70 static const struct
     71 {
     72   const char *dsoname;
     73   const char *emulation;
     74   const char *prefix;
     75   int prefix_len;
     76   int em;
     77   int class;
     78   int data;
     79 } machines[] =
     80 {
     81   { "i386", "elf_i386", "i386", 4, EM_386, ELFCLASS32, ELFDATA2LSB },
     82   { "ia64", "elf_ia64", "ia64", 4, EM_IA_64, ELFCLASS64, ELFDATA2LSB },
     83   { "alpha", "elf_alpha", "alpha", 5, EM_ALPHA, ELFCLASS64, ELFDATA2LSB },
     84   { "x86_64", "elf_x86_64", "x86_64", 6, EM_X86_64, ELFCLASS64, ELFDATA2LSB },
     85   { "ppc", "elf_ppc", "ppc", 3, EM_PPC, ELFCLASS32, ELFDATA2MSB },
     86   { "ppc64", "elf_ppc64", "ppc64", 5, EM_PPC64, ELFCLASS64, ELFDATA2MSB },
     87   // XXX class and machine fields need to be filled in for all archs.
     88   { "sh", "elf_sh", "sh", 2, EM_SH, 0, 0 },
     89   { "arm", "ebl_arm", "arm", 3, EM_ARM, 0, 0 },
     90   { "sparc", "elf_sparcv9", "sparc", 5, EM_SPARCV9, 0, 0 },
     91   { "sparc", "elf_sparc", "sparc", 5, EM_SPARC, 0, 0 },
     92   { "sparc", "elf_sparcv8plus", "sparc", 5, EM_SPARC32PLUS, 0, 0 },
     93   { "s390", "ebl_s390", "s390", 4, EM_S390, 0, 0 },
     94 
     95   { "m32", "elf_m32", "m32", 3, EM_M32, 0, 0 },
     96   { "m68k", "elf_m68k", "m68k", 4, EM_68K, 0, 0 },
     97   { "m88k", "elf_m88k", "m88k", 4, EM_88K, 0, 0 },
     98   { "i860", "elf_i860", "i860", 4, EM_860, 0, 0 },
     99   { "s370", "ebl_s370", "s370", 4, EM_S370, 0, 0 },
    100   { "parisc", "elf_parisc", "parisc", 6, EM_PARISC, 0, 0 },
    101   { "vpp500", "elf_vpp500", "vpp500", 5, EM_VPP500, 0, 0 },
    102   { "sparc", "elf_v8plus", "v8plus", 6, EM_SPARC32PLUS, 0, 0 },
    103   { "i960", "elf_i960", "i960", 4, EM_960, 0, 0 },
    104   { "v800", "ebl_v800", "v800", 4, EM_V800, 0, 0 },
    105   { "fr20", "ebl_fr20", "fr20", 4, EM_FR20, 0, 0 },
    106   { "rh32", "ebl_rh32", "rh32", 4, EM_RH32, 0, 0 },
    107   { "rce", "ebl_rce", "rce", 3, EM_RCE, 0, 0 },
    108   { "tricore", "elf_tricore", "tricore", 7, EM_TRICORE, 0, 0 },
    109   { "arc", "elf_arc", "arc", 3, EM_ARC, 0, 0 },
    110   { "h8", "elf_h8_300", "h8_300", 6, EM_H8_300, 0, 0 },
    111   { "h8", "elf_h8_300h", "h8_300h", 6, EM_H8_300H, 0, 0 },
    112   { "h8", "elf_h8s", "h8s", 6, EM_H8S, 0, 0 },
    113   { "h8", "elf_h8_500", "h8_500", 6, EM_H8_500, 0, 0 },
    114   { "coldfire", "elf_coldfire", "coldfire", 8, EM_COLDFIRE, 0, 0 },
    115   { "m68k", "elf_68hc12", "68hc12", 6, EM_68HC12, 0, 0 },
    116   { "mma", "elf_mma", "mma", 3, EM_MMA, 0, 0 },
    117   { "pcp", "elf_pcp", "pcp", 3, EM_PCP, 0, 0 },
    118   { "ncpu", "elf_ncpu", "ncpu", 4, EM_NCPU, 0, 0 },
    119   { "ndr1", "elf_ndr1", "ndr1", 4, EM_NDR1, 0, 0 },
    120   { "starcore", "elf_starcore", "starcore", 8, EM_STARCORE, 0, 0 },
    121   { "me16", "elf_me16", "em16", 4, EM_ME16, 0, 0 },
    122   { "st100", "elf_st100", "st100", 5, EM_ST100, 0, 0 },
    123   { "tinyj", "elf_tinyj", "tinyj", 5, EM_TINYJ, 0, 0 },
    124   { "pdsp", "elf_pdsp", "pdsp", 4, EM_PDSP, 0, 0 },
    125   { "fx66", "elf_fx66", "fx66", 4, EM_FX66, 0, 0 },
    126   { "st9plus", "elf_st9plus", "st9plus", 7, EM_ST9PLUS, 0, 0 },
    127   { "st7", "elf_st7", "st7", 3, EM_ST7, 0, 0 },
    128   { "m68k", "elf_68hc16", "68hc16", 6, EM_68HC16, 0, 0 },
    129   { "m68k", "elf_68hc11", "68hc11", 6, EM_68HC11, 0, 0 },
    130   { "m68k", "elf_68hc08", "68hc08", 6, EM_68HC08, 0, 0 },
    131   { "m68k", "elf_68hc05", "68hc05", 6, EM_68HC05, 0, 0 },
    132   { "svx", "elf_svx", "svx", 3, EM_SVX, 0, 0 },
    133   { "st19", "elf_st19", "st19", 4, EM_ST19, 0, 0 },
    134   { "vax", "elf_vax", "vax", 3, EM_VAX, 0, 0 },
    135   { "cris", "elf_cris", "cris", 4, EM_CRIS, 0, 0 },
    136   { "javelin", "elf_javelin", "javelin", 7, EM_JAVELIN, 0, 0 },
    137   { "firepath", "elf_firepath", "firepath", 8, EM_FIREPATH, 0, 0 },
    138   { "zsp", "elf_zsp", "zsp", 3, EM_ZSP, 0, 0 },
    139   { "mmix", "elf_mmix", "mmix", 4, EM_MMIX, 0, 0 },
    140   { "hunay", "elf_huany", "huany", 5, EM_HUANY, 0, 0 },
    141   { "prism", "elf_prism", "prism", 5, EM_PRISM, 0, 0 },
    142   { "avr", "elf_avr", "avr", 3, EM_AVR, 0, 0 },
    143   { "fr30", "elf_fr30", "fr30", 4, EM_FR30, 0, 0 },
    144   { "dv10", "elf_dv10", "dv10", 4, EM_D10V, 0, 0 },
    145   { "dv30", "elf_dv30", "dv30", 4, EM_D30V, 0, 0 },
    146   { "v850", "elf_v850", "v850", 4, EM_V850, 0, 0 },
    147   { "m32r", "elf_m32r", "m32r", 4, EM_M32R, 0, 0 },
    148   { "mn10300", "elf_mn10300", "mn10300", 7, EM_MN10300, 0, 0 },
    149   { "mn10200", "elf_mn10200", "mn10200", 7, EM_MN10200, 0, 0 },
    150   { "pj", "elf_pj", "pj", 2, EM_PJ, 0, 0 },
    151   { "openrisc", "elf_openrisc", "openrisc", 8, EM_OPENRISC, 0, 0 },
    152   { "arc", "elf_arc_a5", "arc_a5", 6, EM_ARC_A5, 0, 0 },
    153   { "xtensa", "elf_xtensa", "xtensa", 6, EM_XTENSA, 0, 0 },
    154 };
    155 #define nmachines (sizeof (machines) / sizeof (machines[0]))
    156 
    157 
    158 /* Default callbacks.  Mostly they just return the error value.  */
    159 static const char *default_object_type_name (int ignore, char *buf,
    160 					     size_t len);
    161 static const char *default_reloc_type_name (int ignore, char *buf, size_t len);
    162 static bool default_reloc_type_check (int ignore);
    163 static bool default_reloc_valid_use (Elf *elf, int ignore);
    164 static Elf_Type default_reloc_simple_type (Ebl *ebl, int ignore);
    165 static bool default_gotpc_reloc_check (Elf *elf, int ignore);
    166 static const char *default_segment_type_name (int ignore, char *buf,
    167 					      size_t len);
    168 static const char *default_section_type_name (int ignore, char *buf,
    169 					      size_t len);
    170 static const char *default_section_name (int ignore, int ignore2, char *buf,
    171 					 size_t len);
    172 static const char *default_machine_flag_name (Elf64_Word *ignore);
    173 static bool default_machine_flag_check (Elf64_Word flags);
    174 static bool default_machine_section_flag_check (GElf_Xword flags);
    175 static const char *default_symbol_type_name (int ignore, char *buf,
    176 					     size_t len);
    177 static const char *default_symbol_binding_name (int ignore, char *buf,
    178 						size_t len);
    179 static const char *default_dynamic_tag_name (int64_t ignore, char *buf,
    180 					     size_t len);
    181 static bool default_dynamic_tag_check (int64_t ignore);
    182 static GElf_Word default_sh_flags_combine (GElf_Word flags1, GElf_Word flags2);
    183 static const char *default_osabi_name (int ignore, char *buf, size_t len);
    184 static void default_destr (struct ebl *ignore);
    185 static const char *default_core_note_type_name (uint32_t, char *buf,
    186 						size_t len);
    187 static const char *default_object_note_type_name (uint32_t, char *buf,
    188 						  size_t len);
    189 static int default_core_note (GElf_Word n_type, GElf_Word descsz,
    190 			      GElf_Word *regs_offset, size_t *nregloc,
    191 			      const Ebl_Register_Location **reglocs,
    192 			      size_t *nitems, const Ebl_Core_Item **);
    193 static int default_auxv_info (GElf_Xword a_type,
    194 			      const char **name, const char **format);
    195 static bool default_object_note (const char *name, uint32_t type,
    196 				 uint32_t descsz, const char *desc);
    197 static bool default_debugscn_p (const char *name);
    198 static bool default_copy_reloc_p (int reloc);
    199 /* ANDROID_CHANGE_BEGIN */
    200 #ifndef __APPLE__
    201 static bool default_none_reloc_p (int reloc);
    202 static bool default_relative_reloc_p (int reloc);
    203 #else
    204 #define default_none_reloc_p 		default_copy_reloc_p
    205 #define default_relative_reloc_p 	default_copy_reloc_p
    206 #endif
    207 /* ANDROID_CHANGE_END */
    208 static bool default_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr,
    209 					  const GElf_Sym *sym,
    210 					  const char *name,
    211 					  const GElf_Shdr *destshdr);
    212 static bool default_check_special_section (Ebl *, int,
    213 					   const GElf_Shdr *, const char *);
    214 static bool default_bss_plt_p (Elf *elf, GElf_Ehdr *ehdr);
    215 static int default_return_value_location (Dwarf_Die *functypedie,
    216 					  const Dwarf_Op **locops);
    217 static ssize_t default_register_info (Ebl *ebl,
    218 				      int regno, char *name, size_t namelen,
    219 				      const char **prefix,
    220 				      const char **setname,
    221 				      int *bits, int *type);
    222 static int default_syscall_abi (Ebl *ebl, int *sp, int *pc,
    223 				int *callno, int args[6]);
    224 static bool default_check_object_attribute (Ebl *ebl, const char *vendor,
    225 					    int tag, uint64_t value,
    226 					    const char **tag_name,
    227 					    const char **value_name);
    228 
    229 
    230 static void
    231 fill_defaults (Ebl *result)
    232 {
    233   result->object_type_name = default_object_type_name;
    234   result->reloc_type_name = default_reloc_type_name;
    235   result->reloc_type_check = default_reloc_type_check;
    236   result->reloc_valid_use = default_reloc_valid_use;
    237   result->reloc_simple_type = default_reloc_simple_type;
    238   result->gotpc_reloc_check = default_gotpc_reloc_check;
    239   result->segment_type_name = default_segment_type_name;
    240   result->section_type_name = default_section_type_name;
    241   result->section_name = default_section_name;
    242   result->machine_flag_name = default_machine_flag_name;
    243   result->machine_flag_check = default_machine_flag_check;
    244   result->machine_section_flag_check = default_machine_section_flag_check;
    245   result->check_special_section = default_check_special_section;
    246   result->symbol_type_name = default_symbol_type_name;
    247   result->symbol_binding_name = default_symbol_binding_name;
    248   result->dynamic_tag_name = default_dynamic_tag_name;
    249   result->dynamic_tag_check = default_dynamic_tag_check;
    250   result->sh_flags_combine = default_sh_flags_combine;
    251   result->osabi_name = default_osabi_name;
    252   result->core_note_type_name = default_core_note_type_name;
    253   result->object_note_type_name = default_object_note_type_name;
    254   result->core_note = default_core_note;
    255   result->auxv_info = default_auxv_info;
    256   result->object_note = default_object_note;
    257   result->debugscn_p = default_debugscn_p;
    258   result->copy_reloc_p = default_copy_reloc_p;
    259   result->none_reloc_p = default_none_reloc_p;
    260   result->relative_reloc_p = default_relative_reloc_p;
    261   result->check_special_symbol = default_check_special_symbol;
    262   result->bss_plt_p = default_bss_plt_p;
    263   result->return_value_location = default_return_value_location;
    264   result->register_info = default_register_info;
    265   result->syscall_abi = default_syscall_abi;
    266   result->check_object_attribute = default_check_object_attribute;
    267   result->disasm = NULL;
    268   result->destr = default_destr;
    269   result->sysvhash_entrysize = sizeof (Elf32_Word);
    270 }
    271 
    272 
    273 /* Find an appropriate backend for the file associated with ELF.  */
    274 static Ebl *
    275 openbackend (elf, emulation, machine)
    276      Elf *elf;
    277      const char *emulation;
    278      GElf_Half machine;
    279 {
    280   Ebl *result;
    281   size_t cnt;
    282 
    283   /* First allocate the data structure for the result.  We do this
    284      here since this assures that the structure is always large
    285      enough.  */
    286   result = (Ebl *) calloc (1, sizeof (Ebl));
    287   if (result == NULL)
    288     {
    289       // XXX uncomment
    290       // __libebl_seterror (ELF_E_NOMEM);
    291       return NULL;
    292     }
    293 
    294   /* Fill in the default callbacks.  The initializer for the machine
    295      specific module can overwrite the values.  */
    296   fill_defaults (result);
    297 
    298   /* XXX Currently all we do is to look at 'e_machine' value in the
    299      ELF header.  With an internal mapping table from EM_* value to
    300      DSO name we try to load the appropriate module to handle this
    301      binary type.
    302 
    303      Multiple modules for the same machine type are possible and they
    304      will be tried in sequence.  The lookup process will only stop
    305      when a module which can handle the machine type is found or all
    306      available matching modules are tried.  */
    307   for (cnt = 0; cnt < nmachines; ++cnt)
    308     if ((emulation != NULL && strcmp (emulation, machines[cnt].emulation) == 0)
    309 	|| (emulation == NULL && machines[cnt].em == machine))
    310       {
    311 	/* Well, we know the emulation name now.  */
    312 	result->emulation = machines[cnt].emulation;
    313 
    314 	/* We access some data structures directly.  Make sure the 32 and
    315 	   64 bit variants are laid out the same.  */
    316 	assert (offsetof (Elf32_Ehdr, e_machine)
    317 		== offsetof (Elf64_Ehdr, e_machine));
    318 	assert (sizeof (((Elf32_Ehdr *) 0)->e_machine)
    319 		== sizeof (((Elf64_Ehdr *) 0)->e_machine));
    320 	assert (offsetof (Elf, state.elf32.ehdr)
    321 		== offsetof (Elf, state.elf64.ehdr));
    322 
    323 	/* Prefer taking the information from the ELF file.  */
    324 	if (elf == NULL)
    325 	  {
    326 	    result->machine = machines[cnt].em;
    327 	    result->class = machines[cnt].class;
    328 	    result->data = machines[cnt].data;
    329 	  }
    330 	else
    331 	  {
    332 	    result->machine = elf->state.elf32.ehdr->e_machine;
    333 	    result->class = elf->state.elf32.ehdr->e_ident[EI_CLASS];
    334 	    result->data = elf->state.elf32.ehdr->e_ident[EI_DATA];
    335 	  }
    336 
    337 #ifndef LIBEBL_SUBDIR
    338 # define LIBEBL_SUBDIR PACKAGE
    339 #endif
    340 #define ORIGINDIR "$ORIGIN/../$LIB/" LIBEBL_SUBDIR "/"
    341 
    342 	/* Give it a try.  At least the machine type matches.  First
    343            try to load the module.  */
    344 	char dsoname[100];
    345 	strcpy (stpcpy (stpcpy (dsoname, ORIGINDIR "libebl_"),
    346 			machines[cnt].dsoname),
    347 		".so");
    348 
    349 	void *h = dlopen (dsoname, RTLD_LAZY);
    350 	if (h == NULL)
    351 	  {
    352 	    strcpy (stpcpy (stpcpy (dsoname, "libebl_"),
    353 			    machines[cnt].dsoname),
    354 		    ".so");
    355 	    h = dlopen (dsoname, RTLD_LAZY);
    356 	  }
    357 
    358 	  /* Try without an explicit path.  */
    359 	if (h != NULL)
    360 	  {
    361 	    /* We managed to load the object.  Now see whether the
    362 	       initialization function likes our file.  */
    363 	    static const char version[] = MODVERSION;
    364 	    const char *modversion;
    365 	    ebl_bhinit_t initp;
    366 	    char symname[machines[cnt].prefix_len + sizeof "_init"];
    367 
    368 	    strcpy (mempcpy (symname, machines[cnt].prefix,
    369 			     machines[cnt].prefix_len), "_init");
    370 
    371 	    initp = (ebl_bhinit_t) dlsym (h, symname);
    372 	    if (initp != NULL
    373 		&& (modversion = initp (elf, machine, result, sizeof (Ebl)))
    374 		&& strcmp (version, modversion) == 0)
    375 	      {
    376 		/* We found a module to handle our file.  */
    377 		result->dlhandle = h;
    378 		result->elf = elf;
    379 
    380 		/* A few entries are mandatory.  */
    381 		assert (result->name != NULL);
    382 		assert (result->destr != NULL);
    383 
    384 		return result;
    385 	      }
    386 
    387 	    /* Not the module we need.  */
    388 	    (void) dlclose (h);
    389 	  }
    390 
    391 	/* We cannot find a DSO but the emulation/machine ID matches.
    392 	   Return that information.  */
    393 	result->dlhandle = NULL;
    394 	result->elf = elf;
    395 	result->name = machines[cnt].prefix;
    396 	fill_defaults (result);
    397 
    398 	return result;
    399       }
    400 
    401   /* Nothing matched.  We use only the default callbacks.   */
    402   result->dlhandle = NULL;
    403   result->elf = elf;
    404   result->emulation = "<unknown>";
    405   result->name = "<unknown>";
    406   fill_defaults (result);
    407 
    408   return result;
    409 }
    410 
    411 
    412 /* Find an appropriate backend for the file associated with ELF.  */
    413 Ebl *
    414 ebl_openbackend (elf)
    415      Elf *elf;
    416 {
    417   GElf_Ehdr ehdr_mem;
    418   GElf_Ehdr *ehdr;
    419 
    420   /* Get the ELF header of the object.  */
    421   ehdr = gelf_getehdr (elf, &ehdr_mem);
    422   if (ehdr == NULL)
    423     {
    424       // XXX uncomment
    425       // __libebl_seterror (elf_errno ());
    426       return NULL;
    427     }
    428 
    429   return openbackend (elf, NULL, ehdr->e_machine);
    430 }
    431 
    432 
    433 /* Find backend without underlying ELF file.  */
    434 Ebl *
    435 ebl_openbackend_machine (machine)
    436      GElf_Half machine;
    437 {
    438   return openbackend (NULL, NULL, machine);
    439 }
    440 
    441 
    442 /* Find backend with given emulation name.  */
    443 Ebl *
    444 ebl_openbackend_emulation (const char *emulation)
    445 {
    446   return openbackend (NULL, emulation, EM_NONE);
    447 }
    448 
    449 
    450 /* Default callbacks.  Mostly they just return the error value.  */
    451 static const char *
    452 default_object_type_name (int ignore __attribute__ ((unused)),
    453 			  char *buf __attribute__ ((unused)),
    454 			  size_t len __attribute__ ((unused)))
    455 {
    456   return NULL;
    457 }
    458 
    459 static const char *
    460 default_reloc_type_name (int ignore __attribute__ ((unused)),
    461 			 char *buf __attribute__ ((unused)),
    462 			 size_t len __attribute__ ((unused)))
    463 {
    464   return NULL;
    465 }
    466 
    467 static bool
    468 default_reloc_type_check (int ignore __attribute__ ((unused)))
    469 {
    470   return false;
    471 }
    472 
    473 static bool
    474 default_reloc_valid_use (Elf *elf __attribute__ ((unused)),
    475 			 int ignore __attribute__ ((unused)))
    476 {
    477   return false;
    478 }
    479 
    480 static Elf_Type
    481 default_reloc_simple_type (Ebl *eh __attribute__ ((unused)),
    482 			   int ignore __attribute__ ((unused)))
    483 {
    484   return ELF_T_NUM;
    485 }
    486 
    487 static bool
    488 default_gotpc_reloc_check (Elf *elf __attribute__ ((unused)),
    489 			   int ignore __attribute__ ((unused)))
    490 {
    491   return false;
    492 }
    493 
    494 static const char *
    495 default_segment_type_name (int ignore __attribute__ ((unused)),
    496 			   char *buf __attribute__ ((unused)),
    497 			   size_t len __attribute__ ((unused)))
    498 {
    499   return NULL;
    500 }
    501 
    502 static const char *
    503 default_section_type_name (int ignore __attribute__ ((unused)),
    504 			   char *buf __attribute__ ((unused)),
    505 			   size_t len __attribute__ ((unused)))
    506 {
    507   return NULL;
    508 }
    509 
    510 static const char *
    511 default_section_name (int ignore __attribute__ ((unused)),
    512 		      int ignore2 __attribute__ ((unused)),
    513 		      char *buf __attribute__ ((unused)),
    514 		      size_t len __attribute__ ((unused)))
    515 {
    516   return NULL;
    517 }
    518 
    519 static const char *
    520 default_machine_flag_name (Elf64_Word *ignore __attribute__ ((unused)))
    521 {
    522   return NULL;
    523 }
    524 
    525 static bool
    526 default_machine_flag_check (Elf64_Word flags __attribute__ ((unused)))
    527 {
    528   return flags == 0;
    529 }
    530 
    531 static bool
    532 default_machine_section_flag_check (GElf_Xword flags)
    533 {
    534   return flags == 0;
    535 }
    536 
    537 static bool
    538 default_check_special_section (Ebl *ebl __attribute__ ((unused)),
    539 			       int ndx __attribute__ ((unused)),
    540 			       const GElf_Shdr *shdr __attribute__ ((unused)),
    541 			       const char *sname __attribute__ ((unused)))
    542 {
    543   return false;
    544 }
    545 
    546 static const char *
    547 default_symbol_type_name (int ignore __attribute__ ((unused)),
    548 			  char *buf __attribute__ ((unused)),
    549 			  size_t len __attribute__ ((unused)))
    550 {
    551   return NULL;
    552 }
    553 
    554 static const char *
    555 default_symbol_binding_name (int ignore __attribute__ ((unused)),
    556 			     char *buf __attribute__ ((unused)),
    557 			     size_t len __attribute__ ((unused)))
    558 {
    559   return NULL;
    560 }
    561 
    562 static const char *
    563 default_dynamic_tag_name (int64_t ignore __attribute__ ((unused)),
    564 			  char *buf __attribute__ ((unused)),
    565 			  size_t len __attribute__ ((unused)))
    566 {
    567   return NULL;
    568 }
    569 
    570 static bool
    571 default_dynamic_tag_check (int64_t ignore __attribute__ ((unused)))
    572 {
    573   return false;
    574 }
    575 
    576 static GElf_Word
    577 default_sh_flags_combine (GElf_Word flags1, GElf_Word flags2)
    578 {
    579   return SH_FLAGS_COMBINE (flags1, flags2);
    580 }
    581 
    582 static void
    583 default_destr (struct ebl *ignore __attribute__ ((unused)))
    584 {
    585 }
    586 
    587 static const char *
    588 default_osabi_name (int ignore __attribute__ ((unused)),
    589 		    char *buf __attribute__ ((unused)),
    590 		    size_t len __attribute__ ((unused)))
    591 {
    592   return NULL;
    593 }
    594 
    595 static const char *
    596 default_core_note_type_name (uint32_t ignore __attribute__ ((unused)),
    597 			     char *buf __attribute__ ((unused)),
    598 			     size_t len __attribute__ ((unused)))
    599 {
    600   return NULL;
    601 }
    602 
    603 static int
    604 default_auxv_info (GElf_Xword a_type __attribute__ ((unused)),
    605 		   const char **name __attribute__ ((unused)),
    606 		   const char **format __attribute__ ((unused)))
    607 {
    608   return 0;
    609 }
    610 
    611 static int
    612 default_core_note (GElf_Word n_type __attribute__ ((unused)),
    613 		   GElf_Word descsz __attribute__ ((unused)),
    614 		   GElf_Word *ro __attribute__ ((unused)),
    615 		   size_t *nregloc  __attribute__ ((unused)),
    616 		   const Ebl_Register_Location **reglocs
    617 		   __attribute__ ((unused)),
    618 		   size_t *nitems __attribute__ ((unused)),
    619 		   const Ebl_Core_Item **items __attribute__ ((unused)))
    620 {
    621   return 0;
    622 }
    623 
    624 static const char *
    625 default_object_note_type_name (uint32_t ignore __attribute__ ((unused)),
    626 			       char *buf __attribute__ ((unused)),
    627 			       size_t len __attribute__ ((unused)))
    628 {
    629   return NULL;
    630 }
    631 
    632 static bool
    633 default_object_note (const char *name __attribute__ ((unused)),
    634 		     uint32_t type __attribute__ ((unused)),
    635 		     uint32_t descsz __attribute__ ((unused)),
    636 		     const char *desc __attribute__ ((unused)))
    637 {
    638   return NULL;
    639 }
    640 
    641 static bool
    642 default_debugscn_p (const char *name)
    643 {
    644   /* We know by default only about the DWARF debug sections which have
    645      fixed names.  */
    646   static const char *dwarf_scn_names[] =
    647     {
    648       /* DWARF 1 */
    649       ".debug",
    650       ".line",
    651       /* GNU DWARF 1 extensions */
    652       ".debug_srcinfo",
    653       ".debug_sfnames",
    654       /* DWARF 1.1 and DWARF 2 */
    655       ".debug_aranges",
    656       ".debug_pubnames",
    657       /* DWARF 2 */
    658       ".debug_info",
    659       ".debug_abbrev",
    660       ".debug_line",
    661       ".debug_frame",
    662       ".debug_str",
    663       ".debug_loc",
    664       ".debug_macinfo",
    665       /* DWARF 3 */
    666       ".debug_ranges",
    667       /* SGI/MIPS DWARF 2 extensions */
    668       ".debug_weaknames",
    669       ".debug_funcnames",
    670       ".debug_typenames",
    671       ".debug_varnames"
    672     };
    673   const size_t ndwarf_scn_names = (sizeof (dwarf_scn_names)
    674 				   / sizeof (dwarf_scn_names[0]));
    675   for (size_t cnt = 0; cnt < ndwarf_scn_names; ++cnt)
    676     if (strcmp (name, dwarf_scn_names[cnt]) == 0)
    677       return true;
    678 
    679   return false;
    680 }
    681 
    682 static bool
    683 default_copy_reloc_p (int reloc __attribute__ ((unused)))
    684 {
    685   return false;
    686 }
    687 /* ANDROID_CHANGE_BEGIN */
    688 #ifndef __APPLE__
    689 strong_alias (default_copy_reloc_p, default_none_reloc_p)
    690 strong_alias (default_copy_reloc_p, default_relative_reloc_p)
    691 #endif
    692 /* ANDROID_CHANGE_END */
    693 
    694 static bool
    695 default_check_special_symbol (Elf *elf __attribute__ ((unused)),
    696 			      GElf_Ehdr *ehdr __attribute__ ((unused)),
    697 			      const GElf_Sym *sym __attribute__ ((unused)),
    698 			      const char *name __attribute__ ((unused)),
    699 			      const GElf_Shdr *destshdr __attribute__ ((unused)))
    700 {
    701   return false;
    702 }
    703 
    704 static bool
    705 default_bss_plt_p (Elf *elf __attribute__ ((unused)),
    706 		   GElf_Ehdr *ehdr __attribute__ ((unused)))
    707 {
    708   return false;
    709 }
    710 
    711 static int
    712 default_return_value_location (Dwarf_Die *functypedie __attribute__ ((unused)),
    713 			       const Dwarf_Op **locops __attribute__ ((unused)))
    714 {
    715   return -2;
    716 }
    717 
    718 static ssize_t
    719 default_register_info (Ebl *ebl __attribute__ ((unused)),
    720 		       int regno, char *name, size_t namelen,
    721 		       const char **prefix,
    722 		       const char **setname,
    723 		       int *bits, int *type)
    724 {
    725   if (name == NULL)
    726     return 0;
    727 
    728   *setname = "???";
    729   *prefix = "";
    730   *bits = -1;
    731   *type = DW_ATE_void;
    732   return snprintf (name, namelen, "reg%d", regno);
    733 }
    734 
    735 static int
    736 default_syscall_abi (Ebl *ebl __attribute__ ((unused)),
    737 		     int *sp, int *pc, int *callno, int args[6])
    738 {
    739   *sp = *pc = *callno = -1;
    740   args[0] = -1;
    741   args[1] = -1;
    742   args[2] = -1;
    743   args[3] = -1;
    744   args[4] = -1;
    745   args[5] = -1;
    746   return -1;
    747 }
    748 
    749 static bool
    750 default_check_object_attribute (Ebl *ebl __attribute__ ((unused)),
    751 				const char *vendor  __attribute__ ((unused)),
    752 				int tag __attribute__ ((unused)),
    753 				uint64_t value __attribute__ ((unused)),
    754 				const char **tag_name, const char **value_name)
    755 {
    756   *tag_name = NULL;
    757   *value_name = NULL;
    758   return false;
    759 }
    760