Print this page
10908 Simplify SMAP relocations with krtld


2163         }
2164 
2165         kobj_notify(KOBJ_NOTIFY_MODUNLOADING, modp);
2166 
2167         /*
2168          * Null out mod_mp first, so consumers (debuggers) know not to look
2169          * at the module structure any more.
2170          */
2171         mutex_enter(&mod_lock);
2172         modp->mod_mp = NULL;
2173         mutex_exit(&mod_lock);
2174 
2175         kobj_notify(KOBJ_NOTIFY_MODUNLOADED, modp);
2176         free_module_data(mp);
2177 }
2178 
2179 static void
2180 free_module_data(struct module *mp)
2181 {
2182         struct module_list *lp, *tmp;

2183         int ksyms_exported = 0;
2184 
2185         lp = mp->head;
2186         while (lp) {
2187                 tmp = lp;
2188                 lp = lp->next;
2189                 kobj_free((char *)tmp, sizeof (*tmp));
2190         }
2191 









2192         rw_enter(&ksyms_lock, RW_WRITER);
2193         if (mp->symspace) {
2194                 if (vmem_contains(ksyms_arena, mp->symspace, mp->symsize)) {
2195                         vmem_free(ksyms_arena, mp->symspace, mp->symsize);
2196                         ksyms_exported = 1;
2197                 } else {
2198                         if (mp->flags & KOBJ_NOKSYMS)
2199                                 ksyms_exported = 1;
2200                         kobj_free(mp->symspace, mp->symsize);
2201                 }
2202         }
2203         rw_exit(&ksyms_lock);
2204 
2205         if (mp->ctfdata) {
2206                 if (vmem_contains(ctf_arena, mp->ctfdata, mp->ctfsize))
2207                         vmem_free(ctf_arena, mp->ctfdata, mp->ctfsize);
2208                 else
2209                         kobj_free(mp->ctfdata, mp->ctfsize);
2210         }
2211 


3017                 if (ELF_ST_TYPE(sp->st_info) == STT_TLS) {
3018                         _kobj_printf(ops, "%s: TLS symbol ",
3019                             mp->filename);
3020                         _kobj_printf(ops, "not supported '%s'\n",
3021                             name);
3022                         err = DOSYM_UNDEF;
3023                         continue;
3024                 }
3025 
3026                 if (ELF_ST_BIND(sp->st_info) != STB_LOCAL) {
3027                         if ((sp1 = kobj_lookup_all(mp, name, 0)) != NULL) {
3028                                 sp->st_shndx = SHN_ABS;
3029                                 sp->st_value = sp1->st_value;
3030                                 continue;
3031                         }
3032                 }
3033 
3034                 if (sp->st_shndx == SHN_UNDEF) {
3035                         resolved = 0;
3036 




3037                         if (strncmp(name, sdt_prefix, strlen(sdt_prefix)) == 0)
3038                                 continue;





3039 

3040                         /*
3041                          * If it's not a weak reference and it's
3042                          * not a primary object, it's an error.
3043                          * (Primary objects may take more than
3044                          * one pass to resolve)
3045                          */
3046                         if (!(mp->flags & KOBJ_PRIM) &&
3047                             ELF_ST_BIND(sp->st_info) != STB_WEAK) {
3048                                 _kobj_printf(ops, "%s: undefined symbol",
3049                                     mp->filename);
3050                                 _kobj_printf(ops, " '%s'\n", name);
3051                                 /*
3052                                  * Try to determine whether this symbol
3053                                  * represents a dependency on obsolete
3054                                  * unsafe driver support.  This is just
3055                                  * to make the warning more informative.
3056                                  */
3057                                 if (strcmp(name, "sleep") == 0 ||
3058                                     strcmp(name, "unsleep") == 0 ||
3059                                     strcmp(name, "wakeup") == 0 ||




2163         }
2164 
2165         kobj_notify(KOBJ_NOTIFY_MODUNLOADING, modp);
2166 
2167         /*
2168          * Null out mod_mp first, so consumers (debuggers) know not to look
2169          * at the module structure any more.
2170          */
2171         mutex_enter(&mod_lock);
2172         modp->mod_mp = NULL;
2173         mutex_exit(&mod_lock);
2174 
2175         kobj_notify(KOBJ_NOTIFY_MODUNLOADED, modp);
2176         free_module_data(mp);
2177 }
2178 
2179 static void
2180 free_module_data(struct module *mp)
2181 {
2182         struct module_list *lp, *tmp;
2183         hotinline_desc_t *hid, *next;
2184         int ksyms_exported = 0;
2185 
2186         lp = mp->head;
2187         while (lp) {
2188                 tmp = lp;
2189                 lp = lp->next;
2190                 kobj_free((char *)tmp, sizeof (*tmp));
2191         }
2192 
2193         /* release hotinlines */
2194         hid = mp->hi_calls;
2195         while (hid != NULL) {
2196                 next = hid->hid_next;
2197                 kobj_free(hid->hid_symname, strlen(hid->hid_symname) + 1);
2198                 kobj_free(hid, sizeof (hotinline_desc_t));
2199                 hid = next;
2200         }
2201 
2202         rw_enter(&ksyms_lock, RW_WRITER);
2203         if (mp->symspace) {
2204                 if (vmem_contains(ksyms_arena, mp->symspace, mp->symsize)) {
2205                         vmem_free(ksyms_arena, mp->symspace, mp->symsize);
2206                         ksyms_exported = 1;
2207                 } else {
2208                         if (mp->flags & KOBJ_NOKSYMS)
2209                                 ksyms_exported = 1;
2210                         kobj_free(mp->symspace, mp->symsize);
2211                 }
2212         }
2213         rw_exit(&ksyms_lock);
2214 
2215         if (mp->ctfdata) {
2216                 if (vmem_contains(ctf_arena, mp->ctfdata, mp->ctfsize))
2217                         vmem_free(ctf_arena, mp->ctfdata, mp->ctfsize);
2218                 else
2219                         kobj_free(mp->ctfdata, mp->ctfsize);
2220         }
2221 


3027                 if (ELF_ST_TYPE(sp->st_info) == STT_TLS) {
3028                         _kobj_printf(ops, "%s: TLS symbol ",
3029                             mp->filename);
3030                         _kobj_printf(ops, "not supported '%s'\n",
3031                             name);
3032                         err = DOSYM_UNDEF;
3033                         continue;
3034                 }
3035 
3036                 if (ELF_ST_BIND(sp->st_info) != STB_LOCAL) {
3037                         if ((sp1 = kobj_lookup_all(mp, name, 0)) != NULL) {
3038                                 sp->st_shndx = SHN_ABS;
3039                                 sp->st_value = sp1->st_value;
3040                                 continue;
3041                         }
3042                 }
3043 
3044                 if (sp->st_shndx == SHN_UNDEF) {
3045                         resolved = 0;
3046 
3047                         /*
3048                          * Skip over sdt probes and smap calls,
3049                          * they're relocated later.
3050                          */
3051                         if (strncmp(name, sdt_prefix, strlen(sdt_prefix)) == 0)
3052                                 continue;
3053 #if defined(__x86)
3054                         if (strcmp(name, "smap_enable") == 0 ||
3055                             strcmp(name, "smap_disable") == 0)
3056                                 continue;
3057 #endif /* defined(__x86) */
3058 
3059 
3060                         /*
3061                          * If it's not a weak reference and it's
3062                          * not a primary object, it's an error.
3063                          * (Primary objects may take more than
3064                          * one pass to resolve)
3065                          */
3066                         if (!(mp->flags & KOBJ_PRIM) &&
3067                             ELF_ST_BIND(sp->st_info) != STB_WEAK) {
3068                                 _kobj_printf(ops, "%s: undefined symbol",
3069                                     mp->filename);
3070                                 _kobj_printf(ops, " '%s'\n", name);
3071                                 /*
3072                                  * Try to determine whether this symbol
3073                                  * represents a dependency on obsolete
3074                                  * unsafe driver support.  This is just
3075                                  * to make the warning more informative.
3076                                  */
3077                                 if (strcmp(name, "sleep") == 0 ||
3078                                     strcmp(name, "unsleep") == 0 ||
3079                                     strcmp(name, "wakeup") == 0 ||