Re: [PATCH v2 14/19] gendwarfksyms: Add symbol versioning

From: Sami Tolvanen
Date: Wed Sep 11 2024 - 12:04:40 EST


Hi Petr,

On Wed, Sep 11, 2024 at 3:08 AM Petr Pavlu <petr.pavlu@xxxxxxxx> wrote:
>
> On 8/15/24 19:39, Sami Tolvanen wrote:
> > +static inline unsigned long partial_crc32(const char *s, unsigned long crc)
> > +{
> > + while (*s)
> > + crc = partial_crc32_one(*s++, crc);
> > + return crc;
> > +}
> > +
> > +#endif /* __CRC32_H */
>
> I think the CRC32 code should be ideally shared between genksyms and
> gendwarfksyms. One option would be to stick it under scripts/include,
> not sure if the best one though.

This was carried over from the initial version, which wasn't under
scripts yet. I'm happy to deduplicate this though. Masahiro, any
preferences on where this should go?

> > +static int get_symbol_cache(struct state *state, Dwarf_Die *die,
> > + struct die **cache)
> > +{
> > + checkp(symbol_set_die(state->sym, die));
> > + check(die_map_get(die, SYMBOL, cache));
> > +
> > + if ((*cache)->state != INCOMPLETE)
> > + return 1; /* We already processed a symbol for this DIE */
> > +
> > + (*cache)->tag = dwarf_tag(die);
> > + return 0;
> > +}
>
> Nit: The "get_" prefix in the name of this function is misleading. It
> isn't a plain getter but has an effect of setting the symbol die.
> A different name would be better.

Sure, I'll clean this up.

> > +static int calculate_version(struct version *version, const char *name,
> > + struct type_list *list)
> > +{
> > + check(version_init(version));
> > + check(__calculate_version(version, list));
> > + cache_clear_expanded(&expansion_cache);
> > + return 0;
> > +}
>
> Nit: The name parameter is unused.

Ah, so it is. I'll fix this too.

> More importantly, it made me think which names are included in the CRC
> calculation and which ones are omitted.
>
> If I'm looking correctly, names of structs, enums and enumerators make
> it into the calculation. On the other hand, names of struct members,
> function parameters and exports (functions/variables) are missing.
>
> I think the names of struct members and function parameters should be
> added as well. If the code changes 'struct A { int cols; int rows; }' to
> 'struct A { int rows; int cols; }' then that should be recognized as
> a different API/ABI. The same applies to function parameters.

I did leave out member names because typically renaming a member
doesn't change the ABI, but you're right, it might help capture these
types of changes where fields with identical types are reordered for
some reason. I'll add names.

> I'm not sure about export names. I would probably include them as well,
> if only for consistency.

I would rather leave out the symbol names to have consistent CRCs
between symbols that have identical types. Or is there an actual
benefit in including the symbol name in the CRC? The names are already
rather explicitly involved when symbol versions are checked.

Sami