Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kallsyms: Remove KALLSYMS_ABSOLUTE_PERCPU

x86-64 was the only user.

Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250123190747.745588-16-brgerst@gmail.com

authored by

Brian Gerst and committed by
Ingo Molnar
01157ddc 4b00c116

+13 -78
-5
init/Kconfig
··· 1869 1869 1870 1870 Say N unless you really need all symbols, or kernel live patching. 1871 1871 1872 - config KALLSYMS_ABSOLUTE_PERCPU 1873 - bool 1874 - depends on KALLSYMS 1875 - default n 1876 - 1877 1872 # end of the "standard kernel features (expert users)" menu 1878 1873 1879 1874 config ARCH_HAS_MEMBARRIER_CALLBACKS
+2 -10
kernel/kallsyms.c
··· 148 148 149 149 unsigned long kallsyms_sym_address(int idx) 150 150 { 151 - /* values are unsigned offsets if --absolute-percpu is not in effect */ 152 - if (!IS_ENABLED(CONFIG_KALLSYMS_ABSOLUTE_PERCPU)) 153 - return kallsyms_relative_base + (u32)kallsyms_offsets[idx]; 154 - 155 - /* ...otherwise, positive offsets are absolute values */ 156 - if (kallsyms_offsets[idx] >= 0) 157 - return kallsyms_offsets[idx]; 158 - 159 - /* ...and negative offsets are relative to kallsyms_relative_base - 1 */ 160 - return kallsyms_relative_base - 1 - kallsyms_offsets[idx]; 151 + /* values are unsigned offsets */ 152 + return kallsyms_relative_base + (u32)kallsyms_offsets[idx]; 161 153 } 162 154 163 155 static unsigned int get_symbol_seq(int index)
+11 -59
scripts/kallsyms.c
··· 5 5 * This software may be used and distributed according to the terms 6 6 * of the GNU General Public License, incorporated herein by reference. 7 7 * 8 - * Usage: kallsyms [--all-symbols] [--absolute-percpu] in.map > out.S 8 + * Usage: kallsyms [--all-symbols] in.map > out.S 9 9 * 10 10 * Table compression uses all the unused char codes on the symbols and 11 11 * maps these to the most used substrings (tokens). For instance, it might ··· 37 37 unsigned long long addr; 38 38 unsigned int len; 39 39 unsigned int seq; 40 - bool percpu_absolute; 41 40 unsigned char sym[]; 42 41 }; 43 42 ··· 54 55 #define text_range_text (&text_ranges[0]) 55 56 #define text_range_inittext (&text_ranges[1]) 56 57 57 - static struct addr_range percpu_range = { 58 - "__per_cpu_start", "__per_cpu_end", -1ULL, 0 59 - }; 60 - 61 58 static struct sym_entry **table; 62 59 static unsigned int table_size, table_cnt; 63 60 static int all_symbols; 64 - static int absolute_percpu; 65 61 66 62 static int token_profit[0x10000]; 67 63 ··· 67 73 68 74 static void usage(void) 69 75 { 70 - fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] in.map > out.S\n"); 76 + fprintf(stderr, "Usage: kallsyms [--all-symbols] in.map > out.S\n"); 71 77 exit(1); 72 78 } 73 79 ··· 158 164 return NULL; 159 165 160 166 check_symbol_range(name, addr, text_ranges, ARRAY_SIZE(text_ranges)); 161 - check_symbol_range(name, addr, &percpu_range, 1); 162 167 163 168 /* include the type field in the symbol name, so that it gets 164 169 * compressed together */ ··· 168 175 sym->len = len; 169 176 sym->sym[0] = type; 170 177 strcpy(sym_name(sym), name); 171 - sym->percpu_absolute = false; 172 178 173 179 return sym; 174 180 } ··· 311 319 return total; 312 320 } 313 321 314 - static bool symbol_absolute(const struct sym_entry *s) 315 - { 316 - return s->percpu_absolute; 317 - } 318 - 319 322 static int compare_names(const void *a, const void *b) 320 323 { 321 324 int ret; ··· 442 455 */ 443 456 444 457 long long offset; 445 - bool overflow; 446 458 447 - if (!absolute_percpu) { 448 - offset = table[i]->addr - relative_base; 449 - overflow = offset < 0 || offset > UINT_MAX; 450 - } else if (symbol_absolute(table[i])) { 451 - offset = table[i]->addr; 452 - overflow = offset < 0 || offset > INT_MAX; 453 - } else { 454 - offset = relative_base - table[i]->addr - 1; 455 - overflow = offset < INT_MIN || offset >= 0; 456 - } 457 - if (overflow) { 459 + offset = table[i]->addr - relative_base; 460 + if (offset < 0 || offset > UINT_MAX) { 458 461 fprintf(stderr, "kallsyms failure: " 459 - "%s symbol value %#llx out of range in relative mode\n", 460 - symbol_absolute(table[i]) ? "absolute" : "relative", 462 + "relative symbol value %#llx out of range\n", 461 463 table[i]->addr); 462 464 exit(EXIT_FAILURE); 463 465 } ··· 701 725 qsort(table, table_cnt, sizeof(table[0]), compare_symbols); 702 726 } 703 727 704 - static void make_percpus_absolute(void) 705 - { 706 - unsigned int i; 707 - 708 - for (i = 0; i < table_cnt; i++) 709 - if (symbol_in_range(table[i], &percpu_range, 1)) { 710 - /* 711 - * Keep the 'A' override for percpu symbols to 712 - * ensure consistent behavior compared to older 713 - * versions of this tool. 714 - */ 715 - table[i]->sym[0] = 'A'; 716 - table[i]->percpu_absolute = true; 717 - } 718 - } 719 - 720 728 /* find the minimum non-absolute symbol address */ 721 729 static void record_relative_base(void) 722 730 { 723 - unsigned int i; 724 - 725 - for (i = 0; i < table_cnt; i++) 726 - if (!symbol_absolute(table[i])) { 727 - /* 728 - * The table is sorted by address. 729 - * Take the first non-absolute symbol value. 730 - */ 731 - relative_base = table[i]->addr; 732 - return; 733 - } 731 + /* 732 + * The table is sorted by address. 733 + * Take the first symbol value. 734 + */ 735 + if (table_cnt) 736 + relative_base = table[0]->addr; 734 737 } 735 738 736 739 int main(int argc, char **argv) ··· 717 762 while (1) { 718 763 static const struct option long_options[] = { 719 764 {"all-symbols", no_argument, &all_symbols, 1}, 720 - {"absolute-percpu", no_argument, &absolute_percpu, 1}, 721 765 {}, 722 766 }; 723 767 ··· 733 779 734 780 read_map(argv[optind]); 735 781 shrink_table(); 736 - if (absolute_percpu) 737 - make_percpus_absolute(); 738 782 sort_symbols(); 739 783 record_relative_base(); 740 784 optimize_token_table();