Debian Codegraph @

scripts/gendwarfksyms/examples/symbolptr.c

raw
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2024 Google LLC
4 *
5 * Example for symbol pointers. When compiled with Clang, gendwarfkyms
6 * uses a symbol pointer for `f`.
7 *
8 * $ clang -g -c examples/symbolptr.c -o examples/symbolptr.o
9 * $ echo -e "f\ng\np" | ./gendwarfksyms -d examples/symbolptr.o
10 */
11
12 /* Kernel macros for userspace testing. */
13 #ifndef __used
14 #define __used __attribute__((__used__))
15 #endif
16 #ifndef __section
17 #define __section(section) __attribute__((__section__(section)))
18 #endif
19
20 #define __GENDWARFKSYMS_EXPORT(sym) \
21 static typeof(sym) *__gendwarfksyms_ptr_##sym __used \
22 __section(".discard.gendwarfksyms") = &sym;
23
24 extern void f(unsigned int arg);
25 void g(int *arg);
26 void g(int *arg) {}
27
28 struct s;
29 extern struct s *p;
30
31 __GENDWARFKSYMS_EXPORT(f);
32 __GENDWARFKSYMS_EXPORT(g);
33 __GENDWARFKSYMS_EXPORT(p);