Print this page
10812 ctf tools shouldn't add blank labels
10813 ctf symbol mapping needs work
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libctf/common/ctf_dwarf.c
          +++ new/usr/src/lib/libctf/common/ctf_dwarf.c
↓ open down ↓ 20 lines elided ↑ open up ↑
  21   21  /*
  22   22   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  /*
  26   26   * Copyright 2012 Jason King.  All rights reserved.
  27   27   * Use is subject to license terms.
  28   28   */
  29   29  
  30   30  /*
  31      - * Copyright 2018 Joyent, Inc.
       31 + * Copyright 2019 Joyent, Inc.
  32   32   */
  33   33  
  34   34  /*
  35   35   * CTF DWARF conversion theory.
  36   36   *
  37   37   * DWARF data contains a series of compilation units. Each compilation unit
  38   38   * generally refers to an object file or what once was, in the case of linked
  39   39   * binaries and shared objects. Each compilation unit has a series of what DWARF
  40   40   * calls a DIE (Debugging Information Entry). The set of entries that we care
  41   41   * about have type information stored in a series of attributes. Each DIE also
↓ open down ↓ 233 lines elided ↑ open up ↑
 275  275  
 276  276  static int ctf_dwarf_offset(ctf_cu_t *, Dwarf_Die, Dwarf_Off *);
 277  277  static int ctf_dwarf_convert_die(ctf_cu_t *, Dwarf_Die);
 278  278  static int ctf_dwarf_convert_type(ctf_cu_t *, Dwarf_Die, ctf_id_t *, int);
 279  279  
 280  280  static int ctf_dwarf_function_count(ctf_cu_t *, Dwarf_Die, ctf_funcinfo_t *,
 281  281      boolean_t);
 282  282  static int ctf_dwarf_convert_fargs(ctf_cu_t *, Dwarf_Die, ctf_funcinfo_t *,
 283  283      ctf_id_t *);
 284  284  
 285      -typedef int (ctf_dwarf_symtab_f)(ctf_cu_t *, const GElf_Sym *, ulong_t,
 286      -    const char *, const char *, void *);
 287      -
 288  285  /*
 289  286   * This is a generic way to set a CTF Conversion backend error depending on what
 290  287   * we were doing. Unless it was one of a specific set of errors that don't
 291  288   * indicate a programming / translation bug, eg. ENOMEM, then we transform it
 292  289   * into a CTF backend error and fill in the error buffer.
 293  290   */
 294  291  static int
 295  292  ctf_dwarf_error(ctf_cu_t *cup, ctf_file_t *cfp, int err, const char *fmt, ...)
 296  293  {
 297  294          va_list ap;
↓ open down ↓ 1861 lines elided ↑ open up ↑
2159 2156                  if (map->cdm_fix == B_FALSE)
2160 2157                          continue;
2161 2158                  if ((ret = ctf_dwarf_fixup_sou(cup, map->cdm_die, map->cdm_id,
2162 2159                      addpass)) != 0)
2163 2160                          return (ret);
2164 2161          }
2165 2162  
2166 2163          return (0);
2167 2164  }
2168 2165  
     2166 +/*
     2167 + * The DWARF information about a symbol and the information in the symbol table
     2168 + * may not be the same due to symbol reduction that is performed by ld due to a
     2169 + * mapfile or other such directive. We process weak symbols at a later time.
     2170 + *
     2171 + * The following are the rules that we employ:
     2172 + *
     2173 + * 1. A DWARF function that is considered exported matches STB_GLOBAL entries
     2174 + * with the same name.
     2175 + *
     2176 + * 2. A DWARF function that is considered exported matches STB_LOCAL entries
     2177 + * with the same name and the same file. This case may happen due to mapfile
     2178 + * reduction.
     2179 + *
     2180 + * 3. A DWARF function that is not considered exported matches STB_LOCAL entries
     2181 + * with the same name and the same file.
     2182 + *
     2183 + * 4. A DWARF function that has the same name as the symbol table entry, but the
     2184 + * files do not match. This is considered a 'fuzzy' match. This may also happen
     2185 + * due to a mapfile reduction. Fuzzy matching is only used when we know that the
     2186 + * file in question refers to the primary object. This is because when a symbol
     2187 + * is reduced in a mapfile, it's always going to be tagged as a local value in
     2188 + * the generated output and it is considered as to belong to the primary file
     2189 + * which is the first STT_FILE symbol we see.
     2190 + */
     2191 +static boolean_t
     2192 +ctf_dwarf_symbol_match(const char *symtab_file, const char *symtab_name,
     2193 +    uint_t symtab_bind, const char *dwarf_file, const char *dwarf_name,
     2194 +    boolean_t dwarf_global, boolean_t *is_fuzzy)
     2195 +{
     2196 +        *is_fuzzy = B_FALSE;
     2197 +
     2198 +        if (symtab_bind != STB_LOCAL && symtab_bind != STB_GLOBAL) {
     2199 +                return (B_FALSE);
     2200 +        }
     2201 +
     2202 +        if (strcmp(symtab_name, dwarf_name) != 0) {
     2203 +                return (B_FALSE);
     2204 +        }
     2205 +
     2206 +        if (symtab_bind == STB_GLOBAL) {
     2207 +                return (dwarf_global);
     2208 +        }
     2209 +
     2210 +        if (strcmp(symtab_file, dwarf_file) == 0) {
     2211 +                return (B_TRUE);
     2212 +        }
     2213 +
     2214 +        if (dwarf_global) {
     2215 +                *is_fuzzy = B_TRUE;
     2216 +                return (B_TRUE);
     2217 +        }
     2218 +
     2219 +        return (B_FALSE);
     2220 +}
     2221 +
2169 2222  static ctf_dwfunc_t *
2170 2223  ctf_dwarf_match_func(ctf_cu_t *cup, const char *file, const char *name,
2171      -    int bind)
     2224 +    uint_t bind, boolean_t primary)
2172 2225  {
2173      -        ctf_dwfunc_t *cdf;
     2226 +        ctf_dwfunc_t *cdf, *fuzzy = NULL;
2174 2227  
2175 2228          if (bind == STB_WEAK)
2176 2229                  return (NULL);
2177 2230  
2178      -        /* Nothing we can do if we can't find a name to compare it to. */
2179 2231          if (bind == STB_LOCAL && (file == NULL || cup->cu_name == NULL))
2180 2232                  return (NULL);
2181 2233  
2182 2234          for (cdf = ctf_list_next(&cup->cu_funcs); cdf != NULL;
2183 2235              cdf = ctf_list_next(cdf)) {
2184      -                if (bind == STB_GLOBAL && cdf->cdf_global == B_FALSE)
2185      -                        continue;
2186      -                if (bind == STB_LOCAL && cdf->cdf_global == B_TRUE)
2187      -                        continue;
2188      -                if (strcmp(name, cdf->cdf_name) != 0)
2189      -                        continue;
2190      -                if (bind == STB_LOCAL && strcmp(file, cup->cu_name) != 0)
2191      -                        continue;
2192      -                return (cdf);
     2236 +                boolean_t is_fuzzy = B_FALSE;
     2237 +
     2238 +                if (ctf_dwarf_symbol_match(file, name, bind, cup->cu_name,
     2239 +                    cdf->cdf_name, cdf->cdf_global, &is_fuzzy)) {
     2240 +                        if (is_fuzzy) {
     2241 +                                if (primary) {
     2242 +                                        fuzzy = cdf;
     2243 +                                }
     2244 +                                continue;
     2245 +                        } else {
     2246 +                                return (cdf);
     2247 +                        }
     2248 +                }
2193 2249          }
2194 2250  
2195      -        return (NULL);
     2251 +        return (fuzzy);
2196 2252  }
     2253 +
2197 2254  static ctf_dwvar_t *
2198 2255  ctf_dwarf_match_var(ctf_cu_t *cup, const char *file, const char *name,
2199      -    int bind)
     2256 +    uint_t bind, boolean_t primary)
2200 2257  {
2201      -        ctf_dwvar_t *cdv;
     2258 +        ctf_dwvar_t *cdv, *fuzzy = NULL;
2202 2259  
2203      -        /* Nothing we can do if we can't find a name to compare it to. */
     2260 +        if (bind == STB_WEAK)
     2261 +                return (NULL);
     2262 +
2204 2263          if (bind == STB_LOCAL && (file == NULL || cup->cu_name == NULL))
2205 2264                  return (NULL);
2206      -        ctf_dprintf("Still considering %s\n", name);
2207 2265  
2208 2266          for (cdv = ctf_list_next(&cup->cu_vars); cdv != NULL;
2209 2267              cdv = ctf_list_next(cdv)) {
2210      -                if (bind == STB_GLOBAL && cdv->cdv_global == B_FALSE)
2211      -                        continue;
2212      -                if (bind == STB_LOCAL && cdv->cdv_global == B_TRUE)
2213      -                        continue;
2214      -                if (strcmp(name, cdv->cdv_name) != 0)
2215      -                        continue;
2216      -                if (bind == STB_LOCAL && strcmp(file, cup->cu_name) != 0)
2217      -                        continue;
2218      -                return (cdv);
2219      -        }
     2268 +                boolean_t is_fuzzy = B_FALSE;
2220 2269  
2221      -        return (NULL);
2222      -}
2223      -
2224      -static int
2225      -ctf_dwarf_symtab_iter(ctf_cu_t *cup, ctf_dwarf_symtab_f *func, void *arg)
2226      -{
2227      -        int ret;
2228      -        ulong_t i;
2229      -        ctf_file_t *fp = cup->cu_ctfp;
2230      -        const char *file = NULL;
2231      -        uintptr_t symbase = (uintptr_t)fp->ctf_symtab.cts_data;
2232      -        uintptr_t strbase = (uintptr_t)fp->ctf_strtab.cts_data;
2233      -
2234      -        for (i = 0; i < fp->ctf_nsyms; i++) {
2235      -                const char *name;
2236      -                int type;
2237      -                GElf_Sym gsym;
2238      -                const GElf_Sym *gsymp;
2239      -
2240      -                if (fp->ctf_symtab.cts_entsize == sizeof (Elf32_Sym)) {
2241      -                        const Elf32_Sym *symp = (Elf32_Sym *)symbase + i;
2242      -                        type = ELF32_ST_TYPE(symp->st_info);
2243      -                        if (type == STT_FILE) {
2244      -                                file = (char *)(strbase + symp->st_name);
2245      -                                continue;
     2270 +                if (ctf_dwarf_symbol_match(file, name, bind, cup->cu_name,
     2271 +                    cdv->cdv_name, cdv->cdv_global, &is_fuzzy)) {
     2272 +                        if (is_fuzzy) {
     2273 +                                if (primary) {
     2274 +                                        fuzzy = cdv;
     2275 +                                }
     2276 +                        } else {
     2277 +                                return (cdv);
2246 2278                          }
2247      -                        if (type != STT_OBJECT && type != STT_FUNC)
2248      -                                continue;
2249      -                        if (ctf_sym_valid(strbase, type, symp->st_shndx,
2250      -                            symp->st_value, symp->st_name) == B_FALSE)
2251      -                                continue;
2252      -                        name = (char *)(strbase + symp->st_name);
2253      -                        gsym.st_name = symp->st_name;
2254      -                        gsym.st_value = symp->st_value;
2255      -                        gsym.st_size = symp->st_size;
2256      -                        gsym.st_info = symp->st_info;
2257      -                        gsym.st_other = symp->st_other;
2258      -                        gsym.st_shndx = symp->st_shndx;
2259      -                        gsymp = &gsym;
2260      -                } else {
2261      -                        const Elf64_Sym *symp = (Elf64_Sym *)symbase + i;
2262      -                        type = ELF64_ST_TYPE(symp->st_info);
2263      -                        if (type == STT_FILE) {
2264      -                                file = (char *)(strbase + symp->st_name);
2265      -                                continue;
2266      -                        }
2267      -                        if (type != STT_OBJECT && type != STT_FUNC)
2268      -                                continue;
2269      -                        if (ctf_sym_valid(strbase, type, symp->st_shndx,
2270      -                            symp->st_value, symp->st_name) == B_FALSE)
2271      -                                continue;
2272      -                        name = (char *)(strbase + symp->st_name);
2273      -                        gsymp = symp;
2274 2279                  }
2275      -
2276      -                ret = func(cup, gsymp, i, file, name, arg);
2277      -                if (ret != 0)
2278      -                        return (ret);
2279 2280          }
2280 2281  
2281      -        return (0);
     2282 +        return (fuzzy);
2282 2283  }
2283 2284  
2284 2285  static int
2285      -ctf_dwarf_conv_funcvars_cb(ctf_cu_t *cup, const GElf_Sym *symp, ulong_t idx,
2286      -    const char *file, const char *name, void *arg)
     2286 +ctf_dwarf_conv_funcvars_cb(const Elf64_Sym *symp, ulong_t idx,
     2287 +    const char *file, const char *name, boolean_t primary, void *arg)
2287 2288  {
2288      -        int ret, bind, type;
     2289 +        int ret;
     2290 +        uint_t bind, type;
     2291 +        ctf_cu_t *cup = arg;
2289 2292  
2290 2293          bind = GELF_ST_BIND(symp->st_info);
2291 2294          type = GELF_ST_TYPE(symp->st_info);
2292 2295  
2293 2296          /*
2294 2297           * Come back to weak symbols in another pass
2295 2298           */
2296 2299          if (bind == STB_WEAK)
2297 2300                  return (0);
2298 2301  
2299 2302          if (type == STT_OBJECT) {
2300 2303                  ctf_dwvar_t *cdv = ctf_dwarf_match_var(cup, file, name,
2301      -                    bind);
2302      -                ctf_dprintf("match for %s (%d): %p\n", name, idx, cdv);
     2304 +                    bind, primary);
2303 2305                  if (cdv == NULL)
2304 2306                          return (0);
2305 2307                  ret = ctf_add_object(cup->cu_ctfp, idx, cdv->cdv_type);
2306      -                ctf_dprintf("added object %s\n", name);
     2308 +                ctf_dprintf("added object %s->%ld\n", name, cdv->cdv_type);
2307 2309          } else {
2308 2310                  ctf_dwfunc_t *cdf = ctf_dwarf_match_func(cup, file, name,
2309      -                    bind);
     2311 +                    bind, primary);
2310 2312                  if (cdf == NULL)
2311 2313                          return (0);
2312 2314                  ret = ctf_add_function(cup->cu_ctfp, idx, &cdf->cdf_fip,
2313 2315                      cdf->cdf_argv);
     2316 +                ctf_dprintf("added function %s\n", name);
2314 2317          }
2315 2318  
2316 2319          if (ret == CTF_ERR) {
2317 2320                  return (ctf_errno(cup->cu_ctfp));
2318 2321          }
2319 2322  
2320 2323          return (0);
2321 2324  }
2322 2325  
2323 2326  static int
2324 2327  ctf_dwarf_conv_funcvars(ctf_cu_t *cup)
2325 2328  {
2326      -        return (ctf_dwarf_symtab_iter(cup, ctf_dwarf_conv_funcvars_cb, NULL));
     2329 +        return (ctf_symtab_iter(cup->cu_ctfp, ctf_dwarf_conv_funcvars_cb, cup));
2327 2330  }
2328 2331  
2329 2332  /*
2330 2333   * If we have a weak symbol, attempt to find the strong symbol it will resolve
2331 2334   * to.  Note: the code where this actually happens is in sym_process() in
2332 2335   * cmd/sgs/libld/common/syms.c
2333 2336   *
2334 2337   * Finding the matching symbol is unfortunately not trivial.  For a symbol to be
2335 2338   * a candidate, it must:
2336 2339   *
↓ open down ↓ 21 lines elided ↑ open up ↑
2358 2361   * that was scoped to local via a mapfile.  In the former case, curfile is
2359 2362   * likely inaccurate since the linker does not preserve the needed curfile in
2360 2363   * the order of the symbol table (see the comments about locally scoped symbols
2361 2364   * in libld's update_osym()).  As we can't tell this case from the former one,
2362 2365   * we use this symbol iff no other matching symbol is found.
2363 2366   *
2364 2367   * What we really need here is a SUNW section containing weak<->strong mappings
2365 2368   * that we can consume.
2366 2369   */
2367 2370  typedef struct ctf_dwarf_weak_arg {
2368      -        const GElf_Sym *cweak_symp;
     2371 +        const Elf64_Sym *cweak_symp;
2369 2372          const char *cweak_file;
2370 2373          boolean_t cweak_candidate;
2371 2374          ulong_t cweak_idx;
2372 2375  } ctf_dwarf_weak_arg_t;
2373 2376  
2374 2377  static int
2375      -ctf_dwarf_conv_check_weak(ctf_cu_t *cup, const GElf_Sym *symp,
2376      -    ulong_t idx, const char *file, const char *name, void *arg)
     2378 +ctf_dwarf_conv_check_weak(const Elf64_Sym *symp, ulong_t idx, const char *file,
     2379 +    const char *name, boolean_t primary, void *arg)
2377 2380  {
2378 2381          ctf_dwarf_weak_arg_t *cweak = arg;
2379      -        const GElf_Sym *wsymp = cweak->cweak_symp;
2380 2382  
     2383 +        const Elf64_Sym *wsymp = cweak->cweak_symp;
     2384 +
2381 2385          ctf_dprintf("comparing weak to %s\n", name);
2382 2386  
2383 2387          if (GELF_ST_BIND(symp->st_info) == STB_WEAK) {
2384 2388                  return (0);
2385 2389          }
2386 2390  
2387 2391          if (GELF_ST_TYPE(wsymp->st_info) != GELF_ST_TYPE(symp->st_info)) {
2388 2392                  return (0);
2389 2393          }
2390 2394  
↓ open down ↓ 78 lines elided ↑ open up ↑
2469 2473          ret = ctf_add_function(cup->cu_ctfp, idx, &fip, args);
2470 2474          if (args != NULL)
2471 2475                  ctf_free(args, sizeof (ctf_id_t) * fip.ctc_argc);
2472 2476          if (ret == CTF_ERR)
2473 2477                  return (ctf_errno(cup->cu_ctfp));
2474 2478  
2475 2479          return (0);
2476 2480  }
2477 2481  
2478 2482  static int
2479      -ctf_dwarf_conv_weaks_cb(ctf_cu_t *cup, const GElf_Sym *symp,
2480      -    ulong_t idx, const char *file, const char *name, void *arg)
     2483 +ctf_dwarf_conv_weaks_cb(const Elf64_Sym *symp, ulong_t idx, const char *file,
     2484 +    const char *name, boolean_t primary, void *arg)
2481 2485  {
2482 2486          int ret, type;
2483 2487          ctf_dwarf_weak_arg_t cweak;
     2488 +        ctf_cu_t *cup = arg;
2484 2489  
2485 2490          /*
2486 2491           * We only care about weak symbols.
2487 2492           */
2488 2493          if (GELF_ST_BIND(symp->st_info) != STB_WEAK)
2489 2494                  return (0);
2490 2495  
2491 2496          type = GELF_ST_TYPE(symp->st_info);
2492 2497          ASSERT(type == STT_OBJECT || type == STT_FUNC);
2493 2498  
↓ open down ↓ 2 lines elided ↑ open up ↑
2496 2501           * to try and find a match. We should probably think about other
2497 2502           * techniques to try and save us time in the future.
2498 2503           */
2499 2504          cweak.cweak_symp = symp;
2500 2505          cweak.cweak_file = file;
2501 2506          cweak.cweak_candidate = B_FALSE;
2502 2507          cweak.cweak_idx = 0;
2503 2508  
2504 2509          ctf_dprintf("Trying to find weak equiv for %s\n", name);
2505 2510  
2506      -        ret = ctf_dwarf_symtab_iter(cup, ctf_dwarf_conv_check_weak, &cweak);
     2511 +        ret = ctf_symtab_iter(cup->cu_ctfp, ctf_dwarf_conv_check_weak, &cweak);
2507 2512          VERIFY(ret == 0 || ret == 1);
2508 2513  
2509 2514          /*
2510 2515           * Nothing was ever found, we're not going to add anything for this
2511 2516           * entry.
2512 2517           */
2513 2518          if (ret == 0 && cweak.cweak_candidate == B_FALSE) {
2514 2519                  ctf_dprintf("found no weak match for %s\n", name);
2515 2520                  return (0);
2516 2521          }
2517 2522  
2518 2523          /*
2519 2524           * Now, finally go and add the type based on the match.
2520 2525           */
     2526 +        ctf_dprintf("matched weak symbol %lu to %lu\n", idx, cweak.cweak_idx);
2521 2527          if (type == STT_OBJECT) {
2522 2528                  ret = ctf_dwarf_duplicate_sym(cup, idx, cweak.cweak_idx);
2523 2529          } else {
2524 2530                  ret = ctf_dwarf_duplicate_func(cup, idx, cweak.cweak_idx);
2525 2531          }
2526 2532  
2527 2533          return (ret);
2528 2534  }
2529 2535  
2530 2536  static int
2531 2537  ctf_dwarf_conv_weaks(ctf_cu_t *cup)
2532 2538  {
2533      -        return (ctf_dwarf_symtab_iter(cup, ctf_dwarf_conv_weaks_cb, NULL));
     2539 +        return (ctf_symtab_iter(cup->cu_ctfp, ctf_dwarf_conv_weaks_cb, cup));
2534 2540  }
2535 2541  
2536 2542  /* ARGSUSED */
2537 2543  static int
2538 2544  ctf_dwarf_convert_one(void *arg, void *unused)
2539 2545  {
2540 2546          int ret;
2541 2547          ctf_file_t *dedup;
2542 2548          ctf_cu_t *cup = arg;
2543 2549  
↓ open down ↓ 50 lines elided ↑ open up ↑
2594 2600                          return (ctf_dwarf_error(cup, NULL, ret,
2595 2601                              "failed to convert weak functions and variables"));
2596 2602                  }
2597 2603  
2598 2604                  if (ctf_update(cup->cu_ctfp) != 0) {
2599 2605                          return (ctf_dwarf_error(cup, cup->cu_ctfp, 0,
2600 2606                              "failed to update output ctf container"));
2601 2607                  }
2602 2608          }
2603 2609  
2604      -        ctf_phase_dump(cup->cu_ctfp, "pre-dedup");
     2610 +        ctf_phase_dump(cup->cu_ctfp, "pre-dwarf-dedup", cup->cu_name);
2605 2611          ctf_dprintf("adding inputs for dedup\n");
2606 2612          if ((ret = ctf_merge_add(cup->cu_cmh, cup->cu_ctfp)) != 0) {
2607 2613                  return (ctf_dwarf_error(cup, NULL, ret,
2608 2614                      "failed to add inputs for merge"));
2609 2615          }
2610 2616  
2611      -        ctf_dprintf("starting merge\n");
     2617 +        ctf_dprintf("starting dedup of %s\n", cup->cu_name);
2612 2618          if ((ret = ctf_merge_dedup(cup->cu_cmh, &dedup)) != 0) {
2613 2619                  return (ctf_dwarf_error(cup, NULL, ret,
2614 2620                      "failed to deduplicate die"));
2615 2621          }
2616 2622          ctf_close(cup->cu_ctfp);
2617 2623          cup->cu_ctfp = dedup;
     2624 +        ctf_phase_dump(cup->cu_ctfp, "post-dwarf-dedup", cup->cu_name);
2618 2625  
2619 2626          return (0);
2620 2627  }
2621 2628  
2622 2629  /*
2623 2630   * Note, we expect that if we're returning a ctf_file_t from one of the dies,
2624 2631   * say in the single node case, it's been saved and the entry here has been set
2625 2632   * to NULL, which ctf_close happily ignores.
2626 2633   */
2627 2634  static void
↓ open down ↓ 269 lines elided ↑ open up ↑
2897 2904                              dwarf_errmsg(derr));
2898 2905                          *errp = ECTF_CONVBKERR;
2899 2906                          return (CTF_CONV_ERROR);
2900 2907                  }
2901 2908  
2902 2909                  ret = ctf_dwarf_init_die(fd, elf, &cdies[i], i, errmsg, errlen);
2903 2910                  if (ret != 0) {
2904 2911                          *errp = ret;
2905 2912                          goto out;
2906 2913                  }
     2914 +
2907 2915                  cup->cu_doweaks = ndies > 1 ? B_FALSE : B_TRUE;
2908 2916          }
2909 2917  
2910      -        ctf_dprintf("found %d DWARF die(s)\n", ndies);
     2918 +        ctf_dprintf("found %d DWARF CUs\n", ndies);
2911 2919  
2912 2920          /*
2913 2921           * If we only have one compilation unit, there's no reason to use
2914 2922           * multiple threads, even if the user requested them. After all, they
2915 2923           * just gave us an upper bound.
2916 2924           */
2917 2925          if (ndies == 1)
2918 2926                  nthrs = 1;
2919 2927  
2920 2928          if (workq_init(&wqp, nthrs) == -1) {
2921 2929                  *errp = errno;
2922 2930                  goto out;
2923 2931          }
2924 2932  
2925 2933          for (i = 0; i < ndies; i++) {
2926 2934                  cup = &cdies[i];
2927      -                ctf_dprintf("adding die %s: %p, %x %x\n", cup->cu_name,
     2935 +                ctf_dprintf("adding cu %s: %p, %x %x\n", cup->cu_name,
2928 2936                      cup->cu_cu, cup->cu_cuoff, cup->cu_maxoff);
2929 2937                  if (workq_add(wqp, cup) == -1) {
2930 2938                          *errp = errno;
2931 2939                          goto out;
2932 2940                  }
2933 2941          }
2934 2942  
2935 2943          ret = workq_work(wqp, ctf_dwarf_convert_one, NULL, errp);
2936 2944          if (ret == WORKQ_ERROR) {
2937 2945                  *errp = errno;
2938 2946                  goto out;
2939 2947          } else if (ret == WORKQ_UERROR) {
2940 2948                  ctf_dprintf("internal convert failed: %s\n",
2941 2949                      ctf_errmsg(*errp));
2942 2950                  goto out;
2943 2951          }
2944 2952  
2945      -        ctf_dprintf("Determining next phase: have %d dies\n", ndies);
     2953 +        ctf_dprintf("Determining next phase: have %d CUs\n", ndies);
2946 2954          if (ndies != 1) {
2947 2955                  ctf_merge_t *cmp;
2948 2956  
2949 2957                  cmp = ctf_merge_init(fd, &ret);
2950 2958                  if (cmp == NULL) {
2951 2959                          *errp = ret;
2952 2960                          goto out;
2953 2961                  }
2954 2962  
2955 2963                  ctf_dprintf("setting threads\n");
2956 2964                  if ((ret = ctf_merge_set_nthreads(cmp, nthrs)) != 0) {
2957 2965                          ctf_merge_fini(cmp);
2958 2966                          *errp = ret;
2959 2967                          goto out;
2960 2968                  }
2961 2969  
2962      -                ctf_dprintf("adding dies\n");
2963 2970                  for (i = 0; i < ndies; i++) {
2964 2971                          cup = &cdies[i];
     2972 +                        ctf_dprintf("adding cu %s (%p)\n", cup->cu_name,
     2973 +                            cup->cu_ctfp);
2965 2974                          if ((ret = ctf_merge_add(cmp, cup->cu_ctfp)) != 0) {
2966 2975                                  ctf_merge_fini(cmp);
2967 2976                                  *errp = ret;
2968 2977                                  goto out;
2969 2978                          }
2970 2979                  }
2971 2980  
2972 2981                  ctf_dprintf("performing merge\n");
2973 2982                  ret = ctf_merge_merge(cmp, fpp);
2974 2983                  if (ret != 0) {
↓ open down ↓ 21 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX