diff options
Diffstat (limited to 'libctf')
-rw-r--r-- | libctf/ChangeLog | 13 | ||||
-rw-r--r-- | libctf/ctf-archive.c | 19 | ||||
-rw-r--r-- | libctf/ctf-create.c | 2 | ||||
-rw-r--r-- | libctf/ctf-impl.h | 1 | ||||
-rw-r--r-- | libctf/ctf-link.c | 9 | ||||
-rw-r--r-- | libctf/ctf-open-bfd.c | 34 | ||||
-rw-r--r-- | libctf/libctf.ver | 2 |
7 files changed, 72 insertions, 8 deletions
diff --git a/libctf/ChangeLog b/libctf/ChangeLog index 804f131..6670a6a 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,5 +1,18 @@ 2020-11-20 Nick Alcock <nick.alcock@oracle.com> + * ctf-link.c (ctf_link_shuffle_syms): Adjust. + (ctf_link_add_linker_symbol): New, unimplemented stub. + * libctf.ver: Add it. + * ctf-create.c (ctf_serialize): Set CTF_F_DYNSTR on newly-serialized + dicts. + * ctf-open-bfd.c (ctf_bfdopen_ctfsect): Check for the flag: open the + symtab/strtab if not present, dynsym/dynstr otherwise. + * ctf-archive.c (ctf_arc_bufpreamble): New, get the preamble from + some arbitrary member of a CTF archive. + * ctf-impl.h (ctf_arc_bufpreamble): Declare it. + +2020-11-20 Nick Alcock <nick.alcock@oracle.com> + * ctf-archive.c (ctf_arc_open_by_offset): Rename to... (ctf_dict_open_by_offset): ... this. Adjust callers. (ctf_arc_open_by_name_internal): Rename to... diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c index 72cdef9..25c30f6 100644 --- a/libctf/ctf-archive.c +++ b/libctf/ctf-archive.c @@ -377,6 +377,25 @@ ctf_new_archive_internal (int is_archive, int unmap_on_close, return arci; } +/* Get the CTF preamble from data in a buffer, which may be either an archive or + a CTF dict. If multiple dicts are present in an archive, the preamble comes + from an arbitrary dict. The preamble is a pointer into the ctfsect passed + in. */ + +const ctf_preamble_t * +ctf_arc_bufpreamble (const ctf_sect_t *ctfsect) +{ + if (ctfsect->cts_size > sizeof (uint64_t) && + (le64toh ((*(uint64_t *) ctfsect->cts_data)) == CTFA_MAGIC)) + { + struct ctf_archive *arc = (struct ctf_archive *) ctfsect->cts_data; + return (const ctf_preamble_t *) ((char *) arc + le64toh (arc->ctfa_ctfs) + + sizeof (uint64_t)); + } + else + return (const ctf_preamble_t *) ctfsect->cts_data; +} + /* Open a CTF archive or dictionary from data in a buffer (which the caller must preserve until ctf_arc_close() time). Returns the archive, or NULL and an error in *err (if not NULL). */ diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index c1a7a8a..384e8cf 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -298,6 +298,8 @@ ctf_serialize (ctf_dict_t *fp) hdr.cth_magic = CTF_MAGIC; hdr.cth_version = CTF_VERSION; + hdr.cth_flags = CTF_F_DYNSTR; + /* Iterate through the dynamic type definition list and compute the size of the CTF type section we will need to generate. */ diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index 3f4cfac..0e09a45 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -683,6 +683,7 @@ ctf_new_archive_internal (int is_archive, int unmap_on_close, const ctf_sect_t *strsect, int *errp); extern struct ctf_archive *ctf_arc_open_internal (const char *, int *); extern void ctf_arc_close_internal (struct ctf_archive *); +extern const ctf_preamble_t *ctf_arc_bufpreamble (const ctf_sect_t *); extern void *ctf_set_open_errno (int *, int); extern unsigned long ctf_set_errno (ctf_dict_t *, int); diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c index 192d4fd..3f4f2ee 100644 --- a/libctf/ctf-link.c +++ b/libctf/ctf-link.c @@ -1596,9 +1596,12 @@ ctf_link_add_strtab (ctf_dict_t *fp, ctf_link_strtab_string_f *add_string, /* Not yet implemented. */ int -ctf_link_shuffle_syms (ctf_dict_t *fp _libctf_unused_, - ctf_link_iter_symbol_f *add_sym _libctf_unused_, - void *arg _libctf_unused_) +ctf_link_add_linker_symbol (ctf_dict_t *fp, ctf_link_sym_t *sym) +{ + return 0; +} +int +ctf_link_shuffle_syms (ctf_dict_t *fp) { return 0; } diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c index 449347e..a6f0d3f 100644 --- a/libctf/ctf-open-bfd.c +++ b/libctf/ctf-open-bfd.c @@ -100,12 +100,36 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_, #ifdef HAVE_BFD_ELF ctf_sect_t symsect, strsect; - Elf_Internal_Shdr *symhdr = &elf_symtab_hdr (abfd); + Elf_Internal_Shdr *symhdr; size_t symcount; Elf_Internal_Sym *isymbuf; bfd_byte *symtab = NULL; + const char *symtab_name; const char *strtab = NULL; + const char *strtab_name; size_t strsize; + const ctf_preamble_t *preamble; + + if (ctfsect->cts_data == NULL) + { + bfderrstr = N_("CTF section is NULL"); + goto err; + } + preamble = ctf_arc_bufpreamble (ctfsect); + + if (preamble->ctp_flags & CTF_F_DYNSTR) + { + symhdr = &elf_tdata (abfd)->dynsymtab_hdr; + strtab_name = ".dynstr"; + symtab_name = ".dynsym"; + } + else + { + symhdr = &elf_tdata (abfd)->symtab_hdr; + strtab_name = ".strtab"; + symtab_name = ".symtab"; + } + /* TODO: handle SYMTAB_SHNDX. */ /* Get the symtab, and the strtab associated with it. */ @@ -145,12 +169,12 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_, strtab = (const char *) strhdr->contents; } } - else /* No symtab: just try getting .strtab by name. */ + else /* No symtab: just try getting .strtab or .dynstr by name. */ { bfd_byte *str_bcontents; asection *str_asect; - if ((str_asect = bfd_get_section_by_name (abfd, ".strtab")) != NULL) + if ((str_asect = bfd_get_section_by_name (abfd, strtab_name)) != NULL) { if (bfd_malloc_and_get_section (abfd, str_asect, &str_bcontents)) { @@ -168,7 +192,7 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_, use it for anything but debugging. */ strsect.cts_data = strtab; - strsect.cts_name = ".strtab"; + strsect.cts_name = strtab_name; strsect.cts_size = strsize; strsectp = &strsect; } @@ -176,7 +200,7 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_, if (symtab) { assert (symhdr->sh_entsize == get_elf_backend_data (abfd)->s->sizeof_sym); - symsect.cts_name = ".symtab"; + symsect.cts_name = symtab_name; symsect.cts_entsize = symhdr->sh_entsize; symsect.cts_size = symhdr->sh_size; symsect.cts_data = symtab; diff --git a/libctf/libctf.ver b/libctf/libctf.ver index cf4fa73..317913e 100644 --- a/libctf/libctf.ver +++ b/libctf/libctf.ver @@ -181,4 +181,6 @@ LIBCTF_1.1 { ctf_dict_open_sections; ctf_dict_close; ctf_parent_dict; + + ctf_link_add_linker_symbol; } LIBCTF_1.0; |