Print this page
4009 size(1) can't find sections in relocatable objects with extended sections

@@ -66,38 +66,39 @@
 
 void
 process(Elf * elf)
 {
         /* EXTERNAL VARIABLES USED */
-        extern int      fflag, /* full format for sections */
-                        Fflag, /* full format for segments */
-                        nflag; /* include non-loadable segments or sections */
+        extern int      fflag; /* full format for sections */
+        extern int      Fflag; /* full format for segments */
+        extern int      nflag; /* include non-loadable segments or sections */
         extern int      numbase; /* hex, octal, or decimal */
         extern char     *fname;
         extern char     *archive;
         extern int      is_archive;
         extern int      oneflag;
 
         /* LOCAL VARIABLES */
-        GElf_Xword      size, /* total size in non-default case for sections */
+        GElf_Xword      size; /* total size in non-default case for sections */
                         /*
                          * size of first, second, third number and total size
                          * in default case for sections.
                          */
-                        first,
-                        second,
-                        third,
-                        totsize;
+        GElf_Xword      first;
+        GElf_Xword      second;
+        GElf_Xword      third;
+        GElf_Xword      totsize;
         GElf_Ehdr       ehdr;
         GElf_Shdr       shdr;
         Elf_Scn         *scn;
-        unsigned        ndx = 0;
+        size_t          ndx = 0, shnum = 0;
         int             numsect = 0;
         int             notfirst = 0;
         int             i;
         char            *name = 0;
 
+
 /*
  * If there is a program header and the -f flag requesting section infor-
  * mation is not set, then process segments with the process_phdr function.
  * Otherwise, process sections.  For the default case, the first number
  * shall be the size of all sections that are allocatable, nonwritable and

@@ -122,18 +123,23 @@
         if (is_archive) {
                 (void) printf("%s[%s]: ", archive, fname);
         } else if (!oneflag && !is_archive) {
                 (void) printf("%s: ", fname);
         }
-        ndx = ehdr.e_shstrndx;
+        if (elf_getshdrstrndx(elf, &ndx) == -1)
+                error(fname, "no string table");
         scn = 0;
         size = 0;
         first = second = third = totsize = 0;
-        if (ehdr.e_shnum == 0) {
+
+        if (elf_getshdrnum(elf, &shnum) == -1)
+                error(fname, "can't get number of sections");
+
+        if (shnum == 0)
                 error(fname, "no section data");
-        }
-        numsect = ehdr.e_shnum;
+
+        numsect = shnum;
         for (i = 0; i < numsect; i++) {
                 if ((scn = elf_nextscn(elf, scn)) == 0) {
                         break;
                 }
                 if (gelf_getshdr(scn, &shdr) == 0) {

@@ -213,16 +219,16 @@
 process_phdr(Elf * elf, GElf_Half num)
 {
         int             i;
         int             notfirst = 0;
         GElf_Phdr       p;
-        GElf_Xword      memsize,
-                        total,
-                        First,
-                        Second,
-                        Third,
-                        Totsize;
+        GElf_Xword      memsize;
+        GElf_Xword      total;
+        GElf_Xword      First;
+        GElf_Xword      Second;
+        GElf_Xword      Third;
+        GElf_Xword      Totsize;
                 extern int Fflag;
                 extern int nflag;
                 extern int numbase;
                 extern char *fname;
                 extern char *archive;