Print this page
10366 ld(1) should support GNU-style linker sets
10581 ld(1) should know kernel modules are a thing

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/sgs/libld/common/syms.c
          +++ new/usr/src/cmd/sgs/libld/common/syms.c
↓ open down ↓ 628 lines elided ↑ open up ↑
 629  629   * other symbol directives will the nodirect binding be recorded.  This ensures
 630  630   * we don't create syminfo sections for all objects we create, as this might add
 631  631   * unnecessary bloat to users who haven't explicitly requested extra symbol
 632  632   * information.
 633  633   */
 634  634  static uintptr_t
 635  635  sym_add_spec(const char *name, const char *uname, Word sdaux_id,
 636  636      sd_flag_t sdflags_u, sd_flag_t sdflags, Ofl_desc *ofl)
 637  637  {
 638  638          Sym_desc        *sdp;
 639      -        Sym_desc        *usdp;
      639 +        Sym_desc        *usdp;
 640  640          Sym             *sym;
 641  641          Word            hash;
 642  642          avl_index_t     where;
 643  643  
 644  644          /* LINTED */
 645  645          hash = (Word)elf_hash(uname);
 646  646          if (usdp = ld_sym_find(uname, hash, &where, ofl)) {
 647  647                  /*
 648  648                   * If the underscore symbol exists and is undefined, or was
 649  649                   * defined in a shared library, convert it to a local symbol.
↓ open down ↓ 35 lines elided ↑ open up ↑
 685  685                          usdp->sd_flags |= sdflags;
 686  686  
 687  687                          /*
 688  688                           * If the reference originated from a mapfile ensure
 689  689                           * we mark the symbol as used.
 690  690                           */
 691  691                          if (usdp->sd_flags & FLG_SY_MAPREF)
 692  692                                  usdp->sd_flags |= FLG_SY_MAPUSED;
 693  693  
 694  694                          DBG_CALL(Dbg_syms_updated(ofl, usdp, uname));
 695      -                } else
      695 +                } else {
 696  696                          ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_SYM_RESERVE),
 697  697                              uname, usdp->sd_file->ifl_name);
      698 +                }
 698  699          } else {
 699  700                  /*
 700  701                   * If the symbol does not exist create it.
 701  702                   */
 702  703                  if ((sym = libld_calloc(sizeof (Sym), 1)) == NULL)
 703  704                          return (S_ERROR);
 704  705                  sym->st_shndx = SHN_ABS;
 705  706                  sym->st_info = ELF_ST_INFO(STB_GLOBAL, STT_OBJECT);
 706  707                  sym->st_size = 0;
 707  708                  sym->st_value = 0;
↓ open down ↓ 80 lines elided ↑ open up ↑
 788  789  /*
 789  790   * Undefined symbols can fall into one of four types:
 790  791   *
 791  792   *  -   the symbol is really undefined (SHN_UNDEF).
 792  793   *
 793  794   *  -   versioning has been enabled, however this symbol has not been assigned
 794  795   *      to one of the defined versions.
 795  796   *
 796  797   *  -   the symbol has been defined by an implicitly supplied library, ie. one
 797  798   *      which was encounted because it was NEEDED by another library, rather
 798      - *      than from a command line supplied library which would become the only
      799 + *      than from a command line supplied library which would become the only
 799  800   *      dependency of the output file being produced.
 800  801   *
 801  802   *  -   the symbol has been defined by a version of a shared object that is
 802  803   *      not permitted for this link-edit.
 803  804   *
 804  805   * In all cases the file who made the first reference to this symbol will have
 805  806   * been recorded via the `sa_rfile' pointer.
 806  807   */
 807  808  typedef enum {
 808  809          UNDEF,          NOVERSION,      IMPLICIT,       NOTAVAIL,
↓ open down ↓ 69 lines elided ↑ open up ↑
 878  879                  break;
 879  880          default:
 880  881                  return;
 881  882          }
 882  883  
 883  884          ld_eprintf(ofl, ERR_NONE, MSG_INTL(format[type]),
 884  885              demangle(sdp->sd_name), name1, name2, name3);
 885  886  }
 886  887  
 887  888  /*
      889 + * If an undef symbol exists naming a bound for the output section,
      890 + * turn it into a defined symbol with the correct value.
      891 + *
      892 + * We set an arbitrary 1KB limit on the resulting symbol names.
      893 + */
      894 +static void
      895 +sym_add_bounds(Ofl_desc *ofl, Os_desc *osp, Word bound)
      896 +{
      897 +        Sym_desc *bsdp;
      898 +        char symn[1024];
      899 +        size_t nsz;
      900 +
      901 +        switch (bound) {
      902 +        case SDAUX_ID_SECBOUND_START:
      903 +                nsz = snprintf(symn, sizeof (symn), "%s%s",
      904 +                    MSG_ORIG(MSG_SYM_SECBOUND_START), osp->os_name);
      905 +                if (nsz >= sizeof (symn))
      906 +                        return;
      907 +                break;
      908 +        case SDAUX_ID_SECBOUND_STOP:
      909 +                nsz = snprintf(symn, sizeof (symn), "%s%s",
      910 +                    MSG_ORIG(MSG_SYM_SECBOUND_STOP), osp->os_name);
      911 +                if (nsz >= sizeof (symn))
      912 +                        return;
      913 +                break;
      914 +        default:
      915 +                assert(0);
      916 +        }
      917 +
      918 +        if ((bsdp = ld_sym_find(symn, SYM_NOHASH, NULL, ofl)) != NULL) {
      919 +                if ((bsdp->sd_shndx != SHN_UNDEF) &&
      920 +                    (bsdp->sd_ref == REF_REL_NEED)) {
      921 +                        ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_SYM_RESERVE),
      922 +                            symn, bsdp->sd_file->ifl_name);
      923 +                        return;
      924 +                }
      925 +
      926 +                DBG_CALL(Dbg_syms_updated(ofl, bsdp, symn));
      927 +
      928 +                bsdp->sd_aux->sa_symspec = bound;
      929 +                bsdp->sd_aux->sa_boundsec = osp;
      930 +                bsdp->sd_flags |= FLG_SY_SPECSEC;
      931 +                bsdp->sd_ref = REF_REL_NEED;
      932 +                bsdp->sd_sym->st_info = ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE);
      933 +                bsdp->sd_sym->st_other = STV_PROTECTED;
      934 +                bsdp->sd_isc = NULL;
      935 +                bsdp->sd_sym->st_size = 0;
      936 +                bsdp->sd_sym->st_value = 0;
      937 +                bsdp->sd_shndx = bsdp->sd_sym->st_shndx = SHN_ABS;
      938 +        }
      939 +}
      940 +
      941 +static Boolean
      942 +is_cname(const char *name)
      943 +{
      944 +        if (strlen(name) == strspn(name,
      945 +            "abcdefghijklmnopqrstuvwxyz"
      946 +            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
      947 +            "0123456789"
      948 +            "_"))
      949 +                return (TRUE);
      950 +        else
      951 +                return (FALSE);
      952 +}
      953 +
      954 +/*
 888  955   * At this point all symbol input processing has been completed, therefore
 889  956   * complete the symbol table entries by generating any necessary internal
 890  957   * symbols.
 891  958   */
 892  959  uintptr_t
 893  960  ld_sym_spec(Ofl_desc *ofl)
 894  961  {
 895  962          Sym_desc        *sdp;
      963 +        Sg_desc         *sgp;
      964 +
      965 +        DBG_CALL(Dbg_syms_spec_title(ofl->ofl_lml));
      966 +
      967 +        /*
      968 +         * For each section in the output file, look for symbols named for the
      969 +         * __start/__stop patterns.  If references exist, flesh the symbols to
      970 +         * be defined.
      971 +         *
      972 +         * The symbols are given values at the same time as the other special
      973 +         * symbols.
      974 +         */
      975 +        if (!(ofl->ofl_flags & FLG_OF_RELOBJ) ||
      976 +            (ofl->ofl_flags & FLG_OF_KMOD)) {
      977 +                Aliste          idx1;
      978 +
      979 +                for (APLIST_TRAVERSE(ofl->ofl_segs, idx1, sgp)) {
      980 +                        Os_desc *osp;
      981 +                        Aliste idx2;
      982 +
      983 +                        for (APLIST_TRAVERSE(sgp->sg_osdescs, idx2, osp)) {
      984 +                                if (is_cname(osp->os_name)) {
      985 +                                        sym_add_bounds(ofl, osp,
      986 +                                            SDAUX_ID_SECBOUND_START);
      987 +                                        sym_add_bounds(ofl, osp,
      988 +                                            SDAUX_ID_SECBOUND_STOP);
      989 +                                }
      990 +                        }
      991 +                }
      992 +        }
 896  993  
 897  994          if (ofl->ofl_flags & FLG_OF_RELOBJ)
 898  995                  return (1);
 899  996  
 900      -        DBG_CALL(Dbg_syms_spec_title(ofl->ofl_lml));
 901      -
 902  997          if (sym_add_spec(MSG_ORIG(MSG_SYM_ETEXT), MSG_ORIG(MSG_SYM_ETEXT_U),
 903  998              SDAUX_ID_ETEXT, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
 904  999              ofl) == S_ERROR)
 905 1000                  return (S_ERROR);
 906 1001          if (sym_add_spec(MSG_ORIG(MSG_SYM_EDATA), MSG_ORIG(MSG_SYM_EDATA_U),
 907 1002              SDAUX_ID_EDATA, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
 908 1003              ofl) == S_ERROR)
 909 1004                  return (S_ERROR);
 910 1005          if (sym_add_spec(MSG_ORIG(MSG_SYM_END), MSG_ORIG(MSG_SYM_END_U),
 911 1006              SDAUX_ID_END, FLG_SY_DYNSORT, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
↓ open down ↓ 214 lines elided ↑ open up ↑
1126 1221  
1127 1222          return (ret);
1128 1223  }
1129 1224  
1130 1225  /*
1131 1226   * After all symbol table input processing has been finished, and all relocation
1132 1227   * counting has been carried out (ie. no more symbols will be read, generated,
1133 1228   * or modified), validate and count the relevant entries:
1134 1229   *
1135 1230   *  -   check and print any undefined symbols remaining.  Note that if a symbol
1136      - *      has been defined by virtue of the inclusion of  an implicit shared
     1231 + *      has been defined by virtue of the inclusion of  an implicit shared
1137 1232   *      library, it is still classed as undefined.
1138 1233   *
1139 1234   *  -   count the number of global needed symbols together with the size of
1140 1235   *      their associated name strings (if scoping has been indicated these
1141 1236   *      symbols may be reduced to locals).
1142 1237   *
1143 1238   *  -   establish the size and alignment requirements for the global .bss
1144      - *      section (the alignment of this section is based on the  first symbol
     1239 + *      section (the alignment of this section is based on the first symbol
1145 1240   *      that it will contain).
1146 1241   */
1147 1242  uintptr_t
1148 1243  ld_sym_validate(Ofl_desc *ofl)
1149 1244  {
1150 1245          Sym_avlnode     *sav;
1151 1246          Sym_desc        *sdp;
1152 1247          Sym             *sym;
1153 1248          ofl_flag_t      oflags = ofl->ofl_flags;
1154 1249          ofl_flag_t      undef = 0, needed = 0, verdesc = 0;
↓ open down ↓ 728 lines elided ↑ open up ↑
1883 1978          Sym_desc        *c_osdp;        /* original symbol */
1884 1979          Cap_group       *c_group;       /* symbol capability group */
1885 1980          Word            c_ndx;          /* symbol index */
1886 1981  } Cap_pair;
1887 1982  
1888 1983  /*
1889 1984   * Process the symbol table for the specified input file.  At this point all
1890 1985   * input sections from this input file have been assigned an input section
1891 1986   * descriptor which is saved in the `ifl_isdesc' array.
1892 1987   *
1893      - *  -   local symbols are saved (as is) if the input file is a  relocatable
     1988 + *  -   local symbols are saved (as is) if the input file is a  relocatable
1894 1989   *      object
1895 1990   *
1896 1991   *  -   global symbols are added to the linkers internal symbol table if they
1897 1992   *      are not already present, otherwise a symbol resolution function is
1898 1993   *      called upon to resolve the conflict.
1899 1994   */
1900 1995  uintptr_t
1901 1996  ld_sym_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
1902 1997  {
1903 1998          /*
↓ open down ↓ 1232 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX