mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	kallsyms: get rid of code for absolute kallsyms
Commit cf8e865810 ("arch: Remove Itanium (IA-64) architecture")
removed the last use of the absolute kallsyms.
Signed-off-by: Jann Horn <jannh@google.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/all/20240221202655.2423854-1-jannh@google.com/
[masahiroy@kernel.org: rebase the code and reword the commit description]
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
			
			
This commit is contained in:
		
							parent
							
								
									7efcb39e0d
								
							
						
					
					
						commit
						64e166099b
					
				
					 7 changed files with 32 additions and 77 deletions
				
			
		
							
								
								
									
										18
									
								
								init/Kconfig
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								init/Kconfig
									
									
									
									
									
								
							| 
						 | 
					@ -1789,24 +1789,6 @@ config KALLSYMS_ABSOLUTE_PERCPU
 | 
				
			||||||
	depends on KALLSYMS
 | 
						depends on KALLSYMS
 | 
				
			||||||
	default X86_64 && SMP
 | 
						default X86_64 && SMP
 | 
				
			||||||
 | 
					
 | 
				
			||||||
config KALLSYMS_BASE_RELATIVE
 | 
					 | 
				
			||||||
	bool
 | 
					 | 
				
			||||||
	depends on KALLSYMS
 | 
					 | 
				
			||||||
	default y
 | 
					 | 
				
			||||||
	help
 | 
					 | 
				
			||||||
	  Instead of emitting them as absolute values in the native word size,
 | 
					 | 
				
			||||||
	  emit the symbol references in the kallsyms table as 32-bit entries,
 | 
					 | 
				
			||||||
	  each containing a relative value in the range [base, base + U32_MAX]
 | 
					 | 
				
			||||||
	  or, when KALLSYMS_ABSOLUTE_PERCPU is in effect, each containing either
 | 
					 | 
				
			||||||
	  an absolute value in the range [0, S32_MAX] or a relative value in the
 | 
					 | 
				
			||||||
	  range [base, base + S32_MAX], where base is the lowest relative symbol
 | 
					 | 
				
			||||||
	  address encountered in the image.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	  On 64-bit builds, this reduces the size of the address table by 50%,
 | 
					 | 
				
			||||||
	  but more importantly, it results in entries whose values are build
 | 
					 | 
				
			||||||
	  time constants, and no relocation pass is required at runtime to fix
 | 
					 | 
				
			||||||
	  up the entries based on the runtime load address of the kernel.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# end of the "standard kernel features (expert users)" menu
 | 
					# end of the "standard kernel features (expert users)" menu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
config ARCH_HAS_MEMBARRIER_CALLBACKS
 | 
					config ARCH_HAS_MEMBARRIER_CALLBACKS
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -148,9 +148,6 @@ static unsigned int get_symbol_offset(unsigned long pos)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned long kallsyms_sym_address(int idx)
 | 
					unsigned long kallsyms_sym_address(int idx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!IS_ENABLED(CONFIG_KALLSYMS_BASE_RELATIVE))
 | 
					 | 
				
			||||||
		return kallsyms_addresses[idx];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* values are unsigned offsets if --absolute-percpu is not in effect */
 | 
						/* values are unsigned offsets if --absolute-percpu is not in effect */
 | 
				
			||||||
	if (!IS_ENABLED(CONFIG_KALLSYMS_ABSOLUTE_PERCPU))
 | 
						if (!IS_ENABLED(CONFIG_KALLSYMS_ABSOLUTE_PERCPU))
 | 
				
			||||||
		return kallsyms_relative_base + (u32)kallsyms_offsets[idx];
 | 
							return kallsyms_relative_base + (u32)kallsyms_offsets[idx];
 | 
				
			||||||
| 
						 | 
					@ -325,7 +322,7 @@ static unsigned long get_symbol_pos(unsigned long addr,
 | 
				
			||||||
	unsigned long symbol_start = 0, symbol_end = 0;
 | 
						unsigned long symbol_start = 0, symbol_end = 0;
 | 
				
			||||||
	unsigned long i, low, high, mid;
 | 
						unsigned long i, low, high, mid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Do a binary search on the sorted kallsyms_addresses array. */
 | 
						/* Do a binary search on the sorted kallsyms_offsets array. */
 | 
				
			||||||
	low = 0;
 | 
						low = 0;
 | 
				
			||||||
	high = kallsyms_num_syms;
 | 
						high = kallsyms_num_syms;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <linux/types.h>
 | 
					#include <linux/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern const unsigned long kallsyms_addresses[];
 | 
					 | 
				
			||||||
extern const int kallsyms_offsets[];
 | 
					extern const int kallsyms_offsets[];
 | 
				
			||||||
extern const u8 kallsyms_names[];
 | 
					extern const u8 kallsyms_names[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -216,12 +216,8 @@ static int __init crash_save_vmcoreinfo_init(void)
 | 
				
			||||||
	VMCOREINFO_SYMBOL(kallsyms_num_syms);
 | 
						VMCOREINFO_SYMBOL(kallsyms_num_syms);
 | 
				
			||||||
	VMCOREINFO_SYMBOL(kallsyms_token_table);
 | 
						VMCOREINFO_SYMBOL(kallsyms_token_table);
 | 
				
			||||||
	VMCOREINFO_SYMBOL(kallsyms_token_index);
 | 
						VMCOREINFO_SYMBOL(kallsyms_token_index);
 | 
				
			||||||
#ifdef CONFIG_KALLSYMS_BASE_RELATIVE
 | 
					 | 
				
			||||||
	VMCOREINFO_SYMBOL(kallsyms_offsets);
 | 
						VMCOREINFO_SYMBOL(kallsyms_offsets);
 | 
				
			||||||
	VMCOREINFO_SYMBOL(kallsyms_relative_base);
 | 
						VMCOREINFO_SYMBOL(kallsyms_relative_base);
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
	VMCOREINFO_SYMBOL(kallsyms_addresses);
 | 
					 | 
				
			||||||
#endif /* CONFIG_KALLSYMS_BASE_RELATIVE */
 | 
					 | 
				
			||||||
#endif /* CONFIG_KALLSYMS */
 | 
					#endif /* CONFIG_KALLSYMS */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	arch_crash_save_vmcoreinfo();
 | 
						arch_crash_save_vmcoreinfo();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@
 | 
				
			||||||
 * of the GNU General Public License, incorporated herein by reference.
 | 
					 * of the GNU General Public License, incorporated herein by reference.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Usage: kallsyms [--all-symbols] [--absolute-percpu]
 | 
					 * Usage: kallsyms [--all-symbols] [--absolute-percpu]
 | 
				
			||||||
 *                         [--base-relative] [--lto-clang] in.map > out.S
 | 
					 *                         [--lto-clang] in.map > out.S
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *      Table compression uses all the unused char codes on the symbols and
 | 
					 *      Table compression uses all the unused char codes on the symbols and
 | 
				
			||||||
 *  maps these to the most used substrings (tokens). For instance, it might
 | 
					 *  maps these to the most used substrings (tokens). For instance, it might
 | 
				
			||||||
| 
						 | 
					@ -63,7 +63,6 @@ static struct sym_entry **table;
 | 
				
			||||||
static unsigned int table_size, table_cnt;
 | 
					static unsigned int table_size, table_cnt;
 | 
				
			||||||
static int all_symbols;
 | 
					static int all_symbols;
 | 
				
			||||||
static int absolute_percpu;
 | 
					static int absolute_percpu;
 | 
				
			||||||
static int base_relative;
 | 
					 | 
				
			||||||
static int lto_clang;
 | 
					static int lto_clang;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int token_profit[0x10000];
 | 
					static int token_profit[0x10000];
 | 
				
			||||||
| 
						 | 
					@ -76,7 +75,7 @@ static unsigned char best_table_len[256];
 | 
				
			||||||
static void usage(void)
 | 
					static void usage(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] "
 | 
						fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] "
 | 
				
			||||||
			"[--base-relative] [--lto-clang] in.map > out.S\n");
 | 
								"[--lto-clang] in.map > out.S\n");
 | 
				
			||||||
	exit(1);
 | 
						exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -491,54 +490,43 @@ static void write_src(void)
 | 
				
			||||||
		printf("\t.short\t%d\n", best_idx[i]);
 | 
							printf("\t.short\t%d\n", best_idx[i]);
 | 
				
			||||||
	printf("\n");
 | 
						printf("\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!base_relative)
 | 
						output_label("kallsyms_offsets");
 | 
				
			||||||
		output_label("kallsyms_addresses");
 | 
					 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
		output_label("kallsyms_offsets");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < table_cnt; i++) {
 | 
						for (i = 0; i < table_cnt; i++) {
 | 
				
			||||||
		if (base_relative) {
 | 
							/*
 | 
				
			||||||
			/*
 | 
							 * Use the offset relative to the lowest value
 | 
				
			||||||
			 * Use the offset relative to the lowest value
 | 
							 * encountered of all relative symbols, and emit
 | 
				
			||||||
			 * encountered of all relative symbols, and emit
 | 
							 * non-relocatable fixed offsets that will be fixed
 | 
				
			||||||
			 * non-relocatable fixed offsets that will be fixed
 | 
							 * up at runtime.
 | 
				
			||||||
			 * up at runtime.
 | 
							 */
 | 
				
			||||||
			 */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			long long offset;
 | 
							long long offset;
 | 
				
			||||||
			int overflow;
 | 
							int overflow;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (!absolute_percpu) {
 | 
							if (!absolute_percpu) {
 | 
				
			||||||
				offset = table[i]->addr - relative_base;
 | 
								offset = table[i]->addr - relative_base;
 | 
				
			||||||
				overflow = (offset < 0 || offset > UINT_MAX);
 | 
								overflow = (offset < 0 || offset > UINT_MAX);
 | 
				
			||||||
			} else if (symbol_absolute(table[i])) {
 | 
							} else if (symbol_absolute(table[i])) {
 | 
				
			||||||
				offset = table[i]->addr;
 | 
								offset = table[i]->addr;
 | 
				
			||||||
				overflow = (offset < 0 || offset > INT_MAX);
 | 
								overflow = (offset < 0 || offset > INT_MAX);
 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				offset = relative_base - table[i]->addr - 1;
 | 
					 | 
				
			||||||
				overflow = (offset < INT_MIN || offset >= 0);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if (overflow) {
 | 
					 | 
				
			||||||
				fprintf(stderr, "kallsyms failure: "
 | 
					 | 
				
			||||||
					"%s symbol value %#llx out of range in relative mode\n",
 | 
					 | 
				
			||||||
					symbol_absolute(table[i]) ? "absolute" : "relative",
 | 
					 | 
				
			||||||
					table[i]->addr);
 | 
					 | 
				
			||||||
				exit(EXIT_FAILURE);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			printf("\t.long\t%#x	/* %s */\n", (int)offset, table[i]->sym);
 | 
					 | 
				
			||||||
		} else if (!symbol_absolute(table[i])) {
 | 
					 | 
				
			||||||
			output_address(table[i]->addr);
 | 
					 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			printf("\tPTR\t%#llx\n", table[i]->addr);
 | 
								offset = relative_base - table[i]->addr - 1;
 | 
				
			||||||
 | 
								overflow = (offset < INT_MIN || offset >= 0);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if (overflow) {
 | 
				
			||||||
 | 
								fprintf(stderr, "kallsyms failure: "
 | 
				
			||||||
 | 
									"%s symbol value %#llx out of range in relative mode\n",
 | 
				
			||||||
 | 
									symbol_absolute(table[i]) ? "absolute" : "relative",
 | 
				
			||||||
 | 
									table[i]->addr);
 | 
				
			||||||
 | 
								exit(EXIT_FAILURE);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							printf("\t.long\t%#x	/* %s */\n", (int)offset, table[i]->sym);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	printf("\n");
 | 
						printf("\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (base_relative) {
 | 
						output_label("kallsyms_relative_base");
 | 
				
			||||||
		output_label("kallsyms_relative_base");
 | 
						output_address(relative_base);
 | 
				
			||||||
		output_address(relative_base);
 | 
						printf("\n");
 | 
				
			||||||
		printf("\n");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (lto_clang)
 | 
						if (lto_clang)
 | 
				
			||||||
		for (i = 0; i < table_cnt; i++)
 | 
							for (i = 0; i < table_cnt; i++)
 | 
				
			||||||
| 
						 | 
					@ -820,7 +808,6 @@ int main(int argc, char **argv)
 | 
				
			||||||
		static const struct option long_options[] = {
 | 
							static const struct option long_options[] = {
 | 
				
			||||||
			{"all-symbols",     no_argument, &all_symbols,     1},
 | 
								{"all-symbols",     no_argument, &all_symbols,     1},
 | 
				
			||||||
			{"absolute-percpu", no_argument, &absolute_percpu, 1},
 | 
								{"absolute-percpu", no_argument, &absolute_percpu, 1},
 | 
				
			||||||
			{"base-relative",   no_argument, &base_relative,   1},
 | 
					 | 
				
			||||||
			{"lto-clang",       no_argument, <o_clang,       1},
 | 
								{"lto-clang",       no_argument, <o_clang,       1},
 | 
				
			||||||
			{},
 | 
								{},
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
| 
						 | 
					@ -841,8 +828,7 @@ int main(int argc, char **argv)
 | 
				
			||||||
	if (absolute_percpu)
 | 
						if (absolute_percpu)
 | 
				
			||||||
		make_percpus_absolute();
 | 
							make_percpus_absolute();
 | 
				
			||||||
	sort_symbols();
 | 
						sort_symbols();
 | 
				
			||||||
	if (base_relative)
 | 
						record_relative_base();
 | 
				
			||||||
		record_relative_base();
 | 
					 | 
				
			||||||
	optimize_token_table();
 | 
						optimize_token_table();
 | 
				
			||||||
	write_src();
 | 
						write_src();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -156,10 +156,6 @@ kallsyms()
 | 
				
			||||||
		kallsymopt="${kallsymopt} --absolute-percpu"
 | 
							kallsymopt="${kallsymopt} --absolute-percpu"
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if is_enabled CONFIG_KALLSYMS_BASE_RELATIVE; then
 | 
					 | 
				
			||||||
		kallsymopt="${kallsymopt} --base-relative"
 | 
					 | 
				
			||||||
	fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if is_enabled CONFIG_LTO_CLANG; then
 | 
						if is_enabled CONFIG_LTO_CLANG; then
 | 
				
			||||||
		kallsymopt="${kallsymopt} --lto-clang"
 | 
							kallsymopt="${kallsymopt} --lto-clang"
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,6 @@ static bool is_ignored_symbol(const char *name, char type)
 | 
				
			||||||
		 * when --all-symbols is specified so exclude them to get a
 | 
							 * when --all-symbols is specified so exclude them to get a
 | 
				
			||||||
		 * stable symbol list.
 | 
							 * stable symbol list.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		"kallsyms_addresses",
 | 
					 | 
				
			||||||
		"kallsyms_offsets",
 | 
							"kallsyms_offsets",
 | 
				
			||||||
		"kallsyms_relative_base",
 | 
							"kallsyms_relative_base",
 | 
				
			||||||
		"kallsyms_num_syms",
 | 
							"kallsyms_num_syms",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue