Print this page
3616 SHF_GROUP sections should not be discarded via other COMDAT mechanisms
3709 need sloppy relocation for GNU .debug_macro
Reviewed by: Joshua M. Clulow <josh@sysmgr.org>
Reviewed by: Robert Mustacchi <rm@joyent.com>


 101                 Word    *data;
 102 
 103                 if (isp->is_shdr->sh_type == SHT_GROUP) {
 104                         if (isp->is_scnndx == gdp->gd_isc->is_scnndx)
 105                                 return (gdp);
 106                         continue;
 107                 }
 108 
 109                 data = gdp->gd_data;
 110                 for (ndx = 1; ndx < gdp->gd_cnt; ndx++) {
 111                         if (data[ndx] == scnndx)
 112                                 return (gdp);
 113                 }
 114         }
 115 
 116         ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ELF_NOGROUPSECT),
 117             ifl->ifl_name, EC_WORD(isp->is_scnndx), isp->is_name);
 118         return (NULL);
 119 }
 120 








































 121 uintptr_t
 122 ld_group_process(Is_desc *gisc, Ofl_desc *ofl)
 123 {
 124         Ifl_desc        *gifl = gisc->is_file;
 125         Shdr            *sshdr, *gshdr = gisc->is_shdr;
 126         Is_desc         *isc;
 127         Sym             *sym;
 128         const char      *str;
 129         Group_desc      gd;
 130         size_t          ndx;
 131         int             gnu_stt_section;
 132 
 133         /*
 134          * Confirm that the sh_link points to a valid section.
 135          */
 136         if ((gshdr->sh_link == SHN_UNDEF) ||
 137             (gshdr->sh_link >= gifl->ifl_shnum) ||
 138             ((isc = gifl->ifl_isdesc[gshdr->sh_link]) == NULL)) {
 139                 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHLINK),
 140                     gifl->ifl_name, EC_WORD(gisc->is_scnndx),


 204          */
 205         if ((gd.gd_data[0] & GRP_COMDAT) && !gnu_stt_section &&
 206             ((ELF_ST_BIND(sym->st_info) == STB_LOCAL) ||
 207             (sym->st_shndx == SHN_UNDEF))) {
 208                 /* If section symbol, construct a printable name for it */
 209                 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) {
 210                         if (gisc->is_sym_name == NULL)
 211                                 (void) ld_stt_section_sym_name(gisc);
 212 
 213                         if (gisc->is_sym_name != NULL)
 214                                 str = gisc->is_sym_name;
 215                 }
 216 
 217                 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_GRP_INVALSYM),
 218                     gifl->ifl_name, EC_WORD(gisc->is_scnndx),
 219                     gisc->is_name, str);
 220                 return (0);
 221         }
 222 
 223         /*











 224          * Validate the section indices within the group.  If this is a COMDAT
 225          * group, mark each section as COMDAT.
 226          */
 227         for (ndx = 1; ndx < gd.gd_cnt; ndx++) {
 228                 Word    gndx;
 229 
 230                 if ((gndx = gd.gd_data[ndx]) >= gifl->ifl_shnum) {
 231                         ld_eprintf(ofl, ERR_FATAL,
 232                             MSG_INTL(MSG_GRP_INVALNDX), gifl->ifl_name,
 233                             EC_WORD(gisc->is_scnndx), gisc->is_name, ndx, gndx);
 234                         return (0);
 235                 }
 236 
 237                 if (gd.gd_data[0] & GRP_COMDAT)
 238                         gifl->ifl_isdesc[gndx]->is_flags |= FLG_IS_COMDAT;
 239         }
 240 
 241         /*
 242          * If this is a COMDAT group, determine whether this group has already
 243          * been encountered, or whether this is the first instance of the group.


 101                 Word    *data;
 102 
 103                 if (isp->is_shdr->sh_type == SHT_GROUP) {
 104                         if (isp->is_scnndx == gdp->gd_isc->is_scnndx)
 105                                 return (gdp);
 106                         continue;
 107                 }
 108 
 109                 data = gdp->gd_data;
 110                 for (ndx = 1; ndx < gdp->gd_cnt; ndx++) {
 111                         if (data[ndx] == scnndx)
 112                                 return (gdp);
 113                 }
 114         }
 115 
 116         ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ELF_NOGROUPSECT),
 117             ifl->ifl_name, EC_WORD(isp->is_scnndx), isp->is_name);
 118         return (NULL);
 119 }
 120 
 121 /*
 122  * When creating a .debug_macro section, in an attempt to make certain DWARF
 123  * macro information shareable, the GNU compiler must construct group sections
 124  * with a repeatable signature symbol while nevertheless having no actual
 125  * symbol to refer to (because it relates to macros).
 126  *
 127  * We use this as yet another way to clue ourselves in that sloppy relocation
 128  * will likely be required.
 129  *
 130  * The format of these gensym'd names is:
 131  *    wm<offset size>.<encoded path name>.<lineno>.<32byte hash>
 132  * Where the encoded file name may be absent.
 133  */
 134 static boolean_t
 135 is_header_gensym(const char *name)
 136 {
 137         const char *c = NULL;
 138 
 139         /* No room for leader, hash, and periods */
 140         if (strlen(name) < 37)
 141                 return (B_FALSE);
 142 
 143         if ((strncmp(name, "wm4.", 4) != 0) &&
 144           strncmp(name, "wm8.", 4) != 0)
 145                 return (B_FALSE);
 146 
 147         c = &name[strlen(name) - 33];
 148         if (*c++ != '.')
 149                 return (B_FALSE);
 150 
 151         for (; *c != '\0'; c++) {
 152                 if (!(((*c >= 'a') && (*c <= 'f')) ||
 153                     ((*c >= '0') && (*c <= '9')))) {
 154                         return (B_FALSE);
 155                 }
 156         }
 157 
 158         return (B_TRUE);
 159 }
 160 
 161 uintptr_t
 162 ld_group_process(Is_desc *gisc, Ofl_desc *ofl)
 163 {
 164         Ifl_desc        *gifl = gisc->is_file;
 165         Shdr            *sshdr, *gshdr = gisc->is_shdr;
 166         Is_desc         *isc;
 167         Sym             *sym;
 168         const char      *str;
 169         Group_desc      gd;
 170         size_t          ndx;
 171         int             gnu_stt_section;
 172 
 173         /*
 174          * Confirm that the sh_link points to a valid section.
 175          */
 176         if ((gshdr->sh_link == SHN_UNDEF) ||
 177             (gshdr->sh_link >= gifl->ifl_shnum) ||
 178             ((isc = gifl->ifl_isdesc[gshdr->sh_link]) == NULL)) {
 179                 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHLINK),
 180                     gifl->ifl_name, EC_WORD(gisc->is_scnndx),


 244          */
 245         if ((gd.gd_data[0] & GRP_COMDAT) && !gnu_stt_section &&
 246             ((ELF_ST_BIND(sym->st_info) == STB_LOCAL) ||
 247             (sym->st_shndx == SHN_UNDEF))) {
 248                 /* If section symbol, construct a printable name for it */
 249                 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) {
 250                         if (gisc->is_sym_name == NULL)
 251                                 (void) ld_stt_section_sym_name(gisc);
 252 
 253                         if (gisc->is_sym_name != NULL)
 254                                 str = gisc->is_sym_name;
 255                 }
 256 
 257                 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_GRP_INVALSYM),
 258                     gifl->ifl_name, EC_WORD(gisc->is_scnndx),
 259                     gisc->is_name, str);
 260                 return (0);
 261         }
 262 
 263         /*
 264          * If the signature symbol is a name generated by the GNU compiler to
 265          * refer to a header, we need sloppy relocation.
 266          */
 267         if (is_header_gensym(str)) {
 268             if ((ofl->ofl_flags1 & FLG_OF1_NRLXREL) == 0)
 269                 ofl->ofl_flags1 |= FLG_OF1_RLXREL;
 270             DBG_CALL(Dbg_sec_gnu_comdat(ofl->ofl_lml, gisc, TRUE,
 271               (ofl->ofl_flags1 & FLG_OF1_RLXREL) != 0));
 272         }
 273 
 274         /*
 275          * Validate the section indices within the group.  If this is a COMDAT
 276          * group, mark each section as COMDAT.
 277          */
 278         for (ndx = 1; ndx < gd.gd_cnt; ndx++) {
 279                 Word    gndx;
 280 
 281                 if ((gndx = gd.gd_data[ndx]) >= gifl->ifl_shnum) {
 282                         ld_eprintf(ofl, ERR_FATAL,
 283                             MSG_INTL(MSG_GRP_INVALNDX), gifl->ifl_name,
 284                             EC_WORD(gisc->is_scnndx), gisc->is_name, ndx, gndx);
 285                         return (0);
 286                 }
 287 
 288                 if (gd.gd_data[0] & GRP_COMDAT)
 289                         gifl->ifl_isdesc[gndx]->is_flags |= FLG_IS_COMDAT;
 290         }
 291 
 292         /*
 293          * If this is a COMDAT group, determine whether this group has already
 294          * been encountered, or whether this is the first instance of the group.