19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1988 AT&T
24 * All Rights Reserved
25 *
26 *
27 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
28 */
29
30 /*
31 * Symbol table management routines
32 */
33
34 #define ELF_TARGET_AMD64
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <debug.h>
39 #include <alloca.h>
40 #include "msg.h"
41 #include "_libld.h"
42
43 /*
44 * AVL tree comparator function:
45 *
46 * The primary key is the symbol name hash with a secondary key of the symbol
47 * name itself.
48 */
49 int
50 ld_sym_avl_comp(const void *elem1, const void *elem2)
51 {
52 Sym_avlnode *sav1 = (Sym_avlnode *)elem1;
53 Sym_avlnode *sav2 = (Sym_avlnode *)elem2;
54 int res;
55
56 res = sav1->sav_hash - sav2->sav_hash;
57
58 if (res < 0)
59 return (-1);
886 demangle(sdp->sd_name), name1, name2, name3);
887 }
888
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;
944 * complete the symbol table entries by generating any necessary internal
945 * symbols.
946 */
947 uintptr_t
948 ld_sym_spec(Ofl_desc *ofl)
949 {
950 Sym_desc *sdp;
951 Sg_desc *sgp;
952 Aliste idx1;
953
954 if (ofl->ofl_flags & FLG_OF_RELOBJ)
955 return (1);
956
957 DBG_CALL(Dbg_syms_spec_title(ofl->ofl_lml));
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
977 if (sym_add_spec(MSG_ORIG(MSG_SYM_ETEXT), MSG_ORIG(MSG_SYM_ETEXT_U),
978 SDAUX_ID_ETEXT, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
979 ofl) == S_ERROR)
980 return (S_ERROR);
981 if (sym_add_spec(MSG_ORIG(MSG_SYM_EDATA), MSG_ORIG(MSG_SYM_EDATA_U),
982 SDAUX_ID_EDATA, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
983 ofl) == S_ERROR)
984 return (S_ERROR);
|
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1988 AT&T
24 * All Rights Reserved
25 *
26 *
27 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
28 */
29
30 /*
31 * Symbol table management routines
32 */
33
34 #define ELF_TARGET_AMD64
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <debug.h>
39 #include "msg.h"
40 #include "_libld.h"
41
42 /*
43 * AVL tree comparator function:
44 *
45 * The primary key is the symbol name hash with a secondary key of the symbol
46 * name itself.
47 */
48 int
49 ld_sym_avl_comp(const void *elem1, const void *elem2)
50 {
51 Sym_avlnode *sav1 = (Sym_avlnode *)elem1;
52 Sym_avlnode *sav2 = (Sym_avlnode *)elem2;
53 int res;
54
55 res = sav1->sav_hash - sav2->sav_hash;
56
57 if (res < 0)
58 return (-1);
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 + 1);
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 + 1);
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;
943 * complete the symbol table entries by generating any necessary internal
944 * symbols.
945 */
946 uintptr_t
947 ld_sym_spec(Ofl_desc *ofl)
948 {
949 Sym_desc *sdp;
950 Sg_desc *sgp;
951 Aliste idx1;
952
953 if (ofl->ofl_flags & FLG_OF_RELOBJ)
954 return (1);
955
956 DBG_CALL(Dbg_syms_spec_title(ofl->ofl_lml));
957
958 /*
959 * For each section in the output file, look for symbols named for the
960 * __start/__stop patterns. If references exist, flesh the symbols to
961 * be defined.
962 *
963 * The symbols are given values at the same time as the other special
964 * symbols.
965 */
966 for (APLIST_TRAVERSE(ofl->ofl_segs, idx1, sgp)) {
967 Os_desc *osp;
968 Aliste idx2;
969
970 for (APLIST_TRAVERSE(sgp->sg_osdescs, idx2, osp)) {
971 sym_add_bounds(ofl, osp, SDAUX_ID_SECBOUND_START);
972 sym_add_bounds(ofl, osp, SDAUX_ID_SECBOUND_STOP);
973 }
974 }
975
976 if (sym_add_spec(MSG_ORIG(MSG_SYM_ETEXT), MSG_ORIG(MSG_SYM_ETEXT_U),
977 SDAUX_ID_ETEXT, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
978 ofl) == S_ERROR)
979 return (S_ERROR);
980 if (sym_add_spec(MSG_ORIG(MSG_SYM_EDATA), MSG_ORIG(MSG_SYM_EDATA_U),
981 SDAUX_ID_EDATA, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
982 ofl) == S_ERROR)
983 return (S_ERROR);
|