diff options
| author | Richard Lowe <richlowe@richlowe.net> | 2019-05-13 20:41:26 +0000 |
|---|---|---|
| committer | Richard Lowe <richlowe@richlowe.net> | 2019-05-29 22:22:04 +0000 |
| commit | 0bc0887e1cf0f912077b83256f295ad0ed1c715c (patch) | |
| tree | 239001490647b3089935ad0b27724c0cee3ab0e8 /usr/src/cmd/sgs/libld | |
| parent | b3b3563308068a7fafd98cf3021c73aedc1caa6c (diff) | |
| download | illumos-joyent-0bc0887e1cf0f912077b83256f295ad0ed1c715c.tar.gz | |
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>
Diffstat (limited to 'usr/src/cmd/sgs/libld')
| -rw-r--r-- | usr/src/cmd/sgs/libld/common/entry.c | 2 | ||||
| -rw-r--r-- | usr/src/cmd/sgs/libld/common/machrel.amd.c | 30 | ||||
| -rw-r--r-- | usr/src/cmd/sgs/libld/common/machrel.intel.c | 30 | ||||
| -rw-r--r-- | usr/src/cmd/sgs/libld/common/machrel.sparc.c | 42 |
4 files changed, 97 insertions, 7 deletions
diff --git a/usr/src/cmd/sgs/libld/common/entry.c b/usr/src/cmd/sgs/libld/common/entry.c index 396075d09f..f55e2cf723 100644 --- a/usr/src/cmd/sgs/libld/common/entry.c +++ b/usr/src/cmd/sgs/libld/common/entry.c @@ -472,7 +472,7 @@ ld_ent_setup(Ofl_desc *ofl, Xword segalign) 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 diff --git a/usr/src/cmd/sgs/libld/common/machrel.amd.c b/usr/src/cmd/sgs/libld/common/machrel.amd.c index ebf7cc5a8f..dbdae79bd1 100644 --- a/usr/src/cmd/sgs/libld/common/machrel.amd.c +++ b/usr/src/cmd/sgs/libld/common/machrel.amd.c @@ -435,7 +435,20 @@ ld_perform_outreloc(Rel_desc * orsp, Ofl_desc * ofl, Boolean *remain_seen) 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 @@ ld_perform_outreloc(Rel_desc * orsp, Ofl_desc * ofl, Boolean *remain_seen) */ 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 @@ ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl) 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. diff --git a/usr/src/cmd/sgs/libld/common/machrel.intel.c b/usr/src/cmd/sgs/libld/common/machrel.intel.c index 28999e7d89..d2b72c78a6 100644 --- a/usr/src/cmd/sgs/libld/common/machrel.intel.c +++ b/usr/src/cmd/sgs/libld/common/machrel.intel.c @@ -355,7 +355,20 @@ ld_perform_outreloc(Rel_desc * orsp, Ofl_desc * ofl, Boolean *remain_seen) 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 @@ ld_perform_outreloc(Rel_desc * orsp, Ofl_desc * ofl, Boolean *remain_seen) */ 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 @@ ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl) 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. diff --git a/usr/src/cmd/sgs/libld/common/machrel.sparc.c b/usr/src/cmd/sgs/libld/common/machrel.sparc.c index 6b56e9c444..02d180b1c2 100644 --- a/usr/src/cmd/sgs/libld/common/machrel.sparc.c +++ b/usr/src/cmd/sgs/libld/common/machrel.sparc.c @@ -145,7 +145,7 @@ ld_mach_eflags(Ehdr *ehdr, Ofl_desc *ofl) * 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 @@ ld_perform_outreloc(Rel_desc *orsp, Ofl_desc *ofl, Boolean *remain_seen) 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 @@ ld_perform_outreloc(Rel_desc *orsp, Ofl_desc *ofl, Boolean *remain_seen) */ 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 @@ tls_fixups(Ofl_desc *ofl, Rel_desc *arsp) 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 @@ gotop_fixups(Ofl_desc *ofl, Rel_desc *arsp) 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 @@ ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl) 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. |
