Print this page
3450 elfdump crashes on non-Solaris/Linux objects


2208 /*
2209  * Display version section information if the flags require it.
2210  * Return version information needed by other output.
2211  *
2212  * entry:
2213  *      cache - Cache of all section headers
2214  *      shnum - # of sections in cache
2215  *      file - Name of file
2216  *      flags - Command line option flags
2217  *      versym - VERSYM_STATE block to be filled in.
2218  */
2219 static void
2220 versions(Cache *cache, Word shnum, const char *file, uint_t flags,
2221     VERSYM_STATE *versym)
2222 {
2223         GElf_Word       cnt;
2224         Cache           *verdef_cache = NULL, *verneed_cache = NULL;
2225 
2226 
2227         /* Gather information about the version sections */
2228         bzero(versym, sizeof (*versym));
2229         versym->max_verndx = 1;
2230         for (cnt = 1; cnt < shnum; cnt++) {
2231                 Cache           *_cache = &cache[cnt];
2232                 Shdr            *shdr = _cache->c_shdr;
2233                 Dyn             *dyn;
2234                 ulong_t         numdyn;
2235 
2236                 switch (shdr->sh_type) {
2237                 case SHT_DYNAMIC:
2238                         /*
2239                          * The GNU ld puts a DT_VERSYM entry in the dynamic
2240                          * section so that the runtime linker can use it to
2241                          * implement their versioning rules. They allow multiple
2242                          * incompatible functions with the same name to exist
2243                          * in different versions. The Solaris ld does not
2244                          * support this mechanism, and as such, does not
2245                          * produce DT_VERSYM. We use this fact to determine
2246                          * which ld produced this object, and how to interpret
2247                          * the version values.
2248                          */


4722                         return (0);
4723         } else {
4724                 if (shdr_cache(file, elf, ehdr, shstrndx, *shnum,
4725                     cache, *flags) == 0)
4726                         return (0);
4727         }
4728 
4729         return (1);
4730 }
4731 
4732 int
4733 regular(const char *file, int fd, Elf *elf, uint_t flags,
4734     const char *wname, int wfd, uchar_t osabi)
4735 {
4736         enum { CACHE_NEEDED, CACHE_OK, CACHE_FAIL} cache_state = CACHE_NEEDED;
4737         Elf_Scn         *scn;
4738         Ehdr            *ehdr;
4739         size_t          ndx, shstrndx, shnum, phnum;
4740         Shdr            *shdr;
4741         Cache           *cache;
4742         VERSYM_STATE    versym;
4743         int             ret = 0;
4744         int             addr_align;
4745 
4746         if ((ehdr = elf_getehdr(elf)) == NULL) {
4747                 failure(file, MSG_ORIG(MSG_ELF_GETEHDR));
4748                 return (ret);
4749         }
4750 
4751         if (elf_getshdrnum(elf, &shnum) == -1) {
4752                 failure(file, MSG_ORIG(MSG_ELF_GETSHDRNUM));
4753                 return (ret);
4754         }
4755 
4756         if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
4757                 failure(file, MSG_ORIG(MSG_ELF_GETSHDRSTRNDX));
4758                 return (ret);
4759         }
4760 
4761         if (elf_getphdrnum(elf, &phnum) == -1) {
4762                 failure(file, MSG_ORIG(MSG_ELF_GETPHDRNUM));




2208 /*
2209  * Display version section information if the flags require it.
2210  * Return version information needed by other output.
2211  *
2212  * entry:
2213  *      cache - Cache of all section headers
2214  *      shnum - # of sections in cache
2215  *      file - Name of file
2216  *      flags - Command line option flags
2217  *      versym - VERSYM_STATE block to be filled in.
2218  */
2219 static void
2220 versions(Cache *cache, Word shnum, const char *file, uint_t flags,
2221     VERSYM_STATE *versym)
2222 {
2223         GElf_Word       cnt;
2224         Cache           *verdef_cache = NULL, *verneed_cache = NULL;
2225 
2226 
2227         /* Gather information about the version sections */

2228         versym->max_verndx = 1;
2229         for (cnt = 1; cnt < shnum; cnt++) {
2230                 Cache           *_cache = &cache[cnt];
2231                 Shdr            *shdr = _cache->c_shdr;
2232                 Dyn             *dyn;
2233                 ulong_t         numdyn;
2234 
2235                 switch (shdr->sh_type) {
2236                 case SHT_DYNAMIC:
2237                         /*
2238                          * The GNU ld puts a DT_VERSYM entry in the dynamic
2239                          * section so that the runtime linker can use it to
2240                          * implement their versioning rules. They allow multiple
2241                          * incompatible functions with the same name to exist
2242                          * in different versions. The Solaris ld does not
2243                          * support this mechanism, and as such, does not
2244                          * produce DT_VERSYM. We use this fact to determine
2245                          * which ld produced this object, and how to interpret
2246                          * the version values.
2247                          */


4721                         return (0);
4722         } else {
4723                 if (shdr_cache(file, elf, ehdr, shstrndx, *shnum,
4724                     cache, *flags) == 0)
4725                         return (0);
4726         }
4727 
4728         return (1);
4729 }
4730 
4731 int
4732 regular(const char *file, int fd, Elf *elf, uint_t flags,
4733     const char *wname, int wfd, uchar_t osabi)
4734 {
4735         enum { CACHE_NEEDED, CACHE_OK, CACHE_FAIL} cache_state = CACHE_NEEDED;
4736         Elf_Scn         *scn;
4737         Ehdr            *ehdr;
4738         size_t          ndx, shstrndx, shnum, phnum;
4739         Shdr            *shdr;
4740         Cache           *cache;
4741         VERSYM_STATE    versym = { 0 };
4742         int             ret = 0;
4743         int             addr_align;
4744 
4745         if ((ehdr = elf_getehdr(elf)) == NULL) {
4746                 failure(file, MSG_ORIG(MSG_ELF_GETEHDR));
4747                 return (ret);
4748         }
4749 
4750         if (elf_getshdrnum(elf, &shnum) == -1) {
4751                 failure(file, MSG_ORIG(MSG_ELF_GETSHDRNUM));
4752                 return (ret);
4753         }
4754 
4755         if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
4756                 failure(file, MSG_ORIG(MSG_ELF_GETSHDRSTRNDX));
4757                 return (ret);
4758         }
4759 
4760         if (elf_getphdrnum(elf, &phnum) == -1) {
4761                 failure(file, MSG_ORIG(MSG_ELF_GETPHDRNUM));