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


  51 };
  52 
  53 static const char *prusum[3] = {
  54         " = 0x%llx\n",
  55         " = 0%llo\n",
  56         " = %lld\n"
  57 };
  58 
  59 static const char *format[3] = {
  60         "%llx + %llx + %llx = 0x%llx\n",
  61         "%llo + %llo + %llo = 0%llo\n",
  62         "%lld + %lld + %lld = %lld\n"
  63 };
  64 
  65 static void     process_phdr(Elf *elf, GElf_Half num);
  66 
  67 void
  68 process(Elf * elf)
  69 {
  70         /* EXTERNAL VARIABLES USED */
  71         extern int      fflag, /* full format for sections */
  72                         Fflag, /* full format for segments */
  73                         nflag; /* include non-loadable segments or sections */
  74         extern int      numbase; /* hex, octal, or decimal */
  75         extern char     *fname;
  76         extern char     *archive;
  77         extern int      is_archive;
  78         extern int      oneflag;
  79 
  80         /* LOCAL VARIABLES */
  81         GElf_Xword      size, /* total size in non-default case for sections */
  82                         /*
  83                          * size of first, second, third number and total size
  84                          * in default case for sections.
  85                          */
  86                         first,
  87                         second,
  88                         third,
  89                         totsize;
  90         GElf_Ehdr       ehdr;
  91         GElf_Shdr       shdr;
  92         Elf_Scn         *scn;
  93         unsigned        ndx = 0;
  94         int             numsect = 0;
  95         int             notfirst = 0;
  96         int             i;
  97         char            *name = 0;
  98 

  99 /*
 100  * If there is a program header and the -f flag requesting section infor-
 101  * mation is not set, then process segments with the process_phdr function.
 102  * Otherwise, process sections.  For the default case, the first number
 103  * shall be the size of all sections that are allocatable, nonwritable and
 104  * not of type NOBITS; the second number shall be the size of all sections
 105  * that are allocatable, writable, and not of type NOBITS; the third number
 106  * is the size of all sections that are writable and not of type NOBITS.
 107  * If -f is set, print the size of each allocatable section, followed by
 108  * the section name in parentheses.
 109  * If -n is set, print the size of all sections, followed by the section
 110  * name in parentheses.
 111  */
 112 
 113         if (gelf_getehdr(elf, &ehdr) == 0) {
 114                 error(fname, "invalid file type");
 115                 return;
 116         }
 117         if ((ehdr.e_phnum != 0) && !(fflag)) {
 118                 process_phdr(elf, ehdr.e_phnum);
 119                 return;
 120         }
 121 
 122         if (is_archive) {
 123                 (void) printf("%s[%s]: ", archive, fname);
 124         } else if (!oneflag && !is_archive) {
 125                 (void) printf("%s: ", fname);
 126         }
 127         ndx = ehdr.e_shstrndx;

 128         scn = 0;
 129         size = 0;
 130         first = second = third = totsize = 0;
 131         if (ehdr.e_shnum == 0) {




 132                 error(fname, "no section data");
 133         }
 134         numsect = ehdr.e_shnum;
 135         for (i = 0; i < numsect; i++) {
 136                 if ((scn = elf_nextscn(elf, scn)) == 0) {
 137                         break;
 138                 }
 139                 if (gelf_getshdr(scn, &shdr) == 0) {
 140                         error(fname, "could not get section header");
 141                         break;
 142                 }
 143                 if ((Fflag) && !(fflag)) {
 144                         error(fname, "no segment data");
 145                         return;
 146                 } else if ((!(shdr.sh_flags & SHF_ALLOC)) &&
 147                         fflag && !(nflag)) {
 148                         continue;
 149                 } else if ((!(shdr.sh_flags & SHF_ALLOC)) && !(nflag)) {
 150                         continue;
 151                 } else if ((shdr.sh_flags & SHF_ALLOC) &&
 152                         (!(shdr.sh_flags & SHF_WRITE)) &&
 153                         (!(shdr.sh_type == SHT_NOBITS)) &&
 154                         !(fflag) && !(nflag)) {


 198 
 199 /*
 200  * If there is a program exection header, process segments. In the default
 201  * case, the first number is the file size of all nonwritable segments
 202  * of type PT_LOAD; the second number is the file size of all writable
 203  * segments whose type is PT_LOAD; the third number is the memory size
 204  * minus the file size of all writable segments of type PT_LOAD.
 205  * If the -F flag is set, size will print the memory size of each loadable
 206  * segment, followed by its permission flags.
 207  * If -n is set, size will print the memory size of all loadable segments
 208  * and the file size of all non-loadable segments, followed by their
 209  * permission flags.
 210  */
 211 
 212 static void
 213 process_phdr(Elf * elf, GElf_Half num)
 214 {
 215         int             i;
 216         int             notfirst = 0;
 217         GElf_Phdr       p;
 218         GElf_Xword      memsize,
 219                         total,
 220                         First,
 221                         Second,
 222                         Third,
 223                         Totsize;
 224                 extern int Fflag;
 225                 extern int nflag;
 226                 extern int numbase;
 227                 extern char *fname;
 228                 extern char *archive;
 229                 extern int is_archive;
 230                 extern int oneflag;
 231 
 232         memsize = total = 0;
 233         First = Second = Third = Totsize = 0;
 234 
 235         if (is_archive) {
 236                 (void) printf("%s[%s]: ", archive, fname);
 237         } else if (!oneflag && !is_archive) {
 238                 (void) printf("%s: ", fname);
 239         }
 240 
 241         for (i = 0; i < (int)num; i++) {
 242                 if (gelf_getphdr(elf, i, &p) == NULL) {
 243                         error(fname, "no segment data");




  51 };
  52 
  53 static const char *prusum[3] = {
  54         " = 0x%llx\n",
  55         " = 0%llo\n",
  56         " = %lld\n"
  57 };
  58 
  59 static const char *format[3] = {
  60         "%llx + %llx + %llx = 0x%llx\n",
  61         "%llo + %llo + %llo = 0%llo\n",
  62         "%lld + %lld + %lld = %lld\n"
  63 };
  64 
  65 static void     process_phdr(Elf *elf, GElf_Half num);
  66 
  67 void
  68 process(Elf * elf)
  69 {
  70         /* EXTERNAL VARIABLES USED */
  71         extern int      fflag; /* full format for sections */
  72         extern int      Fflag; /* full format for segments */
  73         extern int      nflag; /* include non-loadable segments or sections */
  74         extern int      numbase; /* hex, octal, or decimal */
  75         extern char     *fname;
  76         extern char     *archive;
  77         extern int      is_archive;
  78         extern int      oneflag;
  79 
  80         /* LOCAL VARIABLES */
  81         GElf_Xword      size; /* total size in non-default case for sections */
  82         /*
  83          * size of first, second, third number and total size
  84          * in default case for sections.
  85          */
  86         GElf_Xword      first;
  87         GElf_Xword      second;
  88         GElf_Xword      third;
  89         GElf_Xword      totsize;
  90         GElf_Ehdr       ehdr;
  91         GElf_Shdr       shdr;
  92         Elf_Scn         *scn;
  93         size_t          ndx = 0, shnum = 0;
  94         int             numsect = 0;
  95         int             notfirst = 0;
  96         int             i;
  97         char            *name = 0;
  98 
  99 
 100 /*
 101  * If there is a program header and the -f flag requesting section infor-
 102  * mation is not set, then process segments with the process_phdr function.
 103  * Otherwise, process sections.  For the default case, the first number
 104  * shall be the size of all sections that are allocatable, nonwritable and
 105  * not of type NOBITS; the second number shall be the size of all sections
 106  * that are allocatable, writable, and not of type NOBITS; the third number
 107  * is the size of all sections that are writable and not of type NOBITS.
 108  * If -f is set, print the size of each allocatable section, followed by
 109  * the section name in parentheses.
 110  * If -n is set, print the size of all sections, followed by the section
 111  * name in parentheses.
 112  */
 113 
 114         if (gelf_getehdr(elf, &ehdr) == 0) {
 115                 error(fname, "invalid file type");
 116                 return;
 117         }
 118         if ((ehdr.e_phnum != 0) && !(fflag)) {
 119                 process_phdr(elf, ehdr.e_phnum);
 120                 return;
 121         }
 122 
 123         if (is_archive) {
 124                 (void) printf("%s[%s]: ", archive, fname);
 125         } else if (!oneflag && !is_archive) {
 126                 (void) printf("%s: ", fname);
 127         }
 128         if (elf_getshdrstrndx(elf, &ndx) == -1)
 129                 error(fname, "no string table");
 130         scn = 0;
 131         size = 0;
 132         first = second = third = totsize = 0;
 133 
 134         if (elf_getshdrnum(elf, &shnum) == -1)
 135                 error(fname, "can't get number of sections");
 136 
 137         if (shnum == 0)
 138                 error(fname, "no section data");
 139 
 140         numsect = shnum;
 141         for (i = 0; i < numsect; i++) {
 142                 if ((scn = elf_nextscn(elf, scn)) == 0) {
 143                         break;
 144                 }
 145                 if (gelf_getshdr(scn, &shdr) == 0) {
 146                         error(fname, "could not get section header");
 147                         break;
 148                 }
 149                 if ((Fflag) && !(fflag)) {
 150                         error(fname, "no segment data");
 151                         return;
 152                 } else if ((!(shdr.sh_flags & SHF_ALLOC)) &&
 153                     fflag && !(nflag)) {
 154                         continue;
 155                 } else if ((!(shdr.sh_flags & SHF_ALLOC)) && !(nflag)) {
 156                         continue;
 157                 } else if ((shdr.sh_flags & SHF_ALLOC) &&
 158                     (!(shdr.sh_flags & SHF_WRITE)) &&
 159                     (!(shdr.sh_type == SHT_NOBITS)) &&
 160                     !(fflag) && !(nflag)) {


 204 
 205 /*
 206  * If there is a program exection header, process segments. In the default
 207  * case, the first number is the file size of all nonwritable segments
 208  * of type PT_LOAD; the second number is the file size of all writable
 209  * segments whose type is PT_LOAD; the third number is the memory size
 210  * minus the file size of all writable segments of type PT_LOAD.
 211  * If the -F flag is set, size will print the memory size of each loadable
 212  * segment, followed by its permission flags.
 213  * If -n is set, size will print the memory size of all loadable segments
 214  * and the file size of all non-loadable segments, followed by their
 215  * permission flags.
 216  */
 217 
 218 static void
 219 process_phdr(Elf * elf, GElf_Half num)
 220 {
 221         int             i;
 222         int             notfirst = 0;
 223         GElf_Phdr       p;
 224         GElf_Xword      memsize;
 225         GElf_Xword      total;
 226         GElf_Xword      First;
 227         GElf_Xword      Second;
 228         GElf_Xword      Third;
 229         GElf_Xword      Totsize;
 230         extern int Fflag;
 231         extern int nflag;
 232         extern int numbase;
 233         extern char *fname;
 234         extern char *archive;
 235         extern int is_archive;
 236         extern int oneflag;
 237 
 238         memsize = total = 0;
 239         First = Second = Third = Totsize = 0;
 240 
 241         if (is_archive) {
 242                 (void) printf("%s[%s]: ", archive, fname);
 243         } else if (!oneflag && !is_archive) {
 244                 (void) printf("%s: ", fname);
 245         }
 246 
 247         for (i = 0; i < (int)num; i++) {
 248                 if (gelf_getphdr(elf, i, &p) == NULL) {
 249                         error(fname, "no segment data");