Skip to content

Commit 13610aa

Browse files
masahir0ytorvalds
authored andcommitted
kernel/configs: use .incbin directive to embed config_data.gz
This slightly optimizes the kernel/configs.c build. bin2c is not very efficient because it converts a data file into a huge array to embed it into a *.c file. Instead, we can use the .incbin directive. Also, this simplifies the code; Makefile is cleaner, and the way to get the offset/size of the config_data.gz is more straightforward. I used the "asm" statement in *.c instead of splitting it into *.S because MODULE_* tags are not supported in *.S files. I also cleaned up kernel/.gitignore; "config_data.gz" is unneeded because the top-level .gitignore takes care of the "*.gz" pattern. [[email protected]: v2] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Masahiro Yamada <[email protected]> Cc: Randy Dunlap <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Alexander Popov <[email protected]> Cc: Kees Cook <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Dan Williams <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Richard Guy Briggs <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 3337d5c commit 13610aa

File tree

4 files changed

+21
-35
lines changed

4 files changed

+21
-35
lines changed

Documentation/dontdiff

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ compile.h*
106106
conf
107107
config
108108
config-*
109-
config_data.h*
110109
config.mak
111110
config.mak.autogen
112111
conmakehash

kernel/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#
22
# Generated files
33
#
4-
config_data.h
5-
config_data.gz
64
timeconst.h
75
hz.bc

kernel/Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,8 @@ obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o
116116
KASAN_SANITIZE_stackleak.o := n
117117
KCOV_INSTRUMENT_stackleak.o := n
118118

119-
$(obj)/configs.o: $(obj)/config_data.h
119+
$(obj)/configs.o: $(obj)/config_data.gz
120120

121121
targets += config_data.gz
122122
$(obj)/config_data.gz: $(KCONFIG_CONFIG) FORCE
123123
$(call if_changed,gzip)
124-
125-
filechk_ikconfiggz = \
126-
echo "static const char kernel_config_data[] __used = MAGIC_START"; \
127-
cat $< | scripts/bin2c; \
128-
echo "MAGIC_END;"
129-
130-
targets += config_data.h
131-
$(obj)/config_data.h: $(obj)/config_data.gz FORCE
132-
$(call filechk,ikconfiggz)

kernel/configs.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,35 @@
3030
#include <linux/init.h>
3131
#include <linux/uaccess.h>
3232

33-
/**************************************************/
34-
/* the actual current config file */
35-
3633
/*
37-
* Define kernel_config_data and kernel_config_data_size, which contains the
38-
* wrapped and compressed configuration file. The file is first compressed
39-
* with gzip and then bounded by two eight byte magic numbers to allow
40-
* extraction from a binary kernel image:
41-
*
42-
* IKCFG_ST
43-
* <image>
44-
* IKCFG_ED
34+
* "IKCFG_ST" and "IKCFG_ED" are used to extract the config data from
35+
* a binary kernel image or a module. See scripts/extract-ikconfig.
4536
*/
46-
#define MAGIC_START "IKCFG_ST"
47-
#define MAGIC_END "IKCFG_ED"
48-
#include "config_data.h"
49-
50-
51-
#define MAGIC_SIZE (sizeof(MAGIC_START) - 1)
52-
#define kernel_config_data_size \
53-
(sizeof(kernel_config_data) - 1 - MAGIC_SIZE * 2)
37+
asm (
38+
" .pushsection .rodata, \"a\" \n"
39+
" .ascii \"IKCFG_ST\" \n"
40+
" .global kernel_config_data \n"
41+
"kernel_config_data: \n"
42+
" .incbin \"kernel/config_data.gz\" \n"
43+
" .global kernel_config_data_end \n"
44+
"kernel_config_data_end: \n"
45+
" .ascii \"IKCFG_ED\" \n"
46+
" .popsection \n"
47+
);
5448

5549
#ifdef CONFIG_IKCONFIG_PROC
5650

51+
extern char kernel_config_data;
52+
extern char kernel_config_data_end;
53+
5754
static ssize_t
5855
ikconfig_read_current(struct file *file, char __user *buf,
5956
size_t len, loff_t * offset)
6057
{
6158
return simple_read_from_buffer(buf, len, offset,
62-
kernel_config_data + MAGIC_SIZE,
63-
kernel_config_data_size);
59+
&kernel_config_data,
60+
&kernel_config_data_end -
61+
&kernel_config_data);
6462
}
6563

6664
static const struct file_operations ikconfig_file_ops = {
@@ -79,7 +77,7 @@ static int __init ikconfig_init(void)
7977
if (!entry)
8078
return -ENOMEM;
8179

82-
proc_set_size(entry, kernel_config_data_size);
80+
proc_set_size(entry, &kernel_config_data_end - &kernel_config_data);
8381

8482
return 0;
8583
}

0 commit comments

Comments
 (0)