Add --redefine-sym to objcopy.
[binutils-gdb.git] / binutils / readelf.c
index aeeae9ebc1a2e03c2df5e8043d0141093add937a..050ef9c386eed68c978af2e6e11a253ee148d2e4 100644 (file)
@@ -1,5 +1,5 @@
 /* readelf.c -- display contents of an ELF format file
-   Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1998, 99, 2000 Free Software Foundation, Inc.
 
    Originally developed by Eric Youngdale <eric@andante.jic.com>
    Modifications by Nick Clifton <nickc@cygnus.com>
@@ -23,6 +23,7 @@
 \f
 
 #include <assert.h>
+#include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <time.h>
@@ -68,6 +69,7 @@
 #include "elf/mcore.h"
 #include "elf/i960.h"
 #include "elf/pj.h"
+#include "elf/avr.h"
 
 #include "bucomm.h"
 #include "getopt.h"
@@ -805,6 +807,10 @@ dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
          rtype = elf_i960_reloc_type (type);
          break;
 
+       case EM_AVR:
+         rtype = elf_avr_reloc_type (type);
+         break;
+
        case EM_OLD_SPARCV9:
        case EM_SPARC32PLUS:
        case EM_SPARCV9:
@@ -1694,7 +1700,7 @@ usage ()
   fprintf (stdout, _("  -I or --histogram         Display histogram of bucket list lengths\n"));
   fprintf (stdout, _("  -v or --version           Display the version number of readelf\n"));
   fprintf (stdout, _("  -H or --help              Display this information\n"));
-  fprintf (stdout, _("Report bugs to bug-gnu-utils@gnu.org\n"));
+  fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
 
   exit (0);
 }
@@ -1933,7 +1939,9 @@ get_osabi_name (osabi)
     {
     case ELFOSABI_SYSV:       return _("UNIX - System V");
     case ELFOSABI_HPUX:       return _("UNIX - HP-UX");
+    case ELFOSABI_LINUX:      return _("UNIX - Linux");
     case ELFOSABI_STANDALONE: return _("Standalone App");
+    case ELFOSABI_ARM:        return _("ARM");
     default:
       sprintf (buff, _("<unknown: %x>"), osabi);
       return buff;
@@ -2998,9 +3006,10 @@ get_dynamic_flags (flags)
        case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
        case DF_TEXTREL:  strcat (buff, "TEXTREL "); break;
        case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
-       default:          strcat (buff, "unknown "); return;
+       default:          strcat (buff, "unknown "); break;
        }
     }
+  return buff;
 }
 
 /* Parse and display the contents of the dynamic segment.  */
@@ -3165,11 +3174,14 @@ process_dynamic_segment (file)
     {
       if (do_dynamic)
        {
+         const char *dtype;
+
          putchar (' ');
          print_vma (entry->d_tag, FULL_HEX);
-         printf (" (%s)%*s",
-                 get_dynamic_type (entry->d_tag),
-                 (is_32bit_elf ? 27 : 19) - strlen (get_dynamic_type (entry->d_tag)),
+         dtype = get_dynamic_type (entry->d_tag);
+         printf (" (%s)%*s", dtype,
+                 ((is_32bit_elf ? 27 : 19)
+                  - (int) strlen (dtype)),
                  " ");
        }
 
@@ -3177,7 +3189,7 @@ process_dynamic_segment (file)
        {
        case DT_FLAGS:
          if (do_dynamic)
-           printf (get_dynamic_flags (entry->d_un.d_val));
+           printf ("%s", get_dynamic_flags (entry->d_un.d_val));
          break;
          
        case DT_AUXILIARY:
@@ -3737,6 +3749,7 @@ process_version_sections (file)
            for (cnt = 0; cnt < total; cnt += 4)
              {
                int j, nn;
+               char *name;
 
                printf ("  %03x:", cnt);
 
@@ -3770,8 +3783,8 @@ process_version_sections (file)
                            {
                              Elf_External_Verneed   evn;
                              Elf_External_Vernaux   evna;
-                             Elf_Internal_Vernaux     ivna;
-                             unsigned long            vna_off;
+                             Elf_Internal_Vernaux   ivna;
+                             unsigned long          vna_off;
 
                              GET_DATA (offset, evn, "version need");
 
@@ -3797,10 +3810,10 @@ process_version_sections (file)
                                {
                                  ivna.vna_name = BYTE_GET (evna.vna_name);
 
+                                 name = strtab + ivna.vna_name;
                                  nn += printf ("(%s%-*s",
-                                               strtab + ivna.vna_name,
-                                               12 - strlen (strtab
-                                                            + ivna.vna_name),
+                                               name,
+                                               12 - (int) strlen (name),
                                                ")");
                                  break;
                                }
@@ -3843,12 +3856,11 @@ process_version_sections (file)
                                          ivda.vda_name =
                                            BYTE_GET (evda.vda_name);
 
+                                         name = strtab + ivda.vda_name;
                                          nn +=
                                            printf ("(%s%-*s",
-                                                   strtab + ivda.vda_name,
-                                                   12
-                                                   - strlen (strtab
-                                                             + ivda.vda_name),
+                                                   name,
+                                                   12 - (int) strlen (name),
                                                    ")");
                                        }
                                    }
@@ -3870,10 +3882,10 @@ process_version_sections (file)
 
                          do
                            {
-                             Elf_Internal_Vernaux     ivna;
+                             Elf_Internal_Vernaux   ivna;
                              Elf_External_Verneed   evn;
                              Elf_External_Vernaux   evna;
-                             unsigned long            a_off;
+                             unsigned long          a_off;
 
                              GET_DATA (offset, evn, "version need");
 
@@ -3899,10 +3911,10 @@ process_version_sections (file)
                                {
                                  ivna.vna_name = BYTE_GET (evna.vna_name);
 
+                                 name = strtab + ivna.vna_name;
                                  nn += printf ("(%s%-*s",
-                                               strtab + ivna.vna_name,
-                                               12 - strlen (strtab
-                                                            + ivna.vna_name),
+                                               name,
+                                               12 - (int) strlen (name),
                                                ")");
                                  break;
                                }
@@ -3944,10 +3956,10 @@ process_version_sections (file)
 
                              ivda.vda_name = BYTE_GET (evda.vda_name);
 
+                             name = strtab + ivda.vda_name;
                              nn += printf ("(%s%-*s",
-                                           strtab + ivda.vda_name,
-                                           12 - strlen (strtab
-                                                        + ivda.vda_name),
+                                           name,
+                                           12 - (int) strlen (name),
                                            ")");
                            }
                        }
@@ -4178,9 +4190,9 @@ process_symbol_table (file)
 
       printf (_("\nSymbol table for image:\n"));
       if (is_32bit_elf)
-       printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ot Ndx Name\n"));
+       printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
       else
-       printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ot Ndx Name\n"));
+       printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
 
       for (hn = 0; hn < nbuckets; hn++)
        {
@@ -4201,7 +4213,6 @@ process_symbol_table (file)
              printf ("  %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
              printf (" %6s",  get_symbol_binding (ELF_ST_BIND (psym->st_info)));
              printf (" %3s",  get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
-             printf (" %2d",  ELF_ST_OTHER (psym->st_other));
              printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
              printf (" %s\n", dynamic_strings + psym->st_name);
            }
@@ -4229,9 +4240,9 @@ process_symbol_table (file)
                  SECTION_NAME (section),
                  (unsigned long) (section->sh_size / section->sh_entsize));
          if (is_32bit_elf)
-           printf (_("   Num:    Value  Size Type    Bind   Vis      Ot Ndx Name\n"));
+           printf (_("   Num:    Value  Size Type    Bind   Vis      Ndx Name\n"));
          else
-           printf (_("   Num:    Value          Size Type    Bind   Vis      Ot  Ndx Name\n"));
+           printf (_("   Num:    Value          Size Type    Bind   Vis      Ndx Name\n"));
 
          symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
                                    section->sh_size / section->sh_entsize);
@@ -4261,7 +4272,6 @@ process_symbol_table (file)
              printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
              printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
              printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
-             printf (" %2d", ELF_ST_OTHER (psym->st_other));
              printf (" %4s", get_symbol_index_type (psym->st_shndx));
              printf (" %s", strtab + psym->st_name);
 
@@ -4300,15 +4310,15 @@ process_symbol_table (file)
                          offset = version_info
                            [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
 
-                         GET_DATA (offset, evn, "version need");
-
-                         ivn.vn_aux  = BYTE_GET (evn.vn_aux);
-                         ivn.vn_next = BYTE_GET (evn.vn_next);
-
                          do
                            {
                              unsigned long  vna_off;
 
+                             GET_DATA (offset, evn, "version need");
+
+                             ivn.vn_aux  = BYTE_GET (evn.vn_aux);
+                             ivn.vn_next = BYTE_GET (evn.vn_next);
+
                              vna_off = offset + ivn.vn_aux;
 
                              do
@@ -5964,7 +5974,7 @@ read_and_display_attr (attribute, form, data, pointer_size)
     case DW_FORM_ref_addr:
     case DW_FORM_addr:
       uvalue = byte_get (data, pointer_size);
-      printf (is_ref ? " <%x>" : " %#x", uvalue);
+      printf (is_ref ? " <%lx>" : " %#lx", uvalue);
       data += pointer_size;
       break;
 
@@ -5972,21 +5982,21 @@ read_and_display_attr (attribute, form, data, pointer_size)
     case DW_FORM_flag:
     case DW_FORM_data1:
       uvalue = byte_get (data ++, 1);
-      printf (is_ref ? " <%x>" : " %d", uvalue);
+      printf (is_ref ? " <%lx>" : " %ld", uvalue);
       break;
 
     case DW_FORM_ref2:
     case DW_FORM_data2:
       uvalue = byte_get (data, 2);
       data += 2;
-      printf (is_ref ? " <%x>" : " %d", uvalue);
+      printf (is_ref ? " <%lx>" : " %ld", uvalue);
       break;
 
     case DW_FORM_ref4:
     case DW_FORM_data4:
       uvalue = byte_get (data, 4);
       data += 4;
-      printf (is_ref ? " <%x>" : " %d", uvalue);
+      printf (is_ref ? " <%lx>" : " %ld", uvalue);
       break;
 
     case DW_FORM_ref8:
@@ -6609,7 +6619,8 @@ process_mips_specific (file)
       GET_DATA_ALLOC (liblist_offset, liblistno * sizeof (Elf32_External_Lib),
                      elib, Elf32_External_Lib *, "liblist");
 
-      printf ("\nSection '.liblist' contains %d entries:\n", liblistno);
+      printf ("\nSection '.liblist' contains %lu entries:\n",
+             (unsigned long) liblistno);
       fputs ("     Library              Time Stamp          Checksum   Version Flags\n",
             stdout);
 
@@ -6627,7 +6638,7 @@ process_mips_specific (file)
 
          strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time));
 
-         printf ("%3d: %-20s %s %#10lx %-7ld", cnt,
+         printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt,
                  dynamic_strings + liblist.l_name, timebuf,
                  liblist.l_checksum, liblist.l_version);
 
@@ -6911,7 +6922,7 @@ process_mips_specific (file)
        {
          Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
 
-         printf ("%5u: %8lu  ", cnt, iconf[cnt]);
+         printf ("%5lu: %8lu  ", (unsigned long) cnt, iconf[cnt]);
          print_vma (psym->st_value, FULL_HEX);
          printf ("  %s\n", dynamic_strings + psym->st_name);
        }
@@ -6980,7 +6991,9 @@ process_corefile_note_segment (file, offset, length)
 
   external = pnotes;
 
-  printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"), offset, length);
+  printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
+         (unsigned long) offset,
+         (unsigned long) length);
   printf (_("  Owner\t\tData size\tDescription\n"));
 
   while (external < (Elf_External_Note *)((char *) pnotes + length))