From 49ea9b450bb1ca97f6e40c420c8cde5878e11048 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Sat, 20 Jul 2019 14:44:44 +0100 Subject: libctf: add CU-mapping machinery Once the deduplicator is capable of actually detecting conflicting types with the same name (i.e., not yet) we will place such conflicting types, and types that depend on them, into CTF dictionaries that are the child of the main dictionary we usually emit: currently, this will lead to the .ctf section becoming a CTF archive rather than a single dictionary, with the default-named archive member (_CTF_SECTION, or NULL) being the main shared dictionary with most of the types in it. By default, the sections are named after the compilation unit they come from (complete path and all), with the cuname field in the CTF header providing further evidence of the name without requiring the caller to engage in tiresome parsing. But some callers may not wish the mapping from input CU to output sub-dictionary to be purely CU-based. The machinery here allows this to be freely changed, in two ways: - callers can call ctf_link_add_cu_mapping to specify that a single input compilation unit should have its types placed in some other CU if they conflict: the CU will always be created, even if empty, so the consuming program can depend on its existence. You can map multiple input CUs to one output CU to force all their types to be merged together: if some of *those* types conflict, the behaviour is currently unspecified (the new deduplicator will specify it). - callers can call ctf_link_set_memb_name_changer to provide a function which is passed every CTF sub-dictionary name in turn (including _CTF_SECTION) and can return a new name, or NULL if no change is desired. The mapping from input to output names should not map two input names to the same output name: if this happens, the two are not merged but will result in an archive with two members with the same name (technically valid, but it's hard to access the second same-named member: you have to do an iteration over archive members). This is used by the kernel's ctfarchive machinery (not yet upstream) to encode CTF under member names like {module name}.ctf rather than .ctf.CU, but it is anticipated that other large projects may wish to have their own storage for CTF outside of .ctf sections and may wish to have new naming schemes that suit their special-purpose consumers. New in v3. v4: check for strdup failure. v5: fix tabdamage. include/ * ctf-api.h (ctf_link_add_cu_mapping): New. (ctf_link_memb_name_changer_f): New. (ctf_link_set_memb_name_changer): New. libctf/ * ctf-impl.h (ctf_file_t) : New. : Likewise. : Likewise. * ctf-create.c (ctf_update): Update accordingly. * ctf-open.c (ctf_file_close): Likewise. * ctf-link.c (ctf_create_per_cu): Apply the cu mapping. (ctf_link_add_cu_mapping): New. (ctf_link_set_memb_name_changer): Likewise. (ctf_change_parent_name): New. (ctf_name_list_accum_cb_arg_t) : New, storage for names allocated by the caller's ctf_link_memb_name_changer. : Likewise. (ctf_accumulate_archive_names): Call the ctf_link_memb_name_changer. (ctf_link_write): Likewise (for _CTF_SECTION only): also call ctf_change_parent_name. Free any resulting names. --- include/ChangeLog | 6 ++++++ include/ctf-api.h | 10 ++++++++++ 2 files changed, 16 insertions(+) (limited to 'include') diff --git a/include/ChangeLog b/include/ChangeLog index 0122c1d6280..ce7c17377a0 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,9 @@ +2019-07-30 Nick Alcock + + * ctf-api.h (ctf_link_add_cu_mapping): New. + (ctf_link_memb_name_changer_f): New. + (ctf_link_set_memb_name_changer): New. + 2019-07-13 Nick Alcock * ctf-api.h (ECTF_INTERNAL): New. diff --git a/include/ctf-api.h b/include/ctf-api.h index 4130a2ecd19..4ac5fea8bc6 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -421,6 +421,16 @@ extern int ctf_link_shuffle_syms (ctf_file_t *, ctf_link_iter_symbol_f *, extern unsigned char *ctf_link_write (ctf_file_t *, size_t *size, size_t threshold); +/* Specialist linker functions. These functions are not used by ld, but can be + used by other prgorams making use of the linker machinery for other purposes + to customize its output. */ +extern int ctf_link_add_cu_mapping (ctf_file_t *, const char *from, + const char *to); +typedef char *ctf_link_memb_name_changer_f (ctf_file_t *, + const char *, void *); +extern void ctf_link_set_memb_name_changer + (ctf_file_t *, ctf_link_memb_name_changer_f *, void *); + extern void ctf_setdebug (int debug); extern int ctf_getdebug (void); -- cgit v1.2.3-65-gdbad