mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 08:38:45 +02:00 
			
		
		
		
	 fa624569b7
			
		
	
	
		fa624569b7
		
	
	
	
	
		
			
			The compiler may choose not to emit type information in DWARF for
external symbols. Clang, for example, does this for symbols not
defined in the current TU.
To provide a way to work around this issue, add support for
__gendwarfksyms_ptr_<symbol> pointers that force the compiler to emit
the necessary type information in DWARF also for the missing symbols.
Example usage:
  #define GENDWARFKSYMS_PTR(sym) \
      static typeof(sym) *__gendwarfksyms_ptr_##sym __used  \
          __section(".discard.gendwarfksyms") = &sym;
  extern int external_symbol(void);
  GENDWARFKSYMS_PTR(external_symbol);
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
		
	
			
		
			
				
	
	
		
			33 lines
		
	
	
	
		
			840 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
	
		
			840 B
		
	
	
	
		
			C
		
	
	
	
	
	
| // SPDX-License-Identifier: GPL-2.0
 | |
| /*
 | |
|  * Copyright (C) 2024 Google LLC
 | |
|  *
 | |
|  * Example for symbol pointers. When compiled with Clang, gendwarfkyms
 | |
|  * uses a symbol pointer for `f`.
 | |
|  *
 | |
|  * $ clang -g -c examples/symbolptr.c -o examples/symbolptr.o
 | |
|  * $ echo -e "f\ng\np" | ./gendwarfksyms -d examples/symbolptr.o
 | |
|  */
 | |
| 
 | |
| /* Kernel macros for userspace testing. */
 | |
| #ifndef __used
 | |
| #define __used __attribute__((__used__))
 | |
| #endif
 | |
| #ifndef __section
 | |
| #define __section(section) __attribute__((__section__(section)))
 | |
| #endif
 | |
| 
 | |
| #define __GENDWARFKSYMS_EXPORT(sym)				\
 | |
| 	static typeof(sym) *__gendwarfksyms_ptr_##sym __used	\
 | |
| 		__section(".discard.gendwarfksyms") = &sym;
 | |
| 
 | |
| extern void f(unsigned int arg);
 | |
| void g(int *arg);
 | |
| void g(int *arg) {}
 | |
| 
 | |
| struct s;
 | |
| extern struct s *p;
 | |
| 
 | |
| __GENDWARFKSYMS_EXPORT(f);
 | |
| __GENDWARFKSYMS_EXPORT(g);
 | |
| __GENDWARFKSYMS_EXPORT(p);
 |