Mercurial > illumos > git > illumos-omnios
changeset 21394:82bd57df837e
11057 hidden undefined weak symbols should not leave relocations
11058 libld entrance descriptor assertions get NDEBUG check backwards
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Gordon Ross <gwr@nexenta.com>
author | Richard Lowe <richlowe@richlowe.net> |
---|---|
date | Mon, 13 May 2019 20:41:26 +0000 |
parents | b2ac1bdfc9d1 |
children | b2bf0d068923 |
files | usr/src/cmd/sgs/libld/common/entry.c usr/src/cmd/sgs/libld/common/machrel.amd.c usr/src/cmd/sgs/libld/common/machrel.intel.c usr/src/cmd/sgs/libld/common/machrel.sparc.c usr/src/cmd/sgs/packages/common/SUNWonld-README |
diffstat | 5 files changed, 98 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/sgs/libld/common/entry.c Wed May 22 18:11:33 2019 -0400 +++ b/usr/src/cmd/sgs/libld/common/entry.c Mon May 13 20:41:26 2019 +0000 @@ -472,7 +472,7 @@ AL_CNT_SEGMENTS)) == NULL) return (S_ERROR); -#ifdef NDEBUG /* assert() is enabled */ +#ifndef NDEBUG /* assert() is enabled */ /* * Enforce the segment name rule: Any segment that can * be referenced by an entrance descriptor must have
--- a/usr/src/cmd/sgs/libld/common/machrel.amd.c Wed May 22 18:11:33 2019 -0400 +++ b/usr/src/cmd/sgs/libld/common/machrel.amd.c Mon May 13 20:41:26 2019 +0000 @@ -435,7 +435,20 @@ if (orsp->rel_rtype == R_AMD64_DTPMOD64) raddend = 0; - relbits = (char *)relosp->os_outdata->d_buf; + if ((orsp->rel_rtype != M_R_NONE) && + (orsp->rel_rtype != M_R_RELATIVE)) { + if (ndx == 0) { + Conv_inv_buf_t inv_buf; + Is_desc *isp = orsp->rel_isdesc; + + ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_NOSYMBOL), + conv_reloc_type(ofl->ofl_nehdr->e_machine, + orsp->rel_rtype, 0, &inv_buf), + isp->is_file->ifl_name, EC_WORD(isp->is_scnndx), + isp->is_name, EC_XWORD(roffset)); + return (S_ERROR); + } + } rea.r_info = ELF_R_INFO(ndx, orsp->rel_rtype); rea.r_offset = roffset; @@ -448,6 +461,8 @@ */ assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size); + relbits = (char *)relosp->os_outdata->d_buf; + (void) memcpy((relbits + relosp->os_szoutrels), (char *)&rea, sizeof (Rela)); relosp->os_szoutrels += (Xword)sizeof (Rela); @@ -1135,6 +1150,19 @@ return (1); /* + * If the symbol will be reduced, we can't leave outstanding + * relocations against it, as nothing will ever be able to satisfy them + * (and the symbol won't be in .dynsym + */ + if ((sdp != NULL) && + (sdp->sd_sym->st_shndx == SHN_UNDEF) && + (rsp->rel_rtype != M_R_NONE) && + (rsp->rel_rtype != M_R_RELATIVE)) { + if (ld_sym_reducable(ofl, sdp)) + return (1); + } + + /* * If we are adding a output relocation against a section * symbol (non-RELATIVE) then mark that section. These sections * will be added to the .dynsym symbol table.
--- a/usr/src/cmd/sgs/libld/common/machrel.intel.c Wed May 22 18:11:33 2019 -0400 +++ b/usr/src/cmd/sgs/libld/common/machrel.intel.c Mon May 13 20:41:26 2019 +0000 @@ -355,7 +355,20 @@ return (S_ERROR); } - relbits = (char *)relosp->os_outdata->d_buf; + if ((orsp->rel_rtype != M_R_NONE) && + (orsp->rel_rtype != M_R_RELATIVE)) { + if (ndx == 0) { + Conv_inv_buf_t inv_buf; + Is_desc *isp = orsp->rel_isdesc; + + ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_NOSYMBOL), + conv_reloc_type(ofl->ofl_nehdr->e_machine, + orsp->rel_rtype, 0, &inv_buf), + isp->is_file->ifl_name, EC_WORD(isp->is_scnndx), + isp->is_name, EC_XWORD(roffset)); + return (S_ERROR); + } + } rea.r_info = ELF_R_INFO(ndx, orsp->rel_rtype); rea.r_offset = roffset; @@ -367,6 +380,8 @@ */ assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size); + relbits = (char *)relosp->os_outdata->d_buf; + (void) memcpy((relbits + relosp->os_szoutrels), (char *)&rea, sizeof (Rel)); relosp->os_szoutrels += sizeof (Rel); @@ -1136,6 +1151,19 @@ return (1); /* + * If the symbol will be reduced, we can't leave outstanding + * relocations against it, as nothing will ever be able to satisfy them + * (and the symbol won't be in .dynsym + */ + if ((sdp != NULL) && + (sdp->sd_sym->st_shndx == SHN_UNDEF) && + (rsp->rel_rtype != M_R_NONE) && + (rsp->rel_rtype != M_R_RELATIVE)) { + if (ld_sym_reducable(ofl, sdp)) + return (1); + } + + /* * If we are adding a output relocation against a section * symbol (non-RELATIVE) then mark that section. These sections * will be added to the .dynsym symbol table.
--- a/usr/src/cmd/sgs/libld/common/machrel.sparc.c Wed May 22 18:11:33 2019 -0400 +++ b/usr/src/cmd/sgs/libld/common/machrel.sparc.c Mon May 13 20:41:26 2019 +0000 @@ -145,7 +145,7 @@ * Determine which memory model to mark the binary with. The options * are (most restrictive to least): * - * EF_SPARCV9_TSO 0x0 Total Store Order + * EF_SPARCV9_TSO 0x0 Total Store Order * EF_SPARCV9_PSO 0x1 Partial Store Order * EF_SPARCV9_RMO 0x2 Relaxed Memory Order * @@ -779,7 +779,25 @@ if (orsp->rel_rtype == M_R_DTPMOD) raddend = 0; - relbits = (char *)relosp->os_outdata->d_buf; + /* + * Note that the other case which writes out the relocation, above, is + * M_R_REGISTER specific and so does not need this check. + */ + if ((orsp->rel_rtype != M_R_NONE) && + (orsp->rel_rtype != M_R_REGISTER) && + (orsp->rel_rtype != M_R_RELATIVE)) { + if (ndx == 0) { + Conv_inv_buf_t inv_buf; + Is_desc *isp = orsp->rel_isdesc; + + ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_NOSYMBOL), + conv_reloc_type(ofl->ofl_nehdr->e_machine, + orsp->rel_rtype, 0, &inv_buf), + isp->is_file->ifl_name, EC_WORD(isp->is_scnndx), + isp->is_name, EC_XWORD(roffset)); + return (S_ERROR); + } + } rea.r_info = ELF_R_INFO(ndx, ELF_R_TYPE_INFO(RELAUX_GET_TYPEDATA(orsp), orsp->rel_rtype)); @@ -793,6 +811,8 @@ */ assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size); + relbits = (char *)relosp->os_outdata->d_buf; + (void) memcpy((relbits + relosp->os_szoutrels), (char *)&rea, sizeof (Rela)); relosp->os_szoutrels += (Xword)sizeof (Rela); @@ -927,7 +947,7 @@ case R_SPARC_TLS_IE_LDX: /* * Current instruction: - * ld{x} [r1 + r2], r3 + * ld{x} [r1 + r2], r3 * * Need to update this to: * @@ -1009,7 +1029,7 @@ case R_SPARC_GOTDATA_OP: /* * Current instruction: - * ld{x} [r1 + r2], r3 + * ld{x} [r1 + r2], r3 * * Need to update this to: * @@ -1411,6 +1431,20 @@ return (1); /* + * If the symbol will be reduced, we can't leave outstanding + * relocations against it, as nothing will ever be able to satisfy them + * (and the symbol won't be in .dynsym + */ + if ((sdp != NULL) && + (sdp->sd_sym->st_shndx == SHN_UNDEF) && + (rsp->rel_rtype != M_R_NONE) && + (rsp->rel_rtype != M_R_REGISTER) && + (rsp->rel_rtype != M_R_RELATIVE)) { + if (ld_sym_reducable(ofl, sdp)) + return (1); + } + + /* * Certain relocations do not make sense in a 64bit shared object, * if building a shared object do a sanity check on the output * relocations being created.
--- a/usr/src/cmd/sgs/packages/common/SUNWonld-README Wed May 22 18:11:33 2019 -0400 +++ b/usr/src/cmd/sgs/packages/common/SUNWonld-README Mon May 13 20:41:26 2019 +0000 @@ -1667,3 +1667,4 @@ producing relocatable objects 10366 ld(1) should support GNU-style linker sets 10581 ld(1) should know kernel modules are a thing +11057 hidden undefined weak symbols should not leave relocations