summaryrefslogtreecommitdiff
path: root/scripts/gendwarfksyms/types.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gendwarfksyms/types.c')
-rw-r--r--scripts/gendwarfksyms/types.c122
1 files changed, 120 insertions, 2 deletions
diff --git a/scripts/gendwarfksyms/types.c b/scripts/gendwarfksyms/types.c
index 21d7a34228eb..6c03265f4d10 100644
--- a/scripts/gendwarfksyms/types.c
+++ b/scripts/gendwarfksyms/types.c
@@ -6,6 +6,7 @@
#define _GNU_SOURCE
#include <inttypes.h>
#include <stdio.h>
+#include <zlib.h>
#include "gendwarfksyms.h"
@@ -179,6 +180,33 @@ static void type_map_free(void)
}
/*
+ * CRC for a type, with an optional fully expanded type string for
+ * debugging.
+ */
+struct version {
+ struct type_expansion type;
+ unsigned long crc;
+};
+
+static void version_init(struct version *version)
+{
+ version->crc = crc32(0, NULL, 0);
+ type_expansion_init(&version->type);
+}
+
+static void version_free(struct version *version)
+{
+ type_expansion_free(&version->type);
+}
+
+static void version_add(struct version *version, const char *s)
+{
+ version->crc = crc32(version->crc, (void *)s, strlen(s));
+ if (dump_versions)
+ type_expansion_append(&version->type, s, NULL);
+}
+
+/*
* Type reference format: <prefix>#<name>, where prefix:
* s -> structure
* u -> union
@@ -187,6 +215,12 @@ static void type_map_free(void)
*
* Names with spaces are additionally wrapped in single quotes.
*/
+static inline bool is_type_prefix(const char *s)
+{
+ return (s[0] == 's' || s[0] == 'u' || s[0] == 'e' || s[0] == 't') &&
+ s[1] == '#';
+}
+
static char get_type_prefix(int tag)
{
switch (tag) {
@@ -214,6 +248,8 @@ static char *get_type_name(struct die *cache)
warn("found incomplete cache entry: %p", cache);
return NULL;
}
+ if (cache->state == DIE_SYMBOL)
+ return NULL;
if (!cache->fqn || !*cache->fqn)
return NULL;
@@ -231,6 +267,39 @@ static char *get_type_name(struct die *cache)
return name;
}
+static void __calculate_version(struct version *version, struct list_head *list)
+{
+ struct type_list_entry *entry;
+ struct type_expansion *e;
+
+ /* Calculate a CRC over an expanded type string */
+ list_for_each_entry(entry, list, list) {
+ if (is_type_prefix(entry->str)) {
+ check(type_map_get(entry->str, &e));
+
+ /*
+ * It's sufficient to expand each type reference just
+ * once to detect changes.
+ */
+ if (cache_was_expanded(&expansion_cache, e)) {
+ version_add(version, entry->str);
+ } else {
+ cache_mark_expanded(&expansion_cache, e);
+ __calculate_version(version, &e->expanded);
+ }
+ } else {
+ version_add(version, entry->str);
+ }
+ }
+}
+
+static void calculate_version(struct version *version, struct list_head *list)
+{
+ version_init(version);
+ __calculate_version(version, list);
+ cache_free(&expansion_cache);
+}
+
static void __type_expand(struct die *cache, struct type_expansion *type,
bool recursive);
@@ -337,7 +406,49 @@ static void expand_type(struct die *cache, void *arg)
free(name);
}
-void generate_symtypes(FILE *file)
+static void expand_symbol(struct symbol *sym, void *arg)
+{
+ struct type_expansion type;
+ struct version version;
+ struct die *cache;
+
+ /*
+ * No need to expand again unless we want a symtypes file entry
+ * for the symbol. Note that this means `sym` has the same address
+ * as another symbol that was already processed.
+ */
+ if (!symtypes && sym->state == SYMBOL_PROCESSED)
+ return;
+
+ if (__die_map_get(sym->die_addr, DIE_SYMBOL, &cache))
+ return; /* We'll warn about missing CRCs later. */
+
+ type_expand(cache, &type, false);
+
+ /* If the symbol already has a version, don't calculate it again. */
+ if (sym->state != SYMBOL_PROCESSED) {
+ calculate_version(&version, &type.expanded);
+ symbol_set_crc(sym, version.crc);
+ debug("%s = %lx", sym->name, version.crc);
+
+ if (dump_versions) {
+ checkp(fputs(sym->name, stderr));
+ checkp(fputs(" ", stderr));
+ type_list_write(&version.type.expanded, stderr);
+ checkp(fputs("\n", stderr));
+ }
+
+ version_free(&version);
+ }
+
+ /* These aren't needed in type_map unless we want a symtypes file. */
+ if (symtypes)
+ type_map_add(sym->name, &type);
+
+ type_expansion_free(&type);
+}
+
+void generate_symtypes_and_versions(FILE *file)
{
cache_init(&expansion_cache);
@@ -355,7 +466,14 @@ void generate_symtypes(FILE *file)
die_map_for_each(expand_type, NULL);
/*
- * 2. If a symtypes file is requested, write type_map contents to
+ * 2. For each exported symbol, expand the die_map type, and use
+ * type_map expansions to calculate a symbol version from the
+ * fully expanded type string.
+ */
+ symbol_for_each(expand_symbol, NULL);
+
+ /*
+ * 3. If a symtypes file is requested, write type_map contents to
* the file.
*/
type_map_write(file);