Skip to content

Commit

Permalink
Merge pull request torvalds#221 from andreas-abel/kallsyms_rodata
Browse files Browse the repository at this point in the history
lkl: Add a config option to select section for kallsyms
  • Loading branch information
Octavian Purdila authored Sep 9, 2016
2 parents d58310d + 1643276 commit e496a1f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions arch/lkl/defconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CONFIG_LOCALVERSION_AUTO is not set
CONFIG_NO_HZ_IDLE=y
# CONFIG_SYSFS_SYSCALL is not set
CONFIG_KALLSYMS_USE_DATA_SECTION=y
CONFIG_KALLSYMS_ALL=y
# CONFIG_BASE_FULL is not set
# CONFIG_FUTEX is not set
Expand Down
12 changes: 12 additions & 0 deletions init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,18 @@ config KALLSYMS_BASE_RELATIVE
time constants, and no relocation pass is required at runtime to fix
up the entries based on the runtime load address of the kernel.

config KALLSYMS_USE_DATA_SECTION
bool "Use .data instead of .rodata section for kallsyms"
depends on KALLSYMS
default n
help
Enabling this option will put the kallsyms data in the .data section
instead of the .rodata section.

This is useful when building the kernel as a library, as it avoids
relocations in the text segment that could otherwise occur if the
.rodata section is in the same segment as the .text section.

config PRINTK
default y
bool "Enable support for printk" if EXPERT
Expand Down
17 changes: 12 additions & 5 deletions scripts/kallsyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ static struct addr_range percpu_range = {

static struct sym_entry *table;
static unsigned int table_size, table_cnt;
static int all_symbols = 0;
static int absolute_percpu = 0;
static int all_symbols;
static int use_data_section;
static int absolute_percpu;
static char symbol_prefix_char = '\0';
static unsigned long long kernel_start_addr = 0;
static int base_relative = 0;
static unsigned long long kernel_start_addr;
static int base_relative;

int token_profit[0x10000];

Expand All @@ -76,6 +77,7 @@ unsigned char best_table_len[256];
static void usage(void)
{
fprintf(stderr, "Usage: kallsyms [--all-symbols] "
"[--use-data-section] "
"[--symbol-prefix=<prefix char>] "
"[--page-offset=<CONFIG_PAGE_OFFSET>] "
"[--base-relative] < in.map > out.S\n");
Expand Down Expand Up @@ -352,7 +354,10 @@ static void write_src(void)
printf("#define ALGN .align 4\n");
printf("#endif\n");

printf("\t.section .rodata, \"a\"\n");
if (use_data_section)
printf("\t.section .data\n");
else
printf("\t.section .rodata, \"a\"\n");

/* Provide proper symbols relocatability by their relativeness
* to a fixed anchor point in the runtime image, either '_text'
Expand Down Expand Up @@ -759,6 +764,8 @@ int main(int argc, char **argv)
all_symbols = 1;
else if (strcmp(argv[i], "--absolute-percpu") == 0)
absolute_percpu = 1;
else if (strcmp(argv[i], "--use-data-section") == 0)
use_data_section = 1;
else if (strncmp(argv[i], "--symbol-prefix=", 16) == 0) {
char *p = &argv[i][16];
/* skip quote */
Expand Down
4 changes: 4 additions & 0 deletions scripts/link-vmlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ kallsyms()
kallsymopt="${kallsymopt} --base-relative"
fi

if [ -n "${CONFIG_KALLSYMS_USE_DATA_SECTION}" ]; then
kallsymopt="${kallsymopt} --use-data-section"
fi

local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"

Expand Down

0 comments on commit e496a1f

Please sign in to comment.