2005-04-17 02:20:36 +04:00
|
|
|
/* Generate assembler source containing symbol information
|
|
|
|
*
|
|
|
|
* Copyright 2002 by Kai Germaschewski
|
|
|
|
*
|
|
|
|
* This software may be used and distributed according to the terms
|
|
|
|
* of the GNU General Public License, incorporated herein by reference.
|
|
|
|
*
|
|
|
|
* Usage: nm -n vmlinux | scripts/kallsyms [--all-symbols] > symbols.S
|
|
|
|
*
|
|
|
|
* Table compression uses all the unused char codes on the symbols and
|
|
|
|
* maps these to the most used substrings (tokens). For instance, it might
|
|
|
|
* map char code 0xF7 to represent "write_" and then in every symbol where
|
|
|
|
* "write_" appears it can be replaced by 0xF7, saving 5 bytes.
|
|
|
|
* The used codes themselves are also placed in the table so that the
|
|
|
|
* decompresion can work without "special cases".
|
|
|
|
* Applied to kernel symbols, this usually produces a compression ratio
|
|
|
|
* of about 50%.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
#include <limits.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-06-09 03:12:13 +04:00
|
|
|
#ifndef ARRAY_SIZE
|
|
|
|
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
|
|
|
#endif
|
|
|
|
|
2007-07-17 15:03:51 +04:00
|
|
|
#define KSYM_NAME_LEN 128
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
struct sym_entry {
|
|
|
|
unsigned long long addr;
|
2005-09-07 02:16:31 +04:00
|
|
|
unsigned int len;
|
2008-02-06 12:37:33 +03:00
|
|
|
unsigned int start_pos;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned char *sym;
|
kallsyms: don't overload absolute symbol type for percpu symbols
Commit c6bda7c988a5 ("kallsyms: fix percpu vars on x86-64 with
relocation") overloaded the 'A' (absolute) symbol type to signify that a
symbol is not subject to dynamic relocation. However, the original A
type does not imply that at all, and depending on the version of the
toolchain, many A type symbols are emitted that are in fact relative to
the kernel text, i.e., if the kernel is relocated at runtime, these
symbols should be updated as well.
For instance, on sparc32, the following symbols are emitted as absolute
(kindly provided by Guenter Roeck):
f035a420 A _etext
f03d9000 A _sdata
f03de8c4 A jiffies
f03f8860 A _edata
f03fc000 A __init_begin
f041bdc8 A __init_text_end
f0423000 A __bss_start
f0423000 A __init_end
f044457d A __bss_stop
f044457d A _end
On x86_64, similar behavior can be observed:
ffffffff81a00000 A __end_rodata_hpage_align
ffffffff81b19000 A __vvar_page
ffffffff81d3d000 A _end
Even if only a couple of them pass the symbol range check that results
in them to be taken into account for the final kallsyms symbol table, it
is obvious that 'A' does not mean the symbol does not need to be updated
at relocation time, and overloading its meaning to signify that is
perhaps not a good idea.
So instead, add a new percpu_absolute member to struct sym_entry, and
when --absolute-percpu is in effect, use it to record symbols whose
addresses should be emitted as final values rather than values that
still require relocation at runtime. That way, we can drop the check
against the 'A' type.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:15 +03:00
|
|
|
unsigned int percpu_absolute;
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2014-03-17 06:48:27 +04:00
|
|
|
struct addr_range {
|
|
|
|
const char *start_sym, *end_sym;
|
2009-06-09 03:12:13 +04:00
|
|
|
unsigned long long start, end;
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned long long _text;
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
static unsigned long long relative_base;
|
2014-03-17 06:48:27 +04:00
|
|
|
static struct addr_range text_ranges[] = {
|
2009-06-09 03:12:13 +04:00
|
|
|
{ "_stext", "_etext" },
|
|
|
|
{ "_sinittext", "_einittext" },
|
|
|
|
{ "_stext_l1", "_etext_l1" }, /* Blackfin on-chip L1 inst SRAM */
|
|
|
|
{ "_stext_l2", "_etext_l2" }, /* Blackfin on-chip L2 SRAM */
|
|
|
|
};
|
|
|
|
#define text_range_text (&text_ranges[0])
|
|
|
|
#define text_range_inittext (&text_ranges[1])
|
|
|
|
|
2014-03-17 07:35:46 +04:00
|
|
|
static struct addr_range percpu_range = {
|
|
|
|
"__per_cpu_start", "__per_cpu_end", -1ULL, 0
|
|
|
|
};
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static struct sym_entry *table;
|
2005-09-07 02:16:31 +04:00
|
|
|
static unsigned int table_size, table_cnt;
|
2005-04-17 02:20:36 +04:00
|
|
|
static int all_symbols = 0;
|
2014-03-17 07:35:46 +04:00
|
|
|
static int absolute_percpu = 0;
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
static int base_relative = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
int token_profit[0x10000];
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* the table that holds the result of the compression */
|
2005-09-07 02:16:31 +04:00
|
|
|
unsigned char best_table[256][2];
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned char best_table_len[256];
|
|
|
|
|
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
static void usage(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2013-11-02 02:41:33 +04:00
|
|
|
fprintf(stderr, "Usage: kallsyms [--all-symbols] "
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
"[--base-relative] < in.map > out.S\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This ignores the intensely annoying "mapping symbols" found
|
|
|
|
* in ARM ELF files: $a, $t and $d.
|
|
|
|
*/
|
2005-09-07 02:16:31 +04:00
|
|
|
static inline int is_arm_mapping_symbol(const char *str)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2014-09-17 01:37:18 +04:00
|
|
|
return str[0] == '$' && strchr("axtd", str[1])
|
2005-04-17 02:20:36 +04:00
|
|
|
&& (str[2] == '\0' || str[2] == '.');
|
|
|
|
}
|
|
|
|
|
2014-03-17 06:48:27 +04:00
|
|
|
static int check_symbol_range(const char *sym, unsigned long long addr,
|
|
|
|
struct addr_range *ranges, int entries)
|
2009-06-09 03:12:13 +04:00
|
|
|
{
|
|
|
|
size_t i;
|
2014-03-17 06:48:27 +04:00
|
|
|
struct addr_range *ar;
|
2009-06-09 03:12:13 +04:00
|
|
|
|
2014-03-17 06:48:27 +04:00
|
|
|
for (i = 0; i < entries; ++i) {
|
|
|
|
ar = &ranges[i];
|
2009-06-09 03:12:13 +04:00
|
|
|
|
2014-03-17 06:48:27 +04:00
|
|
|
if (strcmp(sym, ar->start_sym) == 0) {
|
|
|
|
ar->start = addr;
|
2009-06-09 03:12:13 +04:00
|
|
|
return 0;
|
2014-03-17 06:48:27 +04:00
|
|
|
} else if (strcmp(sym, ar->end_sym) == 0) {
|
|
|
|
ar->end = addr;
|
2009-06-09 03:12:13 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
static int read_symbol(FILE *in, struct sym_entry *s)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-05-09 10:23:47 +03:00
|
|
|
char sym[500], stype;
|
2005-04-17 02:20:36 +04:00
|
|
|
int rc;
|
|
|
|
|
2018-05-09 10:23:47 +03:00
|
|
|
rc = fscanf(in, "%llx %c %499s\n", &s->addr, &stype, sym);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (rc != 3) {
|
2018-05-09 10:23:47 +03:00
|
|
|
if (rc != EOF && fgets(sym, 500, in) == NULL)
|
2010-09-11 09:13:33 +04:00
|
|
|
fprintf(stderr, "Read error or end of file.\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2018-05-09 10:23:47 +03:00
|
|
|
if (strlen(sym) > KSYM_NAME_LEN) {
|
2013-11-08 06:45:01 +04:00
|
|
|
fprintf(stderr, "Symbol %s too long for kallsyms (%zu vs %d).\n"
|
2014-06-10 14:08:13 +04:00
|
|
|
"Please increase KSYM_NAME_LEN both in kernel and kallsyms.c\n",
|
2018-05-09 10:23:47 +03:00
|
|
|
sym, strlen(sym), KSYM_NAME_LEN);
|
2013-10-23 17:07:53 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Ignore most absolute/undefined (?) symbols. */
|
2006-12-07 04:14:04 +03:00
|
|
|
if (strcmp(sym, "_text") == 0)
|
|
|
|
_text = s->addr;
|
2014-03-17 06:48:27 +04:00
|
|
|
else if (check_symbol_range(sym, s->addr, text_ranges,
|
|
|
|
ARRAY_SIZE(text_ranges)) == 0)
|
2009-06-09 03:12:13 +04:00
|
|
|
/* nothing to do */;
|
2005-09-07 02:16:31 +04:00
|
|
|
else if (toupper(stype) == 'A')
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
/* Keep these useful absolute symbols */
|
2005-05-01 19:59:06 +04:00
|
|
|
if (strcmp(sym, "__kernel_syscall_via_break") &&
|
|
|
|
strcmp(sym, "__kernel_syscall_via_epc") &&
|
|
|
|
strcmp(sym, "__kernel_sigtramp") &&
|
|
|
|
strcmp(sym, "__gp"))
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
2005-09-07 02:16:31 +04:00
|
|
|
else if (toupper(stype) == 'U' ||
|
2005-05-01 19:59:06 +04:00
|
|
|
is_arm_mapping_symbol(sym))
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
2005-09-07 02:16:41 +04:00
|
|
|
/* exclude also MIPS ELF local symbols ($L123 instead of .L123) */
|
2018-05-09 10:23:47 +03:00
|
|
|
else if (sym[0] == '$')
|
2005-09-07 02:16:41 +04:00
|
|
|
return -1;
|
2008-05-19 22:07:58 +04:00
|
|
|
/* exclude debugging symbols */
|
2017-10-14 01:57:58 +03:00
|
|
|
else if (stype == 'N' || stype == 'n')
|
2008-05-19 22:07:58 +04:00
|
|
|
return -1;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* include the type field in the symbol name, so that it gets
|
|
|
|
* compressed together */
|
2018-05-09 10:23:47 +03:00
|
|
|
s->len = strlen(sym) + 1;
|
2005-09-07 02:16:31 +04:00
|
|
|
s->sym = malloc(s->len + 1);
|
2006-03-25 14:07:46 +03:00
|
|
|
if (!s->sym) {
|
|
|
|
fprintf(stderr, "kallsyms failure: "
|
|
|
|
"unable to allocate required amount of memory\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2018-05-09 10:23:47 +03:00
|
|
|
strcpy((char *)s->sym + 1, sym);
|
2005-09-07 02:16:31 +04:00
|
|
|
s->sym[0] = stype;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
kallsyms: don't overload absolute symbol type for percpu symbols
Commit c6bda7c988a5 ("kallsyms: fix percpu vars on x86-64 with
relocation") overloaded the 'A' (absolute) symbol type to signify that a
symbol is not subject to dynamic relocation. However, the original A
type does not imply that at all, and depending on the version of the
toolchain, many A type symbols are emitted that are in fact relative to
the kernel text, i.e., if the kernel is relocated at runtime, these
symbols should be updated as well.
For instance, on sparc32, the following symbols are emitted as absolute
(kindly provided by Guenter Roeck):
f035a420 A _etext
f03d9000 A _sdata
f03de8c4 A jiffies
f03f8860 A _edata
f03fc000 A __init_begin
f041bdc8 A __init_text_end
f0423000 A __bss_start
f0423000 A __init_end
f044457d A __bss_stop
f044457d A _end
On x86_64, similar behavior can be observed:
ffffffff81a00000 A __end_rodata_hpage_align
ffffffff81b19000 A __vvar_page
ffffffff81d3d000 A _end
Even if only a couple of them pass the symbol range check that results
in them to be taken into account for the final kallsyms symbol table, it
is obvious that 'A' does not mean the symbol does not need to be updated
at relocation time, and overloading its meaning to signify that is
perhaps not a good idea.
So instead, add a new percpu_absolute member to struct sym_entry, and
when --absolute-percpu is in effect, use it to record symbols whose
addresses should be emitted as final values rather than values that
still require relocation at runtime. That way, we can drop the check
against the 'A' type.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:15 +03:00
|
|
|
s->percpu_absolute = 0;
|
|
|
|
|
2014-03-17 07:35:46 +04:00
|
|
|
/* Record if we've found __per_cpu_start/end. */
|
|
|
|
check_symbol_range(sym, s->addr, &percpu_range, 1);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-17 06:48:27 +04:00
|
|
|
static int symbol_in_range(struct sym_entry *s, struct addr_range *ranges,
|
|
|
|
int entries)
|
2009-06-09 03:12:13 +04:00
|
|
|
{
|
|
|
|
size_t i;
|
2014-03-17 06:48:27 +04:00
|
|
|
struct addr_range *ar;
|
2009-06-09 03:12:13 +04:00
|
|
|
|
2014-03-17 06:48:27 +04:00
|
|
|
for (i = 0; i < entries; ++i) {
|
|
|
|
ar = &ranges[i];
|
2009-06-09 03:12:13 +04:00
|
|
|
|
2014-03-17 06:48:27 +04:00
|
|
|
if (s->addr >= ar->start && s->addr <= ar->end)
|
2009-06-15 15:52:48 +04:00
|
|
|
return 1;
|
2009-06-09 03:12:13 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 15:52:48 +04:00
|
|
|
return 0;
|
2009-06-09 03:12:13 +04:00
|
|
|
}
|
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
static int symbol_valid(struct sym_entry *s)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
/* Symbols which vary between passes. Passes 1 and 2 must have
|
2009-01-14 23:38:20 +03:00
|
|
|
* identical symbol lists. The kallsyms_* symbols below are only added
|
|
|
|
* after pass 1, they would be included in pass 2 when --all-symbols is
|
|
|
|
* specified so exclude them to get a stable symbol list.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
static char *special_symbols[] = {
|
2009-01-14 23:38:20 +03:00
|
|
|
"kallsyms_addresses",
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
"kallsyms_offsets",
|
|
|
|
"kallsyms_relative_base",
|
2009-01-14 23:38:20 +03:00
|
|
|
"kallsyms_num_syms",
|
|
|
|
"kallsyms_names",
|
|
|
|
"kallsyms_markers",
|
|
|
|
"kallsyms_token_table",
|
|
|
|
"kallsyms_token_index",
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Exclude linker generated symbols which vary between passes */
|
|
|
|
"_SDA_BASE_", /* ppc */
|
|
|
|
"_SDA2_BASE_", /* ppc */
|
|
|
|
NULL };
|
2015-03-30 16:20:31 +03:00
|
|
|
|
2017-02-03 12:54:05 +03:00
|
|
|
static char *special_prefixes[] = {
|
|
|
|
"__crc_", /* modversions */
|
2018-03-01 20:19:01 +03:00
|
|
|
"__efistub_", /* arm64 EFI stub namespace */
|
2017-02-03 12:54:05 +03:00
|
|
|
NULL };
|
|
|
|
|
2015-03-30 16:20:31 +03:00
|
|
|
static char *special_suffixes[] = {
|
|
|
|
"_veneer", /* arm */
|
2016-04-01 16:33:48 +03:00
|
|
|
"_from_arm", /* arm */
|
|
|
|
"_from_thumb", /* arm */
|
2015-03-30 16:20:31 +03:00
|
|
|
NULL };
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
int i;
|
2015-03-30 16:20:31 +03:00
|
|
|
char *sym_name = (char *)s->sym + 1;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* if --all-symbols is not specified, then symbols outside the text
|
|
|
|
* and inittext sections are discarded */
|
|
|
|
if (!all_symbols) {
|
2014-03-17 06:48:27 +04:00
|
|
|
if (symbol_in_range(s, text_ranges,
|
|
|
|
ARRAY_SIZE(text_ranges)) == 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
/* Corner case. Discard any symbols with the same value as
|
2008-02-06 12:36:26 +03:00
|
|
|
* _etext _einittext; they can move between pass 1 and 2 when
|
|
|
|
* the kallsyms data are added. If these symbols move then
|
|
|
|
* they may get dropped in pass 2, which breaks the kallsyms
|
|
|
|
* rules.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2009-06-09 03:12:13 +04:00
|
|
|
if ((s->addr == text_range_text->end &&
|
2015-03-30 16:20:31 +03:00
|
|
|
strcmp(sym_name,
|
2014-03-17 06:48:27 +04:00
|
|
|
text_range_text->end_sym)) ||
|
2009-06-09 03:12:13 +04:00
|
|
|
(s->addr == text_range_inittext->end &&
|
2015-03-30 16:20:31 +03:00
|
|
|
strcmp(sym_name,
|
2014-03-17 06:48:27 +04:00
|
|
|
text_range_inittext->end_sym)))
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exclude symbols which vary between passes. */
|
|
|
|
for (i = 0; special_symbols[i]; i++)
|
2015-03-30 16:20:31 +03:00
|
|
|
if (strcmp(sym_name, special_symbols[i]) == 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
|
2017-02-03 12:54:05 +03:00
|
|
|
for (i = 0; special_prefixes[i]; i++) {
|
|
|
|
int l = strlen(special_prefixes[i]);
|
|
|
|
|
|
|
|
if (l <= strlen(sym_name) &&
|
|
|
|
strncmp(sym_name, special_prefixes[i], l) == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-30 16:20:31 +03:00
|
|
|
for (i = 0; special_suffixes[i]; i++) {
|
|
|
|
int l = strlen(sym_name) - strlen(special_suffixes[i]);
|
|
|
|
|
|
|
|
if (l >= 0 && strcmp(sym_name + l, special_suffixes[i]) == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
static void read_map(FILE *in)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
while (!feof(in)) {
|
2005-09-07 02:16:31 +04:00
|
|
|
if (table_cnt >= table_size) {
|
|
|
|
table_size += 10000;
|
|
|
|
table = realloc(table, sizeof(*table) * table_size);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!table) {
|
|
|
|
fprintf(stderr, "out of memory\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
2008-02-06 12:37:33 +03:00
|
|
|
if (read_symbol(in, &table[table_cnt]) == 0) {
|
|
|
|
table[table_cnt].start_pos = table_cnt;
|
2005-09-07 02:16:31 +04:00
|
|
|
table_cnt++;
|
2008-02-06 12:37:33 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_label(char *label)
|
|
|
|
{
|
2018-05-09 10:23:47 +03:00
|
|
|
printf(".globl %s\n", label);
|
2005-04-17 02:20:36 +04:00
|
|
|
printf("\tALGN\n");
|
2018-05-09 10:23:47 +03:00
|
|
|
printf("%s:\n", label);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* uncompress a compressed symbol. When this function is called, the best table
|
|
|
|
* might still be compressed itself, so the function needs to be recursive */
|
|
|
|
static int expand_symbol(unsigned char *data, int len, char *result)
|
|
|
|
{
|
|
|
|
int c, rlen, total=0;
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
c = *data;
|
|
|
|
/* if the table holds a single char that is the same as the one
|
|
|
|
* we are looking for, then end the search */
|
|
|
|
if (best_table[c][0]==c && best_table_len[c]==1) {
|
|
|
|
*result++ = c;
|
|
|
|
total++;
|
|
|
|
} else {
|
|
|
|
/* if not, recurse and expand */
|
|
|
|
rlen = expand_symbol(best_table[c], best_table_len[c], result);
|
|
|
|
total += rlen;
|
|
|
|
result += rlen;
|
|
|
|
}
|
|
|
|
data++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
*result=0;
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2014-03-17 06:48:27 +04:00
|
|
|
static int symbol_absolute(struct sym_entry *s)
|
|
|
|
{
|
kallsyms: don't overload absolute symbol type for percpu symbols
Commit c6bda7c988a5 ("kallsyms: fix percpu vars on x86-64 with
relocation") overloaded the 'A' (absolute) symbol type to signify that a
symbol is not subject to dynamic relocation. However, the original A
type does not imply that at all, and depending on the version of the
toolchain, many A type symbols are emitted that are in fact relative to
the kernel text, i.e., if the kernel is relocated at runtime, these
symbols should be updated as well.
For instance, on sparc32, the following symbols are emitted as absolute
(kindly provided by Guenter Roeck):
f035a420 A _etext
f03d9000 A _sdata
f03de8c4 A jiffies
f03f8860 A _edata
f03fc000 A __init_begin
f041bdc8 A __init_text_end
f0423000 A __bss_start
f0423000 A __init_end
f044457d A __bss_stop
f044457d A _end
On x86_64, similar behavior can be observed:
ffffffff81a00000 A __end_rodata_hpage_align
ffffffff81b19000 A __vvar_page
ffffffff81d3d000 A _end
Even if only a couple of them pass the symbol range check that results
in them to be taken into account for the final kallsyms symbol table, it
is obvious that 'A' does not mean the symbol does not need to be updated
at relocation time, and overloading its meaning to signify that is
perhaps not a good idea.
So instead, add a new percpu_absolute member to struct sym_entry, and
when --absolute-percpu is in effect, use it to record symbols whose
addresses should be emitted as final values rather than values that
still require relocation at runtime. That way, we can drop the check
against the 'A' type.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:15 +03:00
|
|
|
return s->percpu_absolute;
|
2014-03-17 06:48:27 +04:00
|
|
|
}
|
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
static void write_src(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-09-07 02:16:31 +04:00
|
|
|
unsigned int i, k, off;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int best_idx[256];
|
|
|
|
unsigned int *markers;
|
2007-07-17 15:03:51 +04:00
|
|
|
char buf[KSYM_NAME_LEN];
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
printf("#include <asm/types.h>\n");
|
|
|
|
printf("#if BITS_PER_LONG == 64\n");
|
|
|
|
printf("#define PTR .quad\n");
|
|
|
|
printf("#define ALGN .align 8\n");
|
|
|
|
printf("#else\n");
|
|
|
|
printf("#define PTR .long\n");
|
|
|
|
printf("#define ALGN .align 4\n");
|
|
|
|
printf("#endif\n");
|
|
|
|
|
2006-12-08 13:35:57 +03:00
|
|
|
printf("\t.section .rodata, \"a\"\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
/* Provide proper symbols relocatability by their relativeness
|
|
|
|
* to a fixed anchor point in the runtime image, either '_text'
|
|
|
|
* for absolute address tables, in which case the linker will
|
|
|
|
* emit the final addresses at build time. Otherwise, use the
|
|
|
|
* offset relative to the lowest value encountered of all relative
|
|
|
|
* symbols, and emit non-relocatable fixed offsets that will be fixed
|
|
|
|
* up at runtime.
|
|
|
|
*
|
|
|
|
* The symbol names cannot be used to construct normal symbol
|
|
|
|
* references as the list of symbols contains symbols that are
|
|
|
|
* declared static and are private to their .o files. This prevents
|
|
|
|
* .tmp_kallsyms.o or any other object from referencing them.
|
2006-12-07 04:14:04 +03:00
|
|
|
*/
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
if (!base_relative)
|
|
|
|
output_label("kallsyms_addresses");
|
|
|
|
else
|
|
|
|
output_label("kallsyms_offsets");
|
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
for (i = 0; i < table_cnt; i++) {
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
if (base_relative) {
|
|
|
|
long long offset;
|
|
|
|
int overflow;
|
|
|
|
|
|
|
|
if (!absolute_percpu) {
|
|
|
|
offset = table[i].addr - relative_base;
|
|
|
|
overflow = (offset < 0 || offset > UINT_MAX);
|
|
|
|
} else if (symbol_absolute(&table[i])) {
|
|
|
|
offset = table[i].addr;
|
|
|
|
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\n", (int)offset);
|
|
|
|
} else if (!symbol_absolute(&table[i])) {
|
2006-12-07 04:14:10 +03:00
|
|
|
if (_text <= table[i].addr)
|
|
|
|
printf("\tPTR\t_text + %#llx\n",
|
|
|
|
table[i].addr - _text);
|
|
|
|
else
|
2014-03-11 02:49:48 +04:00
|
|
|
printf("\tPTR\t_text - %#llx\n",
|
|
|
|
_text - table[i].addr);
|
2006-12-07 04:14:04 +03:00
|
|
|
} else {
|
|
|
|
printf("\tPTR\t%#llx\n", table[i].addr);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
if (base_relative) {
|
|
|
|
output_label("kallsyms_relative_base");
|
|
|
|
printf("\tPTR\t_text - %#llx\n", _text - relative_base);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
output_label("kallsyms_num_syms");
|
2018-05-24 06:16:12 +03:00
|
|
|
printf("\tPTR\t%u\n", table_cnt);
|
2005-04-17 02:20:36 +04:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* table of offset markers, that give the offset in the compressed stream
|
|
|
|
* every 256 symbols */
|
2006-03-25 14:07:46 +03:00
|
|
|
markers = malloc(sizeof(unsigned int) * ((table_cnt + 255) / 256));
|
|
|
|
if (!markers) {
|
|
|
|
fprintf(stderr, "kallsyms failure: "
|
|
|
|
"unable to allocate required memory\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
output_label("kallsyms_names");
|
|
|
|
off = 0;
|
2005-09-07 02:16:31 +04:00
|
|
|
for (i = 0; i < table_cnt; i++) {
|
|
|
|
if ((i & 0xFF) == 0)
|
|
|
|
markers[i >> 8] = off;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
printf("\t.byte 0x%02x", table[i].len);
|
|
|
|
for (k = 0; k < table[i].len; k++)
|
|
|
|
printf(", 0x%02x", table[i].sym[k]);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
off += table[i].len + 1;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
output_label("kallsyms_markers");
|
2005-09-07 02:16:31 +04:00
|
|
|
for (i = 0; i < ((table_cnt + 255) >> 8); i++)
|
2005-04-17 02:20:36 +04:00
|
|
|
printf("\tPTR\t%d\n", markers[i]);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
free(markers);
|
|
|
|
|
|
|
|
output_label("kallsyms_token_table");
|
|
|
|
off = 0;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
best_idx[i] = off;
|
2005-09-07 02:16:31 +04:00
|
|
|
expand_symbol(best_table[i], best_table_len[i], buf);
|
2005-04-17 02:20:36 +04:00
|
|
|
printf("\t.asciz\t\"%s\"\n", buf);
|
|
|
|
off += strlen(buf) + 1;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
output_label("kallsyms_token_index");
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
printf("\t.short\t%d\n", best_idx[i]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* table lookup compression functions */
|
|
|
|
|
|
|
|
/* count all the possible tokens in a symbol */
|
|
|
|
static void learn_symbol(unsigned char *symbol, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len - 1; i++)
|
2005-09-07 02:16:31 +04:00
|
|
|
token_profit[ symbol[i] + (symbol[i + 1] << 8) ]++;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* decrease the count for all the possible tokens in a symbol */
|
|
|
|
static void forget_symbol(unsigned char *symbol, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len - 1; i++)
|
2005-09-07 02:16:31 +04:00
|
|
|
token_profit[ symbol[i] + (symbol[i + 1] << 8) ]--;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
/* remove all the invalid symbols from the table and do the initial token count */
|
2005-04-17 02:20:36 +04:00
|
|
|
static void build_initial_tok_table(void)
|
|
|
|
{
|
2005-09-07 02:16:31 +04:00
|
|
|
unsigned int i, pos;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
pos = 0;
|
|
|
|
for (i = 0; i < table_cnt; i++) {
|
2005-04-17 02:20:36 +04:00
|
|
|
if ( symbol_valid(&table[i]) ) {
|
2005-09-07 02:16:31 +04:00
|
|
|
if (pos != i)
|
|
|
|
table[pos] = table[i];
|
|
|
|
learn_symbol(table[pos].sym, table[pos].len);
|
|
|
|
pos++;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
2005-09-07 02:16:31 +04:00
|
|
|
table_cnt = pos;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-06-20 21:09:00 +04:00
|
|
|
static void *find_token(unsigned char *str, int len, unsigned char *token)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len - 1; i++) {
|
|
|
|
if (str[i] == token[0] && str[i+1] == token[1])
|
|
|
|
return &str[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* replace a given token in all the valid symbols. Use the sampled symbols
|
|
|
|
* to update the counts */
|
2005-09-07 02:16:31 +04:00
|
|
|
static void compress_symbols(unsigned char *str, int idx)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-09-07 02:16:31 +04:00
|
|
|
unsigned int i, len, size;
|
|
|
|
unsigned char *p1, *p2;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
for (i = 0; i < table_cnt; i++) {
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
len = table[i].len;
|
2005-09-07 02:16:31 +04:00
|
|
|
p1 = table[i].sym;
|
|
|
|
|
|
|
|
/* find the token on the symbol */
|
2007-06-20 21:09:00 +04:00
|
|
|
p2 = find_token(p1, len, str);
|
2005-09-07 02:16:31 +04:00
|
|
|
if (!p2) continue;
|
|
|
|
|
|
|
|
/* decrease the counts for this symbol's tokens */
|
|
|
|
forget_symbol(table[i].sym, len);
|
|
|
|
|
|
|
|
size = len;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
do {
|
2005-09-07 02:16:31 +04:00
|
|
|
*p2 = idx;
|
|
|
|
p2++;
|
|
|
|
size -= (p2 - p1);
|
|
|
|
memmove(p2, p2 + 1, size);
|
|
|
|
p1 = p2;
|
|
|
|
len--;
|
|
|
|
|
|
|
|
if (size < 2) break;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* find the token on the symbol */
|
2007-06-20 21:09:00 +04:00
|
|
|
p2 = find_token(p1, size, str);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
} while (p2);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
table[i].len = len;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
/* increase the counts for this symbol's new tokens */
|
|
|
|
learn_symbol(table[i].sym, len);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search the token with the maximum profit */
|
2005-09-07 02:16:31 +04:00
|
|
|
static int find_best_token(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-09-07 02:16:31 +04:00
|
|
|
int i, best, bestprofit;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
bestprofit=-10000;
|
2005-09-07 02:16:31 +04:00
|
|
|
best = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
for (i = 0; i < 0x10000; i++) {
|
|
|
|
if (token_profit[i] > bestprofit) {
|
|
|
|
best = i;
|
|
|
|
bestprofit = token_profit[i];
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the core of the algorithm: calculate the "best" table */
|
|
|
|
static void optimize_result(void)
|
|
|
|
{
|
2005-09-07 02:16:31 +04:00
|
|
|
int i, best;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* using the '\0' symbol last allows compress_symbols to use standard
|
|
|
|
* fast string functions */
|
|
|
|
for (i = 255; i >= 0; i--) {
|
|
|
|
|
|
|
|
/* if this table slot is empty (it is not used by an actual
|
|
|
|
* original char code */
|
|
|
|
if (!best_table_len[i]) {
|
|
|
|
|
2018-02-27 11:16:19 +03:00
|
|
|
/* find the token with the best profit value */
|
2005-04-17 02:20:36 +04:00
|
|
|
best = find_best_token();
|
2011-05-01 07:41:41 +04:00
|
|
|
if (token_profit[best] == 0)
|
|
|
|
break;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* place it in the "best" table */
|
2005-09-07 02:16:31 +04:00
|
|
|
best_table_len[i] = 2;
|
|
|
|
best_table[i][0] = best & 0xFF;
|
|
|
|
best_table[i][1] = (best >> 8) & 0xFF;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* replace this token in all the valid symbols */
|
2005-09-07 02:16:31 +04:00
|
|
|
compress_symbols(best_table[i], i);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start by placing the symbols that are actually used on the table */
|
|
|
|
static void insert_real_symbols_in_table(void)
|
|
|
|
{
|
2005-09-07 02:16:31 +04:00
|
|
|
unsigned int i, j, c;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
memset(best_table, 0, sizeof(best_table));
|
|
|
|
memset(best_table_len, 0, sizeof(best_table_len));
|
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
for (i = 0; i < table_cnt; i++) {
|
|
|
|
for (j = 0; j < table[i].len; j++) {
|
|
|
|
c = table[i].sym[j];
|
|
|
|
best_table[c][0]=c;
|
|
|
|
best_table_len[c]=1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void optimize_token_table(void)
|
|
|
|
{
|
|
|
|
build_initial_tok_table();
|
|
|
|
|
|
|
|
insert_real_symbols_in_table();
|
|
|
|
|
2005-05-01 19:59:06 +04:00
|
|
|
/* When valid symbol is not registered, exit to error */
|
2005-09-07 02:16:31 +04:00
|
|
|
if (!table_cnt) {
|
2005-05-01 19:59:06 +04:00
|
|
|
fprintf(stderr, "No valid symbol.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
optimize_result();
|
|
|
|
}
|
|
|
|
|
kallsyms, tracing: output more proper symbol name
Impact: bugfix, output more reliable symbol lookup result
Debug tools(dump_stack(), ftrace...) are like to print out symbols.
But it is always print out the first aliased symbol.(Aliased symbols
are symbols with the same address), and the first aliased symbol is
sometime not proper.
# echo function_graph > current_tracer
# cat trace
......
1) 1.923 us | select_nohz_load_balancer();
1) + 76.692 us | }
1) | default_idle() {
1) ==========> | __irqentry_text_start() {
1) 0.000 us | native_apic_mem_write();
1) | irq_enter() {
1) 0.000 us | idle_cpu();
1) | tick_check_idle() {
1) 0.000 us | tick_check_oneshot_broadcast();
1) | tick_nohz_stop_idle() {
......
It's very embarrassing, it ouputs "__irqentry_text_start()",
actually, it should output "smp_apic_timer_interrupt()".
(these two symbol are the same address, but "__irqentry_text_start"
is deemed to the first aliased symbol by scripts/kallsyms)
This patch puts symbols like "__irqentry_text_start" to the second
aliased symbols. And a more proper symbol name becomes the first.
Aliased symbols mostly come from linker script. The solution is
guessing "is this symbol defined in linker script", the symbols
defined in linker script will not become the first aliased symbol.
And if symbols are found to be equal in this "linker script provided"
criteria, symbols are sorted by the number of prefix underscores.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Reviewed-by: Paulo Marques <pmarques@grupopie.com>
LKML-Reference: <49BA06E2.7080807@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-13 10:10:26 +03:00
|
|
|
/* guess for "linker script provide" symbol */
|
|
|
|
static int may_be_linker_script_provide_symbol(const struct sym_entry *se)
|
|
|
|
{
|
|
|
|
const char *symbol = (char *)se->sym + 1;
|
|
|
|
int len = se->len - 1;
|
|
|
|
|
|
|
|
if (len < 8)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (symbol[0] != '_' || symbol[1] != '_')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* __start_XXXXX */
|
|
|
|
if (!memcmp(symbol + 2, "start_", 6))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* __stop_XXXXX */
|
|
|
|
if (!memcmp(symbol + 2, "stop_", 5))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* __end_XXXXX */
|
|
|
|
if (!memcmp(symbol + 2, "end_", 4))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* __XXXXX_start */
|
|
|
|
if (!memcmp(symbol + len - 6, "_start", 6))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* __XXXXX_end */
|
|
|
|
if (!memcmp(symbol + len - 4, "_end", 4))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int prefix_underscores_count(const char *str)
|
|
|
|
{
|
|
|
|
const char *tail = str;
|
|
|
|
|
2009-09-23 03:44:12 +04:00
|
|
|
while (*tail == '_')
|
kallsyms, tracing: output more proper symbol name
Impact: bugfix, output more reliable symbol lookup result
Debug tools(dump_stack(), ftrace...) are like to print out symbols.
But it is always print out the first aliased symbol.(Aliased symbols
are symbols with the same address), and the first aliased symbol is
sometime not proper.
# echo function_graph > current_tracer
# cat trace
......
1) 1.923 us | select_nohz_load_balancer();
1) + 76.692 us | }
1) | default_idle() {
1) ==========> | __irqentry_text_start() {
1) 0.000 us | native_apic_mem_write();
1) | irq_enter() {
1) 0.000 us | idle_cpu();
1) | tick_check_idle() {
1) 0.000 us | tick_check_oneshot_broadcast();
1) | tick_nohz_stop_idle() {
......
It's very embarrassing, it ouputs "__irqentry_text_start()",
actually, it should output "smp_apic_timer_interrupt()".
(these two symbol are the same address, but "__irqentry_text_start"
is deemed to the first aliased symbol by scripts/kallsyms)
This patch puts symbols like "__irqentry_text_start" to the second
aliased symbols. And a more proper symbol name becomes the first.
Aliased symbols mostly come from linker script. The solution is
guessing "is this symbol defined in linker script", the symbols
defined in linker script will not become the first aliased symbol.
And if symbols are found to be equal in this "linker script provided"
criteria, symbols are sorted by the number of prefix underscores.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Reviewed-by: Paulo Marques <pmarques@grupopie.com>
LKML-Reference: <49BA06E2.7080807@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-13 10:10:26 +03:00
|
|
|
tail++;
|
|
|
|
|
|
|
|
return tail - str;
|
|
|
|
}
|
|
|
|
|
2008-02-06 12:37:33 +03:00
|
|
|
static int compare_symbols(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct sym_entry *sa;
|
|
|
|
const struct sym_entry *sb;
|
|
|
|
int wa, wb;
|
|
|
|
|
|
|
|
sa = a;
|
|
|
|
sb = b;
|
|
|
|
|
|
|
|
/* sort by address first */
|
|
|
|
if (sa->addr > sb->addr)
|
|
|
|
return 1;
|
|
|
|
if (sa->addr < sb->addr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* sort by "weakness" type */
|
|
|
|
wa = (sa->sym[0] == 'w') || (sa->sym[0] == 'W');
|
|
|
|
wb = (sb->sym[0] == 'w') || (sb->sym[0] == 'W');
|
|
|
|
if (wa != wb)
|
|
|
|
return wa - wb;
|
|
|
|
|
kallsyms, tracing: output more proper symbol name
Impact: bugfix, output more reliable symbol lookup result
Debug tools(dump_stack(), ftrace...) are like to print out symbols.
But it is always print out the first aliased symbol.(Aliased symbols
are symbols with the same address), and the first aliased symbol is
sometime not proper.
# echo function_graph > current_tracer
# cat trace
......
1) 1.923 us | select_nohz_load_balancer();
1) + 76.692 us | }
1) | default_idle() {
1) ==========> | __irqentry_text_start() {
1) 0.000 us | native_apic_mem_write();
1) | irq_enter() {
1) 0.000 us | idle_cpu();
1) | tick_check_idle() {
1) 0.000 us | tick_check_oneshot_broadcast();
1) | tick_nohz_stop_idle() {
......
It's very embarrassing, it ouputs "__irqentry_text_start()",
actually, it should output "smp_apic_timer_interrupt()".
(these two symbol are the same address, but "__irqentry_text_start"
is deemed to the first aliased symbol by scripts/kallsyms)
This patch puts symbols like "__irqentry_text_start" to the second
aliased symbols. And a more proper symbol name becomes the first.
Aliased symbols mostly come from linker script. The solution is
guessing "is this symbol defined in linker script", the symbols
defined in linker script will not become the first aliased symbol.
And if symbols are found to be equal in this "linker script provided"
criteria, symbols are sorted by the number of prefix underscores.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Reviewed-by: Paulo Marques <pmarques@grupopie.com>
LKML-Reference: <49BA06E2.7080807@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-13 10:10:26 +03:00
|
|
|
/* sort by "linker script provide" type */
|
|
|
|
wa = may_be_linker_script_provide_symbol(sa);
|
|
|
|
wb = may_be_linker_script_provide_symbol(sb);
|
|
|
|
if (wa != wb)
|
|
|
|
return wa - wb;
|
|
|
|
|
|
|
|
/* sort by the number of prefix underscores */
|
|
|
|
wa = prefix_underscores_count((const char *)sa->sym + 1);
|
|
|
|
wb = prefix_underscores_count((const char *)sb->sym + 1);
|
|
|
|
if (wa != wb)
|
|
|
|
return wa - wb;
|
|
|
|
|
2008-02-06 12:37:33 +03:00
|
|
|
/* sort by initial order, so that other symbols are left undisturbed */
|
|
|
|
return sa->start_pos - sb->start_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sort_symbols(void)
|
|
|
|
{
|
|
|
|
qsort(table, table_cnt, sizeof(struct sym_entry), compare_symbols);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-03-17 07:35:46 +04:00
|
|
|
static void make_percpus_absolute(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < table_cnt; i++)
|
kallsyms: don't overload absolute symbol type for percpu symbols
Commit c6bda7c988a5 ("kallsyms: fix percpu vars on x86-64 with
relocation") overloaded the 'A' (absolute) symbol type to signify that a
symbol is not subject to dynamic relocation. However, the original A
type does not imply that at all, and depending on the version of the
toolchain, many A type symbols are emitted that are in fact relative to
the kernel text, i.e., if the kernel is relocated at runtime, these
symbols should be updated as well.
For instance, on sparc32, the following symbols are emitted as absolute
(kindly provided by Guenter Roeck):
f035a420 A _etext
f03d9000 A _sdata
f03de8c4 A jiffies
f03f8860 A _edata
f03fc000 A __init_begin
f041bdc8 A __init_text_end
f0423000 A __bss_start
f0423000 A __init_end
f044457d A __bss_stop
f044457d A _end
On x86_64, similar behavior can be observed:
ffffffff81a00000 A __end_rodata_hpage_align
ffffffff81b19000 A __vvar_page
ffffffff81d3d000 A _end
Even if only a couple of them pass the symbol range check that results
in them to be taken into account for the final kallsyms symbol table, it
is obvious that 'A' does not mean the symbol does not need to be updated
at relocation time, and overloading its meaning to signify that is
perhaps not a good idea.
So instead, add a new percpu_absolute member to struct sym_entry, and
when --absolute-percpu is in effect, use it to record symbols whose
addresses should be emitted as final values rather than values that
still require relocation at runtime. That way, we can drop the check
against the 'A' type.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:15 +03:00
|
|
|
if (symbol_in_range(&table[i], &percpu_range, 1)) {
|
|
|
|
/*
|
|
|
|
* Keep the 'A' override for percpu symbols to
|
|
|
|
* ensure consistent behavior compared to older
|
|
|
|
* versions of this tool.
|
|
|
|
*/
|
2014-03-17 07:35:46 +04:00
|
|
|
table[i].sym[0] = 'A';
|
kallsyms: don't overload absolute symbol type for percpu symbols
Commit c6bda7c988a5 ("kallsyms: fix percpu vars on x86-64 with
relocation") overloaded the 'A' (absolute) symbol type to signify that a
symbol is not subject to dynamic relocation. However, the original A
type does not imply that at all, and depending on the version of the
toolchain, many A type symbols are emitted that are in fact relative to
the kernel text, i.e., if the kernel is relocated at runtime, these
symbols should be updated as well.
For instance, on sparc32, the following symbols are emitted as absolute
(kindly provided by Guenter Roeck):
f035a420 A _etext
f03d9000 A _sdata
f03de8c4 A jiffies
f03f8860 A _edata
f03fc000 A __init_begin
f041bdc8 A __init_text_end
f0423000 A __bss_start
f0423000 A __init_end
f044457d A __bss_stop
f044457d A _end
On x86_64, similar behavior can be observed:
ffffffff81a00000 A __end_rodata_hpage_align
ffffffff81b19000 A __vvar_page
ffffffff81d3d000 A _end
Even if only a couple of them pass the symbol range check that results
in them to be taken into account for the final kallsyms symbol table, it
is obvious that 'A' does not mean the symbol does not need to be updated
at relocation time, and overloading its meaning to signify that is
perhaps not a good idea.
So instead, add a new percpu_absolute member to struct sym_entry, and
when --absolute-percpu is in effect, use it to record symbols whose
addresses should be emitted as final values rather than values that
still require relocation at runtime. That way, we can drop the check
against the 'A' type.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:15 +03:00
|
|
|
table[i].percpu_absolute = 1;
|
|
|
|
}
|
2014-03-17 07:35:46 +04:00
|
|
|
}
|
|
|
|
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
/* find the minimum non-absolute symbol address */
|
|
|
|
static void record_relative_base(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
relative_base = -1ULL;
|
|
|
|
for (i = 0; i < table_cnt; i++)
|
|
|
|
if (!symbol_absolute(&table[i]) &&
|
|
|
|
table[i].addr < relative_base)
|
|
|
|
relative_base = table[i].addr;
|
|
|
|
}
|
|
|
|
|
2005-09-07 02:16:31 +04:00
|
|
|
int main(int argc, char **argv)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-05-01 19:59:06 +04:00
|
|
|
if (argc >= 2) {
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if(strcmp(argv[i], "--all-symbols") == 0)
|
|
|
|
all_symbols = 1;
|
2014-03-17 07:35:46 +04:00
|
|
|
else if (strcmp(argv[i], "--absolute-percpu") == 0)
|
|
|
|
absolute_percpu = 1;
|
2018-05-09 10:23:47 +03:00
|
|
|
else if (strcmp(argv[i], "--base-relative") == 0)
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
base_relative = 1;
|
|
|
|
else
|
2005-05-01 19:59:06 +04:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
} else if (argc != 1)
|
2005-04-17 02:20:36 +04:00
|
|
|
usage();
|
|
|
|
|
|
|
|
read_map(stdin);
|
2014-03-17 07:35:46 +04:00
|
|
|
if (absolute_percpu)
|
|
|
|
make_percpus_absolute();
|
kallsyms: add support for relative offsets in kallsyms address table
Similar to how relative extables are implemented, it is possible to emit
the kallsyms table in such a way that it contains offsets relative to
some anchor point in the kernel image rather than absolute addresses.
On 64-bit architectures, it cuts the size of the kallsyms address table
in half, since offsets between kernel symbols can typically be expressed
in 32 bits. This saves several hundreds of kilobytes of permanent
.rodata on average. In addition, the kallsyms address table is no
longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
effect, so the relocation work done after decompression now doesn't have
to do relocation updates for all these values. This saves up to 24
bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
which easily adds up to a couple of megabytes of uncompressed __init
data on ppc64 or arm64. Even if these relocation entries typically
compress well, the combined size reduction of 2.8 MB uncompressed for a
ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
KB space saving in the compressed image.
Since it is useful for some architectures (like x86) to retain the
ability to emit absolute values as well, this patch also adds support
for capturing both absolute and relative values when
KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
addresses as positive 32-bit values, and addresses relative to the
lowest encountered relative symbol as negative values, which are
subtracted from the runtime address of this base symbol to produce the
actual address.
Support for the above is enabled by default for all architectures except
IA-64 and Tile-GX, whose symbols are too far apart to capture in this
manner.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-16 00:58:19 +03:00
|
|
|
if (base_relative)
|
|
|
|
record_relative_base();
|
2009-01-14 23:38:20 +03:00
|
|
|
sort_symbols();
|
|
|
|
optimize_token_table();
|
2005-04-17 02:20:36 +04:00
|
|
|
write_src();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|