[DTrace-devel] [PATCH 12/15] dlib: Ensure dt_dlib_add_sym_id() does not add duplicates

Nick Alcock nick.alcock at oracle.com
Thu Feb 23 13:10:26 UTC 2023


On 23 Feb 2023, Kris Van Hees via DTrace-devel verbalised:

> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>

Reviewed-by: Nick Alcock <nick.alcock at oracle.com>

(with semantic niggle below)

> ---
>  libdtrace/dt_dlibs.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
> index e3196b63..eea45d8b 100644
> --- a/libdtrace/dt_dlibs.c
> +++ b/libdtrace/dt_dlibs.c
> @@ -152,6 +152,7 @@ dt_dlib_get_xsym(dtrace_hdl_t *dtp, const char *name, int kind)
>  
>  /*
>   * Add a BPF identifier of a given kind with given id.
> + * If the identifier already exists (with the proper id, if any), return it.
>   */
>  static dt_ident_t *
>  dt_dlib_add_sym_id(dtrace_hdl_t *dtp, const char *name, int kind, uint_t id)
> @@ -159,6 +160,10 @@ dt_dlib_add_sym_id(dtrace_hdl_t *dtp, const char *name, int kind, uint_t id)
>  	dt_idhash_t	*dhp = dtp->dt_bpfsyms;
>  	dt_ident_t	*idp;
>  
> +	idp = dt_dlib_get_xsym(dtp, name, kind);
> +	if (idp != NULL && id != DT_IDENT_UNDEF && idp->di_id == id)
> +		return idp;

... if an id is already provided, and is different from what's in the
entry in the symtab, we add another one (with, no doubt, yet another id)
and return it, rather than looking up the symbol with the right id, and
returning that? (And future calls would go even more wrong since now we
have duplicate entries and dt_dlib_get_xsym is only ever going to return
one of them, so we might get duplicates added with the *same* id if this
is called again with the exact same args).

Not really sure that particular behaviour is beneficial unless adding
duplicate symbols with different ids, and then more with identical ids,
is something we really want to do.

-- 
NULL && (void)



More information about the DTrace-devel mailing list