dt_cc.c (237624) | dt_cc.c (238558) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 7 unchanged lines hidden (view full) --- 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 7 unchanged lines hidden (view full) --- 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
24 * Copyright (c) 2011, Joyent Inc. All rights reserved. |
|
24 */ 25 26/* 27 * DTrace D Language Compiler 28 * 29 * The code in this source file implements the main engine for the D language 30 * compiler. The driver routine for the compiler is dt_compile(), below. The 31 * compiler operates on either stdio FILEs or in-memory strings as its input --- 2113 unchanged lines hidden (view full) --- 2145 2146 while ((dld = dt_list_next(&dtp->dt_lib_dep_sorted)) != NULL) { 2147 dt_list_delete(&dtp->dt_lib_dep_sorted, dld); 2148 dt_free(dtp, dld->dtld_library); 2149 dt_free(dtp, dld); 2150 } 2151} 2152 | 25 */ 26 27/* 28 * DTrace D Language Compiler 29 * 30 * The code in this source file implements the main engine for the D language 31 * compiler. The driver routine for the compiler is dt_compile(), below. The 32 * compiler operates on either stdio FILEs or in-memory strings as its input --- 2113 unchanged lines hidden (view full) --- 2146 2147 while ((dld = dt_list_next(&dtp->dt_lib_dep_sorted)) != NULL) { 2148 dt_list_delete(&dtp->dt_lib_dep_sorted, dld); 2149 dt_free(dtp, dld->dtld_library); 2150 dt_free(dtp, dld); 2151 } 2152} 2153 |
2153 | |
2154/* | 2154/* |
2155 * Open all of the .d library files found in the specified directory and 2156 * compile each one in topological order to cache its inlines and translators, 2157 * etc. We silently ignore any missing directories and other files found 2158 * therein. We only fail (and thereby fail dt_load_libs()) if we fail to 2159 * compile a library and the error is something other than #pragma D depends_on. 2160 * Dependency errors are silently ignored to permit a library directory to 2161 * contain libraries which may not be accessible depending on our privileges. | 2155 * Open all the .d library files found in the specified directory and 2156 * compile each one of them. We silently ignore any missing directories and 2157 * other files found therein. We only fail (and thereby fail dt_load_libs()) if 2158 * we fail to compile a library and the error is something other than #pragma D 2159 * depends_on. Dependency errors are silently ignored to permit a library 2160 * directory to contain libraries which may not be accessible depending on our 2161 * privileges. |
2162 */ 2163static int 2164dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path) 2165{ 2166 struct dirent *dp; | 2162 */ 2163static int 2164dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path) 2165{ 2166 struct dirent *dp; |
2167 const char *p; | 2167 const char *p, *end; |
2168 DIR *dirp; 2169 2170 char fname[PATH_MAX]; | 2168 DIR *dirp; 2169 2170 char fname[PATH_MAX]; |
2171 dtrace_prog_t *pgp; | |
2172 FILE *fp; 2173 void *rv; 2174 dt_lib_depend_t *dld; 2175 2176 if ((dirp = opendir(path)) == NULL) { 2177 dt_dprintf("skipping lib dir %s: %s\n", path, strerror(errno)); 2178 return (0); 2179 } --- 7 unchanged lines hidden (view full) --- 2187 "%s/%s", path, dp->d_name); 2188 2189 if ((fp = fopen(fname, "r")) == NULL) { 2190 dt_dprintf("skipping library %s: %s\n", 2191 fname, strerror(errno)); 2192 continue; 2193 } 2194 | 2171 FILE *fp; 2172 void *rv; 2173 dt_lib_depend_t *dld; 2174 2175 if ((dirp = opendir(path)) == NULL) { 2176 dt_dprintf("skipping lib dir %s: %s\n", path, strerror(errno)); 2177 return (0); 2178 } --- 7 unchanged lines hidden (view full) --- 2186 "%s/%s", path, dp->d_name); 2187 2188 if ((fp = fopen(fname, "r")) == NULL) { 2189 dt_dprintf("skipping library %s: %s\n", 2190 fname, strerror(errno)); 2191 continue; 2192 } 2193 |
2194 /* 2195 * Skip files whose name match an already processed library 2196 */ 2197 for (dld = dt_list_next(&dtp->dt_lib_dep); dld != NULL; 2198 dld = dt_list_next(dld)) { 2199 end = strrchr(dld->dtld_library, '/'); 2200 /* dt_lib_depend_add ensures this */ 2201 assert(end != NULL); 2202 if (strcmp(end + 1, dp->d_name) == 0) 2203 break; 2204 } 2205 2206 if (dld != NULL) { 2207 dt_dprintf("skipping library %s, already processed " 2208 "library with the same name: %s", dp->d_name, 2209 dld->dtld_library); 2210 continue; 2211 } 2212 |
|
2195 dtp->dt_filetag = fname; 2196 if (dt_lib_depend_add(dtp, &dtp->dt_lib_dep, fname) != 0) | 2213 dtp->dt_filetag = fname; 2214 if (dt_lib_depend_add(dtp, &dtp->dt_lib_dep, fname) != 0) |
2197 goto err; | 2215 return (-1); /* preserve dt_errno */ |
2198 2199 rv = dt_compile(dtp, DT_CTX_DPROG, 2200 DTRACE_PROBESPEC_NAME, NULL, 2201 DTRACE_C_EMPTY | DTRACE_C_CTL, 0, NULL, fp, NULL); 2202 2203 if (rv != NULL && dtp->dt_errno && 2204 (dtp->dt_errno != EDT_COMPILER || 2205 dtp->dt_errtag != dt_errtag(D_PRAGMA_DEPEND))) | 2216 2217 rv = dt_compile(dtp, DT_CTX_DPROG, 2218 DTRACE_PROBESPEC_NAME, NULL, 2219 DTRACE_C_EMPTY | DTRACE_C_CTL, 0, NULL, fp, NULL); 2220 2221 if (rv != NULL && dtp->dt_errno && 2222 (dtp->dt_errno != EDT_COMPILER || 2223 dtp->dt_errtag != dt_errtag(D_PRAGMA_DEPEND))) |
2206 goto err; | 2224 return (-1); /* preserve dt_errno */ |
2207 2208 if (dtp->dt_errno) 2209 dt_dprintf("error parsing library %s: %s\n", 2210 fname, dtrace_errmsg(dtp, dtrace_errno(dtp))); 2211 2212 (void) fclose(fp); 2213 dtp->dt_filetag = NULL; 2214 } 2215 2216 (void) closedir(dirp); | 2225 2226 if (dtp->dt_errno) 2227 dt_dprintf("error parsing library %s: %s\n", 2228 fname, dtrace_errmsg(dtp, dtrace_errno(dtp))); 2229 2230 (void) fclose(fp); 2231 dtp->dt_filetag = NULL; 2232 } 2233 2234 (void) closedir(dirp); |
2235 2236 return (0); 2237} 2238 2239/* 2240 * Perform a topological sorting of all the libraries found across the entire 2241 * dt_lib_path. Once sorted, compile each one in topological order to cache its 2242 * inlines and translators, etc. We silently ignore any missing directories and 2243 * other files found therein. We only fail (and thereby fail dt_load_libs()) if 2244 * we fail to compile a library and the error is something other than #pragma D 2245 * depends_on. Dependency errors are silently ignored to permit a library 2246 * directory to contain libraries which may not be accessible depending on our 2247 * privileges. 2248 */ 2249static int 2250dt_load_libs_sort(dtrace_hdl_t *dtp) 2251{ 2252 dtrace_prog_t *pgp; 2253 FILE *fp; 2254 dt_lib_depend_t *dld; 2255 |
|
2217 /* 2218 * Finish building the graph containing the library dependencies 2219 * and perform a topological sort to generate an ordered list 2220 * for compilation. 2221 */ 2222 if (dt_lib_depend_sort(dtp) == -1) 2223 goto err; 2224 --- 44 unchanged lines hidden (view full) --- 2269{ 2270 dt_dirpath_t *dirp; 2271 2272 if (dtp->dt_cflags & DTRACE_C_NOLIBS) 2273 return (0); /* libraries already processed */ 2274 2275 dtp->dt_cflags |= DTRACE_C_NOLIBS; 2276 | 2256 /* 2257 * Finish building the graph containing the library dependencies 2258 * and perform a topological sort to generate an ordered list 2259 * for compilation. 2260 */ 2261 if (dt_lib_depend_sort(dtp) == -1) 2262 goto err; 2263 --- 44 unchanged lines hidden (view full) --- 2308{ 2309 dt_dirpath_t *dirp; 2310 2311 if (dtp->dt_cflags & DTRACE_C_NOLIBS) 2312 return (0); /* libraries already processed */ 2313 2314 dtp->dt_cflags |= DTRACE_C_NOLIBS; 2315 |
2277 for (dirp = dt_list_next(&dtp->dt_lib_path); | 2316 /* 2317 * /usr/lib/dtrace is always at the head of the list. The rest of the 2318 * list is specified in the precedence order the user requested. Process 2319 * everything other than the head first. DTRACE_C_NOLIBS has already 2320 * been spcified so dt_vopen will ensure that there is always one entry 2321 * in dt_lib_path. 2322 */ 2323 for (dirp = dt_list_next(dt_list_next(&dtp->dt_lib_path)); |
2278 dirp != NULL; dirp = dt_list_next(dirp)) { 2279 if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) { 2280 dtp->dt_cflags &= ~DTRACE_C_NOLIBS; 2281 return (-1); /* errno is set for us */ 2282 } 2283 } 2284 | 2324 dirp != NULL; dirp = dt_list_next(dirp)) { 2325 if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) { 2326 dtp->dt_cflags &= ~DTRACE_C_NOLIBS; 2327 return (-1); /* errno is set for us */ 2328 } 2329 } 2330 |
2331 /* Handle /usr/lib/dtrace */ 2332 dirp = dt_list_next(&dtp->dt_lib_path); 2333 if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) { 2334 dtp->dt_cflags &= ~DTRACE_C_NOLIBS; 2335 return (-1); /* errno is set for us */ 2336 } 2337 2338 if (dt_load_libs_sort(dtp) < 0) 2339 return (-1); /* errno is set for us */ 2340 |
|
2285 return (0); 2286} 2287 2288static void * 2289dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg, 2290 uint_t cflags, int argc, char *const argv[], FILE *fp, const char *s) 2291{ 2292 dt_node_t *dnp; --- 195 unchanged lines hidden --- | 2341 return (0); 2342} 2343 2344static void * 2345dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg, 2346 uint_t cflags, int argc, char *const argv[], FILE *fp, const char *s) 2347{ 2348 dt_node_t *dnp; --- 195 unchanged lines hidden --- |