From 481461f5109919babbb393d6f68002936b8e2493 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 16 Jul 2023 19:15:54 +0900 Subject: linux/export.h: make independent of CONFIG_MODULES Currently, all files with EXPORT_SYMBOL() are rebuilt when CONFIG_MODULES is flipped due to depending on CONFIG_MODULES. Now that modpost can make a final decision about export symbols, does not need to make EXPORT_SYMBOL() no-op. Instead, modpost can skip emitting KSYMTAB when CONFIG_MODULES is unset. This commit will reduce the number of recompilation when CONFIG_MODULES is toggled. Signed-off-by: Masahiro Yamada --- scripts/Makefile.modpost | 1 + scripts/mod/modpost.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 39472e834b63..739402f45509 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -41,6 +41,7 @@ include $(srctree)/scripts/Kbuild.include MODPOST = scripts/mod/modpost modpost-args = \ + $(if $(CONFIG_MODULES),-M) \ $(if $(CONFIG_MODVERSIONS),-m) \ $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index b29b29707f10..8227641dd087 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -24,6 +24,7 @@ #include "../../include/linux/license.h" #include "../../include/linux/module_symbol.h" +static bool module_enabled; /* Are we using CONFIG_MODVERSIONS? */ static bool modversions; /* Is CONFIG_MODULE_SRCVERSION_ALL set? */ @@ -1242,7 +1243,7 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf, const char *tosec = sec_name(elf, get_secindex(elf, sym)); const struct sectioncheck *mismatch; - if (elf->export_symbol_secndx == fsecndx) { + if (module_enabled && elf->export_symbol_secndx == fsecndx) { check_export_symbol(mod, elf, faddr, tosec, sym); return; } @@ -2272,7 +2273,7 @@ int main(int argc, char **argv) LIST_HEAD(dump_lists); struct dump_list *dl, *dl2; - while ((opt = getopt(argc, argv, "ei:mnT:to:au:WwENd:")) != -1) { + while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:")) != -1) { switch (opt) { case 'e': external_module = true; @@ -2282,6 +2283,9 @@ int main(int argc, char **argv) dl->file = optarg; list_add_tail(&dl->list, &dump_lists); break; + case 'M': + module_enabled = true; + break; case 'm': modversions = true; break; -- cgit From e14f1242a8be413846360b295102abd4c62848ad Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 16 Jul 2023 13:55:07 +0900 Subject: kconfig: menuconfig: simplify global jump key assignment Commit 95ac9b3b585d ("menuconfig: Assign jump keys per-page instead of globally") injected a lot of hacks to the bottom of the textbox infrastructure. I reverted many of them without changing the behavior. (almost) Now, the key markers are inserted when constructing the search result instead of updating the text buffer on-the-fly. The buffer passed to the textbox got back to a constant string. The ugly casts from (const char *) to (char *) went away. A disadvantage is that the same key numbers might be displayed multiple times in the dialog if you use a huge window (but I believe it is unlikely to happen). Signed-off-by: Masahiro Yamada Reviewed-by: Jesse Taube --- scripts/kconfig/lkc.h | 1 + scripts/kconfig/lxdialog/dialog.h | 10 ++--- scripts/kconfig/lxdialog/textbox.c | 68 +++++++++++------------------- scripts/kconfig/mconf.c | 86 ++++++++++++++++++++++---------------- scripts/kconfig/menu.c | 22 ++++++++-- 5 files changed, 97 insertions(+), 90 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index e7118d62a45f..471a59acecec 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -101,6 +101,7 @@ const char *menu_get_prompt(struct menu *menu); struct menu *menu_get_parent_menu(struct menu *menu); bool menu_has_help(struct menu *menu); const char *menu_get_help(struct menu *menu); +int get_jump_key_char(void); struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head); void menu_get_ext_help(struct menu *menu, struct gstr *help); diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h index 347daf25fdc8..a501abf9fa31 100644 --- a/scripts/kconfig/lxdialog/dialog.h +++ b/scripts/kconfig/lxdialog/dialog.h @@ -196,13 +196,9 @@ int first_alpha(const char *string, const char *exempt); int dialog_yesno(const char *title, const char *prompt, int height, int width); int dialog_msgbox(const char *title, const char *prompt, int height, int width, int pause); - - -typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void - *_data); -int dialog_textbox(const char *title, char *tbuf, int initial_height, - int initial_width, int *keys, int *_vscroll, int *_hscroll, - update_text_fn update_text, void *data); +int dialog_textbox(const char *title, const char *tbuf, int initial_height, + int initial_width, int *_vscroll, int *_hscroll, + int (*extra_key_cb)(int, size_t, size_t, void *), void *data); int dialog_menu(const char *title, const char *prompt, const void *selected, int *s_scroll); int dialog_checklist(const char *title, const char *prompt, int height, diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c index bc4d4fb1dc75..058ed0e5bbd5 100644 --- a/scripts/kconfig/lxdialog/textbox.c +++ b/scripts/kconfig/lxdialog/textbox.c @@ -10,8 +10,8 @@ static int hscroll; static int begin_reached, end_reached, page_length; -static char *buf; -static char *page; +static const char *buf, *page; +static size_t start, end; /* * Go back 'n' lines in text. Called by dialog_textbox(). @@ -98,21 +98,10 @@ static void print_line(WINDOW *win, int row, int width) /* * Print a new page of text. */ -static void print_page(WINDOW *win, int height, int width, update_text_fn - update_text, void *data) +static void print_page(WINDOW *win, int height, int width) { int i, passed_end = 0; - if (update_text) { - char *end; - - for (i = 0; i < height; i++) - get_line(); - end = page; - back_lines(height); - update_text(buf, page - buf, end - buf, data); - } - page_length = 0; for (i = 0; i < height; i++) { print_line(win, i, width); @@ -142,24 +131,26 @@ static void print_position(WINDOW *win) * refresh window content */ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw, - int cur_y, int cur_x, update_text_fn update_text, - void *data) + int cur_y, int cur_x) { - print_page(box, boxh, boxw, update_text, data); + start = page - buf; + + print_page(box, boxh, boxw); print_position(dialog); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); + + end = page - buf; } /* * Display text from a file in a dialog box. * * keys is a null-terminated array - * update_text() may not add or remove any '\n' or '\0' in tbuf */ -int dialog_textbox(const char *title, char *tbuf, int initial_height, - int initial_width, int *keys, int *_vscroll, int *_hscroll, - update_text_fn update_text, void *data) +int dialog_textbox(const char *title, const char *tbuf, int initial_height, + int initial_width, int *_vscroll, int *_hscroll, + int (*extra_key_cb)(int, size_t, size_t, void *), void *data) { int i, x, y, cur_x, cur_y, key = 0; int height, width, boxh, boxw; @@ -239,8 +230,7 @@ do_resize: /* Print first page of text */ attr_clear(box, boxh, boxw, dlg.dialog.atr); - refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x, update_text, - data); + refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); while (!done) { key = wgetch(dialog); @@ -259,8 +249,7 @@ do_resize: begin_reached = 1; page = buf; refresh_text_box(dialog, box, boxh, boxw, - cur_y, cur_x, update_text, - data); + cur_y, cur_x); } break; case 'G': /* Last page */ @@ -270,8 +259,7 @@ do_resize: /* point to last char in buf */ page = buf + strlen(buf); back_lines(boxh); - refresh_text_box(dialog, box, boxh, boxw, cur_y, - cur_x, update_text, data); + refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'K': /* Previous line */ case 'k': @@ -280,8 +268,7 @@ do_resize: break; back_lines(page_length + 1); - refresh_text_box(dialog, box, boxh, boxw, cur_y, - cur_x, update_text, data); + refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'B': /* Previous page */ case 'b': @@ -290,8 +277,7 @@ do_resize: if (begin_reached) break; back_lines(page_length + boxh); - refresh_text_box(dialog, box, boxh, boxw, cur_y, - cur_x, update_text, data); + refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'J': /* Next line */ case 'j': @@ -300,8 +286,7 @@ do_resize: break; back_lines(page_length - 1); - refresh_text_box(dialog, box, boxh, boxw, cur_y, - cur_x, update_text, data); + refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case KEY_NPAGE: /* Next page */ case ' ': @@ -310,8 +295,7 @@ do_resize: break; begin_reached = 0; - refresh_text_box(dialog, box, boxh, boxw, cur_y, - cur_x, update_text, data); + refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case '0': /* Beginning of line */ case 'H': /* Scroll left */ @@ -326,8 +310,7 @@ do_resize: hscroll--; /* Reprint current page to scroll horizontally */ back_lines(page_length); - refresh_text_box(dialog, box, boxh, boxw, cur_y, - cur_x, update_text, data); + refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'L': /* Scroll right */ case 'l': @@ -337,8 +320,7 @@ do_resize: hscroll++; /* Reprint current page to scroll horizontally */ back_lines(page_length); - refresh_text_box(dialog, box, boxh, boxw, cur_y, - cur_x, update_text, data); + refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case KEY_ESC: if (on_key_esc(dialog) == KEY_ESC) @@ -351,11 +333,9 @@ do_resize: on_key_resize(); goto do_resize; default: - for (i = 0; keys[i]; i++) { - if (key == keys[i]) { - done = true; - break; - } + if (extra_key_cb && extra_key_cb(key, start, end, data)) { + done = true; + break; } } } diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 53d8834d12fe..15b88921fe6a 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -288,6 +288,7 @@ static int single_menu_mode; static int show_all_options; static int save_and_exit; static int silent; +static int jump_key_char; static void conf(struct menu *menu, struct menu *active_menu); @@ -348,19 +349,19 @@ static void reset_subtitle(void) set_dialog_subtitles(subtitles); } -static int show_textbox_ext(const char *title, char *text, int r, int c, int - *keys, int *vscroll, int *hscroll, update_text_fn - update_text, void *data) +static int show_textbox_ext(const char *title, const char *text, int r, int c, + int *vscroll, int *hscroll, + int (*extra_key_cb)(int, size_t, size_t, void *), + void *data) { dialog_clear(); - return dialog_textbox(title, text, r, c, keys, vscroll, hscroll, - update_text, data); + return dialog_textbox(title, text, r, c, vscroll, hscroll, + extra_key_cb, data); } static void show_textbox(const char *title, const char *text, int r, int c) { - show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL, - NULL, NULL); + show_textbox_ext(title, text, r, c, NULL, NULL, NULL, NULL); } static void show_helptext(const char *title, const char *text) @@ -381,35 +382,51 @@ static void show_help(struct menu *menu) struct search_data { struct list_head *head; - struct menu **targets; - int *keys; + struct menu *target; }; -static void update_text(char *buf, size_t start, size_t end, void *_data) +static int next_jump_key(int key) +{ + if (key < '1' || key > '9') + return '1'; + + key++; + + if (key > '9') + key = '1'; + + return key; +} + +static int handle_search_keys(int key, size_t start, size_t end, void *_data) { struct search_data *data = _data; struct jump_key *pos; - int k = 0; - list_for_each_entry(pos, data->head, entries) { - if (pos->offset >= start && pos->offset < end) { - char header[4]; + if (key < '1' || key > '9') + return 0; - if (k < JUMP_NB) { - int key = '0' + (pos->index % JUMP_NB) + 1; + list_for_each_entry(pos, data->head, entries) { + if (pos->offset < start) + continue; - sprintf(header, "(%c)", key); - data->keys[k] = key; - data->targets[k] = pos->target; - k++; - } else { - sprintf(header, " "); - } + if (pos->offset >= end) + break; - memcpy(buf + pos->offset, header, sizeof(header) - 1); + if (key == '1' + (pos->index % JUMP_NB)) { + data->target = pos->target; + return 1; } } - data->keys[k] = 0; + + return 0; +} + +int get_jump_key_char(void) +{ + jump_key_char = next_jump_key(jump_key_char); + + return jump_key_char; } static void search_conf(void) @@ -456,26 +473,23 @@ again: sym_arr = sym_re_search(dialog_input); do { LIST_HEAD(head); - struct menu *targets[JUMP_NB]; - int keys[JUMP_NB + 1], i; struct search_data data = { .head = &head, - .targets = targets, - .keys = keys, }; struct jump_key *pos, *tmp; + jump_key_char = 0; res = get_relations_str(sym_arr, &head); set_subtitle(); dres = show_textbox_ext("Search Results", str_get(&res), 0, 0, - keys, &vscroll, &hscroll, &update_text, - &data); + &vscroll, &hscroll, + handle_search_keys, &data); again = false; - for (i = 0; i < JUMP_NB && keys[i]; i++) - if (dres == keys[i]) { - conf(targets[i]->parent, targets[i]); - again = true; - } + if (dres >= '1' && dres <= '9') { + assert(data.target != NULL); + conf(data.target->parent, data.target); + again = true; + } str_free(&res); list_for_each_entry_safe(pos, tmp, &head, entries) free(pos); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index b90fff833588..d2f0a8efabb5 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -701,6 +701,11 @@ static void get_dep_str(struct gstr *r, struct expr *expr, const char *prefix) } } +int __attribute__((weak)) get_jump_key_char(void) +{ + return -1; +} + static void get_prompt_str(struct gstr *r, struct property *prop, struct list_head *head) { @@ -743,11 +748,22 @@ static void get_prompt_str(struct gstr *r, struct property *prop, } str_printf(r, " Location:\n"); - for (j = 4; --i >= 0; j += 2) { + for (j = 0; --i >= 0; j++) { + int jk = -1; + int indent = 2 * j + 4; + menu = submenu[i]; - if (jump && menu == location) + if (jump && menu == location) { jump->offset = strlen(r->s); - str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu)); + jk = get_jump_key_char(); + } + + if (jk >= 0) { + str_printf(r, "(%c)", jk); + indent -= 3; + } + + str_printf(r, "%*c-> %s", indent, ' ', menu_get_prompt(menu)); if (menu->sym) { str_printf(r, " (%s [=%s])", menu->sym->name ? menu->sym->name : "", -- cgit From 356f0cb7efd9563112f18a2c8647ceb6d9f2ccef Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 16 Jul 2023 13:55:08 +0900 Subject: kconfig: menuconfig: remove jump_key::index You do not need to remember the index of each jump key because you can count it up after a key is pressed. Signed-off-by: Masahiro Yamada Reviewed-by: Jesse Taube --- scripts/kconfig/expr.h | 1 - scripts/kconfig/mconf.c | 7 ++++--- scripts/kconfig/menu.c | 8 -------- 3 files changed, 4 insertions(+), 12 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 9c9caca5bd5f..4a9a23b1b7e1 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -275,7 +275,6 @@ struct jump_key { struct list_head entries; size_t offset; struct menu *target; - int index; }; extern struct file *file_list; diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 15b88921fe6a..eccc87a441e7 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -22,8 +22,6 @@ #include "lkc.h" #include "lxdialog/dialog.h" -#define JUMP_NB 9 - static const char mconf_readme[] = "Overview\n" "--------\n" @@ -402,18 +400,21 @@ static int handle_search_keys(int key, size_t start, size_t end, void *_data) { struct search_data *data = _data; struct jump_key *pos; + int index = 0; if (key < '1' || key > '9') return 0; list_for_each_entry(pos, data->head, entries) { + index = next_jump_key(index); + if (pos->offset < start) continue; if (pos->offset >= end) break; - if (key == '1' + (pos->index % JUMP_NB)) { + if (key == index) { data->target = pos->target; return 1; } diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index d2f0a8efabb5..61c442d84aef 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -735,15 +735,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop, } if (head && location) { jump = xmalloc(sizeof(struct jump_key)); - jump->target = location; - - if (list_empty(head)) - jump->index = 0; - else - jump->index = list_entry(head->prev, struct jump_key, - entries)->index + 1; - list_add_tail(&jump->entries, head); } -- cgit From 4d15c9fa058e6dee09324cfc93f48858d4296019 Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Tue, 18 Jul 2023 18:58:43 +0200 Subject: Revert "kbuild: Hack for depmod not handling X.Y versions" Remove hack for ancient version of module-init-tools that was added in Linux 3.0. Since then module-init-tools was replaced with kmod. This hack adds an additional indirection, and causes confusing errors to be printed when depmod fails. Reverts commit 8fc62e594253 ("kbuild: Do not write to builddir in modules_install") Reverts commit bfe5424a8b31 ("kbuild: Hack for depmod not handling X.Y versions") Link: https://lore.kernel.org/linux-modules/CAK7LNAQMs3QBYfWcLkmOQdbbq7cj=7wWbK=AWhdTC2rAsKHXzQ@mail.gmail.com/ Signed-off-by: Michal Suchanek Signed-off-by: Masahiro Yamada --- scripts/depmod.sh | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'scripts') diff --git a/scripts/depmod.sh b/scripts/depmod.sh index 3643b4f896ed..fca689ba4f21 100755 --- a/scripts/depmod.sh +++ b/scripts/depmod.sh @@ -23,33 +23,8 @@ if [ -z $(command -v $DEPMOD) ]; then exit 0 fi -# older versions of depmod require the version string to start with three -# numbers, so we cheat with a symlink here -depmod_hack_needed=true -tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX) -mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE" -if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then - if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \ - -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then - depmod_hack_needed=false - fi -fi -rm -rf "$tmp_dir" -if $depmod_hack_needed; then - symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE" - ln -s "$KERNELRELEASE" "$symlink" - KERNELRELEASE=99.98.$KERNELRELEASE -fi - set -- -ae -F System.map if test -n "$INSTALL_MOD_PATH"; then set -- "$@" -b "$INSTALL_MOD_PATH" fi -"$DEPMOD" "$@" "$KERNELRELEASE" -ret=$? - -if $depmod_hack_needed; then - rm -f "$symlink" -fi - -exit $ret +exec "$DEPMOD" "$@" "$KERNELRELEASE" -- cgit From 233046a2afd12a4f699305b92ee634eebf1e4f31 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:48 +0900 Subject: kbuild: rpm-pkg: define _arch conditionally Commit 3089b2be0cce ("kbuild: rpm-pkg: fix build error when _arch is undefined") does not work as intended; _arch is always defined as $UTS_MACHINE. The intention was to define _arch to $UTS_MACHINE only when it is not defined. Fixes: 3089b2be0cce ("kbuild: rpm-pkg: fix build error when _arch is undefined") Signed-off-by: Masahiro Yamada --- scripts/package/mkspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 8049f0e2c110..c9299f9c1f3e 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -57,7 +57,7 @@ $S BuildRequires: gcc make openssl openssl-devel perl python3 rsync # $UTS_MACHINE as a fallback of _arch in case # /usr/lib/rpm/platform/*/macros was not included. - %define _arch %{?_arch:$UTS_MACHINE} + %{!?_arch: %define _arch $UTS_MACHINE} %define __spec_install_post /usr/lib/rpm/brp-compress || : %define debug_package %{nil} -- cgit From 61eca933d0a63f0889df604df6bb38938f3c7cad Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:49 +0900 Subject: kbuild: rpm-pkg: remove unneeded '-f $srctree/Makefile' in spec file This is unneeded because the Makefile in the output directory wraps the top-level Makefile in the srctree. Just run $MAKE irrespective of the build location. Signed-off-by: Masahiro Yamada --- scripts/package/mkspec | 1 - 1 file changed, 1 deletion(-) (limited to 'scripts') diff --git a/scripts/package/mkspec b/scripts/package/mkspec index c9299f9c1f3e..a83b17b4a0d9 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -12,7 +12,6 @@ # how we were called determines which rpms we build and how we build them if [ "$1" = prebuilt ]; then S=DEL - MAKE="$MAKE -f $srctree/Makefile" else S= -- cgit From 192868258d2c9eb421228e4d65c4b09b838e7d93 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:50 +0900 Subject: kbuild: rpm-pkg: do not hard-code $MAKE in spec file Currently, $MAKE will expand to the GNU Make program that created the source RPM. This is problematic if you carry it to a different build host to run 'rpmbuild' there. Consider this command: $ /path/to/my/custom/make srcrpm-pkg The spec file in the SRPM will record '/path/to/my/custom/make', which exists only on that build environment. To create a portable SRPM, the spec file should avoid hard-coding $MAKE. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 5 +++-- scripts/package/mkspec | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index 92dbc889bd7c..e9217e997c68 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -72,7 +72,7 @@ PHONY += rpm-pkg rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) rpm-pkg: srcrpm-pkg +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ - --define='_smp_mflags %{nil}' + --define='_smp_mflags %{nil}' --define='make $(MAKE)' # srcrpm-pkg # --------------------------------------------------------------------------- @@ -89,7 +89,8 @@ binrpm-pkg: $(MAKE) -f $(srctree)/Makefile $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ - $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec + $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec \ + --define='make $(MAKE)' # deb-pkg srcdeb-pkg bindeb-pkg # --------------------------------------------------------------------------- diff --git a/scripts/package/mkspec b/scripts/package/mkspec index a83b17b4a0d9..9b2b4386019d 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -38,6 +38,8 @@ EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \ # $S: this line is enabled only when building source package # $M: this line is enabled only when CONFIG_MODULES is enabled sed -e '/^DEL/d' -e 's/^\t*//' < Date: Sat, 22 Jul 2023 13:47:51 +0900 Subject: kbuild: rpm-pkg: use %{makeflags} to pass common Make options This is useful to pass more common Make options. Signed-off-by: Masahiro Yamada --- scripts/package/mkspec | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 9b2b4386019d..a1ce6677880a 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -39,6 +39,7 @@ EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \ # $M: this line is enabled only when CONFIG_MODULES is enabled sed -e '/^DEL/d' -e 's/^\t*//' < Date: Sat, 22 Jul 2023 13:47:52 +0900 Subject: kbuild: rpm-pkg: record ARCH option in spec file Currently, we rely on the top Makefile defining ARCH option when we run 'make rpm-pkg' or 'make binrpm-pkg'. It does not apply when we run 'make srcrpm-pkg', and separately run 'rpmbuild' for the generated SRPM. This is a problem for cross-build. Just like the Debian package, save the value of ARCH in the spec file. Signed-off-by: Masahiro Yamada --- scripts/package/mkspec | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/package/mkspec b/scripts/package/mkspec index a1ce6677880a..0befb4e2ac6b 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -38,8 +38,10 @@ EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \ # $S: this line is enabled only when building source package # $M: this line is enabled only when CONFIG_MODULES is enabled sed -e '/^DEL/d' -e 's/^\t*//' < Date: Sat, 22 Jul 2023 13:47:53 +0900 Subject: kbuild: rpm-pkg: replace $__KERNELRELEASE in spec file with %{version} ${version} will be replaced with the value of the Version field. Signed-off-by: Masahiro Yamada --- scripts/package/mkspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 0befb4e2ac6b..a6a383aaaea7 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -81,12 +81,12 @@ $S BuildRequires: gcc make openssl openssl-devel perl python3 rsync glibc package. $S$M %package devel -$S$M Summary: Development package for building kernel modules to match the $__KERNELRELEASE kernel +$S$M Summary: Development package for building kernel modules to match the %{version} kernel $S$M Group: System Environment/Kernel $S$M AutoReqProv: no $S$M %description -n kernel-devel $S$M This package provides kernel headers and makefiles sufficient to build modules -$S$M against the $__KERNELRELEASE kernel package. +$S$M against the %{version} kernel package. $S$M $S %prep $S %setup -q -n linux -- cgit From 93ed5605c6185edf3b47c433b257c00854f0a4e1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:54 +0900 Subject: kbuild: rpm-pkg: replace $KERNELRELEASE in spec file with %{KERNELRELEASE} Avoid hard-coding the value of KERNELRELEASE in the generated spec file. Signed-off-by: Masahiro Yamada --- scripts/package/mkspec | 59 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'scripts') diff --git a/scripts/package/mkspec b/scripts/package/mkspec index a6a383aaaea7..34b2489106cf 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -39,6 +39,7 @@ EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \ # $M: this line is enabled only when CONFIG_MODULES is enabled sed -e '/^DEL/d' -e 's/^\t*//' < Date: Sat, 22 Jul 2023 13:47:55 +0900 Subject: kbuild: add a phony target to run a command with Kbuild env vars There are some cases where we want to run a command with the same environment variables as Kbuild uses. For example, 'make coccicheck' invokes scripts/coccicheck from the top Makefile so that the script can reference to ${LINUXINCLUDE}, ${KBUILD_EXTMOD}, etc. The top Makefile defines several phony targets that run a script. We do it also for an internally used script, which results in a somewhat complex call graph. One example: debian/rules binary-arch -> make intdeb-pkg -> scripts/package/builddeb It is also tedious to add a dedicated target like 'intdeb-pkg' for each use case. Add a generic target 'run-command' to run an arbitrary command in an environment with all Kbuild variables set. The usage is: $ make run-command KBUILD_RUN_COMMAND= The concept is similar to: $ dpkg-architecture -c This executes in an environment which has all DEB_* variables defined. Convert the existing 'make intdeb-pkg'. Another possible usage is to interrogate a Make variable. $ make run-command KBUILD_RUN_COMMAND='echo $(KBUILD_CFLAGS)' might be useful to see KBUILD_CFLAGS set by the top Makefile. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 4 ---- scripts/package/mkdebian | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index e9217e997c68..7cd61a374dae 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -146,10 +146,6 @@ deb-pkg srcdeb-pkg bindeb-pkg: --no-check-builddeps) \ $(DPKG_FLAGS)) -PHONY += intdeb-pkg -intdeb-pkg: - +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb - # snap-pkg # --------------------------------------------------------------------------- PHONY += snap-pkg diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian index ba2453e08d40..9105abab9728 100755 --- a/scripts/package/mkdebian +++ b/scripts/package/mkdebian @@ -283,7 +283,8 @@ build: build-arch binary-indep: binary-arch: build-arch \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \ - KERNELRELEASE=\$(KERNELRELEASE) intdeb-pkg + KERNELRELEASE=\$(KERNELRELEASE) \ + run-command KBUILD_RUN_COMMAND=+\$(srctree)/scripts/package/builddeb clean: rm -rf debian/files debian/linux-* -- cgit From fe66b5d2ae72121c9f4f705dbae36d4c3e9f3812 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:56 +0900 Subject: kbuild: refactor kernel-devel RPM package and linux-headers Deb package The kernel-devel RPM package and the linux-headers Debian package provide headers and scripts needed for building external modules. They copy the necessary files in slightly different ways - the RPM copies almost everything except some exclude patterns, while the Debian copies less number of files. There is no need to maintain different code to do the same thing. Split the Debian code out to scripts/package/install-extmod-build, which is called from both of the packages. Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 29 +-------------------------- scripts/package/install-extmod-build | 39 ++++++++++++++++++++++++++++++++++++ scripts/package/mkspec | 6 +----- 3 files changed, 41 insertions(+), 33 deletions(-) create mode 100755 scripts/package/install-extmod-build (limited to 'scripts') diff --git a/scripts/package/builddeb b/scripts/package/builddeb index 032774eb061e..bf3f8561aa68 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -162,34 +162,7 @@ install_kernel_headers () { rm -rf $pdir - ( - cd $srctree - find . arch/$SRCARCH -maxdepth 1 -name Makefile\* - find include scripts -type f -o -type l - find arch/$SRCARCH -name Kbuild.platforms -o -name Platform - find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f - ) > debian/hdrsrcfiles - - { - if is_enabled CONFIG_OBJTOOL; then - echo tools/objtool/objtool - fi - - find arch/$SRCARCH/include Module.symvers include scripts -type f - - if is_enabled CONFIG_GCC_PLUGINS; then - find scripts/gcc-plugins -name \*.so - fi - } > debian/hdrobjfiles - - destdir=$pdir/usr/src/linux-headers-$version - mkdir -p $destdir - tar -c -f - -C $srctree -T debian/hdrsrcfiles | tar -xf - -C $destdir - tar -c -f - -T debian/hdrobjfiles | tar -xf - -C $destdir - rm -f debian/hdrsrcfiles debian/hdrobjfiles - - # copy .config manually to be where it's expected to be - cp $KCONFIG_CONFIG $destdir/.config + "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}" mkdir -p $pdir/lib/modules/$version/ ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build diff --git a/scripts/package/install-extmod-build b/scripts/package/install-extmod-build new file mode 100755 index 000000000000..af7fe9f5b1e4 --- /dev/null +++ b/scripts/package/install-extmod-build @@ -0,0 +1,39 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only + +set -e + +destdir=${1} + +test -n "${srctree}" +test -n "${SRCARCH}" + +is_enabled() { + grep -q "^$1=y" include/config/auto.conf +} + +mkdir -p "${destdir}" + +( + cd "${srctree}" + echo Makefile + find "arch/${SRCARCH}" -maxdepth 1 -name 'Makefile*' + find include scripts -type f -o -type l + find "arch/${SRCARCH}" -name Kbuild.platforms -o -name Platform + find "$(find "arch/${SRCARCH}" -name include -o -name scripts -type d)" -type f +) | tar -c -f - -C "${srctree}" -T - | tar -xf - -C "${destdir}" + +{ + if is_enabled CONFIG_OBJTOOL; then + echo tools/objtool/objtool + fi + + find "arch/${SRCARCH}/include" Module.symvers include scripts -type f + + if is_enabled CONFIG_GCC_PLUGINS; then + find scripts/gcc-plugins -name '*.so' + fi +} | tar -c -f - -T - | tar -xf - -C "${destdir}" + +# copy .config manually to be where it's expected to be +cp "${KCONFIG_CONFIG}" "${destdir}/.config" diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 34b2489106cf..22e290d23d8a 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -28,9 +28,6 @@ else fi __KERNELRELEASE=$(echo $KERNELRELEASE | sed -e "s/-/_/g") -EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \ ---exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation \ ---exclude=.config.old --exclude=.missing-syscalls.d --exclude=*.s" # We can label the here-doc lines for conditional output to the spec file # @@ -112,8 +109,7 @@ $M %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install cp .config %{buildroot}/boot/config-%{KERNELRELEASE} $S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/build $S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/source -$S$M mkdir -p %{buildroot}/usr/src/kernels/%{KERNELRELEASE} -$S$M tar cf - $EXCLUDES . | tar xf - -C %{buildroot}/usr/src/kernels/%{KERNELRELEASE} +$S$M %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='\${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}' $S$M cd %{buildroot}/lib/modules/%{KERNELRELEASE} $S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} build $S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} source -- cgit From d5d2d4cc60888f02dd4a6b2bfb03ff2fd7be4fc2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:57 +0900 Subject: kbuild: rpm-pkg: derive the Version from %{KERNELRELEASE} Avoid hard-coding the Version field in the generated spec file. Signed-off-by: Masahiro Yamada --- scripts/package/mkspec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 22e290d23d8a..783e1997d94a 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -27,8 +27,6 @@ else M=DEL fi -__KERNELRELEASE=$(echo $KERNELRELEASE | sed -e "s/-/_/g") - # We can label the here-doc lines for conditional output to the spec file # # Labels: @@ -43,7 +41,7 @@ sed -e '/^DEL/d' -e 's/^\t*//' </dev/null || echo 1) License: GPL Group: System Environment/Kernel -- cgit From d4f651277e9208b580b55da212e17ddd309c91e7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:58 +0900 Subject: kbuild: rpm-pkg: use a dummy string for _arch when undefined If this affects only %{buildroot}, it should be enough to use a fixed string for _arch when it is undefined. Signed-off-by: Masahiro Yamada --- scripts/package/mkspec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 783e1997d94a..22b980cf3d00 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -36,6 +36,8 @@ sed -e '/^DEL/d' -e 's/^\t*//' < Date: Sat, 22 Jul 2023 13:47:59 +0900 Subject: kbuild: rpm-pkg: invoke the kernel build from rpmbuild for binrpm-pkg To reduce the preprocess of the spec file, invoke the kernel build from rpmbuild. Run init/build-version to increment the release number not only for binrpm-pkg but also for srcrpm-pkg and rpm-pkg. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 2 +- scripts/package/mkspec | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index 7cd61a374dae..8373644a0473 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -86,10 +86,10 @@ srcrpm-pkg: linux.tar.gz # --------------------------------------------------------------------------- PHONY += binrpm-pkg binrpm-pkg: - $(MAKE) -f $(srctree)/Makefile $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec \ + --build-in-place --noprep --define='_smp_mflags %{nil}' \ --define='make $(MAKE)' # deb-pkg srcdeb-pkg bindeb-pkg diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 22b980cf3d00..a9425d993667 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -35,6 +35,7 @@ fi sed -e '/^DEL/d' -e 's/^\t*//' </dev/null || echo 1) + Release: %{pkg_release} License: GPL Group: System Environment/Kernel Vendor: The Linux Community URL: https://www.kernel.org -$S Source0: linux.tar.gz -$S Source1: config -$S Source2: diff.patch + Source0: linux.tar.gz + Source1: config + Source2: diff.patch Provides: kernel-%{KERNELRELEASE} -$S BuildRequires: bc binutils bison dwarves -$S BuildRequires: (elfutils-libelf-devel or libelf-devel) flex -$S BuildRequires: gcc make openssl openssl-devel perl python3 rsync + BuildRequires: bc binutils bison dwarves + BuildRequires: (elfutils-libelf-devel or libelf-devel) flex + BuildRequires: gcc make openssl openssl-devel perl python3 rsync %define __spec_install_post /usr/lib/rpm/brp-compress || : %define debug_package %{nil} @@ -83,14 +84,14 @@ $S$M %description -n kernel-devel $S$M This package provides kernel headers and makefiles sufficient to build modules $S$M against the %{version} kernel package. $S$M -$S %prep -$S %setup -q -n linux -$S cp %{SOURCE1} .config -$S patch -p1 < %{SOURCE2} -$S -$S %build -$S %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release} -$S + %prep + %setup -q -n linux + cp %{SOURCE1} .config + patch -p1 < %{SOURCE2} + + %build + %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release} + %install mkdir -p %{buildroot}/boot %ifarch ia64 -- cgit From b537925fdd689ca33b6d9eed4569bc625550b3ef Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:00 +0900 Subject: kbuild: rpm-pkg: run modules_install for non-modular kernel For the same reason as commit 4243afdb9326 ("kbuild: builddeb: always make modules_install, to install modules.builtin*"), run modules_install even when CONFIG_MODULES=n to install modules.builtin*. Signed-off-by: Masahiro Yamada --- scripts/package/mkspec | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/package/mkspec b/scripts/package/mkspec index a9425d993667..2613e85cd844 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -101,16 +101,13 @@ $S$M %else cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-%{KERNELRELEASE} %endif -$M %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install + %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install cp System.map %{buildroot}/boot/System.map-%{KERNELRELEASE} cp .config %{buildroot}/boot/config-%{KERNELRELEASE} -$S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/build -$S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/source + ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build + ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/source $S$M %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='\${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}' -$S$M cd %{buildroot}/lib/modules/%{KERNELRELEASE} -$S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} build -$S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} source %clean rm -rf %{buildroot} @@ -138,9 +135,9 @@ $S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} source %files %defattr (-, root, root) -$M /lib/modules/%{KERNELRELEASE} -$M %exclude /lib/modules/%{KERNELRELEASE}/build -$M %exclude /lib/modules/%{KERNELRELEASE}/source + /lib/modules/%{KERNELRELEASE} + %exclude /lib/modules/%{KERNELRELEASE}/build + %exclude /lib/modules/%{KERNELRELEASE}/source /boot/* %files headers -- cgit From 2a291fc315b6aec2f209aa44da90515ddd4f89d0 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:01 +0900 Subject: kbuild: rpm-pkg: introduce %{with_devel} switch to select devel package scripts/package/mkspec preprocesses the spec file by sed, but it is unreadable. This commit removes the last portion of the sed scripting. Remove the $S$M prefixes from the conditionally generated lines. Instead, surround the code with %if %{with_devel} ... %endif. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 2 +- scripts/package/mkspec | 53 +++++++++++++++++++++++------------------------- 2 files changed, 26 insertions(+), 29 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index 8373644a0473..c36ae03d6002 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -89,7 +89,7 @@ binrpm-pkg: $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec \ - --build-in-place --noprep --define='_smp_mflags %{nil}' \ + --build-in-place --noprep --define='_smp_mflags %{nil}' --without devel \ --define='make $(MAKE)' # deb-pkg srcdeb-pkg bindeb-pkg diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 2613e85cd844..511cae46a90d 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -10,11 +10,7 @@ # # how we were called determines which rpms we build and how we build them -if [ "$1" = prebuilt ]; then - S=DEL -else - S= - +if [ -z "$1" ]; then mkdir -p rpmbuild/SOURCES cp linux.tar.gz rpmbuild/SOURCES cp "${KCONFIG_CONFIG}" rpmbuild/SOURCES/config @@ -22,17 +18,12 @@ else fi if grep -q CONFIG_MODULES=y include/config/auto.conf; then - M= +echo '%define with_devel %{?_without_devel: 0} %{?!_without_devel: 1}' else - M=DEL +echo '%define with_devel 0' fi -# We can label the here-doc lines for conditional output to the spec file -# -# Labels: -# $S: this line is enabled only when building source package -# $M: this line is enabled only when CONFIG_MODULES is enabled -sed -e '/^DEL/d' -e 's/^\t*//' < Date: Sat, 22 Jul 2023 13:48:03 +0900 Subject: kbuild: rpm-pkg: rename binkernel.spec to kernel.spec Now kernel.spec and binkernel.spec have the exactly same contents. Use kernel.spec for binrpm-pkg as well. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 4 ++-- scripts/remove-stale-files | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index c36ae03d6002..be9602fa98da 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -86,9 +86,9 @@ srcrpm-pkg: linux.tar.gz # --------------------------------------------------------------------------- PHONY += binrpm-pkg binrpm-pkg: - $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec + $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/kernel.spec +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ - $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec \ + $(UTS_MACHINE)-linux -bb $(objtree)/kernel.spec \ --build-in-place --noprep --define='_smp_mflags %{nil}' --without devel \ --define='make $(MAKE)' diff --git a/scripts/remove-stale-files b/scripts/remove-stale-files index f3659ea0335b..8b1a636f8543 100755 --- a/scripts/remove-stale-files +++ b/scripts/remove-stale-files @@ -37,3 +37,5 @@ rm -f .scmversion rm -rf include/ksym find . -name '*.usyms' | xargs rm -f + +rm -f binkernel.spec -- cgit From 6db9ced4641fab2710e83c4d703e9ad60dd3ccf5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:04 +0900 Subject: kbuild: rpm-pkg: build the kernel in-place for rpm-pkg Currently, 'make rpm-pkg' always builds the kernel from the pristine source tree in the ~/rpmbuild/BUILD/ directory. Build the kernel incrementally just like 'make binrpm-pkg'. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index be9602fa98da..bf2da97f29d0 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -72,6 +72,7 @@ PHONY += rpm-pkg rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) rpm-pkg: srcrpm-pkg +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ + --build-in-place --noprep \ --define='_smp_mflags %{nil}' --define='make $(MAKE)' # srcrpm-pkg -- cgit From 37477496d6aa91248184238a95b59b7d91d46921 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:05 +0900 Subject: kbuild: rpm-pkg: refactor *rpm-pkg targets Merge the similar build targets. Also, make the output location consistent. Previously, source packages were created in the build directory, while binary packages under ~/rpmbuild/RPMS/. Now, Kbuild creates the rpmbuild/ directory in the build directory, and saves all packages under it. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 54 ++++++++++++++++++++++++++---------------------- scripts/package/mkspec | 8 ------- 2 files changed, 29 insertions(+), 33 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index bf2da97f29d0..0ace3973a0d1 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -11,7 +11,6 @@ TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \ samples scripts security sound tools usr virt \ .config Makefile \ Kbuild Kconfig COPYING $(wildcard localversion*) -MKSPEC := $(srctree)/scripts/package/mkspec quiet_cmd_src_tar = TAR $(2).tar.gz cmd_src_tar = \ @@ -66,32 +65,37 @@ $(linux-tarballs): archive-args = --prefix=linux/ $$(cat $<) $(linux-tarballs): .tmp_HEAD FORCE $(call if_changed,archive) -# rpm-pkg +# rpm-pkg srcrpm-pkg binrpm-pkg # --------------------------------------------------------------------------- -PHONY += rpm-pkg -rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) -rpm-pkg: srcrpm-pkg - +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ - --build-in-place --noprep \ - --define='_smp_mflags %{nil}' --define='make $(MAKE)' - -# srcrpm-pkg -# --------------------------------------------------------------------------- -PHONY += srcrpm-pkg -srcrpm-pkg: linux.tar.gz - $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec - +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \ - --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .' -# binrpm-pkg -# --------------------------------------------------------------------------- -PHONY += binrpm-pkg -binrpm-pkg: - $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/kernel.spec - +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ - $(UTS_MACHINE)-linux -bb $(objtree)/kernel.spec \ - --build-in-place --noprep --define='_smp_mflags %{nil}' --without devel \ - --define='make $(MAKE)' +quiet_cmd_mkspec = GEN $@ + cmd_mkspec = $(srctree)/scripts/package/mkspec > $@ + +kernel.spec: FORCE + $(call cmd,mkspec) + +PHONY += rpm-sources +rpm-sources: linux.tar.gz + $(Q)mkdir -p rpmbuild/SOURCES + $(Q)ln -f linux.tar.gz rpmbuild/SOURCES/linux.tar.gz + $(Q)cp $(KCONFIG_CONFIG) rpmbuild/SOURCES/config + $(Q)$(srctree)/scripts/package/gen-diff-patch rpmbuild/SOURCES/diff.patch + +PHONY += rpm-pkg srcrpm-pkg binrpm-pkg + +rpm-pkg: private build-type := a +srcrpm-pkg: private build-type := s +binrpm-pkg: private build-type := b + +rpm-pkg srcrpm-pkg: rpm-sources +rpm-pkg srcrpm-pkg binrpm-pkg: kernel.spec + +$(strip rpmbuild -b$(build-type) kernel.spec \ + --define='_topdir $(abspath rpmbuild)' \ + $(if $(filter a b, $(build-type)), \ + --target $(UTS_MACHINE)-linux --build-in-place --noprep --define='_smp_mflags %{nil}') \ + $(if $(filter b, $(build-type)), \ + --without devel) \ + $(RPMOPTS)) # deb-pkg srcdeb-pkg bindeb-pkg # --------------------------------------------------------------------------- diff --git a/scripts/package/mkspec b/scripts/package/mkspec index c08567ae7fb1..d41608efb747 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -9,14 +9,6 @@ # Patched for non-x86 by Opencon (L) 2002 # -# how we were called determines which rpms we build and how we build them -if [ -z "$1" ]; then - mkdir -p rpmbuild/SOURCES - cp linux.tar.gz rpmbuild/SOURCES - cp "${KCONFIG_CONFIG}" rpmbuild/SOURCES/config - "${srctree}/scripts/package/gen-diff-patch" rpmbuild/SOURCES/diff.patch -fi - if grep -q CONFIG_MODULES=y include/config/auto.conf; then echo '%define with_devel %{?_without_devel: 0} %{?!_without_devel: 1}' else -- cgit From 783c55ae7a9551f049b0c1a52cde0ec3a5550501 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:06 +0900 Subject: kbuild: rpm-pkg: skip build dependency check on non-rpm systems Commit 8818039f959b ("kbuild: add ability to make source rpm buildable using koji") added the BuildRequires: field. Checking the build dependency is fine, but one annoyance is that 'make (bin)rpm-pkg' fails on non-rpm systems [1]. For example, Debian provides rpmbuild via 'apt install rpm', but of course cannot meet the requirement listed in the BuildRequires: field. It is possible to pass RPMOPTS=--nodeps to work around it, but it is reasonable to do it automatically. If 'rpm -q rpm' fails, it is not an RPM-managed system. (The command 'rpm' is not installed at all, or was installed by other means.) In that case, pass --nodeps to skip the build dependency check. [1]: https://lore.kernel.org/linux-kbuild/Y6mkdYQYmjUz7bqV@li-4a3a4a4c-28e5-11b2-a85c-a8d192c6f089.ibm.com/ Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index 0ace3973a0d1..85beab0363d7 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -92,7 +92,8 @@ rpm-pkg srcrpm-pkg binrpm-pkg: kernel.spec +$(strip rpmbuild -b$(build-type) kernel.spec \ --define='_topdir $(abspath rpmbuild)' \ $(if $(filter a b, $(build-type)), \ - --target $(UTS_MACHINE)-linux --build-in-place --noprep --define='_smp_mflags %{nil}') \ + --target $(UTS_MACHINE)-linux --build-in-place --noprep --define='_smp_mflags %{nil}' \ + $$(rpm -q rpm >/dev/null 2>&1 || echo --nodeps)) \ $(if $(filter b, $(build-type)), \ --without devel) \ $(RPMOPTS)) -- cgit From a68914a53476d4fa0808219c6323eddca50e0e26 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 Jul 2023 19:04:43 +0900 Subject: modpost: change return type of addend_*_rel() Now that none of addend_*_rel() returns a meaningful value (the return value is always 0), change all of them to return the value of r_addend. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 63 ++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 39 deletions(-) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 8227641dd087..a8e85b7cc0da 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1257,21 +1257,18 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf, tosec, taddr); } -static int addend_386_rel(uint32_t *location, Elf_Rela *r) +static Elf_Addr addend_386_rel(uint32_t *location, Elf_Rela *r) { unsigned int r_typ = ELF_R_TYPE(r->r_info); switch (r_typ) { case R_386_32: - r->r_addend = TO_NATIVE(*location); - break; + return TO_NATIVE(*location); case R_386_PC32: - r->r_addend = TO_NATIVE(*location) + 4; - break; - default: - r->r_addend = (Elf_Addr)(-1); + return TO_NATIVE(*location) + 4; } - return 0; + + return (Elf_Addr)(-1); } #ifndef R_ARM_CALL @@ -1315,7 +1312,7 @@ static int32_t sign_extend32(int32_t value, int index) return (int32_t)(value << shift) >> shift; } -static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) +static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) { unsigned int r_typ = ELF_R_TYPE(r->r_info); uint32_t inst, upper, lower, sign, j1, j2; @@ -1325,22 +1322,19 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) case R_ARM_ABS32: case R_ARM_REL32: inst = TO_NATIVE(*(uint32_t *)loc); - r->r_addend = inst + sym->st_value; - break; + return inst + sym->st_value; case R_ARM_MOVW_ABS_NC: case R_ARM_MOVT_ABS: inst = TO_NATIVE(*(uint32_t *)loc); offset = sign_extend32(((inst & 0xf0000) >> 4) | (inst & 0xfff), 15); - r->r_addend = offset + sym->st_value; - break; + return offset + sym->st_value; case R_ARM_PC24: case R_ARM_CALL: case R_ARM_JUMP24: inst = TO_NATIVE(*(uint32_t *)loc); offset = sign_extend32((inst & 0x00ffffff) << 2, 25); - r->r_addend = offset + sym->st_value + 8; - break; + return offset + sym->st_value + 8; case R_ARM_THM_MOVW_ABS_NC: case R_ARM_THM_MOVT_ABS: upper = TO_NATIVE(*(uint16_t *)loc); @@ -1350,8 +1344,7 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) ((lower & 0x7000) >> 4) | (lower & 0x00ff), 15); - r->r_addend = offset + sym->st_value; - break; + return offset + sym->st_value; case R_ARM_THM_JUMP19: /* * Encoding T3: @@ -1372,8 +1365,7 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) ((upper & 0x03f) << 12) | ((lower & 0x07ff) << 1), 20); - r->r_addend = offset + sym->st_value + 4; - break; + return offset + sym->st_value + 4; case R_ARM_THM_CALL: case R_ARM_THM_JUMP24: /* @@ -1399,15 +1391,13 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) ((upper & 0x03ff) << 12) | ((lower & 0x07ff) << 1), 24); - r->r_addend = offset + sym->st_value + 4; - break; - default: - r->r_addend = (Elf_Addr)(-1); + return offset + sym->st_value + 4; } - return 0; + + return (Elf_Addr)(-1); } -static int addend_mips_rel(uint32_t *location, Elf_Rela *r) +static Elf_Addr addend_mips_rel(uint32_t *location, Elf_Rela *r) { unsigned int r_typ = ELF_R_TYPE(r->r_info); uint32_t inst; @@ -1415,18 +1405,13 @@ static int addend_mips_rel(uint32_t *location, Elf_Rela *r) inst = TO_NATIVE(*location); switch (r_typ) { case R_MIPS_LO16: - r->r_addend = inst & 0xffff; - break; + return inst & 0xffff; case R_MIPS_26: - r->r_addend = (inst & 0x03ffffff) << 2; - break; + return (inst & 0x03ffffff) << 2; case R_MIPS_32: - r->r_addend = inst; - break; - default: - r->r_addend = (Elf_Addr)(-1); + return inst; } - return 0; + return (Elf_Addr)(-1); } #ifndef EM_RISCV @@ -1513,6 +1498,7 @@ static void section_rel(struct module *mod, struct elf_info *elf, for (rel = start; rel < stop; rel++) { Elf_Sym *tsym; + Elf_Addr taddr = 0; void *loc; r.r_offset = TO_NATIVE(rel->r_offset); @@ -1531,27 +1517,26 @@ static void section_rel(struct module *mod, struct elf_info *elf, r.r_info = TO_NATIVE(rel->r_info); r_sym = ELF_R_SYM(r.r_info); #endif - r.r_addend = 0; loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset); tsym = elf->symtab_start + r_sym; switch (elf->hdr->e_machine) { case EM_386: - addend_386_rel(loc, &r); + taddr = addend_386_rel(loc, &r); break; case EM_ARM: - addend_arm_rel(loc, tsym, &r); + taddr = addend_arm_rel(loc, tsym, &r); break; case EM_MIPS: - addend_mips_rel(loc, &r); + taddr = addend_mips_rel(loc, &r); break; default: fatal("Please add code to calculate addend for this architecture\n"); } check_section_mismatch(mod, elf, tsym, - fsecndx, fromsec, r.r_offset, r.r_addend); + fsecndx, fromsec, r.r_offset, taddr); } } -- cgit From 71d965cf3577d68788a3d3ef044eb8e6d85013fa Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 Jul 2023 19:04:44 +0900 Subject: modpost: pass r_type to addend_*_rel() All of addend_*_rel() need the Elf_Rela pointer just for calculating ELF_R_TYPE(r->r_info). You can do it on the caller to de-duplicate the code. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index a8e85b7cc0da..570a6cb6dd00 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1257,11 +1257,9 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf, tosec, taddr); } -static Elf_Addr addend_386_rel(uint32_t *location, Elf_Rela *r) +static Elf_Addr addend_386_rel(uint32_t *location, unsigned int r_type) { - unsigned int r_typ = ELF_R_TYPE(r->r_info); - - switch (r_typ) { + switch (r_type) { case R_386_32: return TO_NATIVE(*location); case R_386_PC32: @@ -1312,13 +1310,12 @@ static int32_t sign_extend32(int32_t value, int index) return (int32_t)(value << shift) >> shift; } -static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) +static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, unsigned int r_type) { - unsigned int r_typ = ELF_R_TYPE(r->r_info); uint32_t inst, upper, lower, sign, j1, j2; int32_t offset; - switch (r_typ) { + switch (r_type) { case R_ARM_ABS32: case R_ARM_REL32: inst = TO_NATIVE(*(uint32_t *)loc); @@ -1397,13 +1394,12 @@ static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) return (Elf_Addr)(-1); } -static Elf_Addr addend_mips_rel(uint32_t *location, Elf_Rela *r) +static Elf_Addr addend_mips_rel(uint32_t *location, unsigned int r_type) { - unsigned int r_typ = ELF_R_TYPE(r->r_info); uint32_t inst; inst = TO_NATIVE(*location); - switch (r_typ) { + switch (r_type) { case R_MIPS_LO16: return inst & 0xffff; case R_MIPS_26: @@ -1500,6 +1496,7 @@ static void section_rel(struct module *mod, struct elf_info *elf, Elf_Sym *tsym; Elf_Addr taddr = 0; void *loc; + unsigned int r_type; r.r_offset = TO_NATIVE(rel->r_offset); #if KERNEL_ELFCLASS == ELFCLASS64 @@ -1520,16 +1517,17 @@ static void section_rel(struct module *mod, struct elf_info *elf, loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset); tsym = elf->symtab_start + r_sym; + r_type = ELF_R_TYPE(r.r_info); switch (elf->hdr->e_machine) { case EM_386: - taddr = addend_386_rel(loc, &r); + taddr = addend_386_rel(loc, r_type); break; case EM_ARM: - taddr = addend_arm_rel(loc, tsym, &r); + taddr = addend_arm_rel(loc, tsym, r_type); break; case EM_MIPS: - taddr = addend_mips_rel(loc, &r); + taddr = addend_mips_rel(loc, r_type); break; default: fatal("Please add code to calculate addend for this architecture\n"); -- cgit From 4732acb75f468c12e2715cf5bf726cac873bc0e5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 Jul 2023 19:04:45 +0900 Subject: modpost: clean up MIPS64 little endian relocation code MIPS64 little endian target has an odd encoding of r_info. This commit makes the special handling less ugly. It is still ugly, but #if conditionals will go away, at least. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 76 +++++++++++++++++++++++++++++---------------------- scripts/mod/modpost.h | 22 --------------- 2 files changed, 43 insertions(+), 55 deletions(-) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 570a6cb6dd00..ca04b87c1679 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1426,6 +1426,41 @@ static Elf_Addr addend_mips_rel(uint32_t *location, unsigned int r_type) #define R_LARCH_SUB32 55 #endif +static void get_rel_type_and_sym(struct elf_info *elf, uint64_t r_info, + unsigned int *r_type, unsigned int *r_sym) +{ + typedef struct { + Elf64_Word r_sym; /* Symbol index */ + unsigned char r_ssym; /* Special symbol for 2nd relocation */ + unsigned char r_type3; /* 3rd relocation type */ + unsigned char r_type2; /* 2nd relocation type */ + unsigned char r_type; /* 1st relocation type */ + } Elf64_Mips_R_Info; + + bool is_64bit = (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64); + + if (elf->hdr->e_machine == EM_MIPS && is_64bit) { + Elf64_Mips_R_Info *mips64_r_info = (void *)&r_info; + + *r_type = mips64_r_info->r_type; + *r_sym = TO_NATIVE(mips64_r_info->r_sym); + return; + } + + if (is_64bit) { + Elf64_Xword r_info64 = r_info; + + r_info = TO_NATIVE(r_info64); + } else { + Elf32_Word r_info32 = r_info; + + r_info = TO_NATIVE(r_info32); + } + + *r_type = ELF_R_TYPE(r_info); + *r_sym = ELF_R_SYM(r_info); +} + static void section_rela(struct module *mod, struct elf_info *elf, Elf_Shdr *sechdr) { @@ -1442,32 +1477,21 @@ static void section_rela(struct module *mod, struct elf_info *elf, return; for (rela = start; rela < stop; rela++) { + unsigned int r_type; + r.r_offset = TO_NATIVE(rela->r_offset); -#if KERNEL_ELFCLASS == ELFCLASS64 - if (elf->hdr->e_machine == EM_MIPS) { - unsigned int r_typ; - r_sym = ELF64_MIPS_R_SYM(rela->r_info); - r_sym = TO_NATIVE(r_sym); - r_typ = ELF64_MIPS_R_TYPE(rela->r_info); - r.r_info = ELF64_R_INFO(r_sym, r_typ); - } else { - r.r_info = TO_NATIVE(rela->r_info); - r_sym = ELF_R_SYM(r.r_info); - } -#else - r.r_info = TO_NATIVE(rela->r_info); - r_sym = ELF_R_SYM(r.r_info); -#endif + get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym); + r.r_addend = TO_NATIVE(rela->r_addend); switch (elf->hdr->e_machine) { case EM_RISCV: if (!strcmp("__ex_table", fromsec) && - ELF_R_TYPE(r.r_info) == R_RISCV_SUB32) + r_type == R_RISCV_SUB32) continue; break; case EM_LOONGARCH: if (!strcmp("__ex_table", fromsec) && - ELF_R_TYPE(r.r_info) == R_LARCH_SUB32) + r_type == R_LARCH_SUB32) continue; break; } @@ -1499,25 +1523,11 @@ static void section_rel(struct module *mod, struct elf_info *elf, unsigned int r_type; r.r_offset = TO_NATIVE(rel->r_offset); -#if KERNEL_ELFCLASS == ELFCLASS64 - if (elf->hdr->e_machine == EM_MIPS) { - unsigned int r_typ; - r_sym = ELF64_MIPS_R_SYM(rel->r_info); - r_sym = TO_NATIVE(r_sym); - r_typ = ELF64_MIPS_R_TYPE(rel->r_info); - r.r_info = ELF64_R_INFO(r_sym, r_typ); - } else { - r.r_info = TO_NATIVE(rel->r_info); - r_sym = ELF_R_SYM(r.r_info); - } -#else - r.r_info = TO_NATIVE(rel->r_info); - r_sym = ELF_R_SYM(r.r_info); -#endif + + get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym); loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset); tsym = elf->symtab_start + r_sym; - r_type = ELF_R_TYPE(r.r_info); switch (elf->hdr->e_machine) { case EM_386: diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index dfdb9484e325..5f94c2c9f2d9 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -50,28 +50,6 @@ #define ELF_R_TYPE ELF64_R_TYPE #endif -/* The 64-bit MIPS ELF ABI uses an unusual reloc format. */ -typedef struct -{ - Elf32_Word r_sym; /* Symbol index */ - unsigned char r_ssym; /* Special symbol for 2nd relocation */ - unsigned char r_type3; /* 3rd relocation type */ - unsigned char r_type2; /* 2nd relocation type */ - unsigned char r_type1; /* 1st relocation type */ -} _Elf64_Mips_R_Info; - -typedef union -{ - Elf64_Xword r_info_number; - _Elf64_Mips_R_Info r_info_fields; -} _Elf64_Mips_R_Info_union; - -#define ELF64_MIPS_R_SYM(i) \ - ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_sym) - -#define ELF64_MIPS_R_TYPE(i) \ - ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_type1) - #if KERNEL_ELFDATA != HOST_ELFDATA static inline void __endian(const void *src, void *dest, unsigned int size) -- cgit From 77f39e9344a151f2c055ce85875c3c57c6cfdfa3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 Jul 2023 19:04:46 +0900 Subject: modpost: remove ElF_Rela variables from for-loop in section_rel(a) Remove the Elf_Rela variables used in the for-loop in section_rel(). This makes the code consistent; section_rel() only uses Elf_Rel, section_rela() only uses Elf_Rela. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index ca04b87c1679..9761f9d0eec0 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1465,8 +1465,6 @@ static void section_rela(struct module *mod, struct elf_info *elf, Elf_Shdr *sechdr) { Elf_Rela *rela; - Elf_Rela r; - unsigned int r_sym; unsigned int fsecndx = sechdr->sh_info; const char *fromsec = sec_name(elf, fsecndx); Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset; @@ -1477,12 +1475,14 @@ static void section_rela(struct module *mod, struct elf_info *elf, return; for (rela = start; rela < stop; rela++) { - unsigned int r_type; + Elf_Addr taddr, r_offset; + unsigned int r_type, r_sym; - r.r_offset = TO_NATIVE(rela->r_offset); + r_offset = TO_NATIVE(rela->r_offset); get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym); - r.r_addend = TO_NATIVE(rela->r_addend); + taddr = TO_NATIVE(rela->r_addend); + switch (elf->hdr->e_machine) { case EM_RISCV: if (!strcmp("__ex_table", fromsec) && @@ -1497,7 +1497,7 @@ static void section_rela(struct module *mod, struct elf_info *elf, } check_section_mismatch(mod, elf, elf->symtab_start + r_sym, - fsecndx, fromsec, r.r_offset, r.r_addend); + fsecndx, fromsec, r_offset, taddr); } } @@ -1505,8 +1505,6 @@ static void section_rel(struct module *mod, struct elf_info *elf, Elf_Shdr *sechdr) { Elf_Rel *rel; - Elf_Rela r; - unsigned int r_sym; unsigned int fsecndx = sechdr->sh_info; const char *fromsec = sec_name(elf, fsecndx); Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset; @@ -1518,15 +1516,14 @@ static void section_rel(struct module *mod, struct elf_info *elf, for (rel = start; rel < stop; rel++) { Elf_Sym *tsym; - Elf_Addr taddr = 0; + Elf_Addr taddr = 0, r_offset; + unsigned int r_type, r_sym; void *loc; - unsigned int r_type; - - r.r_offset = TO_NATIVE(rel->r_offset); + r_offset = TO_NATIVE(rel->r_offset); get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym); - loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset); + loc = sym_get_data_by_offset(elf, fsecndx, r_offset); tsym = elf->symtab_start + r_sym; switch (elf->hdr->e_machine) { @@ -1544,7 +1541,7 @@ static void section_rel(struct module *mod, struct elf_info *elf, } check_section_mismatch(mod, elf, tsym, - fsecndx, fromsec, r.r_offset, taddr); + fsecndx, fromsec, r_offset, taddr); } } -- cgit From 4b970e436523ed34da4ced74ad2b81e5a4f573f2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 1 Aug 2023 21:19:25 +0900 Subject: kbuild: deb-pkg: use Debian compliant shebang for debian/rules Debian Policy "4.9. Main building script: debian/rules" requires "debian/rules must start with the line #!/usr/bin/make -f". [1] Currently, Kbuild does not follow this policy. When Kbuild generates debian/rules, "#!$(command -v $MAKE) -f" is expanded by shell. The resuling string may not be "#!/usr/bin/make -f". There was a reason to opt out the Debian policy. If you run '/path/to/my/custom/make deb-pkg', debian/rules must also be invoked by the same Make program. If #!/usr/bin/make were hard-coded in debian/rules, the sub-make would be executed by a possibly different Make version. This is problematic due to the MAKEFLAGS incompatibility, especially the job server flag. Old Make versions used --jobserver-fds to propagate job server file descriptors, but Make >= 4.2 uses --jobserver-auth. The flag disagreement between the parent/child Makes would result in a process fork explosion. However, having a non-standard path in the shebang causes another issue; the generated source package is not portable as such a path does not exist in other build environments. This commit solves those conflicting demands. Hard-code '#!/usr/bin/make -f' in debian/rules to create a portable and Debian-compliant source package. Pass '--rules-file=$(MAKE) -f debian/rules' when dpkg-buildpackage is invoked from Makefile so that debian/rules is executed by the same Make program as used to start Kbuild. [1] https://www.debian.org/doc/debian-policy/ch-source.html#main-building-script-debian-rules Signed-off-by: Masahiro Yamada Tested-by: Nathan Chancellor Reviewed-by: Nicolas Schier --- scripts/Makefile.package | 2 +- scripts/package/mkdebian | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index 85beab0363d7..f8a948ec2c6b 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -148,7 +148,7 @@ deb-pkg srcdeb-pkg bindeb-pkg: $(if $(findstring source, $(build-type)), \ --unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \ $(if $(findstring binary, $(build-type)), \ - -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \ + --rules-file='$(MAKE) -f debian/rules' -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \ --no-check-builddeps) \ $(DPKG_FLAGS)) diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian index 9105abab9728..2829f5b8aea6 100755 --- a/scripts/package/mkdebian +++ b/scripts/package/mkdebian @@ -264,7 +264,7 @@ EOF fi cat < debian/rules -#!$(command -v $MAKE) -f +#!/usr/bin/make -f srctree ?= . KERNELRELEASE = ${KERNELRELEASE} -- cgit From d9287ea8ffc9be2ab4c81c32e1ca54478425ba38 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 1 Aug 2023 21:19:26 +0900 Subject: kbuild: deb-pkg: split debian/rules debian/rules is generated by shell, but the escape sequence (\$) is unreadable. debian/rules embeds only two variables (ARCH and KERNELRELEASE). Split them out to debian/rules.vars, and check-in the rest of Makefile code to scripts/package/debian/rules. Signed-off-by: Masahiro Yamada Tested-by: Nathan Chancellor Reviewed-by: Nicolas Schier --- scripts/package/debian/rules | 28 ++++++++++++++++++++++++++++ scripts/package/mkdebian | 34 +++++----------------------------- 2 files changed, 33 insertions(+), 29 deletions(-) create mode 100755 scripts/package/debian/rules (limited to 'scripts') diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules new file mode 100755 index 000000000000..226e127efd63 --- /dev/null +++ b/scripts/package/debian/rules @@ -0,0 +1,28 @@ +#!/usr/bin/make -f +# SPDX-License-Identifier: GPL-2.0-only + +include debian/rules.vars + +srctree ?= . + +.PHONY: binary binary-indep binary-arch +binary: binary-arch binary-indep +binary-indep: build-indep +binary-arch: build-arch + $(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) \ + KERNELRELEASE=$(KERNELRELEASE) \ + run-command KBUILD_RUN_COMMAND=+$(srctree)/scripts/package/builddeb + +.PHONY: build build-indep build-arch +build: build-arch build-indep +build-indep: +build-arch: + $(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) \ + KERNELRELEASE=$(KERNELRELEASE) \ + $(shell $(srctree)/scripts/package/deb-build-option) \ + olddefconfig all + +.PHONY: clean +clean: + rm -rf debian/files debian/linux-* + $(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) clean diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian index 2829f5b8aea6..5044224cf671 100755 --- a/scripts/package/mkdebian +++ b/scripts/package/mkdebian @@ -263,35 +263,11 @@ Description: Linux kernel debugging symbols for $version EOF fi -cat < debian/rules -#!/usr/bin/make -f - -srctree ?= . -KERNELRELEASE = ${KERNELRELEASE} - -.PHONY: clean build build-arch build-indep binary binary-arch binary-indep - -build-indep: -build-arch: - \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \ - KERNELRELEASE=\$(KERNELRELEASE) \ - \$(shell \$(srctree)/scripts/package/deb-build-option) \ - olddefconfig all - -build: build-arch - -binary-indep: -binary-arch: build-arch - \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \ - KERNELRELEASE=\$(KERNELRELEASE) \ - run-command KBUILD_RUN_COMMAND=+\$(srctree)/scripts/package/builddeb - -clean: - rm -rf debian/files debian/linux-* - \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} clean - -binary: binary-arch +cat < debian/rules.vars +ARCH := ${ARCH} +KERNELRELEASE := ${KERNELRELEASE} EOF -chmod +x debian/rules + +cp "${srctree}/scripts/package/debian/rules" debian/ exit 0 -- cgit From 3354c64d418460c500080fddb1171d8e17622a06 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Thu, 3 Aug 2023 13:50:20 +0200 Subject: scripts/setlocalversion: clean up stale comment Nobody has complained since 2a73cce2dad3 ("scripts/setlocalversion: remove mercurial, svn and git-svn supports"), so let's also clean up the header comment accordingly. Signed-off-by: Rasmus Villemoes Signed-off-by: Masahiro Yamada --- scripts/setlocalversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 3d3babac8298..4f1d3eb795e9 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-2.0 # # This scripts adds local version information from the version -# control systems git, mercurial (hg) and subversion (svn). +# control system git. # # If something goes wrong, send a mail the kernel build mailinglist # (see MAINTAINERS) and CC Nico Schottelius -- cgit From 01e89a4acefc9d8356e91dde310da11e5b97d22d Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Fri, 4 Aug 2023 14:05:36 +0200 Subject: scripts/setlocalversion: also consider annotated tags of the form vx.y.z-${file_localversion} Commit 6ab7e1f95e96 ("setlocalversion: use only the correct release tag for git-describe") was absolutely correct to limit which annotated tags would be used to compute the -01234-gabcdef suffix. Otherwise, if some random annotated tag exists closer to HEAD than the vX.Y.Z one, the commit count would be too low. However, since the version string always includes the ${file_localversion} part, now the problem is that the count can be too high. For example, building an 6.4.6-rt8 kernel with a few patches on top, I currently get $ make -s kernelrelease 6.4.6-rt8-00128-gd78b7f406397 But those 128 commits include the 100 commits that are in v6.4.6..v6.4.6-rt8, so this is somewhat misleading. Amend the logic so that, in addition to the linux-next consideration, the script also looks for a tag corresponding to the 6.4.6-rt8 part of what will become the `uname -r` string. With this patch (so 29 patches on top of v6.4.6-rt8), one instead gets $ make -s kernelrelease 6.4.6-rt8-00029-gd533209291a2 While there, note that the line git describe --exact-match --match=$tag $tag 2>/dev/null obviously asks if $tag is an annotated tag, but it does not actually tell if the commit pointed to has any relation to HEAD. So remove both uses of --exact-match, and instead just ask if the description generated is identical to the tag we provided. Since we then already have the result of git describe --match=$tag we also end up reducing the number of times we invoke "git describe". Signed-off-by: Rasmus Villemoes Signed-off-by: Masahiro Yamada --- scripts/setlocalversion | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'scripts') diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 4f1d3eb795e9..38b96c6797f4 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -57,21 +57,37 @@ scm_version() return fi - # If a localversion*' file and the corresponding annotated tag exist, - # use it. This is the case in linux-next. + # mainline kernel: 6.2.0-rc5 -> v6.2-rc5 + # stable kernel: 6.1.7 -> v6.1.7 + version_tag=v$(echo "${KERNELVERSION}" | sed -E 's/^([0-9]+\.[0-9]+)\.0(.*)$/\1\2/') + + # If a localversion* file exists, and the corresponding + # annotated tag exists and is an ancestor of HEAD, use + # it. This is the case in linux-next. tag=${file_localversion#-} - tag=$(git describe --exact-match --match=$tag $tag 2>/dev/null) + desc= + if [ -n "${tag}" ]; then + desc=$(git describe --match=$tag 2>/dev/null) + fi + + # Otherwise, if a localversion* file exists, and the tag + # obtained by appending it to the tag derived from + # KERNELVERSION exists and is an ancestor of HEAD, use + # it. This is e.g. the case in linux-rt. + if [ -z "${desc}" ] && [ -n "${file_localversion}" ]; then + tag="${version_tag}${file_localversion}" + desc=$(git describe --match=$tag 2>/dev/null) + fi # Otherwise, default to the annotated tag derived from KERNELVERSION. - # mainline kernel: 6.2.0-rc5 -> v6.2-rc5 - # stable kernel: 6.1.7 -> v6.1.7 - if [ -z "${tag}" ]; then - tag=v$(echo "${KERNELVERSION}" | sed -E 's/^([0-9]+\.[0-9]+)\.0(.*)$/\1\2/') + if [ -z "${desc}" ]; then + tag="${version_tag}" + desc=$(git describe --match=$tag 2>/dev/null) fi # If we are at the tagged commit, we ignore it because the version is # well-defined. - if [ -z "$(git describe --exact-match --match=$tag 2>/dev/null)" ]; then + if [ "${tag}" != "${desc}" ]; then # If only the short version is requested, don't bother # running further git commands @@ -81,8 +97,8 @@ scm_version() fi # If we are past the tagged commit, we pretty print it. # (like 6.1.0-14595-g292a089d78d3) - if atag="$(git describe --match=$tag 2>/dev/null)"; then - echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}' + if [ -n "${desc}" ]; then + echo "${desc}" | awk -F- '{printf("-%05d", $(NF-1))}' fi # Add -g and exactly 12 hex chars. -- cgit From 1ba67cd3281e50a965c5b519f946b14a1c4620a7 Mon Sep 17 00:00:00 2001 From: Jesse Taube Date: Tue, 8 Aug 2023 20:42:20 -0400 Subject: kconfig: nconf: Add search jump feature Menuconfig has a feature where you can "press the key in the (#) prefix to jump directly to that location. You will be returned to the current search results after exiting this new menu." This commit adds this feature to nconfig, with almost identical code. Signed-off-by: Jesse Taube Acked-by: Randy Dunlap Tested-by: Randy Dunlap Signed-off-by: Masahiro Yamada --- scripts/kconfig/nconf.c | 113 ++++++++++++++++++++++++++++++++++++++++---- scripts/kconfig/nconf.gui.c | 37 +++++++++++++-- scripts/kconfig/nconf.h | 5 ++ 3 files changed, 140 insertions(+), 15 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 3ba8b1af390f..143a2c351d57 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -220,7 +220,7 @@ search_help[] = "Location:\n" " -> Bus options (PCI, PCMCIA, EISA, ISA)\n" " -> PCI support (PCI [ = y])\n" -" -> PCI access mode ( [ = y])\n" +"(1) -> PCI access mode ( [ = y])\n" "Selects: LIBCRC32\n" "Selected by: BAR\n" "-----------------------------------------------------------------\n" @@ -231,9 +231,13 @@ search_help[] = "o The 'Depends on:' line lists symbols that need to be defined for\n" " this symbol to be visible and selectable in the menu.\n" "o The 'Location:' lines tell, where in the menu structure this symbol\n" -" is located. A location followed by a [ = y] indicates that this is\n" -" a selectable menu item, and the current value is displayed inside\n" -" brackets.\n" +" is located.\n" +" A location followed by a [ = y] indicates that this is\n" +" a selectable menu item, and the current value is displayed inside\n" +" brackets.\n" +" Press the key in the (#) prefix to jump directly to that\n" +" location. You will be returned to the current search results\n" +" after exiting this new menu.\n" "o The 'Selects:' line tells, what symbol will be automatically selected\n" " if this symbol is selected (y or m).\n" "o The 'Selected by' line tells what symbol has selected this symbol.\n" @@ -275,7 +279,9 @@ static const char *current_instructions = menu_instructions; static char *dialog_input_result; static int dialog_input_result_len; +static int jump_key_char; +static void selected_conf(struct menu *menu, struct menu *active_menu); static void conf(struct menu *menu); static void conf_choice(struct menu *menu); static void conf_string(struct menu *menu); @@ -685,6 +691,57 @@ static int do_exit(void) return 0; } +struct search_data { + struct list_head *head; + struct menu *target; +}; + +static int next_jump_key(int key) +{ + if (key < '1' || key > '9') + return '1'; + + key++; + + if (key > '9') + key = '1'; + + return key; +} + +static int handle_search_keys(int key, size_t start, size_t end, void *_data) +{ + struct search_data *data = _data; + struct jump_key *pos; + int index = 0; + + if (key < '1' || key > '9') + return 0; + + list_for_each_entry(pos, data->head, entries) { + index = next_jump_key(index); + + if (pos->offset < start) + continue; + + if (pos->offset >= end) + break; + + if (key == index) { + data->target = pos->target; + return 1; + } + } + + return 0; +} + +int get_jump_key_char(void) +{ + jump_key_char = next_jump_key(jump_key_char); + + return jump_key_char; +} static void search_conf(void) { @@ -692,7 +749,8 @@ static void search_conf(void) struct gstr res; struct gstr title; char *dialog_input; - int dres; + int dres, vscroll = 0, hscroll = 0; + bool again; title = str_new(); str_printf( &title, "Enter (sub)string or regexp to search for " @@ -721,11 +779,28 @@ again: dialog_input += strlen(CONFIG_); sym_arr = sym_re_search(dialog_input); - res = get_relations_str(sym_arr, NULL); + + do { + LIST_HEAD(head); + struct search_data data = { + .head = &head, + .target = NULL, + }; + jump_key_char = 0; + res = get_relations_str(sym_arr, &head); + dres = show_scroll_win_ext(main_window, + "Search Results", str_get(&res), + &vscroll, &hscroll, + handle_search_keys, &data); + again = false; + if (dres >= '1' && dres <= '9') { + assert(data.target != NULL); + selected_conf(data.target->parent, data.target); + again = true; + } + str_free(&res); + } while (again); free(sym_arr); - show_scroll_win(main_window, - "Search Results", str_get(&res)); - str_free(&res); str_free(&title); } @@ -1062,10 +1137,15 @@ static int do_match(int key, struct match_state *state, int *ans) } static void conf(struct menu *menu) +{ + selected_conf(menu, NULL); +} + +static void selected_conf(struct menu *menu, struct menu *active_menu) { struct menu *submenu = NULL; struct symbol *sym; - int res; + int i, res; int current_index = 0; int last_top_row = 0; struct match_state match_state = { @@ -1081,6 +1161,19 @@ static void conf(struct menu *menu) if (!child_count) break; + if (active_menu != NULL) { + for (i = 0; i < items_num; i++) { + struct mitem *mcur; + + mcur = (struct mitem *) item_userptr(curses_menu_items[i]); + if ((struct menu *) mcur->usrptr == active_menu) { + current_index = i; + break; + } + } + active_menu = NULL; + } + show_menu(menu_get_prompt(menu), menu_instructions, current_index, &last_top_row); keypad((menu_win(curses_menu)), TRUE); diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index 9aedf40f1dc0..25a7263ef3c8 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -497,10 +497,17 @@ void refresh_all_windows(WINDOW *main_window) refresh(); } -/* layman's scrollable window... */ void show_scroll_win(WINDOW *main_window, const char *title, const char *text) +{ + (void)show_scroll_win_ext(main_window, title, (char *)text, NULL, NULL, NULL, NULL); +} + +/* layman's scrollable window... */ +int show_scroll_win_ext(WINDOW *main_window, const char *title, char *text, + int *vscroll, int *hscroll, + extra_key_cb_fn extra_key_cb, void *data) { int res; int total_lines = get_line_no(text); @@ -514,6 +521,12 @@ void show_scroll_win(WINDOW *main_window, WINDOW *win; WINDOW *pad; PANEL *panel; + bool done = false; + + if (hscroll) + start_x = *hscroll; + if (vscroll) + start_y = *vscroll; getmaxyx(stdscr, lines, columns); @@ -549,8 +562,7 @@ void show_scroll_win(WINDOW *main_window, panel = new_panel(win); /* handle scrolling */ - do { - + while (!done) { copywin(pad, win, start_y, start_x, 2, 2, text_lines, text_cols, 0); print_in_middle(win, @@ -593,8 +605,18 @@ void show_scroll_win(WINDOW *main_window, case 'l': start_x++; break; + default: + if (extra_key_cb) { + size_t start = (get_line(text, start_y) - text); + size_t end = (get_line(text, start_y + text_lines) - text); + + if (extra_key_cb(res, start, end, data)) { + done = true; + break; + } + } } - if (res == 10 || res == 27 || res == 'q' || + if (res == 0 || res == 10 || res == 27 || res == 'q' || res == KEY_F(F_HELP) || res == KEY_F(F_BACK) || res == KEY_F(F_EXIT)) break; @@ -606,9 +628,14 @@ void show_scroll_win(WINDOW *main_window, start_x = 0; if (start_x >= total_cols-text_cols) start_x = total_cols-text_cols; - } while (res); + } + if (hscroll) + *hscroll = start_x; + if (vscroll) + *vscroll = start_y; del_panel(panel); delwin(win); refresh_all_windows(main_window); + return res; } diff --git a/scripts/kconfig/nconf.h b/scripts/kconfig/nconf.h index 6f925bc74eb3..ab836d582664 100644 --- a/scripts/kconfig/nconf.h +++ b/scripts/kconfig/nconf.h @@ -67,6 +67,8 @@ typedef enum { void set_colors(void); +typedef int (*extra_key_cb_fn)(int, size_t, size_t, void *); + /* this changes the windows attributes !!! */ void print_in_middle(WINDOW *win, int y, int width, const char *str, int attrs); int get_line_length(const char *line); @@ -78,6 +80,9 @@ int dialog_inputbox(WINDOW *main_window, const char *title, const char *prompt, const char *init, char **resultp, int *result_len); void refresh_all_windows(WINDOW *main_window); +int show_scroll_win_ext(WINDOW *main_window, const char *title, char *text, + int *vscroll, int *hscroll, + extra_key_cb_fn extra_key_cb, void *data); void show_scroll_win(WINDOW *main_window, const char *title, const char *text); -- cgit From 077af782e2c333f056cbd713f065bd0009a79a57 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 9 Aug 2023 13:42:31 +0200 Subject: kconfig: port qconf to work with Qt6 in addition to Qt5 Tested with Qt5 5.15 and Qt6 6.4. Note that earlier versions of Qt5 are no longer guaranteed to work. Signed-off-by: Boris Kolpackov Signed-off-by: Masahiro Yamada --- scripts/kconfig/qconf-cfg.sh | 25 ++++++++++++++++++------- scripts/kconfig/qconf.cc | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 21 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/qconf-cfg.sh b/scripts/kconfig/qconf-cfg.sh index 117f36e568fc..0e113b0f2455 100755 --- a/scripts/kconfig/qconf-cfg.sh +++ b/scripts/kconfig/qconf-cfg.sh @@ -5,7 +5,8 @@ cflags=$1 libs=$2 bin=$3 -PKG="Qt5Core Qt5Gui Qt5Widgets" +PKG5="Qt5Core Qt5Gui Qt5Widgets" +PKG6="Qt6Core Qt6Gui Qt6Widgets" if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then echo >&2 "*" @@ -14,16 +15,26 @@ if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then exit 1 fi -if ${HOSTPKG_CONFIG} --exists $PKG; then - ${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags} - ${HOSTPKG_CONFIG} --libs ${PKG} > ${libs} +if ${HOSTPKG_CONFIG} --exists $PKG6; then + ${HOSTPKG_CONFIG} --cflags ${PKG6} > ${cflags} + # Qt6 requires C++17. + echo -std=c++17 >> ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG6} > ${libs} + ${HOSTPKG_CONFIG} --variable=libexecdir Qt6Core > ${bin} + exit 0 +fi + +if ${HOSTPKG_CONFIG} --exists $PKG5; then + ${HOSTPKG_CONFIG} --cflags ${PKG5} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG5} > ${libs} ${HOSTPKG_CONFIG} --variable=host_bins Qt5Core > ${bin} exit 0 fi echo >&2 "*" -echo >&2 "* Could not find Qt5 via ${HOSTPKG_CONFIG}." -echo >&2 "* Please install Qt5 and make sure it's in PKG_CONFIG_PATH" -echo >&2 "* You need $PKG" +echo >&2 "* Could not find Qt6 or Qt5 via ${HOSTPKG_CONFIG}." +echo >&2 "* Please install Qt6 or Qt5 and make sure it's in PKG_CONFIG_PATH" +echo >&2 "* You need $PKG6 for Qt6" +echo >&2 "* You need $PKG5 for Qt5" echo >&2 "*" exit 1 diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc index 78087b2d9ac6..620a3527c767 100644 --- a/scripts/kconfig/qconf.cc +++ b/scripts/kconfig/qconf.cc @@ -5,10 +5,10 @@ */ #include +#include #include #include #include -#include #include #include #include @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include @@ -1126,7 +1128,7 @@ QString ConfigInfoView::debug_info(struct symbol *sym) QString ConfigInfoView::print_filter(const QString &str) { - QRegExp re("[<>&\"\\n]"); + QRegularExpression re("[<>&\"\\n]"); QString res = str; for (int i = 0; (i = res.indexOf(re, i)) >= 0;) { switch (res[i].toLatin1()) { @@ -1322,15 +1324,15 @@ ConfigMainWindow::ConfigMainWindow(void) int width, height; char title[256]; - QDesktopWidget *d = configApp->desktop(); snprintf(title, sizeof(title), "%s%s", rootmenu.prompt->text, "" ); setWindowTitle(title); - width = configSettings->value("/window width", d->width() - 64).toInt(); - height = configSettings->value("/window height", d->height() - 64).toInt(); + QRect g = configApp->primaryScreen()->geometry(); + width = configSettings->value("/window width", g.width() - 64).toInt(); + height = configSettings->value("/window height", g.height() - 64).toInt(); resize(width, height); x = configSettings->value("/window x"); y = configSettings->value("/window y"); @@ -1379,17 +1381,17 @@ ConfigMainWindow::ConfigMainWindow(void) this, &ConfigMainWindow::goBack); QAction *quitAction = new QAction("&Quit", this); - quitAction->setShortcut(Qt::CTRL + Qt::Key_Q); + quitAction->setShortcut(Qt::CTRL | Qt::Key_Q); connect(quitAction, &QAction::triggered, this, &ConfigMainWindow::close); QAction *loadAction = new QAction(QPixmap(xpm_load), "&Load", this); - loadAction->setShortcut(Qt::CTRL + Qt::Key_L); + loadAction->setShortcut(Qt::CTRL | Qt::Key_L); connect(loadAction, &QAction::triggered, this, &ConfigMainWindow::loadConfig); saveAction = new QAction(QPixmap(xpm_save), "&Save", this); - saveAction->setShortcut(Qt::CTRL + Qt::Key_S); + saveAction->setShortcut(Qt::CTRL | Qt::Key_S); connect(saveAction, &QAction::triggered, this, &ConfigMainWindow::saveConfig); @@ -1403,7 +1405,7 @@ ConfigMainWindow::ConfigMainWindow(void) connect(saveAsAction, &QAction::triggered, this, &ConfigMainWindow::saveConfigAs); QAction *searchAction = new QAction("&Find", this); - searchAction->setShortcut(Qt::CTRL + Qt::Key_F); + searchAction->setShortcut(Qt::CTRL | Qt::Key_F); connect(searchAction, &QAction::triggered, this, &ConfigMainWindow::searchConfig); singleViewAction = new QAction(QPixmap(xpm_single_view), "Single View", this); @@ -1750,11 +1752,21 @@ void ConfigMainWindow::closeEvent(QCloseEvent* e) e->accept(); return; } - QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning, - QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); - mb.setButtonText(QMessageBox::Yes, "&Save Changes"); - mb.setButtonText(QMessageBox::No, "&Discard Changes"); - mb.setButtonText(QMessageBox::Cancel, "Cancel Exit"); + + QMessageBox mb(QMessageBox::Icon::Warning, "qconf", + "Save configuration?"); + + QPushButton *yb = mb.addButton(QMessageBox::Yes); + QPushButton *db = mb.addButton(QMessageBox::No); + QPushButton *cb = mb.addButton(QMessageBox::Cancel); + + yb->setText("&Save Changes"); + db->setText("&Discard Changes"); + cb->setText("Cancel Exit"); + + mb.setDefaultButton(yb); + mb.setEscapeButton(cb); + switch (mb.exec()) { case QMessageBox::Yes: if (saveConfig()) -- cgit From e88ca24319e427a685a2e9e3a124ad5beca01158 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 11 Aug 2023 16:03:20 +0200 Subject: kbuild: consolidate warning flags in scripts/Makefile.extrawarn Warning options are enabled and disabled in inconsistent ways and inconsistent locations. Start rearranging those by moving all options into Makefile.extrawarn. This should not change any behavior, but makes sure we can group them in a way that ensures that each warning that got temporarily disabled is turned back on at an appropriate W=1 level later on. Signed-off-by: Arnd Bergmann Signed-off-by: Masahiro Yamada --- scripts/Makefile.extrawarn | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'scripts') diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index 40cd13eca82e..9cc0e52ebd7e 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn @@ -6,6 +6,96 @@ # They are independent, and can be combined like W=12 or W=123e. # ========================================================================== +# Default set of warnings, always enabled +KBUILD_CFLAGS += -Wall +KBUILD_CFLAGS += -Wundef +KBUILD_CFLAGS += -Werror=implicit-function-declaration +KBUILD_CFLAGS += -Werror=implicit-int +KBUILD_CFLAGS += -Werror=return-type +KBUILD_CFLAGS += -Werror=strict-prototypes +KBUILD_CFLAGS += -Wno-format-security +KBUILD_CFLAGS += -Wno-trigraphs +KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) +KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) +KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) +KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) + +ifneq ($(CONFIG_FRAME_WARN),0) +KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) +endif + +KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror +KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y) +KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds + +ifdef CONFIG_CC_IS_CLANG +# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable. +KBUILD_CFLAGS += -Wno-gnu +else + +# gcc inanely warns about local variables called 'main' +KBUILD_CFLAGS += -Wno-main +endif + +# These warnings generated too much noise in a regular build. +# Use make W=1 to enable them (see scripts/Makefile.extrawarn) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) + +# These result in bogus false positives +KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer) + +# Variable Length Arrays (VLAs) should not be used anywhere in the kernel +KBUILD_CFLAGS += -Wvla + +# disable pointer signed / unsigned warnings in gcc 4.0 +KBUILD_CFLAGS += -Wno-pointer-sign + +# In order to make sure new function cast mismatches are not introduced +# in the kernel (to avoid tripping CFI checking), the kernel should be +# globally built with -Wcast-function-type. +KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) + +# disable stringop warnings in gcc 8+ +KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) + +# We'll want to enable this eventually, but it's not going away for 5.7 at least +KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) + +# Another good warning that we'll want to enable eventually +KBUILD_CFLAGS += $(call cc-disable-warning, restrict) + +# Enabled with W=2, disabled by default as noisy +ifdef CONFIG_CC_IS_GCC +KBUILD_CFLAGS += -Wno-maybe-uninitialized +endif + +# The allocators already balk at large sizes, so silence the compiler +# warnings for bounds checks involving those possible values. While +# -Wno-alloc-size-larger-than would normally be used here, earlier versions +# of gcc (<9.1) weirdly don't handle the option correctly when _other_ +# warnings are produced (?!). Using -Walloc-size-larger-than=SIZE_MAX +# doesn't work (as it is documented to), silently resolving to "0" prior to +# version 9.1 (and producing an error more recently). Numeric values larger +# than PTRDIFF_MAX also don't work prior to version 9.1, which are silently +# ignored, continuing to default to PTRDIFF_MAX. So, left with no other +# choice, we must perform a versioned check to disable this warning. +# https://lore.kernel.org/lkml/20210824115859.187f272f@canb.auug.org.au +KBUILD_CFLAGS-$(call gcc-min-version, 90100) += -Wno-alloc-size-larger-than +KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH) + +# Prohibit date/time macros, which would make the build non-deterministic +KBUILD_CFLAGS += -Werror=date-time + +# enforce correct pointer usage +KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types) + +# Require designated initializers for all marked structures +KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) + +# Warn if there is an enum types mismatch +KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion) + KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) # backward compatibility -- cgit From 2cd3271b7a310b1199aa36bfd536ca67d3c2d5f2 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 11 Aug 2023 16:03:21 +0200 Subject: kbuild: avoid duplicate warning options Some warning options are disabled at one place and then conditionally re-enabled later in scripts/Makefile.extrawarn. For consistency, rework this file so each of those warnings only gets etiher enabled or disabled based on the W= flags but not both. Signed-off-by: Arnd Bergmann Signed-off-by: Masahiro Yamada --- scripts/Makefile.extrawarn | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index 9cc0e52ebd7e..8afbe4706ff1 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn @@ -56,20 +56,12 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# disable stringop warnings in gcc 8+ -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) - # We'll want to enable this eventually, but it's not going away for 5.7 at least KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) # Another good warning that we'll want to enable eventually KBUILD_CFLAGS += $(call cc-disable-warning, restrict) -# Enabled with W=2, disabled by default as noisy -ifdef CONFIG_CC_IS_GCC -KBUILD_CFLAGS += -Wno-maybe-uninitialized -endif - # The allocators already balk at large sizes, so silence the compiler # warnings for bounds checks involving those possible values. While # -Wno-alloc-size-larger-than would normally be used here, earlier versions @@ -96,8 +88,6 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) # Warn if there is an enum types mismatch KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion) -KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) - # backward compatibility KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS) @@ -122,11 +112,6 @@ KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) -# The following turn off the warnings enabled by -Wextra -KBUILD_CFLAGS += -Wno-missing-field-initializers -KBUILD_CFLAGS += -Wno-sign-compare -KBUILD_CFLAGS += -Wno-type-limits -KBUILD_CFLAGS += -Wno-shift-negative-value KBUILD_CPPFLAGS += -Wundef KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1 @@ -135,9 +120,12 @@ else # Some diagnostics enabled by default are noisy. # Suppress them by using -Wno... except for W=1. +KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) +KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) ifdef CONFIG_CC_IS_CLANG -KBUILD_CFLAGS += -Wno-initializer-overrides # Clang before clang-16 would warn on default argument promotions. ifneq ($(call clang-min-version, 160000),y) # Disable -Wformat @@ -151,7 +139,6 @@ ifeq ($(call clang-min-version, 120000),y) KBUILD_CFLAGS += -Wformat-insufficient-args endif endif -KBUILD_CFLAGS += -Wno-sign-compare KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast) KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access) @@ -173,8 +160,25 @@ KBUILD_CFLAGS += -Wtype-limits KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) +ifdef CONFIG_CC_IS_CLANG +KBUILD_CFLAGS += -Winitializer-overrides +endif + KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2 +else + +# The following turn off the warnings enabled by -Wextra +KBUILD_CFLAGS += -Wno-missing-field-initializers +KBUILD_CFLAGS += -Wno-type-limits +KBUILD_CFLAGS += -Wno-shift-negative-value + +ifdef CONFIG_CC_IS_CLANG +KBUILD_CFLAGS += -Wno-initializer-overrides +else +KBUILD_CFLAGS += -Wno-maybe-uninitialized +endif + endif # @@ -196,6 +200,11 @@ KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3 +else + +# The following turn off the warnings enabled by -Wextra +KBUILD_CFLAGS += -Wno-sign-compare + endif # -- cgit From 6d4ab2e97dcfbcd748ae71761a9d8e5e41cc732c Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 11 Aug 2023 16:03:23 +0200 Subject: extrawarn: enable format and stringop overflow warnings in W=1 The stringop and format warnings got disabled globally when they were newly introduced in commit bd664f6b3e376 ("disable new gcc-7.1.1 warnings for now"), 217c3e0196758 ("disable stringop truncation warnings for now") and 5a76021c2eff7 ("gcc-10: disable 'stringop-overflow' warning for now"). In all cases, the sentiment at the time was that the warnings are useful, and we actually addressed a number of real bugs based on them, but we never managed to eliminate them all because even the build bots using W=1 builds only see the -Wstringop-truncation warnings that are enabled at that level. Move these into the W=1 section to give them a larger build coverage and actually eliminate them over time. Signed-off-by: Arnd Bergmann Signed-off-by: Masahiro Yamada --- scripts/Makefile.extrawarn | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index 8afbe4706ff1..4c734bba6e90 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn @@ -16,8 +16,6 @@ KBUILD_CFLAGS += -Werror=strict-prototypes KBUILD_CFLAGS += -Wno-format-security KBUILD_CFLAGS += -Wno-trigraphs KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) -KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) -KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) ifneq ($(CONFIG_FRAME_WARN),0) @@ -56,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# We'll want to enable this eventually, but it's not going away for 5.7 at least -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) - # Another good warning that we'll want to enable eventually KBUILD_CFLAGS += $(call cc-disable-warning, restrict) @@ -111,6 +106,9 @@ KBUILD_CFLAGS += -Wmissing-include-dirs KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) +KBUILD_CFLAGS += $(call cc-option, -Wformat-overflow) +KBUILD_CFLAGS += $(call cc-option, -Wformat-truncation) +KBUILD_CFLAGS += $(call cc-option, -Wstringop-overflow) KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) KBUILD_CPPFLAGS += -Wundef @@ -123,6 +121,9 @@ else KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) +KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) +KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) +KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) ifdef CONFIG_CC_IS_CLANG -- cgit From 26030cb984dd65e0cb2d0c2489d94941cf8897b4 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 11 Aug 2023 16:03:24 +0200 Subject: extrawarn: move -Wrestrict into W=1 warnings There are few of these, so enable them whenever W=1 is enabled. Signed-off-by: Arnd Bergmann Signed-off-by: Masahiro Yamada --- scripts/Makefile.extrawarn | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index 4c734bba6e90..2fe6f2828d37 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn @@ -54,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# Another good warning that we'll want to enable eventually -KBUILD_CFLAGS += $(call cc-disable-warning, restrict) - # The allocators already balk at large sizes, so silence the compiler # warnings for bounds checks involving those possible values. While # -Wno-alloc-size-larger-than would normally be used here, earlier versions @@ -99,6 +96,7 @@ ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter KBUILD_CFLAGS += -Wmissing-declarations +KBUILD_CFLAGS += $(call cc-option, -Wrestrict) KBUILD_CFLAGS += -Wmissing-format-attribute KBUILD_CFLAGS += -Wmissing-prototypes KBUILD_CFLAGS += -Wold-style-definition @@ -120,6 +118,7 @@ else # Suppress them by using -Wno... except for W=1. KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, restrict) KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) -- cgit From ed79c34d3cf8539589257189bf4a08418d7f2abf Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 21 Aug 2023 07:18:02 +0900 Subject: kbuild: deb-pkg: support DEB_BUILD_OPTIONS=parallel=N in debian/rules 'make srcdeb-pkg' generates a source package, which you can build later by using dpkg-buildpackage. In older dpkg versions, 'dpkg-buildpackage --jobs=N' sets not only DEB_BUILD_OPTIONS but also MAKEFLAGS. Hence, passing -j or --jobs to dpkg-buildpackage was enough for kicking the parallel execution. The behavior was changed by commit 1d0ea9b2ba3f ("dpkg-buildpackage: Change -j, --jobs semantics to non-force mode") of dpkg project. [1] Since then, 'dpkg-buildpackage --jobs=N' sets only DEB_BUILD_OPTIONS, which is not parsed by the current debian/rules. To build the package in parallel, you need to pass the alternative --jobs-force option or set the MAKEFLAGS environment variable. Debian policy [2] suggests the following code snippet for debian/rules. ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) MAKEFLAGS += -j$(NUMJOBS) endif I tweaked the code to filter out parallel=1 and passed --jobs=1 to dpkg-buildpackage from scripts/Makefile.package. It is needed to force 'make deb-pkg' without the -j option to run in serial. Please note that dpkg-buildpackage sets parallel= in DEB_BUILD_OPTIONS by default (that is, --jobs=auto is the default) and --jobs=1 is needed to restore the serial execution. When dpkg-buildpackage is invoked from Kbuild, the number of jobs is inherited from the top level Makefile. Passing --jobs=1 to dpkg-buildpackage allows debian/rules to skip parsing DEB_BUILD_OPTIONS. [1] https://salsa.debian.org/dpkg-team/dpkg/-/commit/1d0ea9b2ba3f6a2de5b1a6ff55f3df7b71f73db6 [2] https://www.debian.org/doc/debian-policy/ch-source.html#s-debianrules-options Reported-by: Bastian Germann Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 2 +- scripts/package/debian/rules | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index f8a948ec2c6b..2bcab02da965 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -148,7 +148,7 @@ deb-pkg srcdeb-pkg bindeb-pkg: $(if $(findstring source, $(build-type)), \ --unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \ $(if $(findstring binary, $(build-type)), \ - --rules-file='$(MAKE) -f debian/rules' -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \ + --rules-file='$(MAKE) -f debian/rules' --jobs=1 -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \ --no-check-builddeps) \ $(DPKG_FLAGS)) diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules index 226e127efd63..3dafa9496c63 100755 --- a/scripts/package/debian/rules +++ b/scripts/package/debian/rules @@ -5,6 +5,11 @@ include debian/rules.vars srctree ?= . +ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))) + NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) + MAKEFLAGS += -j$(NUMJOBS) +endif + .PHONY: binary binary-indep binary-arch binary: binary-arch binary-indep binary-indep: build-indep -- cgit From 79b96c332241c06b4c63cfa0e23a539558b79b90 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:43 +0900 Subject: kbuild: move depmod rule to scripts/Makefile.modinst depmod is a part of the module installation. scripts/Makefile.modinst is a better place to run it. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/Makefile.modinst | 9 +++++++++ scripts/depmod.sh | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index ab0c5bd1a60f..7a64ece9b826 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -86,6 +86,15 @@ $(dst)/%.ko: $(extmod_prefix)%.ko FORCE $(call cmd,strip) $(call cmd,sign) +__modinst: depmod + +PHONY += depmod +depmod: $(modules) + $(call cmd,depmod) + +quiet_cmd_depmod = DEPMOD $(MODLIB) + cmd_depmod = $(srctree)/scripts/depmod.sh $(KERNELRELEASE) + else $(dst)/%.ko: FORCE diff --git a/scripts/depmod.sh b/scripts/depmod.sh index fca689ba4f21..e22da27fe13e 100755 --- a/scripts/depmod.sh +++ b/scripts/depmod.sh @@ -1,14 +1,16 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 # -# A depmod wrapper used by the toplevel Makefile +# A depmod wrapper -if test $# -ne 2; then - echo "Usage: $0 /sbin/depmod " >&2 +if test $# -ne 1; then + echo "Usage: $0 " >&2 exit 1 fi -DEPMOD=$1 -KERNELRELEASE=$2 + +KERNELRELEASE=$1 + +: ${DEPMOD:=depmod} if ! test -r System.map ; then echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2 -- cgit From 2dfec887c0fd7d25d26b2ba7e60479208f9b6fb8 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:45 +0900 Subject: kbuild: reduce the number of mkdir calls during modules_install Calling 'mkdir' for every module results in redundant syscalls. Use $(sort ...) to drop the duplicated directories. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/Makefile.modinst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 7a64ece9b826..96fea7c5dbe1 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -9,6 +9,8 @@ __modinst: include include/config/auto.conf include $(srctree)/scripts/Kbuild.include +install-y := + modules := $(call read-file, $(MODORDER)) ifeq ($(KBUILD_EXTMOD),) @@ -27,6 +29,7 @@ suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules)) +install-$(CONFIG_MODULES) += $(modules) __modinst: $(modules) @: @@ -35,7 +38,7 @@ __modinst: $(modules) # Installation # quiet_cmd_install = INSTALL $@ - cmd_install = mkdir -p $(dir $@); cp $< $@ + cmd_install = cp $< $@ # Strip # @@ -81,6 +84,9 @@ endif ifeq ($(modules_sign_only),) +# Create necessary directories +$(shell mkdir -p $(sort $(dir $(install-y)))) + $(dst)/%.ko: $(extmod_prefix)%.ko FORCE $(call cmd,install) $(call cmd,strip) -- cgit From 5e02797b8eb093ba73fcbdc6048d02a3f9fb7379 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:46 +0900 Subject: kbuild: move more module installation code to scripts/Makefile.modinst Move more relevant code to scripts/Makefile.modinst. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/Makefile.modinst | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 96fea7c5dbe1..5e2f98f0e991 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -11,6 +11,33 @@ include $(srctree)/scripts/Kbuild.include install-y := +ifeq ($(KBUILD_EXTMOD)$(modules_sign_only),) + +# remove the old directory and symlink +$(shell rm -fr $(MODLIB)/kernel $(MODLIB)/build) + +install-$(CONFIG_MODULES) += $(addprefix $(MODLIB)/, build modules.order) + +$(MODLIB)/build: FORCE + $(call cmd,symlink) + +quiet_cmd_symlink = SYMLINK $@ + cmd_symlink = ln -s $(CURDIR) $@ + +$(MODLIB)/modules.order: modules.order FORCE + $(call cmd,install_modorder) + +quiet_cmd_install_modorder = INSTALL $@ + cmd_install_modorder = sed 's:^\(.*\)\.o$$:kernel/\1.ko:' $< > $@ + +# Install modules.builtin(.modinfo) even when CONFIG_MODULES is disabled. +install-y += $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo) + +$(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo): $(MODLIB)/%: % FORCE + $(call cmd,install) + +endif + modules := $(call read-file, $(MODORDER)) ifeq ($(KBUILD_EXTMOD),) @@ -31,7 +58,7 @@ suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules)) install-$(CONFIG_MODULES) += $(modules) -__modinst: $(modules) +__modinst: $(install-y) @: # @@ -92,14 +119,16 @@ $(dst)/%.ko: $(extmod_prefix)%.ko FORCE $(call cmd,strip) $(call cmd,sign) +ifdef CONFIG_MODULES __modinst: depmod PHONY += depmod -depmod: $(modules) +depmod: $(install-y) $(call cmd,depmod) quiet_cmd_depmod = DEPMOD $(MODLIB) cmd_depmod = $(srctree)/scripts/depmod.sh $(KERNELRELEASE) +endif else -- cgit From 02e8487bbf1b68b29f7759154728071af08091cb Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:47 +0900 Subject: kbuild: support 'make modules_sign' with CONFIG_MODULE_SIG_ALL=n Commit d890f510c8e4 ("MODSIGN: Add modules_sign make target") introduced 'make modules_sign' to manually sign modules. Some time later, commit d9d8d7ed498e ("MODSIGN: Add option to not sign modules during modules_install") introduced CONFIG_MODULE_SIG_ALL. If it was disabled, mod_sign_cmd was set to no-op ('true' command). It affected not only 'make modules_install' but also 'make modules_sign'. With CONFIG_MODULE_SIG_ALL=n, neither modules_install nor modules_sign is able to sign modules. Kbuild has kept that behavior, and nobody has complained about it, but I think it is weird. CONFIG_MODULE_SIG_ALL=n should turn off signing only for modules_install. If users want to sign modules manually, modules_sign should be offered. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/Makefile.modinst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 5e2f98f0e991..a5fa3ea46652 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -95,7 +95,6 @@ endif # Signing # Don't stop modules_install even if we can't sign external modules. # -ifeq ($(CONFIG_MODULE_SIG_ALL),y) ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),) sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY) else @@ -104,13 +103,15 @@ endif quiet_cmd_sign = SIGN $@ cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \ $(if $(KBUILD_EXTMOD),|| true) -else + +ifeq ($(modules_sign_only),) + +# During modules_install, modules are signed only when CONFIG_MODULE_SIG_ALL=y. +ifndef CONFIG_MODULE_SIG_ALL quiet_cmd_sign := cmd_sign := : endif -ifeq ($(modules_sign_only),) - # Create necessary directories $(shell mkdir -p $(sort $(dir $(install-y)))) -- cgit From 151aeca2179290fb9eb63bb3ee60c47fffd86c5e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:48 +0900 Subject: kbuild: support modules_sign for external modules as well The modules_sign target is currently only available for in-tree modules, but it actually works for external modules as well. Move the modules_sign rule to the common part. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/Makefile.modinst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index a5fa3ea46652..c59cc57286ba 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -11,7 +11,7 @@ include $(srctree)/scripts/Kbuild.include install-y := -ifeq ($(KBUILD_EXTMOD)$(modules_sign_only),) +ifeq ($(KBUILD_EXTMOD)$(sign-only),) # remove the old directory and symlink $(shell rm -fr $(MODLIB)/kernel $(MODLIB)/build) @@ -104,7 +104,7 @@ quiet_cmd_sign = SIGN $@ cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \ $(if $(KBUILD_EXTMOD),|| true) -ifeq ($(modules_sign_only),) +ifeq ($(sign-only),) # During modules_install, modules are signed only when CONFIG_MODULE_SIG_ALL=y. ifndef CONFIG_MODULE_SIG_ALL -- cgit From 1ef061a4e2648f23ab9bd996a7656675933f1c1f Mon Sep 17 00:00:00 2001 From: Denis Nikitin Date: Fri, 25 Aug 2023 00:27:43 -0700 Subject: modpost: Skip .llvm.call-graph-profile section check .llvm.call-graph-profile section is added by clang when the kernel is built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=). Note that .llvm.call-graph-profile intentionally uses REL relocations to decrease the object size, for more details see https://reviews.llvm.org/D104080. The section contains edge information derived from text sections, so .llvm.call-graph-profile itself doesn't need more analysis as the text sections have been analyzed. This change fixes the kernel build with clang and a sample profile which currently fails with: "FATAL: modpost: Please add code to calculate addend for this architecture" Signed-off-by: Denis Nikitin Reviewed-by: Nick Desaulniers Reviewed-by: Fangrui Song Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 9761f9d0eec0..34a5386d444a 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -762,6 +762,7 @@ static const char *const section_white_list[] = ".fmt_slot*", /* EZchip */ ".gnu.lto*", ".discard.*", + ".llvm.call-graph-profile", /* call graph */ NULL }; -- cgit From bfb41e46d0b040ae83c1c4a50292298208b10f73 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Tue, 29 Aug 2023 12:51:06 +0200 Subject: kbuild: dummy-tools: make MPROFILE_KERNEL checks work on BE Commit 2eab791f940b ("kbuild: dummy-tools: support MPROFILE_KERNEL checks for ppc") added support for ppc64le's checks for -mprofile-kernel. Now, commit aec0ba7472a7 ("powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels") added support for -mprofile-kernel even on big-endian ppc. So lift the check in gcc-check-mprofile-kernel.sh to support big-endian too. Fixes: aec0ba7472a7 ("powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels") Signed-off-by: Jiri Slaby Signed-off-by: Masahiro Yamada --- scripts/dummy-tools/gcc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/dummy-tools/gcc b/scripts/dummy-tools/gcc index 1db1889f6d81..07f6dc4c5cf6 100755 --- a/scripts/dummy-tools/gcc +++ b/scripts/dummy-tools/gcc @@ -85,8 +85,7 @@ if arg_contain -S "$@"; then fi # For arch/powerpc/tools/gcc-check-mprofile-kernel.sh - if arg_contain -m64 "$@" && arg_contain -mlittle-endian "$@" && - arg_contain -mprofile-kernel "$@"; then + if arg_contain -m64 "$@" && arg_contain -mprofile-kernel "$@"; then if ! test -t 0 && ! grep -q notrace; then echo "_mcount" fi -- cgit From 7cd343008b967423b06af8f6d3236749c67d12e8 Mon Sep 17 00:00:00 2001 From: Sergey Senozhatsky Date: Wed, 30 Aug 2023 09:49:36 +0900 Subject: kconfig: add warn-unknown-symbols sanity check Introduce KCONFIG_WARN_UNKNOWN_SYMBOLS environment variable, which makes Kconfig warn about unknown config symbols. This is especially useful for continuous kernel uprevs when some symbols can be either removed or renamed between kernel releases (which can go unnoticed otherwise). By default KCONFIG_WARN_UNKNOWN_SYMBOLS generates warnings, which are non-terminal. There is an additional environment variable KCONFIG_WERROR that overrides this behaviour and turns warnings into errors. Signed-off-by: Sergey Senozhatsky Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 992575f1e976..4a6811d77d18 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -349,7 +349,11 @@ int conf_read_simple(const char *name, int def) char *p, *p2; struct symbol *sym; int i, def_flags; + const char *warn_unknown; + const char *werror; + warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS"); + werror = getenv("KCONFIG_WERROR"); if (name) { in = zconf_fopen(name); } else { @@ -437,6 +441,10 @@ load: if (def == S_DEF_USER) { sym = sym_find(line + 2 + strlen(CONFIG_)); if (!sym) { + if (warn_unknown) + conf_warning("unknown symbol: %s", + line + 2 + strlen(CONFIG_)); + conf_set_changed(true); continue; } @@ -471,7 +479,7 @@ load: sym = sym_find(line + strlen(CONFIG_)); if (!sym) { - if (def == S_DEF_AUTO) + if (def == S_DEF_AUTO) { /* * Reading from include/config/auto.conf * If CONFIG_FOO previously existed in @@ -479,8 +487,13 @@ load: * include/config/FOO must be touched. */ conf_touch_dep(line + strlen(CONFIG_)); - else + } else { + if (warn_unknown) + conf_warning("unknown symbol: %s", + line + strlen(CONFIG_)); + conf_set_changed(true); + } continue; } @@ -519,6 +532,10 @@ load: } free(line); fclose(in); + + if (conf_warnings && werror) + exit(1); + return 0; } -- cgit From feec5e1f74f5b735c0c5c02ec70673db1334173f Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Thu, 31 Aug 2023 12:13:39 -0700 Subject: kbuild: Show marked Kconfig fragments in "help" Currently the Kconfig fragments in kernel/configs and arch/*/configs that aren't used internally aren't discoverable through "make help", which consists of hard-coded lists of config fragments. Instead, list all the fragment targets that have a "# Help: " comment prefix so the targets can be generated dynamically. Add logic to the Makefile to search for and display the fragment and comment. Add comments to fragments that are intended to be direct targets. Signed-off-by: Kees Cook Co-developed-by: Masahiro Yamada Acked-by: Michael Ellerman (powerpc) Reviewed-by: Nicolas Schier Signed-off-by: Masahiro Yamada --- scripts/kconfig/Makefile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index af1c96198f49..4eee155121a8 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -93,11 +93,13 @@ endif %_defconfig: $(obj)/conf $(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig) -configfiles=$(wildcard $(srctree)/kernel/configs/$@ $(srctree)/arch/$(SRCARCH)/configs/$@) +configfiles = $(wildcard $(srctree)/kernel/configs/$(1) $(srctree)/arch/$(SRCARCH)/configs/$(1)) +all-config-fragments = $(call configfiles,*.config) +config-fragments = $(call configfiles,$@) %.config: $(obj)/conf - $(if $(call configfiles),, $(error No configuration exists for this target on this architecture)) - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(configfiles) + $(if $(config-fragments),, $(error $@ fragment does not exists on this architecture)) + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(config-fragments) $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig PHONY += tinyconfig @@ -115,6 +117,7 @@ clean-files += tests/.cache # Help text used by make help help: + @echo 'Configuration targets:' @echo ' config - Update current config utilising a line-oriented program' @echo ' nconfig - Update current config utilising a ncurses menu based program' @echo ' menuconfig - Update current config utilising a menu based program' @@ -141,6 +144,12 @@ help: @echo ' default value without prompting' @echo ' tinyconfig - Configure the tiniest possible kernel' @echo ' testconfig - Run Kconfig unit tests (requires python3 and pytest)' + @echo '' + @echo 'Configuration topic targets:' + @$(foreach f, $(all-config-fragments), \ + if help=$$(grep -m1 '^# Help: ' $(f)); then \ + printf ' %-25s - %s\n' '$(notdir $(f))' "$${help#*: }"; \ + fi;) # =========================================================================== # object files used by all kconfig flavours -- cgit From a3b7039bb2b22fcd2ad20d59c00ed4e606ce3754 Mon Sep 17 00:00:00 2001 From: Konstantin Meskhidze Date: Tue, 5 Sep 2023 17:59:14 +0800 Subject: kconfig: fix possible buffer overflow Buffer 'new_argv' is accessed without bound check after accessing with bound check via 'new_argc' index. Fixes: e298f3b49def ("kconfig: add built-in function support") Co-developed-by: Ivanov Mikhail Signed-off-by: Konstantin Meskhidze Signed-off-by: Masahiro Yamada --- scripts/kconfig/preprocess.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'scripts') diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 748da578b418..d1f5bcff4b62 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -396,6 +396,9 @@ static char *eval_clause(const char *str, size_t len, int argc, char *argv[]) p++; } + + if (new_argc >= FUNCTION_MAX_ARGS) + pperror("too many function arguments"); new_argv[new_argc++] = prev; /* -- cgit