libctf, link: add the ability to filter out variables from the link
The CTF variables section (containing variables that have no corresponding symtab entries) can cause the string table to get very voluminous if the names of variables are long. Some callers want to filter out particular variables they know they won't need. So add a "variable filter" callback that does that: it's passed the name of the variable and a corresponding ctf_file_t / ctf_id_t pair, and should return 1 to filter it out. ld doesn't use this machinery yet, but we could easily add it later if desired. (But see later for a commit that turns off CTF variable- section linking in ld entirely by default.) include/ * ctf-api.h (ctf_link_variable_filter_t): New. (ctf_link_set_variable_filter): Likewise. libctf/ * libctf.ver (ctf_link_set_variable_filter): Add. * ctf-impl.h (ctf_file_t) <ctf_link_variable_filter>: New. <ctf_link_variable_filter_arg>: Likewise. * ctf-create.c (ctf_serialize): Adjust. * ctf-link.c (ctf_link_set_variable_filter): New, set it. (ctf_link_one_variable): Call it if set.
This commit is contained in:
parent
19d4b1addc
commit
6dd2819ffc
7 changed files with 48 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
|
||||||
|
|
||||||
|
* ctf-api.h (ctf_link_variable_filter_t): New.
|
||||||
|
(ctf_link_set_variable_filter): Likewise.
|
||||||
|
|
||||||
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
|
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
|
||||||
|
|
||||||
* ctf-api.h (CTF_LINK_EMPTY_CU_MAPPINGS): New.
|
* ctf-api.h (CTF_LINK_EMPTY_CU_MAPPINGS): New.
|
||||||
|
|
|
@ -458,6 +458,12 @@ extern int ctf_compress_write (ctf_file_t * fp, int fd);
|
||||||
extern unsigned char *ctf_write_mem (ctf_file_t *, size_t *, size_t threshold);
|
extern unsigned char *ctf_write_mem (ctf_file_t *, size_t *, size_t threshold);
|
||||||
|
|
||||||
extern int ctf_link_add_ctf (ctf_file_t *, ctf_archive_t *, const char *);
|
extern int ctf_link_add_ctf (ctf_file_t *, ctf_archive_t *, const char *);
|
||||||
|
/* The variable filter should return nonzero if a variable should not
|
||||||
|
appear in the output. */
|
||||||
|
typedef int ctf_link_variable_filter_f (ctf_file_t *, const char *, ctf_id_t,
|
||||||
|
void *);
|
||||||
|
extern int ctf_link_set_variable_filter (ctf_file_t *,
|
||||||
|
ctf_link_variable_filter_f *, void *);
|
||||||
extern int ctf_link (ctf_file_t *, int flags);
|
extern int ctf_link (ctf_file_t *, int flags);
|
||||||
typedef const char *ctf_link_strtab_string_f (uint32_t *offset, void *arg);
|
typedef const char *ctf_link_strtab_string_f (uint32_t *offset, void *arg);
|
||||||
extern int ctf_link_add_strtab (ctf_file_t *, ctf_link_strtab_string_f *,
|
extern int ctf_link_add_strtab (ctf_file_t *, ctf_link_strtab_string_f *,
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
|
||||||
|
|
||||||
|
* libctf.ver (ctf_link_set_variable_filter): Add.
|
||||||
|
* ctf-impl.h (ctf_file_t) <ctf_link_variable_filter>: New.
|
||||||
|
<ctf_link_variable_filter_arg>: Likewise.
|
||||||
|
* ctf-create.c (ctf_serialize): Adjust.
|
||||||
|
* ctf-link.c (ctf_link_set_variable_filter): New, set it.
|
||||||
|
(ctf_link_one_variable): Call it if set.
|
||||||
|
|
||||||
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
|
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
|
||||||
|
|
||||||
* ctf-link.c (ctf_link_one_variable): Check the dst_type for
|
* ctf-link.c (ctf_link_one_variable): Check the dst_type for
|
||||||
|
|
|
@ -543,6 +543,8 @@ ctf_serialize (ctf_file_t *fp)
|
||||||
nfp->ctf_link_type_mapping = fp->ctf_link_type_mapping;
|
nfp->ctf_link_type_mapping = fp->ctf_link_type_mapping;
|
||||||
nfp->ctf_link_memb_name_changer = fp->ctf_link_memb_name_changer;
|
nfp->ctf_link_memb_name_changer = fp->ctf_link_memb_name_changer;
|
||||||
nfp->ctf_link_memb_name_changer_arg = fp->ctf_link_memb_name_changer_arg;
|
nfp->ctf_link_memb_name_changer_arg = fp->ctf_link_memb_name_changer_arg;
|
||||||
|
nfp->ctf_link_variable_filter = fp->ctf_link_variable_filter;
|
||||||
|
nfp->ctf_link_variable_filter_arg = fp->ctf_link_variable_filter_arg;
|
||||||
nfp->ctf_link_flags = fp->ctf_link_flags;
|
nfp->ctf_link_flags = fp->ctf_link_flags;
|
||||||
|
|
||||||
nfp->ctf_snapshot_lu = fp->ctf_snapshots;
|
nfp->ctf_snapshot_lu = fp->ctf_snapshots;
|
||||||
|
|
|
@ -333,7 +333,12 @@ struct ctf_file
|
||||||
|
|
||||||
/* Allow the caller to change the name of link archive members. */
|
/* Allow the caller to change the name of link archive members. */
|
||||||
ctf_link_memb_name_changer_f *ctf_link_memb_name_changer;
|
ctf_link_memb_name_changer_f *ctf_link_memb_name_changer;
|
||||||
void *ctf_link_memb_name_changer_arg; /* Argument for it. */
|
void *ctf_link_memb_name_changer_arg; /* Argument for it. */
|
||||||
|
|
||||||
|
/* Allow the caller to filter out variables they don't care about. */
|
||||||
|
ctf_link_variable_filter_f *ctf_link_variable_filter;
|
||||||
|
void *ctf_link_variable_filter_arg; /* Argument for it. */
|
||||||
|
|
||||||
ctf_dynhash_t *ctf_add_processing; /* Types ctf_add_type is working on now. */
|
ctf_dynhash_t *ctf_add_processing; /* Types ctf_add_type is working on now. */
|
||||||
char *ctf_tmp_typeslice; /* Storage for slicing up type names. */
|
char *ctf_tmp_typeslice; /* Storage for slicing up type names. */
|
||||||
size_t ctf_tmp_typeslicelen; /* Size of the typeslice. */
|
size_t ctf_tmp_typeslicelen; /* Size of the typeslice. */
|
||||||
|
|
|
@ -528,6 +528,16 @@ ctf_link_one_type (ctf_id_t type, int isroot _libctf_unused_, void *arg_)
|
||||||
return 0; /* As above: do not lose types. */
|
return 0; /* As above: do not lose types. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set a function which is used to filter out unwanted variables from the link. */
|
||||||
|
int
|
||||||
|
ctf_link_set_variable_filter (ctf_file_t *fp, ctf_link_variable_filter_f *filter,
|
||||||
|
void *arg)
|
||||||
|
{
|
||||||
|
fp->ctf_link_variable_filter = filter;
|
||||||
|
fp->ctf_link_variable_filter_arg = arg;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if we can safely add a variable with the given type to this container. */
|
/* Check if we can safely add a variable with the given type to this container. */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -564,6 +574,15 @@ ctf_link_one_variable (const char *name, ctf_id_t type, void *arg_)
|
||||||
ctf_file_t *check_fp;
|
ctf_file_t *check_fp;
|
||||||
ctf_dvdef_t *dvd;
|
ctf_dvdef_t *dvd;
|
||||||
|
|
||||||
|
/* See if this variable is filtered out. */
|
||||||
|
|
||||||
|
if (arg->out_fp->ctf_link_variable_filter)
|
||||||
|
{
|
||||||
|
void *farg = arg->out_fp->ctf_link_variable_filter_arg;
|
||||||
|
if (arg->out_fp->ctf_link_variable_filter (arg->in_fp, name, type, farg))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* In unconflicted link mode, if this type is mapped to a type in the parent
|
/* In unconflicted link mode, if this type is mapped to a type in the parent
|
||||||
container, we want to try to add to that first: if it reports a duplicate,
|
container, we want to try to add to that first: if it reports a duplicate,
|
||||||
or if the type is in a child already, add straight to the child. */
|
or if the type is in a child already, add straight to the child. */
|
||||||
|
|
|
@ -159,6 +159,7 @@ LIBCTF_1.0 {
|
||||||
ctf_link_add_ctf;
|
ctf_link_add_ctf;
|
||||||
ctf_link_add_cu_mapping;
|
ctf_link_add_cu_mapping;
|
||||||
ctf_link_set_memb_name_changer;
|
ctf_link_set_memb_name_changer;
|
||||||
|
ctf_link_set_variable_filter;
|
||||||
ctf_link;
|
ctf_link;
|
||||||
ctf_link_add_strtab;
|
ctf_link_add_strtab;
|
||||||
ctf_link_shuffle_syms;
|
ctf_link_shuffle_syms;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue