Print this page
11057 hidden undefined weak symbols should not leave relocations
11058 libld entrance descriptor assertions get NDEBUG check backwards

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/sgs/libld/common/machrel.sparc.c
          +++ new/usr/src/cmd/sgs/libld/common/machrel.sparc.c
↓ open down ↓ 137 lines elided ↑ open up ↑
 138  138          if (firstpass == 0) {
 139  139                  ofl->ofl_dehdr->e_flags |= ehdr->e_flags;
 140  140                  firstpass++;
 141  141                  return;
 142  142          }
 143  143  
 144  144          /*
 145  145           * Determine which memory model to mark the binary with.  The options
 146  146           * are (most restrictive to least):
 147  147           *
 148      -         *      EF_SPARCV9_TSO          0x0     Total Store Order
      148 +         *      EF_SPARCV9_TSO          0x0     Total Store Order
 149  149           *      EF_SPARCV9_PSO          0x1     Partial Store Order
 150  150           *      EF_SPARCV9_RMO          0x2     Relaxed Memory Order
 151  151           *
 152  152           * Mark the binary with the most restrictive option encountered from a
 153  153           * relocatable object included in the link.
 154  154           */
 155  155          eflags |= (ehdr->e_flags & ~EF_SPARCV9_MM);
 156  156          memopt1 = eflags & EF_SPARCV9_MM;
 157  157          memopt2 = ehdr->e_flags & EF_SPARCV9_MM;
 158  158          eflags &= ~EF_SPARCV9_MM;
↓ open down ↓ 613 lines elided ↑ open up ↑
 772  772                  raddend += value;
 773  773  
 774  774          /*
 775  775           * The addend field for R_SPARC_TLS_DTPMOD32 and R_SPARC_TLS_DTPMOD64
 776  776           * mean nothing.  The addend is propagated in the corresponding
 777  777           * R_SPARC_TLS_DTPOFF* relocations.
 778  778           */
 779  779          if (orsp->rel_rtype == M_R_DTPMOD)
 780  780                  raddend = 0;
 781  781  
 782      -        relbits = (char *)relosp->os_outdata->d_buf;
      782 +        /*
      783 +         * Note that the other case which writes out the relocation, above, is
      784 +         * M_R_REGISTER specific and so does not need this check.
      785 +         */
      786 +        if ((orsp->rel_rtype != M_R_NONE) &&
      787 +            (orsp->rel_rtype != M_R_REGISTER) &&
      788 +            (orsp->rel_rtype != M_R_RELATIVE)) {
      789 +                if (ndx == 0) {
      790 +                        Conv_inv_buf_t  inv_buf;
      791 +                        Is_desc *isp = orsp->rel_isdesc;
      792 +
      793 +                        ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_NOSYMBOL),
      794 +                            conv_reloc_type(ofl->ofl_nehdr->e_machine,
      795 +                            orsp->rel_rtype, 0, &inv_buf),
      796 +                            isp->is_file->ifl_name, EC_WORD(isp->is_scnndx),
      797 +                            isp->is_name, EC_XWORD(roffset));
      798 +                        return (S_ERROR);
      799 +                }
      800 +        }
 783  801  
 784  802          rea.r_info = ELF_R_INFO(ndx,
 785  803              ELF_R_TYPE_INFO(RELAUX_GET_TYPEDATA(orsp), orsp->rel_rtype));
 786  804          rea.r_offset = roffset;
 787  805          rea.r_addend = raddend;
 788  806          DBG_CALL(Dbg_reloc_out(ofl, ELF_DBG_LD, SHT_RELA, &rea, relosp->os_name,
 789  807              ld_reloc_sym_name(orsp)));
 790  808  
 791  809          /*
 792  810           * Assert we haven't walked off the end of our relocation table.
 793  811           */
 794  812          assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size);
 795  813  
      814 +        relbits = (char *)relosp->os_outdata->d_buf;
      815 +
 796  816          (void) memcpy((relbits + relosp->os_szoutrels),
 797  817              (char *)&rea, sizeof (Rela));
 798  818          relosp->os_szoutrels += (Xword)sizeof (Rela);
 799  819  
 800  820          /*
 801  821           * Determine if this relocation is against a non-writable, allocatable
 802  822           * section.  If so we may need to provide a text relocation diagnostic.
 803  823           */
 804  824          ld_reloc_remain_entry(orsp, osp, ofl, remain_seen);
 805  825          return (1);
↓ open down ↓ 114 lines elided ↑ open up ↑
 920  940                  w = TLS_GD_LE_XOR |
 921  941                      (w & (FM3_REG_MSK_RS1 | FM3_REG_MSK_RD));
 922  942                  *offset = bswap ? ld_bswap_Word(w) : w;
 923  943                  arsp->rel_rtype = R_SPARC_TLS_LE_LOX10;
 924  944                  return (FIX_RELOC);
 925  945  
 926  946          case R_SPARC_TLS_IE_LD:
 927  947          case R_SPARC_TLS_IE_LDX:
 928  948                  /*
 929  949                   * Current instruction:
 930      -                 *      ld{x}   [r1 + r2], r3
      950 +                 *      ld{x}   [r1 + r2], r3
 931  951                   *
 932  952                   * Need to update this to:
 933  953                   *
 934  954                   *      mov     r2, r3   (or  %g0, r2, r3)
 935  955                   */
 936  956                  DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
 937  957                      R_SPARC_NONE, arsp, ld_reloc_sym_name));
 938  958                  w = bswap ? ld_bswap_Word(*offset) : *offset;
 939  959                  w = (w & (FM3_REG_MSK_RS2 | FM3_REG_MSK_RD)) | TLS_IE_LE_OR;
 940  960                  *offset = bswap ? ld_bswap_Word(w) : w;
↓ open down ↓ 61 lines elided ↑ open up ↑
1002 1022  
1003 1023          case R_SPARC_GOTDATA_OP_LOX10:
1004 1024                  DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
1005 1025                      R_SPARC_GOTDATA_LOX10, arsp, ld_reloc_sym_name));
1006 1026                  arsp->rel_rtype = R_SPARC_GOTDATA_LOX10;
1007 1027                  return (FIX_RELOC);
1008 1028  
1009 1029          case R_SPARC_GOTDATA_OP:
1010 1030                  /*
1011 1031                   * Current instruction:
1012      -                 *      ld{x}   [r1 + r2], r3
     1032 +                 *      ld{x}   [r1 + r2], r3
1013 1033                   *
1014 1034                   * Need to update this to:
1015 1035                   *
1016 1036                   *      add     r1, r2, r3
1017 1037                   */
1018 1038                  DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
1019 1039                      R_SPARC_NONE, arsp, ld_reloc_sym_name));
1020 1040                  offset = (Word *)(uintptr_t)(arsp->rel_roffset +
1021 1041                      _elf_getxoff(arsp->rel_isdesc->is_indata) +
1022 1042                      (uintptr_t)RELAUX_GET_OSDESC(arsp)->os_outdata->d_buf);
↓ open down ↓ 379 lines elided ↑ open up ↑
1402 1422          Conv_inv_buf_t  inv_buf;
1403 1423  
1404 1424          /*
1405 1425           * Static executables *do not* want any relocations against them.
1406 1426           * Since our engine still creates relocations against a WEAK UNDEFINED
1407 1427           * symbol in a static executable, it's best to disable them here
1408 1428           * instead of through out the relocation code.
1409 1429           */
1410 1430          if (OFL_IS_STATIC_EXEC(ofl))
1411 1431                  return (1);
     1432 +
     1433 +        /*
     1434 +         * If the symbol will be reduced, we can't leave outstanding
     1435 +         * relocations against it, as nothing will ever be able to satisfy them
     1436 +         * (and the symbol won't be in .dynsym
     1437 +         */
     1438 +        if ((sdp != NULL) &&
     1439 +            (sdp->sd_sym->st_shndx == SHN_UNDEF) &&
     1440 +            (rsp->rel_rtype != M_R_NONE) &&
     1441 +            (rsp->rel_rtype != M_R_REGISTER) &&
     1442 +            (rsp->rel_rtype != M_R_RELATIVE)) {
     1443 +                if (ld_sym_reducable(ofl, sdp))
     1444 +                        return (1);
     1445 +        }
1412 1446  
1413 1447          /*
1414 1448           * Certain relocations do not make sense in a 64bit shared object,
1415 1449           * if building a shared object do a sanity check on the output
1416 1450           * relocations being created.
1417 1451           */
1418 1452          if (ofl->ofl_flags & FLG_OF_SHAROBJ) {
1419 1453                  Word    rtype = rsp->rel_rtype;
1420 1454                  /*
1421 1455                   * Because the R_SPARC_HIPLT22 & R_SPARC_LOPLT10 relocations
↓ open down ↓ 849 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX