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


 338                 ndx = sdp->sd_symndx;
 339 
 340         /*
 341          * If we have a replacement value for the relocation
 342          * target, put it in place now.
 343          */
 344         if (orsp->rel_flags & FLG_REL_NADDEND) {
 345                 Xword   addend = orsp->rel_raddend;
 346                 uchar_t *addr;
 347 
 348                 /*
 349                  * Get the address of the data item we need to modify.
 350                  */
 351                 addr = (uchar_t *)((uintptr_t)orsp->rel_roffset +
 352                     (uintptr_t)_elf_getxoff(orsp->rel_isdesc->is_indata));
 353                 addr += (uintptr_t)RELAUX_GET_OSDESC(orsp)->os_outdata->d_buf;
 354                 if (ld_reloc_targval_set(ofl, orsp, addr, addend) == 0)
 355                         return (S_ERROR);
 356         }
 357 
 358         relbits = (char *)relosp->os_outdata->d_buf;













 359 
 360         rea.r_info = ELF_R_INFO(ndx, orsp->rel_rtype);
 361         rea.r_offset = roffset;
 362         DBG_CALL(Dbg_reloc_out(ofl, ELF_DBG_LD, SHT_REL, &rea, relosp->os_name,
 363             ld_reloc_sym_name(orsp)));
 364 
 365         /*
 366          * Assert we haven't walked off the end of our relocation table.
 367          */
 368         assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size);
 369 


 370         (void) memcpy((relbits + relosp->os_szoutrels),
 371             (char *)&rea, sizeof (Rel));
 372         relosp->os_szoutrels += sizeof (Rel);
 373 
 374         /*
 375          * Determine if this relocation is against a non-writable, allocatable
 376          * section.  If so we may need to provide a text relocation diagnostic.
 377          * Note that relocations against the .plt (R_386_JMP_SLOT) actually
 378          * result in modifications to the .got.
 379          */
 380         if (orsp->rel_rtype == R_386_JMP_SLOT)
 381                 osp = ofl->ofl_osgot;
 382 
 383         ld_reloc_remain_entry(orsp, osp, ofl, remain_seen);
 384         return (1);
 385 }
 386 
 387 /*
 388  * i386 Instructions for TLS processing
 389  */


1117         return (return_code);
1118 }
1119 
1120 /*
1121  * Add an output relocation record.
1122  */
1123 static uintptr_t
1124 ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl)
1125 {
1126         Rel_desc        *orsp;
1127         Sym_desc        *sdp = rsp->rel_sym;
1128 
1129         /*
1130          * Static executables *do not* want any relocations against them.
1131          * Since our engine still creates relocations against a WEAK UNDEFINED
1132          * symbol in a static executable, it's best to disable them here
1133          * instead of through out the relocation code.
1134          */
1135         if (OFL_IS_STATIC_EXEC(ofl))
1136                 return (1);













1137 
1138         /*
1139          * If we are adding a output relocation against a section
1140          * symbol (non-RELATIVE) then mark that section.  These sections
1141          * will be added to the .dynsym symbol table.
1142          */
1143         if (sdp && (rsp->rel_rtype != M_R_RELATIVE) &&
1144             ((flags & FLG_REL_SCNNDX) ||
1145             (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION))) {
1146 
1147                 /*
1148                  * If this is a COMMON symbol - no output section
1149                  * exists yet - (it's created as part of sym_validate()).
1150                  * So - we mark here that when it's created it should
1151                  * be tagged with the FLG_OS_OUTREL flag.
1152                  */
1153                 if ((sdp->sd_flags & FLG_SY_SPECSEC) &&
1154                     (sdp->sd_sym->st_shndx == SHN_COMMON)) {
1155                         if (ELF_ST_TYPE(sdp->sd_sym->st_info) != STT_TLS)
1156                                 ofl->ofl_flags1 |= FLG_OF1_BSSOREL;




 338                 ndx = sdp->sd_symndx;
 339 
 340         /*
 341          * If we have a replacement value for the relocation
 342          * target, put it in place now.
 343          */
 344         if (orsp->rel_flags & FLG_REL_NADDEND) {
 345                 Xword   addend = orsp->rel_raddend;
 346                 uchar_t *addr;
 347 
 348                 /*
 349                  * Get the address of the data item we need to modify.
 350                  */
 351                 addr = (uchar_t *)((uintptr_t)orsp->rel_roffset +
 352                     (uintptr_t)_elf_getxoff(orsp->rel_isdesc->is_indata));
 353                 addr += (uintptr_t)RELAUX_GET_OSDESC(orsp)->os_outdata->d_buf;
 354                 if (ld_reloc_targval_set(ofl, orsp, addr, addend) == 0)
 355                         return (S_ERROR);
 356         }
 357 
 358         if ((orsp->rel_rtype != M_R_NONE) &&
 359             (orsp->rel_rtype != M_R_RELATIVE)) {
 360                 if (ndx == 0) {
 361                         Conv_inv_buf_t  inv_buf;
 362                         Is_desc *isp = orsp->rel_isdesc;
 363 
 364                         ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_NOSYMBOL),
 365                             conv_reloc_type(ofl->ofl_nehdr->e_machine,
 366                             orsp->rel_rtype, 0, &inv_buf),
 367                             isp->is_file->ifl_name, EC_WORD(isp->is_scnndx),
 368                             isp->is_name, EC_XWORD(roffset));
 369                         return (S_ERROR);
 370                 }
 371         }
 372 
 373         rea.r_info = ELF_R_INFO(ndx, orsp->rel_rtype);
 374         rea.r_offset = roffset;
 375         DBG_CALL(Dbg_reloc_out(ofl, ELF_DBG_LD, SHT_REL, &rea, relosp->os_name,
 376             ld_reloc_sym_name(orsp)));
 377 
 378         /*
 379          * Assert we haven't walked off the end of our relocation table.
 380          */
 381         assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size);
 382 
 383         relbits = (char *)relosp->os_outdata->d_buf;
 384 
 385         (void) memcpy((relbits + relosp->os_szoutrels),
 386             (char *)&rea, sizeof (Rel));
 387         relosp->os_szoutrels += sizeof (Rel);
 388 
 389         /*
 390          * Determine if this relocation is against a non-writable, allocatable
 391          * section.  If so we may need to provide a text relocation diagnostic.
 392          * Note that relocations against the .plt (R_386_JMP_SLOT) actually
 393          * result in modifications to the .got.
 394          */
 395         if (orsp->rel_rtype == R_386_JMP_SLOT)
 396                 osp = ofl->ofl_osgot;
 397 
 398         ld_reloc_remain_entry(orsp, osp, ofl, remain_seen);
 399         return (1);
 400 }
 401 
 402 /*
 403  * i386 Instructions for TLS processing
 404  */


1132         return (return_code);
1133 }
1134 
1135 /*
1136  * Add an output relocation record.
1137  */
1138 static uintptr_t
1139 ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl)
1140 {
1141         Rel_desc        *orsp;
1142         Sym_desc        *sdp = rsp->rel_sym;
1143 
1144         /*
1145          * Static executables *do not* want any relocations against them.
1146          * Since our engine still creates relocations against a WEAK UNDEFINED
1147          * symbol in a static executable, it's best to disable them here
1148          * instead of through out the relocation code.
1149          */
1150         if (OFL_IS_STATIC_EXEC(ofl))
1151                 return (1);
1152 
1153         /*
1154          * If the symbol will be reduced, we can't leave outstanding
1155          * relocations against it, as nothing will ever be able to satisfy them
1156          * (and the symbol won't be in .dynsym
1157          */
1158         if ((sdp != NULL) &&
1159             (sdp->sd_sym->st_shndx == SHN_UNDEF) &&
1160             (rsp->rel_rtype != M_R_NONE) &&
1161             (rsp->rel_rtype != M_R_RELATIVE)) {
1162                 if (ld_sym_reducable(ofl, sdp))
1163                         return (1);
1164         }
1165 
1166         /*
1167          * If we are adding a output relocation against a section
1168          * symbol (non-RELATIVE) then mark that section.  These sections
1169          * will be added to the .dynsym symbol table.
1170          */
1171         if (sdp && (rsp->rel_rtype != M_R_RELATIVE) &&
1172             ((flags & FLG_REL_SCNNDX) ||
1173             (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION))) {
1174 
1175                 /*
1176                  * If this is a COMMON symbol - no output section
1177                  * exists yet - (it's created as part of sym_validate()).
1178                  * So - we mark here that when it's created it should
1179                  * be tagged with the FLG_OS_OUTREL flag.
1180                  */
1181                 if ((sdp->sd_flags & FLG_SY_SPECSEC) &&
1182                     (sdp->sd_sym->st_shndx == SHN_COMMON)) {
1183                         if (ELF_ST_TYPE(sdp->sd_sym->st_info) != STT_TLS)
1184                                 ofl->ofl_flags1 |= FLG_OF1_BSSOREL;