Print this page
10366 ld(1) should support GNU-style linker sets
10367 ld(1) tests should be a real test suite
10368 want an ld(1) regression test for i386 LD tls transition (10267)

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 ↓ 28 lines elided ↑ open up ↑
  29   29  
  30   30  /*
  31   31   * Symbol table management routines
  32   32   */
  33   33  
  34   34  #define ELF_TARGET_AMD64
  35   35  
  36   36  #include        <stdio.h>
  37   37  #include        <string.h>
  38   38  #include        <debug.h>
       39 +#include        <alloca.h>
  39   40  #include        "msg.h"
  40   41  #include        "_libld.h"
  41   42  
  42   43  /*
  43   44   * AVL tree comparator function:
  44   45   *
  45   46   * The primary key is the symbol name hash with a secondary key of the symbol
  46   47   * name itself.
  47   48   */
  48   49  int
↓ open down ↓ 580 lines elided ↑ open up ↑
 629  630   * other symbol directives will the nodirect binding be recorded.  This ensures
 630  631   * we don't create syminfo sections for all objects we create, as this might add
 631  632   * unnecessary bloat to users who haven't explicitly requested extra symbol
 632  633   * information.
 633  634   */
 634  635  static uintptr_t
 635  636  sym_add_spec(const char *name, const char *uname, Word sdaux_id,
 636  637      sd_flag_t sdflags_u, sd_flag_t sdflags, Ofl_desc *ofl)
 637  638  {
 638  639          Sym_desc        *sdp;
 639      -        Sym_desc        *usdp;
      640 +        Sym_desc        *usdp;
 640  641          Sym             *sym;
 641  642          Word            hash;
 642  643          avl_index_t     where;
 643  644  
 644  645          /* LINTED */
 645  646          hash = (Word)elf_hash(uname);
 646  647          if (usdp = ld_sym_find(uname, hash, &where, ofl)) {
 647  648                  /*
 648  649                   * If the underscore symbol exists and is undefined, or was
 649  650                   * defined in a shared library, convert it to a local symbol.
↓ open down ↓ 35 lines elided ↑ open up ↑
 685  686                          usdp->sd_flags |= sdflags;
 686  687  
 687  688                          /*
 688  689                           * If the reference originated from a mapfile ensure
 689  690                           * we mark the symbol as used.
 690  691                           */
 691  692                          if (usdp->sd_flags & FLG_SY_MAPREF)
 692  693                                  usdp->sd_flags |= FLG_SY_MAPUSED;
 693  694  
 694  695                          DBG_CALL(Dbg_syms_updated(ofl, usdp, uname));
 695      -                } else
      696 +                } else {
 696  697                          ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_SYM_RESERVE),
 697  698                              uname, usdp->sd_file->ifl_name);
      699 +                }
 698  700          } else {
 699  701                  /*
 700  702                   * If the symbol does not exist create it.
 701  703                   */
 702  704                  if ((sym = libld_calloc(sizeof (Sym), 1)) == NULL)
 703  705                          return (S_ERROR);
 704  706                  sym->st_shndx = SHN_ABS;
 705  707                  sym->st_info = ELF_ST_INFO(STB_GLOBAL, STT_OBJECT);
 706  708                  sym->st_size = 0;
 707  709                  sym->st_value = 0;
↓ open down ↓ 80 lines elided ↑ open up ↑
 788  790  /*
 789  791   * Undefined symbols can fall into one of four types:
 790  792   *
 791  793   *  -   the symbol is really undefined (SHN_UNDEF).
 792  794   *
 793  795   *  -   versioning has been enabled, however this symbol has not been assigned
 794  796   *      to one of the defined versions.
 795  797   *
 796  798   *  -   the symbol has been defined by an implicitly supplied library, ie. one
 797  799   *      which was encounted because it was NEEDED by another library, rather
 798      - *      than from a command line supplied library which would become the only
      800 + *      than from a command line supplied library which would become the only
 799  801   *      dependency of the output file being produced.
 800  802   *
 801  803   *  -   the symbol has been defined by a version of a shared object that is
 802  804   *      not permitted for this link-edit.
 803  805   *
 804  806   * In all cases the file who made the first reference to this symbol will have
 805  807   * been recorded via the `sa_rfile' pointer.
 806  808   */
 807  809  typedef enum {
 808  810          UNDEF,          NOVERSION,      IMPLICIT,       NOTAVAIL,
↓ open down ↓ 69 lines elided ↑ open up ↑
 878  880                  break;
 879  881          default:
 880  882                  return;
 881  883          }
 882  884  
 883  885          ld_eprintf(ofl, ERR_NONE, MSG_INTL(format[type]),
 884  886              demangle(sdp->sd_name), name1, name2, name3);
 885  887  }
 886  888  
 887  889  /*
      890 + * If an undef symbol exists naming a bound for the output section,
      891 + * turn it into a defined symbol with the correct value.
      892 + *
      893 + * We set an arbitrary 1KB limit on the resulting symbol names.
      894 + */
      895 +static void
      896 +sym_add_bounds(Ofl_desc *ofl, Os_desc *osp, Word bound)
      897 +{
      898 +        Sym_desc *bsdp;
      899 +        char symn[1024];
      900 +        size_t nsz;
      901 +
      902 +        switch (bound) {
      903 +        case SDAUX_ID_SECBOUND_START:
      904 +                nsz = snprintf(symn, sizeof (symn), "%s%s",
      905 +                    MSG_ORIG(MSG_SYM_SECBOUND_START), osp->os_name + 1);
      906 +                if (nsz > sizeof (symn))
      907 +                        return;
      908 +                break;
      909 +        case SDAUX_ID_SECBOUND_STOP:
      910 +                nsz = snprintf(symn, sizeof (symn), "%s%s",
      911 +                    MSG_ORIG(MSG_SYM_SECBOUND_STOP), osp->os_name + 1);
      912 +                if (nsz > sizeof (symn))
      913 +                        return;
      914 +                break;
      915 +        default:
      916 +                assert(0);
      917 +        }
      918 +
      919 +        if ((bsdp = ld_sym_find(symn, SYM_NOHASH, NULL, ofl)) != NULL) {
      920 +                if ((bsdp->sd_shndx != SHN_UNDEF) &&
      921 +                    (bsdp->sd_ref == REF_REL_NEED)) {
      922 +                        ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_SYM_RESERVE),
      923 +                            symn, bsdp->sd_file->ifl_name);
      924 +                        return;
      925 +                }
      926 +
      927 +                DBG_CALL(Dbg_syms_updated(ofl, bsdp, symn));
      928 +
      929 +                bsdp->sd_aux->sa_symspec = bound;
      930 +                bsdp->sd_aux->sa_boundsec = osp;
      931 +                bsdp->sd_flags |= FLG_SY_SPECSEC;
      932 +                bsdp->sd_ref = REF_REL_NEED;
      933 +                bsdp->sd_sym->st_info = ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE);
      934 +                bsdp->sd_sym->st_other = STV_PROTECTED;
      935 +                bsdp->sd_isc = NULL;
      936 +                bsdp->sd_sym->st_size = 0;
      937 +                bsdp->sd_sym->st_value = 0;
      938 +                bsdp->sd_shndx = bsdp->sd_sym->st_shndx = SHN_ABS;
      939 +        }
      940 +}
      941 +
      942 +/*
 888  943   * At this point all symbol input processing has been completed, therefore
 889  944   * complete the symbol table entries by generating any necessary internal
 890  945   * symbols.
 891  946   */
 892  947  uintptr_t
 893  948  ld_sym_spec(Ofl_desc *ofl)
 894  949  {
 895  950          Sym_desc        *sdp;
      951 +        Sg_desc         *sgp;
      952 +        Aliste          idx1;
 896  953  
 897  954          if (ofl->ofl_flags & FLG_OF_RELOBJ)
 898  955                  return (1);
 899  956  
 900  957          DBG_CALL(Dbg_syms_spec_title(ofl->ofl_lml));
 901  958  
      959 +        /*
      960 +         * For each section in the output file, look for symbols named for the
      961 +         * __start/__stop patterns.  If references exist, flesh the symbols to
      962 +         * be defined.
      963 +         *
      964 +         * the symbols are given values at the same time as the other special
      965 +         * symbols.
      966 +         */
      967 +        for (APLIST_TRAVERSE(ofl->ofl_segs, idx1, sgp)) {
      968 +                Os_desc *osp;
      969 +                Aliste idx2;
      970 +
      971 +                for (APLIST_TRAVERSE(sgp->sg_osdescs, idx2, osp)) {
      972 +                        sym_add_bounds(ofl, osp, SDAUX_ID_SECBOUND_START);
      973 +                        sym_add_bounds(ofl, osp, SDAUX_ID_SECBOUND_STOP);
      974 +                }
      975 +        }
      976 +
 902  977          if (sym_add_spec(MSG_ORIG(MSG_SYM_ETEXT), MSG_ORIG(MSG_SYM_ETEXT_U),
 903  978              SDAUX_ID_ETEXT, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
 904  979              ofl) == S_ERROR)
 905  980                  return (S_ERROR);
 906  981          if (sym_add_spec(MSG_ORIG(MSG_SYM_EDATA), MSG_ORIG(MSG_SYM_EDATA_U),
 907  982              SDAUX_ID_EDATA, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
 908  983              ofl) == S_ERROR)
 909  984                  return (S_ERROR);
 910  985          if (sym_add_spec(MSG_ORIG(MSG_SYM_END), MSG_ORIG(MSG_SYM_END_U),
 911  986              SDAUX_ID_END, FLG_SY_DYNSORT, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
↓ open down ↓ 214 lines elided ↑ open up ↑
1126 1201  
1127 1202          return (ret);
1128 1203  }
1129 1204  
1130 1205  /*
1131 1206   * After all symbol table input processing has been finished, and all relocation
1132 1207   * counting has been carried out (ie. no more symbols will be read, generated,
1133 1208   * or modified), validate and count the relevant entries:
1134 1209   *
1135 1210   *  -   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
     1211 + *      has been defined by virtue of the inclusion of  an implicit shared
1137 1212   *      library, it is still classed as undefined.
1138 1213   *
1139 1214   *  -   count the number of global needed symbols together with the size of
1140 1215   *      their associated name strings (if scoping has been indicated these
1141 1216   *      symbols may be reduced to locals).
1142 1217   *
1143 1218   *  -   establish the size and alignment requirements for the global .bss
1144      - *      section (the alignment of this section is based on the  first symbol
     1219 + *      section (the alignment of this section is based on the first symbol
1145 1220   *      that it will contain).
1146 1221   */
1147 1222  uintptr_t
1148 1223  ld_sym_validate(Ofl_desc *ofl)
1149 1224  {
1150 1225          Sym_avlnode     *sav;
1151 1226          Sym_desc        *sdp;
1152 1227          Sym             *sym;
1153 1228          ofl_flag_t      oflags = ofl->ofl_flags;
1154 1229          ofl_flag_t      undef = 0, needed = 0, verdesc = 0;
↓ open down ↓ 728 lines elided ↑ open up ↑
1883 1958          Sym_desc        *c_osdp;        /* original symbol */
1884 1959          Cap_group       *c_group;       /* symbol capability group */
1885 1960          Word            c_ndx;          /* symbol index */
1886 1961  } Cap_pair;
1887 1962  
1888 1963  /*
1889 1964   * Process the symbol table for the specified input file.  At this point all
1890 1965   * input sections from this input file have been assigned an input section
1891 1966   * descriptor which is saved in the `ifl_isdesc' array.
1892 1967   *
1893      - *  -   local symbols are saved (as is) if the input file is a  relocatable
     1968 + *  -   local symbols are saved (as is) if the input file is a  relocatable
1894 1969   *      object
1895 1970   *
1896 1971   *  -   global symbols are added to the linkers internal symbol table if they
1897 1972   *      are not already present, otherwise a symbol resolution function is
1898 1973   *      called upon to resolve the conflict.
1899 1974   */
1900 1975  uintptr_t
1901 1976  ld_sym_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
1902 1977  {
1903 1978          /*
↓ open down ↓ 1232 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX