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


 675                                 if (sdaux_id == SDAUX_ID_GOT) {
 676                                         usdp->sd_flags &= ~FLG_SY_NDIR;
 677                                         usdp->sd_flags |= FLG_SY_PROTECT;
 678                                         usdp->sd_sym->st_other = STV_PROTECTED;
 679                                 } else if (
 680                                     ((usdp->sd_flags & FLG_SY_DIR) == 0) &&
 681                                     ((ofl->ofl_flags & FLG_OF_SYMBOLIC) == 0)) {
 682                                         usdp->sd_flags |= FLG_SY_NDIR;
 683                                 }
 684                         }
 685                         usdp->sd_flags |= sdflags;
 686 
 687                         /*
 688                          * If the reference originated from a mapfile ensure
 689                          * we mark the symbol as used.
 690                          */
 691                         if (usdp->sd_flags & FLG_SY_MAPREF)
 692                                 usdp->sd_flags |= FLG_SY_MAPUSED;
 693 
 694                         DBG_CALL(Dbg_syms_updated(ofl, usdp, uname));
 695                 } else
 696                         ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_SYM_RESERVE),
 697                             uname, usdp->sd_file->ifl_name);

 698         } else {
 699                 /*
 700                  * If the symbol does not exist create it.
 701                  */
 702                 if ((sym = libld_calloc(sizeof (Sym), 1)) == NULL)
 703                         return (S_ERROR);
 704                 sym->st_shndx = SHN_ABS;
 705                 sym->st_info = ELF_ST_INFO(STB_GLOBAL, STT_OBJECT);
 706                 sym->st_size = 0;
 707                 sym->st_value = 0;
 708                 DBG_CALL(Dbg_syms_created(ofl->ofl_lml, uname));
 709                 if ((usdp = ld_sym_enter(uname, sym, hash, (Ifl_desc *)NULL,
 710                     ofl, 0, SHN_ABS, (FLG_SY_SPECSEC | sdflags_u), &where)) ==
 711                     (Sym_desc *)S_ERROR)
 712                         return (S_ERROR);
 713                 usdp->sd_ref = REF_REL_NEED;
 714                 /* LINTED */
 715                 usdp->sd_aux->sa_symspec = (Half)sdaux_id;
 716 
 717                 usdp->sd_aux->sa_overndx = VER_NDX_GLOBAL;


 868                 name1 = ifl->ifl_name;
 869                 break;
 870         case IMPLICIT:
 871                 name1 = sap->sa_rfile;
 872                 name2 = ifl->ifl_name;
 873                 break;
 874         case NOTAVAIL:
 875                 name1 = sap->sa_rfile;
 876                 name2 = sap->sa_vfile;
 877                 name3 = ifl->ifl_verndx[sap->sa_dverndx].vi_name;
 878                 break;
 879         default:
 880                 return;
 881         }
 882 
 883         ld_eprintf(ofl, ERR_NONE, MSG_INTL(format[type]),
 884             demangle(sdp->sd_name), name1, name2, name3);
 885 }
 886 
 887 /*


































































 888  * At this point all symbol input processing has been completed, therefore
 889  * complete the symbol table entries by generating any necessary internal
 890  * symbols.
 891  */
 892 uintptr_t
 893 ld_sym_spec(Ofl_desc *ofl)
 894 {
 895         Sym_desc        *sdp;






























 896 
 897         if (ofl->ofl_flags & FLG_OF_RELOBJ)
 898                 return (1);
 899 
 900         DBG_CALL(Dbg_syms_spec_title(ofl->ofl_lml));
 901 
 902         if (sym_add_spec(MSG_ORIG(MSG_SYM_ETEXT), MSG_ORIG(MSG_SYM_ETEXT_U),
 903             SDAUX_ID_ETEXT, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
 904             ofl) == S_ERROR)
 905                 return (S_ERROR);
 906         if (sym_add_spec(MSG_ORIG(MSG_SYM_EDATA), MSG_ORIG(MSG_SYM_EDATA_U),
 907             SDAUX_ID_EDATA, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
 908             ofl) == S_ERROR)
 909                 return (S_ERROR);
 910         if (sym_add_spec(MSG_ORIG(MSG_SYM_END), MSG_ORIG(MSG_SYM_END_U),
 911             SDAUX_ID_END, FLG_SY_DYNSORT, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
 912             ofl) == S_ERROR)
 913                 return (S_ERROR);
 914         if (sym_add_spec(MSG_ORIG(MSG_SYM_L_END), MSG_ORIG(MSG_SYM_L_END_U),
 915             SDAUX_ID_END, 0, FLG_SY_HIDDEN, ofl) == S_ERROR)
 916                 return (S_ERROR);
 917         if (sym_add_spec(MSG_ORIG(MSG_SYM_L_START), MSG_ORIG(MSG_SYM_L_START_U),
 918             SDAUX_ID_START, 0, FLG_SY_HIDDEN, ofl) == S_ERROR)
 919                 return (S_ERROR);
 920 
 921         /*




 675                                 if (sdaux_id == SDAUX_ID_GOT) {
 676                                         usdp->sd_flags &= ~FLG_SY_NDIR;
 677                                         usdp->sd_flags |= FLG_SY_PROTECT;
 678                                         usdp->sd_sym->st_other = STV_PROTECTED;
 679                                 } else if (
 680                                     ((usdp->sd_flags & FLG_SY_DIR) == 0) &&
 681                                     ((ofl->ofl_flags & FLG_OF_SYMBOLIC) == 0)) {
 682                                         usdp->sd_flags |= FLG_SY_NDIR;
 683                                 }
 684                         }
 685                         usdp->sd_flags |= sdflags;
 686 
 687                         /*
 688                          * If the reference originated from a mapfile ensure
 689                          * we mark the symbol as used.
 690                          */
 691                         if (usdp->sd_flags & FLG_SY_MAPREF)
 692                                 usdp->sd_flags |= FLG_SY_MAPUSED;
 693 
 694                         DBG_CALL(Dbg_syms_updated(ofl, usdp, uname));
 695                 } else {
 696                         ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_SYM_RESERVE),
 697                             uname, usdp->sd_file->ifl_name);
 698                 }
 699         } else {
 700                 /*
 701                  * If the symbol does not exist create it.
 702                  */
 703                 if ((sym = libld_calloc(sizeof (Sym), 1)) == NULL)
 704                         return (S_ERROR);
 705                 sym->st_shndx = SHN_ABS;
 706                 sym->st_info = ELF_ST_INFO(STB_GLOBAL, STT_OBJECT);
 707                 sym->st_size = 0;
 708                 sym->st_value = 0;
 709                 DBG_CALL(Dbg_syms_created(ofl->ofl_lml, uname));
 710                 if ((usdp = ld_sym_enter(uname, sym, hash, (Ifl_desc *)NULL,
 711                     ofl, 0, SHN_ABS, (FLG_SY_SPECSEC | sdflags_u), &where)) ==
 712                     (Sym_desc *)S_ERROR)
 713                         return (S_ERROR);
 714                 usdp->sd_ref = REF_REL_NEED;
 715                 /* LINTED */
 716                 usdp->sd_aux->sa_symspec = (Half)sdaux_id;
 717 
 718                 usdp->sd_aux->sa_overndx = VER_NDX_GLOBAL;


 869                 name1 = ifl->ifl_name;
 870                 break;
 871         case IMPLICIT:
 872                 name1 = sap->sa_rfile;
 873                 name2 = ifl->ifl_name;
 874                 break;
 875         case NOTAVAIL:
 876                 name1 = sap->sa_rfile;
 877                 name2 = sap->sa_vfile;
 878                 name3 = ifl->ifl_verndx[sap->sa_dverndx].vi_name;
 879                 break;
 880         default:
 881                 return;
 882         }
 883 
 884         ld_eprintf(ofl, ERR_NONE, MSG_INTL(format[type]),
 885             demangle(sdp->sd_name), name1, name2, name3);
 886 }
 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 /*
 955  * At this point all symbol input processing has been completed, therefore
 956  * complete the symbol table entries by generating any necessary internal
 957  * symbols.
 958  */
 959 uintptr_t
 960 ld_sym_spec(Ofl_desc *ofl)
 961 {
 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         }
 993 
 994         if (ofl->ofl_flags & FLG_OF_RELOBJ)
 995                 return (1);
 996 


 997         if (sym_add_spec(MSG_ORIG(MSG_SYM_ETEXT), MSG_ORIG(MSG_SYM_ETEXT_U),
 998             SDAUX_ID_ETEXT, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
 999             ofl) == S_ERROR)
1000                 return (S_ERROR);
1001         if (sym_add_spec(MSG_ORIG(MSG_SYM_EDATA), MSG_ORIG(MSG_SYM_EDATA_U),
1002             SDAUX_ID_EDATA, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
1003             ofl) == S_ERROR)
1004                 return (S_ERROR);
1005         if (sym_add_spec(MSG_ORIG(MSG_SYM_END), MSG_ORIG(MSG_SYM_END_U),
1006             SDAUX_ID_END, FLG_SY_DYNSORT, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
1007             ofl) == S_ERROR)
1008                 return (S_ERROR);
1009         if (sym_add_spec(MSG_ORIG(MSG_SYM_L_END), MSG_ORIG(MSG_SYM_L_END_U),
1010             SDAUX_ID_END, 0, FLG_SY_HIDDEN, ofl) == S_ERROR)
1011                 return (S_ERROR);
1012         if (sym_add_spec(MSG_ORIG(MSG_SYM_L_START), MSG_ORIG(MSG_SYM_L_START_U),
1013             SDAUX_ID_START, 0, FLG_SY_HIDDEN, ofl) == S_ERROR)
1014                 return (S_ERROR);
1015 
1016         /*