GNU Binutils with patches for OS216
Revisión | 2f6ecaed667d1597c67991224948e0a3da427cc9 (tree) |
---|---|
Tiempo | 2020-06-26 23:56:39 |
Autor | Nick Alcock <nick.alcock@orac...> |
Commiter | Nick Alcock |
libctf, binutils: support CTF archives like objdump
objdump and readelf have one major CTF-related behavioural difference:
objdump can read .ctf sections that contain CTF archives and extract and
dump their members, while readelf cannot. Since the linker often emits
CTF archives, this means that readelf intermittently and (from the
user's perspective) randomly fails to read CTF in files that ld emits,
with a confusing error message wrongly claiming that the CTF content is
corrupt. This is purely because the archive-opening code in libctf was
needlessly tangled up with the BFD code, so readelf couldn't use it.
Here, we disentangle it, moving ctf_new_archive_internal from
ctf-open-bfd.c into ctf-archive.c and merging it with the helper
function in ctf-archive.c it was already using. We add a new public API
function ctf_arc_bufopen, that looks very like ctf_bufopen but returns
an archive given suitable section data rather than a ctf_file_t: the
archive is a ctf_archive_t, so it can be called on raw CTF dictionaries
(with no archive present) and will return a single-member synthetic
"archive".
There is a tiny lifetime tweak here: before now, the archive code could
assume that the symbol section in the ctf_archive_internal wrapper
structure was always owned by BFD if it was present and should always be
freed: now, the caller can pass one in via ctf_arc_bufopen, wihch has
the usual lifetime rules for such sections (caller frees): so we add an
extra field to track whether this is an internal call from ctf-open-bfd,
in which case we still free the symbol section.
include/
* ctf-api.h (ctf_arc_bufopen): New.
libctf/
* ctf-impl.h (ctf_new_archive_internal): Declare.
(ctf_arc_bufopen): Remove.
(ctf_archive_internal) <ctfi_free_symsect>: New.
* ctf-archive.c (ctf_arc_close): Use it.
(ctf_arc_bufopen): Fuse into...
(ctf_new_archive_internal): ... this, moved across from...
* ctf-open-bfd.c: ... here.
(ctf_bfdopen_ctfsect): Use ctf_arc_bufopen.
* libctf.ver: Add it.
binutils/
* readelf.c (dump_section_as_ctf): Support .ctf archives using
ctf_arc_bufopen. Automatically load the .ctf member of such
archives as the parent of all other members, unless specifically
overridden via --ctf-parent. Split out dumping code into...
(dump_ctf_archive_member): ... here, as in objdump, and call
it once per archive member.
(dump_ctf_indent_lines): Code style fix.
@@ -1,5 +1,15 @@ | ||
1 | 1 | 2020-06-26 Nick Alcock <nick.alcock@oracle.com> |
2 | 2 | |
3 | + * readelf.c (dump_section_as_ctf): Support .ctf archives using | |
4 | + ctf_arc_bufopen. Automatically load the .ctf member of such | |
5 | + archives as the parent of all other members, unless specifically | |
6 | + overridden via --ctf-parent. Split out dumping code into... | |
7 | + (dump_ctf_archive_member): ... here, as in objdump, and call | |
8 | + it once per archive member. | |
9 | + (dump_ctf_indent_lines): Code style fix. | |
10 | + | |
11 | +2020-06-26 Nick Alcock <nick.alcock@oracle.com> | |
12 | + | |
3 | 13 | * configure.ac [--enable-libctf]: New, default yes. |
4 | 14 | Set ENABLE_LIBCTF accordingly. |
5 | 15 | * Makefile.am [!ENABLE_LIBCTF]: Empty LIBCTF and LIBCTF_NOBFD. |
@@ -14151,8 +14151,9 @@ shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata) | ||
14151 | 14151 | it is passed, or a pointer to newly-allocated storage, in which case |
14152 | 14152 | dump_ctf() will free it when it no longer needs it. */ |
14153 | 14153 | |
14154 | -static char *dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, | |
14155 | - char *s, void *arg) | |
14154 | +static char * | |
14155 | +dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, | |
14156 | + char *s, void *arg) | |
14156 | 14157 | { |
14157 | 14158 | const char *blanks = arg; |
14158 | 14159 | char *new_s; |
@@ -14162,6 +14163,55 @@ static char *dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, | ||
14162 | 14163 | return new_s; |
14163 | 14164 | } |
14164 | 14165 | |
14166 | +/* Dump one CTF archive member. */ | |
14167 | + | |
14168 | +static int | |
14169 | +dump_ctf_archive_member (ctf_file_t *ctf, const char *name, void *arg) | |
14170 | +{ | |
14171 | + ctf_file_t *parent = (ctf_file_t *) arg; | |
14172 | + const char *things[] = {"Header", "Labels", "Data objects", | |
14173 | + "Function objects", "Variables", "Types", "Strings", | |
14174 | + ""}; | |
14175 | + const char **thing; | |
14176 | + size_t i; | |
14177 | + | |
14178 | + /* Only print out the name of non-default-named archive members. | |
14179 | + The name .ctf appears everywhere, even for things that aren't | |
14180 | + really archives, so printing it out is liable to be confusing. | |
14181 | + | |
14182 | + The parent, if there is one, is the default-owned archive member: | |
14183 | + avoid importing it into itself. (This does no harm, but looks | |
14184 | + confusing.) */ | |
14185 | + | |
14186 | + if (strcmp (name, ".ctf") != 0) | |
14187 | + { | |
14188 | + printf (_("\nCTF archive member: %s:\n"), name); | |
14189 | + ctf_import (ctf, parent); | |
14190 | + } | |
14191 | + | |
14192 | + for (i = 0, thing = things; *thing[0]; thing++, i++) | |
14193 | + { | |
14194 | + ctf_dump_state_t *s = NULL; | |
14195 | + char *item; | |
14196 | + | |
14197 | + printf ("\n %s:\n", *thing); | |
14198 | + while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines, | |
14199 | + (void *) " ")) != NULL) | |
14200 | + { | |
14201 | + printf ("%s\n", item); | |
14202 | + free (item); | |
14203 | + } | |
14204 | + | |
14205 | + if (ctf_errno (ctf)) | |
14206 | + { | |
14207 | + error (_("Iteration failed: %s, %s\n"), *thing, | |
14208 | + ctf_errmsg (ctf_errno (ctf))); | |
14209 | + return 1; | |
14210 | + } | |
14211 | + } | |
14212 | + return 0; | |
14213 | +} | |
14214 | + | |
14165 | 14215 | static bfd_boolean |
14166 | 14216 | dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) |
14167 | 14217 | { |
@@ -14175,16 +14225,12 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) | ||
14175 | 14225 | ctf_sect_t ctfsect, symsect, strsect, parentsect; |
14176 | 14226 | ctf_sect_t * symsectp = NULL; |
14177 | 14227 | ctf_sect_t * strsectp = NULL; |
14178 | - ctf_file_t * ctf = NULL; | |
14179 | - ctf_file_t * parent = NULL; | |
14228 | + ctf_archive_t * ctfa = NULL; | |
14229 | + ctf_archive_t * parenta = NULL, *lookparent; | |
14230 | + ctf_file_t * parent = NULL; | |
14180 | 14231 | |
14181 | - const char *things[] = {"Header", "Labels", "Data objects", | |
14182 | - "Function objects", "Variables", "Types", "Strings", | |
14183 | - ""}; | |
14184 | - const char **thing; | |
14185 | 14232 | int err; |
14186 | 14233 | bfd_boolean ret = FALSE; |
14187 | - size_t i; | |
14188 | 14234 | |
14189 | 14235 | shdr_to_ctf_sect (&ctfsect, section, filedata); |
14190 | 14236 | data = get_section_contents (section, filedata); |
@@ -14243,9 +14289,11 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) | ||
14243 | 14289 | parentsect.cts_data = parentdata; |
14244 | 14290 | } |
14245 | 14291 | |
14246 | - /* Load the CTF file and dump it. */ | |
14292 | + /* Load the CTF file and dump it. It may be a raw CTF section, or an archive: | |
14293 | + libctf papers over the difference, so we can pretend it is always an | |
14294 | + archive. Possibly open the parent as well, if one was specified. */ | |
14247 | 14295 | |
14248 | - if ((ctf = ctf_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL) | |
14296 | + if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL) | |
14249 | 14297 | { |
14250 | 14298 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); |
14251 | 14299 | goto fail; |
@@ -14253,13 +14301,24 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) | ||
14253 | 14301 | |
14254 | 14302 | if (parentdata) |
14255 | 14303 | { |
14256 | - if ((parent = ctf_bufopen (&parentsect, symsectp, strsectp, &err)) == NULL) | |
14304 | + if ((parenta = ctf_arc_bufopen (&parentsect, symsectp, strsectp, | |
14305 | + &err)) == NULL) | |
14257 | 14306 | { |
14258 | 14307 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); |
14259 | 14308 | goto fail; |
14260 | 14309 | } |
14310 | + lookparent = parenta; | |
14311 | + } | |
14312 | + else | |
14313 | + lookparent = ctfa; | |
14261 | 14314 | |
14262 | - ctf_import (ctf, parent); | |
14315 | + /* Assume that the applicable parent archive member is the default one. | |
14316 | + (This is what all known implementations are expected to do, if they | |
14317 | + put CTFs and their parents in archives together.) */ | |
14318 | + if ((parent = ctf_arc_open_by_name (lookparent, NULL, &err)) == NULL) | |
14319 | + { | |
14320 | + error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
14321 | + goto fail; | |
14263 | 14322 | } |
14264 | 14323 | |
14265 | 14324 | ret = TRUE; |
@@ -14267,30 +14326,13 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) | ||
14267 | 14326 | printf (_("\nDump of CTF section '%s':\n"), |
14268 | 14327 | printable_section_name (filedata, section)); |
14269 | 14328 | |
14270 | - for (i = 0, thing = things; *thing[0]; thing++, i++) | |
14271 | - { | |
14272 | - ctf_dump_state_t *s = NULL; | |
14273 | - char *item; | |
14274 | - | |
14275 | - printf ("\n %s:\n", *thing); | |
14276 | - while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines, | |
14277 | - (void *) " ")) != NULL) | |
14278 | - { | |
14279 | - printf ("%s\n", item); | |
14280 | - free (item); | |
14281 | - } | |
14282 | - | |
14283 | - if (ctf_errno (ctf)) | |
14284 | - { | |
14285 | - error (_("Iteration failed: %s, %s\n"), *thing, | |
14286 | - ctf_errmsg (ctf_errno (ctf))); | |
14287 | - ret = FALSE; | |
14288 | - } | |
14289 | - } | |
14329 | + if (ctf_archive_iter (ctfa, dump_ctf_archive_member, parent) != 0) | |
14330 | + ret = FALSE; | |
14290 | 14331 | |
14291 | 14332 | fail: |
14292 | - ctf_file_close (ctf); | |
14293 | 14333 | ctf_file_close (parent); |
14334 | + ctf_close (ctfa); | |
14335 | + ctf_close (parenta); | |
14294 | 14336 | free (parentdata); |
14295 | 14337 | free (data); |
14296 | 14338 | free (symdata); |
@@ -1,3 +1,7 @@ | ||
1 | +2020-06-26 Nick Alcock <nick.alcock@oracle.com> | |
2 | + | |
3 | + * ctf-api.h (ctf_arc_bufopen): New. | |
4 | + | |
1 | 5 | 2020-06-26 Pat Bernardi <bernardi@adacore.com> |
2 | 6 | |
3 | 7 | * elf/m68k.h: Add enum for GNU object attribute with floating point |
@@ -263,6 +263,10 @@ extern void ctf_close (ctf_archive_t *); | ||
263 | 263 | extern ctf_sect_t ctf_getdatasect (const ctf_file_t *); |
264 | 264 | extern ctf_archive_t *ctf_get_arc (const ctf_file_t *); |
265 | 265 | extern ctf_archive_t *ctf_arc_open (const char *, int *); |
266 | +extern ctf_archive_t *ctf_arc_bufopen (const ctf_sect_t *, | |
267 | + const ctf_sect_t *, | |
268 | + const ctf_sect_t *, | |
269 | + int *); | |
266 | 270 | extern void ctf_arc_close (ctf_archive_t *); |
267 | 271 | extern ctf_file_t *ctf_arc_open_by_name (const ctf_archive_t *, |
268 | 272 | const char *, int *); |
@@ -1,5 +1,17 @@ | ||
1 | 1 | 2020-06-26 Nick Alcock <nick.alcock@oracle.com> |
2 | 2 | |
3 | + * ctf-impl.h (ctf_new_archive_internal): Declare. | |
4 | + (ctf_arc_bufopen): Remove. | |
5 | + (ctf_archive_internal) <ctfi_free_symsect>: New. | |
6 | + * ctf-archive.c (ctf_arc_close): Use it. | |
7 | + (ctf_arc_bufopen): Fuse into... | |
8 | + (ctf_new_archive_internal): ... this, moved across from... | |
9 | + * ctf-open-bfd.c: ... here. | |
10 | + (ctf_bfdopen_ctfsect): Use ctf_arc_bufopen. | |
11 | + * libctf.ver: Add it. | |
12 | + | |
13 | +2020-06-26 Nick Alcock <nick.alcock@oracle.com> | |
14 | + | |
3 | 15 | * ctf-create.c (ctf_add_forward): Intern in the right namespace. |
4 | 16 | (ctf_dtd_delete): Remove correspondingly. |
5 | 17 | (ctf_rollback): Likewise. |
@@ -343,21 +343,71 @@ search_modent_by_name (const void *key, const void *ent) | ||
343 | 343 | return strcmp (k, &search_nametbl[le64toh (v->name_offset)]); |
344 | 344 | } |
345 | 345 | |
346 | -/* A trivial wrapper: open a CTF archive, from data in a buffer (which the | |
347 | - caller must preserve until ctf_arc_close() time). Returns the archive, or | |
348 | - NULL and an error in *err (if not NULL). */ | |
349 | -struct ctf_archive * | |
350 | -ctf_arc_bufopen (const void *buf, size_t size _libctf_unused_, int *errp) | |
346 | +/* Make a new struct ctf_archive_internal wrapper for a ctf_archive or a | |
347 | + ctf_file. Closes ARC and/or FP on error. Arrange to free the SYMSECT or | |
348 | + STRSECT, as needed, on close. */ | |
349 | + | |
350 | +struct ctf_archive_internal * | |
351 | +ctf_new_archive_internal (int is_archive, struct ctf_archive *arc, | |
352 | + ctf_file_t *fp, const ctf_sect_t *symsect, | |
353 | + const ctf_sect_t *strsect, | |
354 | + int *errp) | |
351 | 355 | { |
352 | - struct ctf_archive *arc = (struct ctf_archive *) buf; | |
356 | + struct ctf_archive_internal *arci; | |
353 | 357 | |
354 | - if (le64toh (arc->ctfa_magic) != CTFA_MAGIC) | |
358 | + if ((arci = calloc (1, sizeof (struct ctf_archive_internal))) == NULL) | |
355 | 359 | { |
356 | - if (errp) | |
357 | - *errp = ECTF_FMT; | |
358 | - return NULL; | |
360 | + if (is_archive) | |
361 | + ctf_arc_close_internal (arc); | |
362 | + else | |
363 | + ctf_file_close (fp); | |
364 | + return (ctf_set_open_errno (errp, errno)); | |
359 | 365 | } |
360 | - return arc; | |
366 | + arci->ctfi_is_archive = is_archive; | |
367 | + if (is_archive) | |
368 | + arci->ctfi_archive = arc; | |
369 | + else | |
370 | + arci->ctfi_file = fp; | |
371 | + if (symsect) | |
372 | + memcpy (&arci->ctfi_symsect, symsect, sizeof (struct ctf_sect)); | |
373 | + if (strsect) | |
374 | + memcpy (&arci->ctfi_strsect, strsect, sizeof (struct ctf_sect)); | |
375 | + arci->ctfi_free_symsect = 0; | |
376 | + | |
377 | + return arci; | |
378 | +} | |
379 | + | |
380 | +/* Open a CTF archive or dictionary from data in a buffer (which the caller must | |
381 | + preserve until ctf_arc_close() time). Returns the archive, or NULL and an | |
382 | + error in *err (if not NULL). */ | |
383 | +ctf_archive_t * | |
384 | +ctf_arc_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect, | |
385 | + const ctf_sect_t *strsect, int *errp) | |
386 | +{ | |
387 | + struct ctf_archive *arc = NULL; | |
388 | + int is_archive; | |
389 | + ctf_file_t *fp = NULL; | |
390 | + | |
391 | + if (ctfsect->cts_size > sizeof (uint64_t) && | |
392 | + ((*(uint64_t *) ctfsect->cts_data) == CTFA_MAGIC)) | |
393 | + { | |
394 | + /* The archive is mmappable, so this operation is trivial. */ | |
395 | + | |
396 | + is_archive = 1; | |
397 | + arc = (struct ctf_archive *) ctfsect->cts_data; | |
398 | + } | |
399 | + else | |
400 | + { | |
401 | + is_archive = 0; | |
402 | + if ((fp = ctf_bufopen (ctfsect, symsect, strsect, errp)) == NULL) | |
403 | + { | |
404 | + ctf_dprintf ("ctf_internal_open(): cannot open CTF: %s\n", | |
405 | + ctf_errmsg (*errp)); | |
406 | + return NULL; | |
407 | + } | |
408 | + } | |
409 | + return ctf_new_archive_internal (is_archive, arc, fp, symsect, strsect, | |
410 | + errp); | |
361 | 411 | } |
362 | 412 | |
363 | 413 | /* Open a CTF archive. Returns the archive, or NULL and an error in *err (if |
@@ -436,8 +486,8 @@ ctf_arc_close (ctf_archive_t *arc) | ||
436 | 486 | ctf_arc_close_internal (arc->ctfi_archive); |
437 | 487 | else |
438 | 488 | ctf_file_close (arc->ctfi_file); |
439 | - free ((void *) arc->ctfi_symsect.cts_data); | |
440 | - /* Do not free the ctfi_strsect: it is bound to the bfd. */ | |
489 | + if (arc->ctfi_free_symsect) | |
490 | + free ((void *) arc->ctfi_symsect.cts_data); | |
441 | 491 | free (arc->ctfi_data); |
442 | 492 | if (arc->ctfi_bfd_close) |
443 | 493 | arc->ctfi_bfd_close (arc); |
@@ -309,6 +309,7 @@ struct ctf_archive_internal | ||
309 | 309 | struct ctf_archive *ctfi_archive; |
310 | 310 | ctf_sect_t ctfi_symsect; |
311 | 311 | ctf_sect_t ctfi_strsect; |
312 | + int ctfi_free_symsect; | |
312 | 313 | void *ctfi_data; |
313 | 314 | bfd *ctfi_abfd; /* Optional source of section data. */ |
314 | 315 | void (*ctfi_bfd_close) (struct ctf_archive_internal *); |
@@ -435,8 +436,11 @@ extern void ctf_str_rollback (ctf_file_t *, ctf_snapshot_id_t); | ||
435 | 436 | extern void ctf_str_purge_refs (ctf_file_t *); |
436 | 437 | extern ctf_strs_writable_t ctf_str_write_strtab (ctf_file_t *); |
437 | 438 | |
439 | +extern struct ctf_archive_internal *ctf_new_archive_internal | |
440 | + (int is_archive, struct ctf_archive *arc, | |
441 | + ctf_file_t *fp, const ctf_sect_t *symsect, | |
442 | + const ctf_sect_t *strsect, int *errp); | |
438 | 443 | extern struct ctf_archive *ctf_arc_open_internal (const char *, int *); |
439 | -extern struct ctf_archive *ctf_arc_bufopen (const void *, size_t, int *); | |
440 | 444 | extern void ctf_arc_close_internal (struct ctf_archive *); |
441 | 445 | extern void *ctf_set_open_errno (int *, int); |
442 | 446 | extern unsigned long ctf_set_errno (ctf_file_t *, int); |
@@ -32,40 +32,6 @@ | ||
32 | 32 | |
33 | 33 | #include "elf-bfd.h" |
34 | 34 | |
35 | -/* Make a new struct ctf_archive_internal wrapper for a ctf_archive or a | |
36 | - ctf_file. Closes ARC and/or FP on error. Arrange to free the SYMSECT or | |
37 | - STRSECT, as needed, on close (though the STRSECT interior is bound to the bfd | |
38 | - * and is not actually freed by this machinery). */ | |
39 | - | |
40 | -static struct ctf_archive_internal * | |
41 | -ctf_new_archive_internal (int is_archive, struct ctf_archive *arc, | |
42 | - ctf_file_t *fp, const ctf_sect_t *symsect, | |
43 | - const ctf_sect_t *strsect, | |
44 | - int *errp) | |
45 | -{ | |
46 | - struct ctf_archive_internal *arci; | |
47 | - | |
48 | - if ((arci = calloc (1, sizeof (struct ctf_archive_internal))) == NULL) | |
49 | - { | |
50 | - if (is_archive) | |
51 | - ctf_arc_close_internal (arc); | |
52 | - else | |
53 | - ctf_file_close (fp); | |
54 | - return (ctf_set_open_errno (errp, errno)); | |
55 | - } | |
56 | - arci->ctfi_is_archive = is_archive; | |
57 | - if (is_archive) | |
58 | - arci->ctfi_archive = arc; | |
59 | - else | |
60 | - arci->ctfi_file = fp; | |
61 | - if (symsect) | |
62 | - memcpy (&arci->ctfi_symsect, symsect, sizeof (struct ctf_sect)); | |
63 | - if (strsect) | |
64 | - memcpy (&arci->ctfi_strsect, strsect, sizeof (struct ctf_sect)); | |
65 | - | |
66 | - return arci; | |
67 | -} | |
68 | - | |
69 | 35 | /* Free the BFD bits of a CTF file on ctf_arc_close(). */ |
70 | 36 | |
71 | 37 | static void |
@@ -107,6 +73,7 @@ ctf_bfdopen (struct bfd *abfd, int *errp) | ||
107 | 73 | |
108 | 74 | if ((arc = ctf_bfdopen_ctfsect (abfd, &ctfsect, errp)) != NULL) |
109 | 75 | { |
76 | + /* This frees the cts_data later. */ | |
110 | 77 | arc->ctfi_data = (void *) ctfsect.cts_data; |
111 | 78 | return arc; |
112 | 79 | } |
@@ -116,20 +83,16 @@ ctf_bfdopen (struct bfd *abfd, int *errp) | ||
116 | 83 | } |
117 | 84 | |
118 | 85 | /* Open a CTF file given the specified BFD and CTF section (which may contain a |
119 | - CTF archive or a file). Takes ownership of the ctfsect, and frees it | |
120 | - later. */ | |
86 | + CTF archive or a file). */ | |
121 | 87 | |
122 | 88 | ctf_archive_t * |
123 | 89 | ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_, |
124 | 90 | const ctf_sect_t *ctfsect, int *errp) |
125 | 91 | { |
126 | - struct ctf_archive *arc = NULL; | |
127 | 92 | ctf_archive_t *arci; |
128 | - ctf_file_t *fp = NULL; | |
129 | 93 | ctf_sect_t *symsectp = NULL; |
130 | 94 | ctf_sect_t *strsectp = NULL; |
131 | 95 | const char *bfderrstr = NULL; |
132 | - int is_archive; | |
133 | 96 | |
134 | 97 | #ifdef HAVE_BFD_ELF |
135 | 98 | ctf_sect_t symsect, strsect; |
@@ -192,30 +155,13 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_, | ||
192 | 155 | } |
193 | 156 | #endif |
194 | 157 | |
195 | - if (ctfsect->cts_size > sizeof (uint64_t) && | |
196 | - ((*(uint64_t *) ctfsect->cts_data) == CTFA_MAGIC)) | |
197 | - { | |
198 | - is_archive = 1; | |
199 | - if ((arc = ctf_arc_bufopen ((void *) ctfsect->cts_data, | |
200 | - ctfsect->cts_size, errp)) == NULL) | |
201 | - goto err_free_str; | |
202 | - } | |
203 | - else | |
158 | + arci = ctf_arc_bufopen (ctfsect, symsectp, strsectp, errp); | |
159 | + if (arci) | |
204 | 160 | { |
205 | - is_archive = 0; | |
206 | - if ((fp = ctf_bufopen (ctfsect, symsectp, strsectp, errp)) == NULL) | |
207 | - { | |
208 | - ctf_dprintf ("ctf_internal_open(): cannot open CTF: %s\n", | |
209 | - ctf_errmsg (*errp)); | |
210 | - goto err_free_str; | |
211 | - } | |
161 | + /* Request freeing of the symsect. */ | |
162 | + arci->ctfi_free_symsect = 1; | |
163 | + return arci; | |
212 | 164 | } |
213 | - arci = ctf_new_archive_internal (is_archive, arc, fp, symsectp, strsectp, | |
214 | - errp); | |
215 | - | |
216 | - if (arci) | |
217 | - return arci; | |
218 | - err_free_str: ; | |
219 | 165 | #ifdef HAVE_BFD_ELF |
220 | 166 | err_free_sym: |
221 | 167 | free (symtab); |
@@ -128,6 +128,7 @@ LIBCTF_1.0 { | ||
128 | 128 | ctf_arc_write; |
129 | 129 | ctf_arc_write_fd; |
130 | 130 | ctf_arc_open; |
131 | + ctf_arc_bufopen; | |
131 | 132 | ctf_arc_close; |
132 | 133 | ctf_arc_open_by_name; |
133 | 134 | ctf_arc_open_by_name_sections; |