Print this page
3436 relocatable objects also need sloppy relocation
3439 discarded sections shouldn't end up on output lists

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/sgs/libld/common/place.c
          +++ new/usr/src/cmd/sgs/libld/common/place.c
↓ open down ↓ 843 lines elided ↑ open up ↑
 844  844  
 845  845                          if ((oname = libld_malloc(size + 1)) == NULL)
 846  846                                  return ((Os_desc *)S_ERROR);
 847  847                          (void) strncpy(oname, isp->is_name, size);
 848  848                          oname[size] = '\0';
 849  849                          DBG_CALL(Dbg_sec_redirected(ofl->ofl_lml, isp, oname));
 850  850                  }
 851  851          }
 852  852  
 853  853          /*
      854 +         * When building relocatable objects, we must not redirect COMDAT
      855 +         * section names into their outputs, such that our output object may
      856 +         * be successfully used as an input object also requiring COMDAT
      857 +         * processing
      858 +         */
      859 +
      860 +        /*
 854  861           * GNU section names may follow the convention:
 855  862           *
 856  863           *      .gnu.linkonce.*
 857  864           *
 858  865           * The .gnu.linkonce is a section naming convention that indicates a
 859  866           * COMDAT requirement.  Determine whether this section follows the GNU
 860  867           * pattern, and if so, determine whether this section should be
 861  868           * discarded or retained.  The comparison of is_name[1] with 'g'
 862  869           * is an optimization to skip using strncmp() too much. This is safe,
 863  870           * because we know the name is not NULL, and therefore must have
 864  871           * at least one character plus a NULL termination.
 865  872           */
 866      -        if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) &&
 867      -            (isp->is_name == oname) && (isp->is_name[1] == 'g') &&
      873 +        if ((isp->is_name == oname) && (isp->is_name[1] == 'g') &&
 868  874              (strncmp(MSG_ORIG(MSG_SCN_GNU_LINKONCE), isp->is_name,
 869  875              MSG_SCN_GNU_LINKONCE_SIZE) == 0)) {
 870      -                if ((oname =
 871      -                    (char *)gnu_linkonce_sec(isp->is_name)) != isp->is_name) {
 872      -                        DBG_CALL(Dbg_sec_redirected(ofl->ofl_lml, isp, oname));
      876 +                if ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) {
      877 +                        if ((oname = (char *)gnu_linkonce_sec(isp->is_name)) !=
      878 +                            isp->is_name) {
      879 +                                DBG_CALL(Dbg_sec_redirected(ofl->ofl_lml, isp,
      880 +                                    oname));
      881 +                        }
 873  882                  }
 874  883  
 875  884                  /*
 876  885                   * Explicitly identify this section type as COMDAT.  Also,
 877  886                   * enable relaxed relocation processing, as this is typically
 878  887                   * a requirement with .gnu.linkonce sections.
 879  888                   */
 880  889                  isp->is_flags |= FLG_IS_COMDAT;
 881  890                  if ((ofl->ofl_flags1 & FLG_OF1_NRLXREL) == 0)
 882  891                          ofl->ofl_flags1 |= FLG_OF1_RLXREL;
↓ open down ↓ 4 lines elided ↑ open up ↑
 887  896          /*
 888  897           * GNU section names may also follow the convention:
 889  898           *
 890  899           *      section-name.symbol-name
 891  900           *
 892  901           * This convention is used when defining SHT_GROUP sections of type
 893  902           * COMDAT.  Thus, any group processing will have discovered any group
 894  903           * sections, and this identification can be triggered by a pattern
 895  904           * match section names.
 896  905           */
 897      -        if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) &&
 898      -            (isp->is_name == oname) && (isp->is_flags & FLG_IS_COMDAT) &&
      906 +        if ((isp->is_name == oname) && (isp->is_flags & FLG_IS_COMDAT) &&
 899  907              ((sname = gnu_comdat_sym(ifl, isp)) != NULL)) {
 900  908                  size_t  size = sname - isp->is_name;
 901  909  
 902      -                if ((oname = libld_malloc(size + 1)) == NULL)
 903      -                        return ((Os_desc *)S_ERROR);
 904      -                (void) strncpy(oname, isp->is_name, size);
 905      -                oname[size] = '\0';
 906      -                DBG_CALL(Dbg_sec_redirected(ofl->ofl_lml, isp, oname));
      910 +                if ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) {
      911 +                        if ((oname = libld_malloc(size + 1)) == NULL)
      912 +                                return ((Os_desc *)S_ERROR);
      913 +                        (void) strncpy(oname, isp->is_name, size);
      914 +                        oname[size] = '\0';
      915 +                        DBG_CALL(Dbg_sec_redirected(ofl->ofl_lml, isp, oname));
      916 +                }
 907  917  
 908  918                  /*
 909  919                   * Enable relaxed relocation processing, as this is
 910  920                   * typically a requirement with GNU COMDAT sections.
 911  921                   */
 912  922                  if ((ofl->ofl_flags1 & FLG_OF1_NRLXREL) == 0) {
 913  923                          ofl->ofl_flags1 |= FLG_OF1_RLXREL;
 914  924                          DBG_CALL(Dbg_sec_gnu_comdat(ofl->ofl_lml, isp,
 915  925                              FALSE, TRUE));
 916  926                  }
↓ open down ↓ 275 lines elided ↑ open up ↑
1192 1202                                  break;
1193 1203                          }
1194 1204                  }
1195 1205          }
1196 1206  
1197 1207          /*
1198 1208           * Sections of type SHT_GROUP are added to the ofl->ofl_osgroups list,
1199 1209           * so that they can be updated as a group later.
1200 1210           */
1201 1211          if ((shdr->sh_type == SHT_GROUP) &&
     1212 +            ((isp->is_flags & FLG_IS_DISCARD) == 0) &&
1202 1213              (aplist_append(&ofl->ofl_osgroups, osp,
1203 1214              AL_CNT_OFL_OSGROUPS) == NULL))
1204 1215                  return ((Os_desc *)S_ERROR);
1205 1216  
1206 1217          /*
1207 1218           * If this section is a non-empty TLS section indicate that a PT_TLS
1208 1219           * program header is required.
1209 1220           */
1210 1221          if ((shflags & SHF_TLS) && shdr->sh_size &&
1211 1222              ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0))
↓ open down ↓ 44 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX