1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-08 08:58:27 +03:00

generate-sym-test: search for missing symbols

This slightly extends the symbol file test and checks which symbols are
listed in one list but missing in the other. This is tremendously useful
to quickly determine which symbols wheren't exposed properly but should
have been.

(This is is implemented in pure C, no systemd helpers, to ensure we see
libsystemd.so API as any other tool would.)
This commit is contained in:
Lennart Poettering 2023-05-02 11:21:23 +02:00
parent ab13274a19
commit 4f65fbe990

View File

@ -40,6 +40,8 @@ print('''/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
''')
for header in sys.argv[3:]:
@ -51,10 +53,11 @@ print('''
''')
print('''
static const struct {
struct symbol {
const char *name;
const void *symbol;
} symbols_from_sym[] = {''')
};
static struct symbol symbols_from_sym[] = {''')
with open(sys.argv[1], "r") as f:
process_sym_file(f)
@ -70,9 +73,17 @@ for dirpath, _, filenames in os.walk(sys.argv[2]):
print(''' {}
};
static int sort_callback(const void *a, const void *b) {
const struct symbol *x = a, *y = b;
return strcmp(x->name, y->name);
}
int main(void) {
size_t i, j;
qsort(symbols_from_sym, sizeof(symbols_from_sym)/sizeof(symbols_from_sym[0])-1, sizeof(symbols_from_sym[0]), sort_callback);
qsort(symbols_from_source, sizeof(symbols_from_source)/sizeof(symbols_from_source[0])-1, sizeof(symbols_from_source[0]), sort_callback);
puts("From symbol file:");
for (i = 0; symbols_from_sym[i].name; i++)
printf("%p: %s\\n", symbols_from_sym[i].symbol, symbols_from_sym[i].name);
@ -85,5 +96,17 @@ int main(void) {
printf("Found %zu symbols from symbol file.\\n", i);
printf("Found %zu symbols from source files.\\n", j);
for (i = 0; symbols_from_sym[i].name; i++) {
struct symbol*n = bsearch(symbols_from_sym+i, symbols_from_source, sizeof(symbols_from_source)/sizeof(symbols_from_source[0])-1, sizeof(symbols_from_source[0]), sort_callback);
if (!n)
printf("Found in symbol file, but not in sources: %s\\n", symbols_from_sym[i].name);
}
for (j = 0; symbols_from_source[j].name; j++) {
struct symbol*n = bsearch(symbols_from_source+j, symbols_from_source, sizeof(symbols_from_sym)/sizeof(symbols_from_sym[0])-1, sizeof(symbols_from_sym[0]), sort_callback);
if (!n)
printf("Found in sources, but not in symbol file: %s\\n", symbols_from_source[i].name);
}
return i == j ? EXIT_SUCCESS : EXIT_FAILURE;
}''')