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


 834          *
 835          * Strip out the % from the section name for:
 836          *      - Non-relocatable objects
 837          *      - Relocatable objects if input section sorting is
 838          *        in force for the segment in question.
 839          */
 840         if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) ||
 841             (sgp->sg_flags & FLG_SG_IS_ORDER)) {
 842                 if ((sname = strchr(isp->is_name, '%')) != NULL) {
 843                         size_t  size = sname - isp->is_name;
 844 
 845                         if ((oname = libld_malloc(size + 1)) == NULL)
 846                                 return ((Os_desc *)S_ERROR);
 847                         (void) strncpy(oname, isp->is_name, size);
 848                         oname[size] = '\0';
 849                         DBG_CALL(Dbg_sec_redirected(ofl->ofl_lml, isp, oname));
 850                 }
 851         }
 852 
 853         /*







 854          * GNU section names may follow the convention:
 855          *
 856          *      .gnu.linkonce.*
 857          *
 858          * The .gnu.linkonce is a section naming convention that indicates a
 859          * COMDAT requirement.  Determine whether this section follows the GNU
 860          * pattern, and if so, determine whether this section should be
 861          * discarded or retained.  The comparison of is_name[1] with 'g'
 862          * is an optimization to skip using strncmp() too much. This is safe,
 863          * because we know the name is not NULL, and therefore must have
 864          * at least one character plus a NULL termination.
 865          */
 866         if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) &&
 867             (isp->is_name == oname) && (isp->is_name[1] == 'g') &&
 868             (strncmp(MSG_ORIG(MSG_SCN_GNU_LINKONCE), isp->is_name,
 869             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));



 873                 }
 874 
 875                 /*
 876                  * Explicitly identify this section type as COMDAT.  Also,
 877                  * enable relaxed relocation processing, as this is typically
 878                  * a requirement with .gnu.linkonce sections.
 879                  */
 880                 isp->is_flags |= FLG_IS_COMDAT;
 881                 if ((ofl->ofl_flags1 & FLG_OF1_NRLXREL) == 0)
 882                         ofl->ofl_flags1 |= FLG_OF1_RLXREL;
 883                 DBG_CALL(Dbg_sec_gnu_comdat(ofl->ofl_lml, isp, TRUE,
 884                     (ofl->ofl_flags1 & FLG_OF1_RLXREL) != 0));
 885         }
 886 
 887         /*
 888          * GNU section names may also follow the convention:
 889          *
 890          *      section-name.symbol-name
 891          *
 892          * This convention is used when defining SHT_GROUP sections of type
 893          * COMDAT.  Thus, any group processing will have discovered any group
 894          * sections, and this identification can be triggered by a pattern
 895          * match section names.
 896          */
 897         if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) &&
 898             (isp->is_name == oname) && (isp->is_flags & FLG_IS_COMDAT) &&
 899             ((sname = gnu_comdat_sym(ifl, isp)) != NULL)) {
 900                 size_t  size = sname - isp->is_name;
 901 

 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));

 907 
 908                 /*
 909                  * Enable relaxed relocation processing, as this is
 910                  * typically a requirement with GNU COMDAT sections.
 911                  */
 912                 if ((ofl->ofl_flags1 & FLG_OF1_NRLXREL) == 0) {
 913                         ofl->ofl_flags1 |= FLG_OF1_RLXREL;
 914                         DBG_CALL(Dbg_sec_gnu_comdat(ofl->ofl_lml, isp,
 915                             FALSE, TRUE));
 916                 }
 917         }
 918 
 919         /*
 920          * Assign a hash value now that the output section name has been
 921          * finalized.
 922          */
 923         onamehash = sgs_str_hash(oname);
 924 
 925         /*
 926          * Determine if output section ordering is turned on. If so, return


1182 
1183                 for (refsec = RefSecs; *refsec; refsec++) {
1184                         if (strcmp(osp->os_name, MSG_ORIG(*refsec)) == 0) {
1185                                 osp->os_flags |= FLG_OS_SECTREF;
1186 
1187                                 if ((ifl->ifl_flags & FLG_IF_IGNORE) ||
1188                                     DBG_ENABLED) {
1189                                         isp->is_flags |= FLG_IS_SECTREF;
1190                                         ifl->ifl_flags |= FLG_IF_FILEREF;
1191                                 }
1192                                 break;
1193                         }
1194                 }
1195         }
1196 
1197         /*
1198          * Sections of type SHT_GROUP are added to the ofl->ofl_osgroups list,
1199          * so that they can be updated as a group later.
1200          */
1201         if ((shdr->sh_type == SHT_GROUP) &&

1202             (aplist_append(&ofl->ofl_osgroups, osp,
1203             AL_CNT_OFL_OSGROUPS) == NULL))
1204                 return ((Os_desc *)S_ERROR);
1205 
1206         /*
1207          * If this section is a non-empty TLS section indicate that a PT_TLS
1208          * program header is required.
1209          */
1210         if ((shflags & SHF_TLS) && shdr->sh_size &&
1211             ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0))
1212                 ofl->ofl_flags |= FLG_OF_TLSPHDR;
1213 
1214         /*
1215          * If a non-allocatable section is going to be put into a loadable
1216          * segment then turn on the allocate bit for this section and warn the
1217          * user that we have done so.  This could only happen through the use
1218          * of a mapfile.
1219          */
1220         if ((sgp->sg_phdr.p_type == PT_LOAD) &&
1221             ((osp->os_shdr->sh_flags & SHF_ALLOC) == 0)) {




 834          *
 835          * Strip out the % from the section name for:
 836          *      - Non-relocatable objects
 837          *      - Relocatable objects if input section sorting is
 838          *        in force for the segment in question.
 839          */
 840         if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) ||
 841             (sgp->sg_flags & FLG_SG_IS_ORDER)) {
 842                 if ((sname = strchr(isp->is_name, '%')) != NULL) {
 843                         size_t  size = sname - isp->is_name;
 844 
 845                         if ((oname = libld_malloc(size + 1)) == NULL)
 846                                 return ((Os_desc *)S_ERROR);
 847                         (void) strncpy(oname, isp->is_name, size);
 848                         oname[size] = '\0';
 849                         DBG_CALL(Dbg_sec_redirected(ofl->ofl_lml, isp, oname));
 850                 }
 851         }
 852 
 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         /*
 861          * GNU section names may follow the convention:
 862          *
 863          *      .gnu.linkonce.*
 864          *
 865          * The .gnu.linkonce is a section naming convention that indicates a
 866          * COMDAT requirement.  Determine whether this section follows the GNU
 867          * pattern, and if so, determine whether this section should be
 868          * discarded or retained.  The comparison of is_name[1] with 'g'
 869          * is an optimization to skip using strncmp() too much. This is safe,
 870          * because we know the name is not NULL, and therefore must have
 871          * at least one character plus a NULL termination.
 872          */
 873         if ((isp->is_name == oname) && (isp->is_name[1] == 'g') &&

 874             (strncmp(MSG_ORIG(MSG_SCN_GNU_LINKONCE), isp->is_name,
 875             MSG_SCN_GNU_LINKONCE_SIZE) == 0)) {
 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                         }
 882                 }
 883 
 884                 /*
 885                  * Explicitly identify this section type as COMDAT.  Also,
 886                  * enable relaxed relocation processing, as this is typically
 887                  * a requirement with .gnu.linkonce sections.
 888                  */
 889                 isp->is_flags |= FLG_IS_COMDAT;
 890                 if ((ofl->ofl_flags1 & FLG_OF1_NRLXREL) == 0)
 891                         ofl->ofl_flags1 |= FLG_OF1_RLXREL;
 892                 DBG_CALL(Dbg_sec_gnu_comdat(ofl->ofl_lml, isp, TRUE,
 893                     (ofl->ofl_flags1 & FLG_OF1_RLXREL) != 0));
 894         }
 895 
 896         /*
 897          * GNU section names may also follow the convention:
 898          *
 899          *      section-name.symbol-name
 900          *
 901          * This convention is used when defining SHT_GROUP sections of type
 902          * COMDAT.  Thus, any group processing will have discovered any group
 903          * sections, and this identification can be triggered by a pattern
 904          * match section names.
 905          */
 906         if ((isp->is_name == oname) && (isp->is_flags & FLG_IS_COMDAT) &&

 907             ((sname = gnu_comdat_sym(ifl, isp)) != NULL)) {
 908                 size_t  size = sname - isp->is_name;
 909 
 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                 }
 917 
 918                 /*
 919                  * Enable relaxed relocation processing, as this is
 920                  * typically a requirement with GNU COMDAT sections.
 921                  */
 922                 if ((ofl->ofl_flags1 & FLG_OF1_NRLXREL) == 0) {
 923                         ofl->ofl_flags1 |= FLG_OF1_RLXREL;
 924                         DBG_CALL(Dbg_sec_gnu_comdat(ofl->ofl_lml, isp,
 925                             FALSE, TRUE));
 926                 }
 927         }
 928 
 929         /*
 930          * Assign a hash value now that the output section name has been
 931          * finalized.
 932          */
 933         onamehash = sgs_str_hash(oname);
 934 
 935         /*
 936          * Determine if output section ordering is turned on. If so, return


1192 
1193                 for (refsec = RefSecs; *refsec; refsec++) {
1194                         if (strcmp(osp->os_name, MSG_ORIG(*refsec)) == 0) {
1195                                 osp->os_flags |= FLG_OS_SECTREF;
1196 
1197                                 if ((ifl->ifl_flags & FLG_IF_IGNORE) ||
1198                                     DBG_ENABLED) {
1199                                         isp->is_flags |= FLG_IS_SECTREF;
1200                                         ifl->ifl_flags |= FLG_IF_FILEREF;
1201                                 }
1202                                 break;
1203                         }
1204                 }
1205         }
1206 
1207         /*
1208          * Sections of type SHT_GROUP are added to the ofl->ofl_osgroups list,
1209          * so that they can be updated as a group later.
1210          */
1211         if ((shdr->sh_type == SHT_GROUP) &&
1212             ((isp->is_flags & FLG_IS_DISCARD) == 0) &&
1213             (aplist_append(&ofl->ofl_osgroups, osp,
1214             AL_CNT_OFL_OSGROUPS) == NULL))
1215                 return ((Os_desc *)S_ERROR);
1216 
1217         /*
1218          * If this section is a non-empty TLS section indicate that a PT_TLS
1219          * program header is required.
1220          */
1221         if ((shflags & SHF_TLS) && shdr->sh_size &&
1222             ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0))
1223                 ofl->ofl_flags |= FLG_OF_TLSPHDR;
1224 
1225         /*
1226          * If a non-allocatable section is going to be put into a loadable
1227          * segment then turn on the allocate bit for this section and warn the
1228          * user that we have done so.  This could only happen through the use
1229          * of a mapfile.
1230          */
1231         if ((sgp->sg_phdr.p_type == PT_LOAD) &&
1232             ((osp->os_shdr->sh_flags & SHF_ALLOC) == 0)) {