Print this page
4383 libelf can't write extended sections when ELF_F_LAYOUT

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/sgs/libelf/common/update.c
          +++ new/usr/src/cmd/sgs/libelf/common/update.c
↓ open down ↓ 339 lines elided ↑ open up ↑
 340  340  static size_t
 341  341  _elf_upd_usr(Elf * elf)
 342  342  {
 343  343          NOTE(ASSUMING_PROTECTED(*elf))
 344  344          Lword           hi;
 345  345          Elf_Scn *       s;
 346  346          register Lword  sz;
 347  347          Ehdr *          eh = elf->ed_ehdr;
 348  348          unsigned        ver = eh->e_version;
 349  349          register char   *p = (char *)eh->e_ident;
 350      -
      350 +        size_t          scncnt;
 351  351  
 352  352          /*
 353  353           * Ehdr and Phdr table go first
 354  354           */
 355  355          p[EI_MAG0] = ELFMAG0;
 356  356          p[EI_MAG1] = ELFMAG1;
 357  357          p[EI_MAG2] = ELFMAG2;
 358  358          p[EI_MAG3] = ELFMAG3;
 359  359          p[EI_CLASS] = ELFCLASS;
 360  360          /* LINTED */
↓ open down ↓ 16 lines elided ↑ open up ↑
 377  377                  eh->e_phentsize = 0;
 378  378          if ((sz = eh->e_phoff + eh->e_phentsize * eh->e_phnum) > hi)
 379  379                  hi = sz;
 380  380  
 381  381          /*
 382  382           * Loop through sections, skipping index zero.
 383  383           * Compute section size before changing hi.
 384  384           * Allow null buffers for NOBITS.
 385  385           */
 386  386  
 387      -        if ((s = elf->ed_hdscn) == 0)
      387 +        if ((s = elf->ed_hdscn) == 0) {
 388  388                  eh->e_shnum = 0;
 389      -        else {
 390      -                eh->e_shnum = 1;
 391      -                *(Shdr*)s->s_shdr = _elf_snode_init.sb_shdr;
      389 +                scncnt = 0;
      390 +        } else {
      391 +                scncnt = 1;
 392  392                  s = s->s_next;
 393  393          }
 394  394          for (; s != 0; s = s->s_next) {
 395  395                  register Dnode  *d;
 396  396                  register Lword  fsz, j;
 397  397                  Shdr *sh = s->s_shdr;
 398  398  
 399  399                  if ((s->s_myflags & SF_READY) == 0)
 400  400                          (void) _elfxx_cookscn(s);
 401  401  
 402      -                ++eh->e_shnum;
      402 +                ++scncnt;
 403  403                  sz = 0;
 404  404                  for (d = s->s_hdnode; d != 0; d = d->db_next) {
 405  405                          if ((fsz = elf_fsize(d->db_data.d_type, 1,
 406  406                              ver)) == 0)
 407  407                                  return (0);
 408  408                          j = _elf_msize(d->db_data.d_type, ver);
 409  409                          fsz *= (d->db_data.d_size / j);
 410  410                          d->db_osz = (size_t)fsz;
 411  411  
 412  412                          if ((sh->sh_type != SHT_NOBITS) &&
↓ open down ↓ 5 lines elided ↑ open up ↑
 418  418                          return (0);
 419  419                  }
 420  420                  if ((sh->sh_type != SHT_NOBITS) &&
 421  421                      (hi < sh->sh_offset + sh->sh_size))
 422  422                          hi = sh->sh_offset + sh->sh_size;
 423  423          }
 424  424  
 425  425          /*
 426  426           * Shdr table last.  Comment above for phnum/phoff applies here.
 427  427           */
 428      -        if (eh->e_shnum != 0)
      428 +        if (scncnt != 0) {
 429  429                  /* LINTED */
 430  430                  eh->e_shentsize = (Half)elf_fsize(ELF_T_SHDR, 1, ver);
 431      -        else
      431 +                if (scncnt < SHN_LORESERVE) {
      432 +                        eh->e_shnum = scncnt;
      433 +                } else {
      434 +                        Shdr *sh;
      435 +                        sh = (Shdr *)elf->ed_hdscn->s_shdr;
      436 +                        sh->sh_size = scncnt;
      437 +                        eh->e_shnum = 0;
      438 +                }
      439 +        } else {
 432  440                  eh->e_shentsize = 0;
      441 +        }
 433  442  
 434      -        if ((sz = eh->e_shoff + eh->e_shentsize * eh->e_shnum) > hi)
      443 +        if ((sz = eh->e_shoff + eh->e_shentsize * scncnt) > hi)
 435  444                  hi = sz;
 436  445  
 437  446  #ifdef TEST_SIZE
 438  447          if (test_size(hi) == 0)
 439  448                  return (0);
 440  449  #endif
 441  450  
 442  451          return ((size_t)hi);
 443  452  }
 444  453  
↓ open down ↓ 555 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX