Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
24extern void f(unsigned int arg);
25void g(int *arg);
26void g(int *arg) {}
27
28struct s;
29extern struct s *p;
30
31__GENDWARFKSYMS_EXPORT(f);
32__GENDWARFKSYMS_EXPORT(g);
33__GENDWARFKSYMS_EXPORT(p);