From c40e60f00caf18bc382215c79651777eb40f5f9d Mon Sep 17 00:00:00 2001 From: "Borislav Petkov (AMD)" Date: Wed, 5 Jul 2023 00:19:51 +0200 Subject: [PATCH 01/62] kbuild: Enable -Wenum-conversion by default This diagnostic checks whether there is a type mismatch when converting enums (assign an enum of type A to an enum of type B, for example) and it caught a legit issue recently. The reason it didn't show is because that warning is enabled only with -Wextra with GCC. Clang, however, enables it by default. GCC folks were considering enabling it by default but it was too noisy back then: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78736 Now that due to clang all those warnings have been fixed, enable it with GCC too. allmodconfig tests done with: x86, arm{,64}, powerpc{,64}, riscv crossbuilds. Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Nathan Chancellor Signed-off-by: Masahiro Yamada --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 22e392649b02..d36e5361810f 100644 --- a/Makefile +++ b/Makefile @@ -1090,6 +1090,9 @@ 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) + # change __FILE__ to the relative path from the srctree KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) From 481461f5109919babbb393d6f68002936b8e2493 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 16 Jul 2023 19:15:54 +0900 Subject: [PATCH 02/62] 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 --- include/linux/export.h | 4 ++-- scripts/Makefile.modpost | 1 + scripts/mod/modpost.c | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/linux/export.h b/include/linux/export.h index beed8387e0a4..9911508a9604 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -50,7 +50,7 @@ extern struct module __this_module; __EXPORT_SYMBOL_REF(sym) ASM_NL \ .previous -#if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS) +#if defined(__DISABLE_EXPORTS) /* * Allow symbol exports to be disabled completely so that C code may @@ -75,7 +75,7 @@ extern struct module __this_module; __ADDRESSABLE(sym) \ asm(__stringify(___EXPORT_SYMBOL(sym, license, ns))) -#endif /* CONFIG_MODULES */ +#endif #ifdef DEFAULT_SYMBOL_NAMESPACE #define _EXPORT_SYMBOL(sym, license) __EXPORT_SYMBOL(sym, license, __stringify(DEFAULT_SYMBOL_NAMESPACE)) 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; From e14f1242a8be413846360b295102abd4c62848ad Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 16 Jul 2023 13:55:07 +0900 Subject: [PATCH 03/62] 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(-) 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; + + if (key < '1' || key > '9') + return 0; list_for_each_entry(pos, data->head, entries) { - if (pos->offset >= start && pos->offset < end) { - char header[4]; + if (pos->offset < start) + continue; - if (k < JUMP_NB) { - int key = '0' + (pos->index % JUMP_NB) + 1; + if (pos->offset >= end) + break; - sprintf(header, "(%c)", key); - data->keys[k] = key; - data->targets[k] = pos->target; - k++; - } else { - sprintf(header, " "); - } - - 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 : "", From 356f0cb7efd9563112f18a2c8647ceb6d9f2ccef Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 16 Jul 2023 13:55:08 +0900 Subject: [PATCH 04/62] 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(-) 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); } From 4d15c9fa058e6dee09324cfc93f48858d4296019 Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Tue, 18 Jul 2023 18:58:43 +0200 Subject: [PATCH 05/62] 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(-) 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" From 233046a2afd12a4f699305b92ee634eebf1e4f31 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:48 +0900 Subject: [PATCH 06/62] 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(-) 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} From 61eca933d0a63f0889df604df6bb38938f3c7cad Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:49 +0900 Subject: [PATCH 07/62] 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(-) 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= From 192868258d2c9eb421228e4d65c4b09b838e7d93 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:50 +0900 Subject: [PATCH 08/62] 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(-) 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: [PATCH 09/62] 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(-) 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: [PATCH 10/62] 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(-) 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: [PATCH 11/62] 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(-) 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 From 93ed5605c6185edf3b47c433b257c00854f0a4e1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:54 +0900 Subject: [PATCH 12/62] 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(-) 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: [PATCH 13/62] 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 --- Makefile | 4 ++++ scripts/Makefile.package | 4 ---- scripts/package/mkdebian | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d36e5361810f..8533ba64713c 100644 --- a/Makefile +++ b/Makefile @@ -2148,6 +2148,10 @@ kernelversion: image_name: @echo $(KBUILD_IMAGE) +PHONY += run-command +run-command: + $(Q)$(KBUILD_RUN_COMMAND) + quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) cmd_rmfiles = rm -rf $(rm-files) 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-* From fe66b5d2ae72121c9f4f705dbae36d4c3e9f3812 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:56 +0900 Subject: [PATCH 14/62] 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 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 From d5d2d4cc60888f02dd4a6b2bfb03ff2fd7be4fc2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:57 +0900 Subject: [PATCH 15/62] 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(-) 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 From d4f651277e9208b580b55da212e17ddd309c91e7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:47:58 +0900 Subject: [PATCH 16/62] 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(-) 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: [PATCH 17/62] 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(-) 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 From b537925fdd689ca33b6d9eed4569bc625550b3ef Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:00 +0900 Subject: [PATCH 18/62] 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(-) 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 From 2a291fc315b6aec2f209aa44da90515ddd4f89d0 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:01 +0900 Subject: [PATCH 19/62] 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(-) 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: [PATCH 21/62] 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 --- .gitignore | 2 +- Makefile | 2 +- scripts/Makefile.package | 4 ++-- scripts/remove-stale-files | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 9fd4c9533b3d..0bbae167bf93 100644 --- a/.gitignore +++ b/.gitignore @@ -74,7 +74,7 @@ modules.order # # RPM spec file (make rpm-pkg) # -/*.spec +/kernel.spec /rpmbuild/ # diff --git a/Makefile b/Makefile index 8533ba64713c..4425d87dd2fa 100644 --- a/Makefile +++ b/Makefile @@ -1610,7 +1610,7 @@ MRPROPER_FILES += include/config include/generated \ certs/signing_key.pem \ certs/x509.genkey \ vmlinux-gdb.py \ - *.spec rpmbuild \ + kernel.spec rpmbuild \ rust/libmacros.so # clean - Delete most, but leave enough to build external modules 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 From 6db9ced4641fab2710e83c4d703e9ad60dd3ccf5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:04 +0900 Subject: [PATCH 22/62] 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(+) 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 From 37477496d6aa91248184238a95b59b7d91d46921 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:05 +0900 Subject: [PATCH 23/62] 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 | 52 +++++++++++++++++++++------------------- scripts/package/mkspec | 8 ------- 2 files changed, 28 insertions(+), 32 deletions(-) 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 .' +quiet_cmd_mkspec = GEN $@ + cmd_mkspec = $(srctree)/scripts/package/mkspec > $@ -# 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)' +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 From 783c55ae7a9551f049b0c1a52cde0ec3a5550501 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Jul 2023 13:48:06 +0900 Subject: [PATCH 24/62] 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(-) 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)) From a68914a53476d4fa0808219c6323eddca50e0e26 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 Jul 2023 19:04:43 +0900 Subject: [PATCH 25/62] 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(-) 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); } } From 71d965cf3577d68788a3d3ef044eb8e6d85013fa Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 Jul 2023 19:04:44 +0900 Subject: [PATCH 26/62] 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(-) 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"); From 4732acb75f468c12e2715cf5bf726cac873bc0e5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 Jul 2023 19:04:45 +0900 Subject: [PATCH 27/62] 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(-) 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) From 77f39e9344a151f2c055ce85875c3c57c6cfdfa3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 Jul 2023 19:04:46 +0900 Subject: [PATCH 28/62] 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(-) 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); } } From 4b970e436523ed34da4ced74ad2b81e5a4f573f2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 1 Aug 2023 21:19:25 +0900 Subject: [PATCH 29/62] 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(-) 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} From d9287ea8ffc9be2ab4c81c32e1ca54478425ba38 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 1 Aug 2023 21:19:26 +0900 Subject: [PATCH 30/62] 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 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 From 3354c64d418460c500080fddb1171d8e17622a06 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Thu, 3 Aug 2023 13:50:20 +0200 Subject: [PATCH 31/62] 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(-) 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 From 01e89a4acefc9d8356e91dde310da11e5b97d22d Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Fri, 4 Aug 2023 14:05:36 +0200 Subject: [PATCH 32/62] 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(-) 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. From 1ba67cd3281e50a965c5b519f946b14a1c4620a7 Mon Sep 17 00:00:00 2001 From: Jesse Taube Date: Tue, 8 Aug 2023 20:42:20 -0400 Subject: [PATCH 33/62] 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(-) 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); From 45a7371d5be21c174be201b8cde0e91b0357c606 Mon Sep 17 00:00:00 2001 From: Jesse Taube Date: Fri, 4 Aug 2023 23:44:45 -0400 Subject: [PATCH 34/62] docs: kbuild: Document 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 feature is poorly documented, so add it to the kconfig.rst documentation. Signed-off-by: Jesse Taube Acked-by: Randy Dunlap Signed-off-by: Masahiro Yamada --- Documentation/kbuild/kconfig.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/kbuild/kconfig.rst b/Documentation/kbuild/kconfig.rst index 5967c79c3baa..463914a7fdec 100644 --- a/Documentation/kbuild/kconfig.rst +++ b/Documentation/kbuild/kconfig.rst @@ -210,6 +210,10 @@ Searching in menuconfig: first (and in alphabetical order), then come all other symbols, sorted in alphabetical order. + In this menu, pressing the key in the (#) prefix will jump + directly to that location. You will be returned to the current + search results after exiting this new menu. + ---------------------------------------------------------------------- User interface options for 'menuconfig' @@ -262,6 +266,10 @@ Searching in nconfig: F8 (SymSearch) searches the configuration symbols for the given string or regular expression (regex). + In the SymSearch, pressing the key in the (#) prefix will + jump directly to that location. You will be returned to the + current search results after exiting this new menu. + NCONFIG_MODE ------------ This mode shows all sub-menus in one large tree. From 077af782e2c333f056cbd713f065bd0009a79a57 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 9 Aug 2023 13:42:31 +0200 Subject: [PATCH 35/62] 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(-) 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()) From e88ca24319e427a685a2e9e3a124ad5beca01158 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 11 Aug 2023 16:03:20 +0200 Subject: [PATCH 36/62] 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 --- Makefile | 88 ------------------------------------- scripts/Makefile.extrawarn | 90 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 88 deletions(-) diff --git a/Makefile b/Makefile index 4425d87dd2fa..4382cdb38fba 100644 --- a/Makefile +++ b/Makefile @@ -563,14 +563,6 @@ KBUILD_CFLAGS += -funsigned-char KBUILD_CFLAGS += -fno-common KBUILD_CFLAGS += -fno-PIE KBUILD_CFLAGS += -fno-strict-aliasing -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_CPPFLAGS := -D__KERNEL__ KBUILD_RUSTFLAGS := $(rust_common_flags) \ @@ -823,10 +815,6 @@ endif # may-sync-config endif # need-config KBUILD_CFLAGS += -fno-delete-null-pointer-checks -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) ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE KBUILD_CFLAGS += -O2 @@ -857,40 +845,15 @@ ifdef CONFIG_READABLE_ASM KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining endif -ifneq ($(CONFIG_FRAME_WARN),0) -KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) -endif - stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong KBUILD_CFLAGS += $(stackp-flags-y) -KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror -KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y) -KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds - KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y) -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) - ifdef CONFIG_FRAME_POINTER KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y @@ -1025,51 +988,12 @@ endif # arch Makefile may override CC so keep this after arch Makefile is included NOSTDINC_FLAGS += -nostdinc -# 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) - # To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, # the kernel uses only C99 flexible arrays for dynamically sized trailing # arrays. Enforce this for everything that may examine structure sizes and # perform bounds checking. KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3) -# 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) - # disable invalid "can't wrap" optimizations for signed / pointers KBUILD_CFLAGS += -fno-strict-overflow @@ -1081,18 +1005,6 @@ ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += -fconserve-stack endif -# 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) - # change __FILE__ to the relative path from the srctree KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) 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 From 2cd3271b7a310b1199aa36bfd536ca67d3c2d5f2 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 11 Aug 2023 16:03:21 +0200 Subject: [PATCH 37/62] 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(-) 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 # From 6d4ab2e97dcfbcd748ae71761a9d8e5e41cc732c Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 11 Aug 2023 16:03:23 +0200 Subject: [PATCH 38/62] 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(-) 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 From 26030cb984dd65e0cb2d0c2489d94941cf8897b4 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 11 Aug 2023 16:03:24 +0200 Subject: [PATCH 39/62] 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(-) 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) From bd964ab4f21f2af920e5042e0c700a61d1ab302c Mon Sep 17 00:00:00 2001 From: Nicolas Schier Date: Wed, 16 Aug 2023 08:22:19 +0200 Subject: [PATCH 40/62] MAINTAINERS: Add usr/ (initramfs generation) to KBUILD Add scripts for generating initramfs to KBUILD, to prevent idling of patches for usr/. Signed-off-by: Nicolas Schier Signed-off-by: Masahiro Yamada --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index d516295978a4..eff293e8d3bf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11296,6 +11296,7 @@ F: scripts/dummy-tools/ F: scripts/mk* F: scripts/mod/ F: scripts/package/ +F: usr/ KERNEL HARDENING (not covered by other areas) M: Kees Cook From 1fdd729019f96d0a6b532be1a8bf7735c59305d8 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 19 Aug 2023 20:43:01 +0900 Subject: [PATCH 41/62] kbuild: remove include/ksym from CLEAN_FILES This is a remnant of commit 5e9e95cc9148 ("kbuild: implement CONFIG_TRIM_UNUSED_KSYMS without recursion"). Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4382cdb38fba..64c114e9ce5f 100644 --- a/Makefile +++ b/Makefile @@ -1508,7 +1508,7 @@ endif # make distclean Remove editor backup files, patch leftover files and the like # Directories & files removed with 'make clean' -CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \ +CLEAN_FILES += vmlinux.symvers modules-only.symvers \ modules.builtin modules.builtin.modinfo modules.nsdeps \ compile_commands.json .thinlto-cache rust/test rust/doc \ rust-project.json .vmlinux.objs .vmlinux.export.c From 4cdb71b6ba3283fb2b7eaccc333f8f2c5b81797b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 20 Aug 2023 08:33:48 +0900 Subject: [PATCH 42/62] sparc: replace #include with #include Commit ddb5cdbafaaa ("kbuild: generate KSYMTAB entries by modpost") deprecated , which is now a wrapper of . Replace #include with #include . After all the lines are converted, and will be removed. Signed-off-by: Masahiro Yamada Acked-by: Sam Ravnborg --- arch/sparc/kernel/entry.S | 2 +- arch/sparc/kernel/head_32.S | 2 +- arch/sparc/kernel/head_64.S | 2 +- arch/sparc/lib/U1memcpy.S | 2 +- arch/sparc/lib/VISsave.S | 2 +- arch/sparc/lib/ashldi3.S | 2 +- arch/sparc/lib/ashrdi3.S | 2 +- arch/sparc/lib/atomic_64.S | 2 +- arch/sparc/lib/bitops.S | 2 +- arch/sparc/lib/blockops.S | 2 +- arch/sparc/lib/bzero.S | 2 +- arch/sparc/lib/checksum_32.S | 2 +- arch/sparc/lib/checksum_64.S | 2 +- arch/sparc/lib/clear_page.S | 2 +- arch/sparc/lib/copy_in_user.S | 2 +- arch/sparc/lib/copy_page.S | 2 +- arch/sparc/lib/copy_user.S | 2 +- arch/sparc/lib/csum_copy.S | 2 +- arch/sparc/lib/divdi3.S | 2 +- arch/sparc/lib/ffs.S | 2 +- arch/sparc/lib/fls.S | 2 +- arch/sparc/lib/fls64.S | 2 +- arch/sparc/lib/hweight.S | 2 +- arch/sparc/lib/ipcsum.S | 2 +- arch/sparc/lib/locks.S | 2 +- arch/sparc/lib/lshrdi3.S | 2 +- arch/sparc/lib/mcount.S | 2 +- arch/sparc/lib/memcmp.S | 2 +- arch/sparc/lib/memcpy.S | 3 ++- arch/sparc/lib/memmove.S | 2 +- arch/sparc/lib/memscan_32.S | 2 +- arch/sparc/lib/memscan_64.S | 2 +- arch/sparc/lib/memset.S | 2 +- arch/sparc/lib/muldi3.S | 2 +- arch/sparc/lib/multi3.S | 2 +- arch/sparc/lib/strlen.S | 2 +- arch/sparc/lib/strncmp_32.S | 2 +- arch/sparc/lib/strncmp_64.S | 2 +- arch/sparc/lib/xor.S | 2 +- 39 files changed, 40 insertions(+), 39 deletions(-) diff --git a/arch/sparc/kernel/entry.S b/arch/sparc/kernel/entry.S index a269ad2fe6df..a3fdee4cd6fa 100644 --- a/arch/sparc/kernel/entry.S +++ b/arch/sparc/kernel/entry.S @@ -8,6 +8,7 @@ * Copyright (C) 1997 Anton Blanchard (anton@progsoc.uts.edu.au) */ +#include #include #include #include @@ -30,7 +31,6 @@ #include #include -#include #define curptr g6 diff --git a/arch/sparc/kernel/head_32.S b/arch/sparc/kernel/head_32.S index 6044b82b9767..964c61b5cd03 100644 --- a/arch/sparc/kernel/head_32.S +++ b/arch/sparc/kernel/head_32.S @@ -11,6 +11,7 @@ * CompactPCI platform by Eric Brower, 1999. */ +#include #include #include @@ -25,7 +26,6 @@ #include /* TI_UWINMASK */ #include #include /* PGDIR_SHIFT */ -#include .data /* The following are used with the prom_vector node-ops to figure out diff --git a/arch/sparc/kernel/head_64.S b/arch/sparc/kernel/head_64.S index 72a5bdc833ea..cf0549134234 100644 --- a/arch/sparc/kernel/head_64.S +++ b/arch/sparc/kernel/head_64.S @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -33,7 +34,6 @@ #include #include #include -#include /* This section from from _start to sparc64_boot_end should fit into * 0x0000000000404000 to 0x0000000000408000. diff --git a/arch/sparc/lib/U1memcpy.S b/arch/sparc/lib/U1memcpy.S index a6f4ee391897..635398ec7540 100644 --- a/arch/sparc/lib/U1memcpy.S +++ b/arch/sparc/lib/U1memcpy.S @@ -6,10 +6,10 @@ */ #ifdef __KERNEL__ +#include #include #include #include -#include #define GLOBAL_SPARE g7 #else #define GLOBAL_SPARE g5 diff --git a/arch/sparc/lib/VISsave.S b/arch/sparc/lib/VISsave.S index 9c8eb2017d5b..31a0c336c185 100644 --- a/arch/sparc/lib/VISsave.S +++ b/arch/sparc/lib/VISsave.S @@ -7,6 +7,7 @@ * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz) */ +#include #include #include @@ -14,7 +15,6 @@ #include #include #include -#include /* On entry: %o5=current FPRS value, %g7 is callers address */ /* May clobber %o5, %g1, %g2, %g3, %g7, %icc, %xcc */ diff --git a/arch/sparc/lib/ashldi3.S b/arch/sparc/lib/ashldi3.S index 2d72de88af90..2a9e7c4fb260 100644 --- a/arch/sparc/lib/ashldi3.S +++ b/arch/sparc/lib/ashldi3.S @@ -6,8 +6,8 @@ * Copyright (C) 1999 David S. Miller (davem@redhat.com) */ +#include #include -#include .text ENTRY(__ashldi3) diff --git a/arch/sparc/lib/ashrdi3.S b/arch/sparc/lib/ashrdi3.S index 05dfda9f5005..8fd0b311722f 100644 --- a/arch/sparc/lib/ashrdi3.S +++ b/arch/sparc/lib/ashrdi3.S @@ -6,8 +6,8 @@ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) */ +#include #include -#include .text ENTRY(__ashrdi3) diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S index 8245d4a97301..4f8cab2fb9cd 100644 --- a/arch/sparc/lib/atomic_64.S +++ b/arch/sparc/lib/atomic_64.S @@ -4,10 +4,10 @@ * Copyright (C) 1999, 2007 2012 David S. Miller (davem@davemloft.net) */ +#include #include #include #include -#include .text diff --git a/arch/sparc/lib/bitops.S b/arch/sparc/lib/bitops.S index 9d647f977618..9c91cbb310e7 100644 --- a/arch/sparc/lib/bitops.S +++ b/arch/sparc/lib/bitops.S @@ -4,10 +4,10 @@ * Copyright (C) 2000, 2007 David S. Miller (davem@davemloft.net) */ +#include #include #include #include -#include .text diff --git a/arch/sparc/lib/blockops.S b/arch/sparc/lib/blockops.S index 76ddd1ff6833..5b92959a4d48 100644 --- a/arch/sparc/lib/blockops.S +++ b/arch/sparc/lib/blockops.S @@ -5,9 +5,9 @@ * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) */ +#include #include #include -#include /* Zero out 64 bytes of memory at (buf + offset). * Assumes %g1 contains zero. diff --git a/arch/sparc/lib/bzero.S b/arch/sparc/lib/bzero.S index 87fec4cbe10c..2bfa44a6b25e 100644 --- a/arch/sparc/lib/bzero.S +++ b/arch/sparc/lib/bzero.S @@ -5,8 +5,8 @@ * Copyright (C) 2005 David S. Miller */ +#include #include -#include .text diff --git a/arch/sparc/lib/checksum_32.S b/arch/sparc/lib/checksum_32.S index 781e39b3c009..84ad709cbecb 100644 --- a/arch/sparc/lib/checksum_32.S +++ b/arch/sparc/lib/checksum_32.S @@ -14,8 +14,8 @@ * BSD4.4 portable checksum routine */ +#include #include -#include #define CSUM_BIGCHUNK(buf, offset, sum, t0, t1, t2, t3, t4, t5) \ ldd [buf + offset + 0x00], t0; \ diff --git a/arch/sparc/lib/checksum_64.S b/arch/sparc/lib/checksum_64.S index 9700ef1730df..32b626f3fe4d 100644 --- a/arch/sparc/lib/checksum_64.S +++ b/arch/sparc/lib/checksum_64.S @@ -14,7 +14,7 @@ * BSD4.4 portable checksum routine */ -#include +#include .text csum_partial_fix_alignment: diff --git a/arch/sparc/lib/clear_page.S b/arch/sparc/lib/clear_page.S index 302d3454a994..e63458194f5a 100644 --- a/arch/sparc/lib/clear_page.S +++ b/arch/sparc/lib/clear_page.S @@ -5,13 +5,13 @@ * Copyright (C) 1997 Jakub Jelinek (jakub@redhat.com) */ +#include #include #include #include #include #include #include -#include /* What we used to do was lock a TLB entry into a specific * TLB slot, clear the page with interrupts disabled, then diff --git a/arch/sparc/lib/copy_in_user.S b/arch/sparc/lib/copy_in_user.S index 66e90bf528e2..e23e6a69ff92 100644 --- a/arch/sparc/lib/copy_in_user.S +++ b/arch/sparc/lib/copy_in_user.S @@ -4,9 +4,9 @@ * Copyright (C) 1999, 2000, 2004 David S. Miller (davem@redhat.com) */ +#include #include #include -#include #define XCC xcc diff --git a/arch/sparc/lib/copy_page.S b/arch/sparc/lib/copy_page.S index 5ebcfd479f4f..7a041f3ebc58 100644 --- a/arch/sparc/lib/copy_page.S +++ b/arch/sparc/lib/copy_page.S @@ -5,13 +5,13 @@ * Copyright (C) 1997 Jakub Jelinek (jakub@redhat.com) */ +#include #include #include #include #include #include #include -#include /* What we used to do was lock a TLB entry into a specific * TLB slot, clear the page with interrupts disabled, then diff --git a/arch/sparc/lib/copy_user.S b/arch/sparc/lib/copy_user.S index 954572c78539..7bb2ef68881d 100644 --- a/arch/sparc/lib/copy_user.S +++ b/arch/sparc/lib/copy_user.S @@ -12,11 +12,11 @@ * Returns 0 if successful, otherwise count of bytes not copied yet */ +#include #include #include #include #include -#include /* Work around cpp -rob */ #define ALLOC #alloc diff --git a/arch/sparc/lib/csum_copy.S b/arch/sparc/lib/csum_copy.S index d839956407a7..f968e83bc93b 100644 --- a/arch/sparc/lib/csum_copy.S +++ b/arch/sparc/lib/csum_copy.S @@ -4,7 +4,7 @@ * Copyright (C) 2005 David S. Miller */ -#include +#include #ifdef __KERNEL__ #define GLOBAL_SPARE %g7 diff --git a/arch/sparc/lib/divdi3.S b/arch/sparc/lib/divdi3.S index a7389409d9fa..4ba901acd572 100644 --- a/arch/sparc/lib/divdi3.S +++ b/arch/sparc/lib/divdi3.S @@ -5,7 +5,7 @@ This file is part of GNU CC. */ -#include +#include .text .align 4 .globl __divdi3 diff --git a/arch/sparc/lib/ffs.S b/arch/sparc/lib/ffs.S index 5a11d864fa05..3a9ad8ffdfe8 100644 --- a/arch/sparc/lib/ffs.S +++ b/arch/sparc/lib/ffs.S @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include -#include .register %g2,#scratch diff --git a/arch/sparc/lib/fls.S b/arch/sparc/lib/fls.S index 06b8d300bcae..ccf97fb7d8cd 100644 --- a/arch/sparc/lib/fls.S +++ b/arch/sparc/lib/fls.S @@ -5,8 +5,8 @@ * and onward. */ +#include #include -#include .text .register %g2, #scratch diff --git a/arch/sparc/lib/fls64.S b/arch/sparc/lib/fls64.S index c83e22ae9586..87005b67d378 100644 --- a/arch/sparc/lib/fls64.S +++ b/arch/sparc/lib/fls64.S @@ -5,8 +5,8 @@ * and onward. */ +#include #include -#include .text .register %g2, #scratch diff --git a/arch/sparc/lib/hweight.S b/arch/sparc/lib/hweight.S index 0ddbbb031822..eebee59b0655 100644 --- a/arch/sparc/lib/hweight.S +++ b/arch/sparc/lib/hweight.S @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include -#include .text .align 32 diff --git a/arch/sparc/lib/ipcsum.S b/arch/sparc/lib/ipcsum.S index 531d89c9d5d9..7fa8fd4b795a 100644 --- a/arch/sparc/lib/ipcsum.S +++ b/arch/sparc/lib/ipcsum.S @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include -#include .text ENTRY(ip_fast_csum) /* %o0 = iph, %o1 = ihl */ diff --git a/arch/sparc/lib/locks.S b/arch/sparc/lib/locks.S index 9a1289a3fb28..47a39f4384a2 100644 --- a/arch/sparc/lib/locks.S +++ b/arch/sparc/lib/locks.S @@ -7,11 +7,11 @@ * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz) */ +#include #include #include #include #include -#include .text .align 4 diff --git a/arch/sparc/lib/lshrdi3.S b/arch/sparc/lib/lshrdi3.S index 509ca6682da8..09bf581a0ba5 100644 --- a/arch/sparc/lib/lshrdi3.S +++ b/arch/sparc/lib/lshrdi3.S @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include -#include ENTRY(__lshrdi3) cmp %o2, 0 diff --git a/arch/sparc/lib/mcount.S b/arch/sparc/lib/mcount.S index deba6fa0bc78..f7f7910eb41e 100644 --- a/arch/sparc/lib/mcount.S +++ b/arch/sparc/lib/mcount.S @@ -6,8 +6,8 @@ * This can also be tweaked for kernel stack overflow detection. */ +#include #include -#include /* * This is the main variant and is called by C code. GCC's -pg option diff --git a/arch/sparc/lib/memcmp.S b/arch/sparc/lib/memcmp.S index a18076ef5af1..c87e8000feba 100644 --- a/arch/sparc/lib/memcmp.S +++ b/arch/sparc/lib/memcmp.S @@ -5,9 +5,9 @@ * Copyright (C) 2000, 2008 David S. Miller (davem@davemloft.net) */ +#include #include #include -#include .text ENTRY(memcmp) diff --git a/arch/sparc/lib/memcpy.S b/arch/sparc/lib/memcpy.S index ee823d8c9215..57b1ae0f5924 100644 --- a/arch/sparc/lib/memcpy.S +++ b/arch/sparc/lib/memcpy.S @@ -8,7 +8,8 @@ * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz) */ -#include +#include + #define FUNC(x) \ .globl x; \ .type x,@function; \ diff --git a/arch/sparc/lib/memmove.S b/arch/sparc/lib/memmove.S index 3132b6316144..543dda7b9dac 100644 --- a/arch/sparc/lib/memmove.S +++ b/arch/sparc/lib/memmove.S @@ -5,8 +5,8 @@ * Copyright (C) 1996, 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz) */ +#include #include -#include .text ENTRY(memmove) /* o0=dst o1=src o2=len */ diff --git a/arch/sparc/lib/memscan_32.S b/arch/sparc/lib/memscan_32.S index c4c2d5b3a2e9..5386a3a20019 100644 --- a/arch/sparc/lib/memscan_32.S +++ b/arch/sparc/lib/memscan_32.S @@ -5,7 +5,7 @@ * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) */ -#include +#include /* In essence, this is just a fancy strlen. */ diff --git a/arch/sparc/lib/memscan_64.S b/arch/sparc/lib/memscan_64.S index 36dd638905c3..70a4f21057f2 100644 --- a/arch/sparc/lib/memscan_64.S +++ b/arch/sparc/lib/memscan_64.S @@ -6,7 +6,7 @@ * Copyright (C) 1998 David S. Miller (davem@redhat.com) */ - #include +#include #define HI_MAGIC 0x8080808080808080 #define LO_MAGIC 0x0101010101010101 diff --git a/arch/sparc/lib/memset.S b/arch/sparc/lib/memset.S index eaff68213fdf..a33419dbb464 100644 --- a/arch/sparc/lib/memset.S +++ b/arch/sparc/lib/memset.S @@ -9,8 +9,8 @@ * clear_user. */ +#include #include -#include /* Work around cpp -rob */ #define ALLOC #alloc diff --git a/arch/sparc/lib/muldi3.S b/arch/sparc/lib/muldi3.S index 53054dee66d6..7e1e8cd30a22 100644 --- a/arch/sparc/lib/muldi3.S +++ b/arch/sparc/lib/muldi3.S @@ -5,7 +5,7 @@ This file is part of GNU CC. */ -#include +#include .text .align 4 .globl __muldi3 diff --git a/arch/sparc/lib/multi3.S b/arch/sparc/lib/multi3.S index 2f187b299345..5bb4c122a2cf 100644 --- a/arch/sparc/lib/multi3.S +++ b/arch/sparc/lib/multi3.S @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include -#include .text .align 4 diff --git a/arch/sparc/lib/strlen.S b/arch/sparc/lib/strlen.S index dd111bbad5df..27478b3f1647 100644 --- a/arch/sparc/lib/strlen.S +++ b/arch/sparc/lib/strlen.S @@ -6,9 +6,9 @@ * Copyright (C) 1996, 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) */ +#include #include #include -#include #define LO_MAGIC 0x01010101 #define HI_MAGIC 0x80808080 diff --git a/arch/sparc/lib/strncmp_32.S b/arch/sparc/lib/strncmp_32.S index 794733f036b6..387bbf621548 100644 --- a/arch/sparc/lib/strncmp_32.S +++ b/arch/sparc/lib/strncmp_32.S @@ -4,8 +4,8 @@ * generic strncmp routine. */ +#include #include -#include .text ENTRY(strncmp) diff --git a/arch/sparc/lib/strncmp_64.S b/arch/sparc/lib/strncmp_64.S index 3d37d65f674c..76c1207ecf5a 100644 --- a/arch/sparc/lib/strncmp_64.S +++ b/arch/sparc/lib/strncmp_64.S @@ -5,9 +5,9 @@ * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) */ +#include #include #include -#include .text ENTRY(strncmp) diff --git a/arch/sparc/lib/xor.S b/arch/sparc/lib/xor.S index f6af7c7ee6fc..35461e3b2a9b 100644 --- a/arch/sparc/lib/xor.S +++ b/arch/sparc/lib/xor.S @@ -9,12 +9,12 @@ * Copyright (C) 2006 David S. Miller */ +#include #include #include #include #include #include -#include /* * Requirements: From ee8aff7fbea3ee4b7352b6cf8202d6619072a28d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 20 Aug 2023 08:33:49 +0900 Subject: [PATCH 43/62] sparc: remove All *.S files under arch/sparc/ have been converted to include instead of . Remove . Signed-off-by: Masahiro Yamada Acked-by: Sam Ravnborg --- arch/sparc/include/asm/Kbuild | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/sparc/include/asm/Kbuild b/arch/sparc/include/asm/Kbuild index 595ca0be286b..43b0ae4c2c21 100644 --- a/arch/sparc/include/asm/Kbuild +++ b/arch/sparc/include/asm/Kbuild @@ -2,6 +2,5 @@ generated-y += syscall_table_32.h generated-y += syscall_table_64.h generic-y += agp.h -generic-y += export.h generic-y += kvm_para.h generic-y += mcs_spinlock.h From ab03e604bb91819cb0dcd0decc64f6919c2c7039 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 20 Aug 2023 08:33:50 +0900 Subject: [PATCH 44/62] ia64: replace #include with #include Commit ddb5cdbafaaa ("kbuild: generate KSYMTAB entries by modpost") deprecated , which is now a wrapper of . Replace #include with #include . After all the lines are converted, and will be removed. Signed-off-by: Masahiro Yamada --- arch/ia64/kernel/entry.S | 3 +-- arch/ia64/kernel/esi_stub.S | 2 +- arch/ia64/kernel/head.S | 3 +-- arch/ia64/kernel/ivt.S | 3 +-- arch/ia64/kernel/pal.S | 2 +- arch/ia64/lib/clear_page.S | 2 +- arch/ia64/lib/clear_user.S | 2 +- arch/ia64/lib/copy_page.S | 2 +- arch/ia64/lib/copy_page_mck.S | 2 +- arch/ia64/lib/copy_user.S | 2 +- arch/ia64/lib/flush.S | 3 +-- arch/ia64/lib/idiv32.S | 2 +- arch/ia64/lib/idiv64.S | 2 +- arch/ia64/lib/ip_fast_csum.S | 2 +- arch/ia64/lib/memcpy.S | 2 +- arch/ia64/lib/memcpy_mck.S | 2 +- arch/ia64/lib/memset.S | 2 +- arch/ia64/lib/strlen.S | 2 +- arch/ia64/lib/strncpy_from_user.S | 2 +- arch/ia64/lib/strnlen_user.S | 2 +- arch/ia64/lib/xor.S | 2 +- 21 files changed, 21 insertions(+), 25 deletions(-) diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S index 5eba3fb2e311..ac06d44b9b27 100644 --- a/arch/ia64/kernel/entry.S +++ b/arch/ia64/kernel/entry.S @@ -37,7 +37,7 @@ * pNonSys: !pSys */ - +#include #include #include #include @@ -49,7 +49,6 @@ #include #include #include -#include #include "minstate.h" diff --git a/arch/ia64/kernel/esi_stub.S b/arch/ia64/kernel/esi_stub.S index 821e68d10598..9928c5b2957c 100644 --- a/arch/ia64/kernel/esi_stub.S +++ b/arch/ia64/kernel/esi_stub.S @@ -34,9 +34,9 @@ #define PSR_BITS_TO_SET \ (IA64_PSR_BN) +#include #include #include -#include /* * Inputs: diff --git a/arch/ia64/kernel/head.S b/arch/ia64/kernel/head.S index c096500590e9..85c8a57da402 100644 --- a/arch/ia64/kernel/head.S +++ b/arch/ia64/kernel/head.S @@ -20,7 +20,7 @@ * Support for CPU Hotplug */ - +#include #include #include #include @@ -33,7 +33,6 @@ #include #include #include -#include #ifdef CONFIG_HOTPLUG_CPU #define SAL_PSR_BITS_TO_SET \ diff --git a/arch/ia64/kernel/ivt.S b/arch/ia64/kernel/ivt.S index 7a418e324d30..da90c49df628 100644 --- a/arch/ia64/kernel/ivt.S +++ b/arch/ia64/kernel/ivt.S @@ -47,7 +47,7 @@ * Table is based upon EAS2.6 (Oct 1999) */ - +#include #include #include #include @@ -58,7 +58,6 @@ #include #include #include -#include #if 0 # define PSR_DEFAULT_BITS psr.ac diff --git a/arch/ia64/kernel/pal.S b/arch/ia64/kernel/pal.S index 06d01a070aae..fb6db6966f70 100644 --- a/arch/ia64/kernel/pal.S +++ b/arch/ia64/kernel/pal.S @@ -13,9 +13,9 @@ * 05/24/2000 eranian Added support for physical mode static calls */ +#include #include #include -#include .data pal_entry_point: diff --git a/arch/ia64/lib/clear_page.S b/arch/ia64/lib/clear_page.S index 65b75085c8f4..ba0dd2538fa5 100644 --- a/arch/ia64/lib/clear_page.S +++ b/arch/ia64/lib/clear_page.S @@ -10,9 +10,9 @@ * 3/08/02 davidm Some more tweaking */ +#include #include #include -#include #ifdef CONFIG_ITANIUM # define L3_LINE_SIZE 64 // Itanium L3 line size diff --git a/arch/ia64/lib/clear_user.S b/arch/ia64/lib/clear_user.S index a28f39d349eb..1d9e45ccf8e5 100644 --- a/arch/ia64/lib/clear_user.S +++ b/arch/ia64/lib/clear_user.S @@ -12,8 +12,8 @@ * Stephane Eranian */ +#include #include -#include // // arguments diff --git a/arch/ia64/lib/copy_page.S b/arch/ia64/lib/copy_page.S index 176f857c522e..c0a0e6b2af00 100644 --- a/arch/ia64/lib/copy_page.S +++ b/arch/ia64/lib/copy_page.S @@ -15,9 +15,9 @@ * * 4/06/01 davidm Tuned to make it perform well both for cached and uncached copies. */ +#include #include #include -#include #define PIPE_DEPTH 3 #define EPI p[PIPE_DEPTH-1] diff --git a/arch/ia64/lib/copy_page_mck.S b/arch/ia64/lib/copy_page_mck.S index d6fd56e4f1c1..5e8bb4b4b535 100644 --- a/arch/ia64/lib/copy_page_mck.S +++ b/arch/ia64/lib/copy_page_mck.S @@ -60,9 +60,9 @@ * to fetch the second-half of the L2 cache line into L1, and the tX words are copied in * an order that avoids bank conflicts. */ +#include #include #include -#include #define PREFETCH_DIST 8 // McKinley sustains 16 outstanding L2 misses (8 ld, 8 st) diff --git a/arch/ia64/lib/copy_user.S b/arch/ia64/lib/copy_user.S index f681556c6b86..8daab72cfe77 100644 --- a/arch/ia64/lib/copy_user.S +++ b/arch/ia64/lib/copy_user.S @@ -30,8 +30,8 @@ * - fix extraneous stop bit introduced by the EX() macro. */ +#include #include -#include // // Tuneable parameters diff --git a/arch/ia64/lib/flush.S b/arch/ia64/lib/flush.S index 8573d59c9ed1..f8e795fe45cb 100644 --- a/arch/ia64/lib/flush.S +++ b/arch/ia64/lib/flush.S @@ -8,9 +8,8 @@ * 05/28/05 Zoltan Menyhart Dynamic stride size */ +#include #include -#include - /* * flush_icache_range(start,end) diff --git a/arch/ia64/lib/idiv32.S b/arch/ia64/lib/idiv32.S index def92b708e6e..83586fbc51ff 100644 --- a/arch/ia64/lib/idiv32.S +++ b/arch/ia64/lib/idiv32.S @@ -15,8 +15,8 @@ * (http://www.goodreads.com/book/show/2019887.Ia_64_and_Elementary_Functions) */ +#include #include -#include #ifdef MODULO # define OP mod diff --git a/arch/ia64/lib/idiv64.S b/arch/ia64/lib/idiv64.S index a8ba3bd3d4d8..5c9113691f72 100644 --- a/arch/ia64/lib/idiv64.S +++ b/arch/ia64/lib/idiv64.S @@ -15,8 +15,8 @@ * (http://www.goodreads.com/book/show/2019887.Ia_64_and_Elementary_Functions) */ +#include #include -#include #ifdef MODULO # define OP mod diff --git a/arch/ia64/lib/ip_fast_csum.S b/arch/ia64/lib/ip_fast_csum.S index dc9e6e6fe876..fcc0b812ce2e 100644 --- a/arch/ia64/lib/ip_fast_csum.S +++ b/arch/ia64/lib/ip_fast_csum.S @@ -13,8 +13,8 @@ * Copyright (C) 2002, 2006 Ken Chen */ +#include #include -#include /* * Since we know that most likely this function is called with buf aligned diff --git a/arch/ia64/lib/memcpy.S b/arch/ia64/lib/memcpy.S index 91a625fddbf0..35c9069a8345 100644 --- a/arch/ia64/lib/memcpy.S +++ b/arch/ia64/lib/memcpy.S @@ -14,8 +14,8 @@ * Stephane Eranian * David Mosberger-Tang */ +#include #include -#include GLOBAL_ENTRY(memcpy) diff --git a/arch/ia64/lib/memcpy_mck.S b/arch/ia64/lib/memcpy_mck.S index cc4e6ac914b6..c0d4362217ae 100644 --- a/arch/ia64/lib/memcpy_mck.S +++ b/arch/ia64/lib/memcpy_mck.S @@ -14,9 +14,9 @@ * Copyright (C) 2002 Intel Corp. * Copyright (C) 2002 Ken Chen */ +#include #include #include -#include #define EK(y...) EX(y) diff --git a/arch/ia64/lib/memset.S b/arch/ia64/lib/memset.S index 07a8b92c6496..552c5c7e4d06 100644 --- a/arch/ia64/lib/memset.S +++ b/arch/ia64/lib/memset.S @@ -18,8 +18,8 @@ Since a stf.spill f0 can store 16B in one go, we use this instruction to get peak speed when value = 0. */ +#include #include -#include #undef ret #define dest in0 diff --git a/arch/ia64/lib/strlen.S b/arch/ia64/lib/strlen.S index d66de5966974..1f4a46c15127 100644 --- a/arch/ia64/lib/strlen.S +++ b/arch/ia64/lib/strlen.S @@ -17,8 +17,8 @@ * 09/24/99 S.Eranian add speculation recovery code */ +#include #include -#include // // diff --git a/arch/ia64/lib/strncpy_from_user.S b/arch/ia64/lib/strncpy_from_user.S index 49eb81b69cd2..a287169bd953 100644 --- a/arch/ia64/lib/strncpy_from_user.S +++ b/arch/ia64/lib/strncpy_from_user.S @@ -17,8 +17,8 @@ * by Andreas Schwab ). */ +#include #include -#include GLOBAL_ENTRY(__strncpy_from_user) alloc r2=ar.pfs,3,0,0,0 diff --git a/arch/ia64/lib/strnlen_user.S b/arch/ia64/lib/strnlen_user.S index 4b684d4da106..a7eb56e840a9 100644 --- a/arch/ia64/lib/strnlen_user.S +++ b/arch/ia64/lib/strnlen_user.S @@ -13,8 +13,8 @@ * Copyright (C) 1999, 2001 David Mosberger-Tang */ +#include #include -#include GLOBAL_ENTRY(__strnlen_user) .prologue diff --git a/arch/ia64/lib/xor.S b/arch/ia64/lib/xor.S index 5413dafe6b2e..6e2a69662c06 100644 --- a/arch/ia64/lib/xor.S +++ b/arch/ia64/lib/xor.S @@ -5,8 +5,8 @@ * Optimized RAID-5 checksumming functions for IA-64. */ +#include #include -#include GLOBAL_ENTRY(xor_ia64_2) .prologue From b154f642399a9754f21257411a93ac15fc28efab Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 20 Aug 2023 08:33:51 +0900 Subject: [PATCH 45/62] ia64: remove All *.S files under arch/ia64/ have been converted to include instead of . Remove . Signed-off-by: Masahiro Yamada --- arch/ia64/include/asm/Kbuild | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/ia64/include/asm/Kbuild b/arch/ia64/include/asm/Kbuild index 33733245f42b..aefae2efde9f 100644 --- a/arch/ia64/include/asm/Kbuild +++ b/arch/ia64/include/asm/Kbuild @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 generated-y += syscall_table.h generic-y += agp.h -generic-y += export.h generic-y += kvm_para.h generic-y += mcs_spinlock.h generic-y += vtime.h From f3c78e949d3fb0afcc1bdd8e44b0902897fc2f84 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 20 Aug 2023 08:33:52 +0900 Subject: [PATCH 46/62] alpha: replace #include with #include Commit ddb5cdbafaaa ("kbuild: generate KSYMTAB entries by modpost") deprecated , which is now a wrapper of . Replace #include with #include . After all the lines are converted, and will be removed. Signed-off-by: Masahiro Yamada --- arch/alpha/lib/callback_srm.S | 2 +- arch/alpha/lib/clear_page.S | 2 +- arch/alpha/lib/clear_user.S | 2 +- arch/alpha/lib/copy_page.S | 2 +- arch/alpha/lib/copy_user.S | 2 +- arch/alpha/lib/csum_ipv6_magic.S | 2 +- arch/alpha/lib/divide.S | 2 +- arch/alpha/lib/ev6-clear_page.S | 2 +- arch/alpha/lib/ev6-clear_user.S | 2 +- arch/alpha/lib/ev6-copy_page.S | 2 +- arch/alpha/lib/ev6-copy_user.S | 2 +- arch/alpha/lib/ev6-csum_ipv6_magic.S | 2 +- arch/alpha/lib/ev6-divide.S | 2 +- arch/alpha/lib/ev6-memchr.S | 2 +- arch/alpha/lib/ev6-memcpy.S | 2 +- arch/alpha/lib/ev6-memset.S | 2 +- arch/alpha/lib/ev67-strcat.S | 2 +- arch/alpha/lib/ev67-strchr.S | 2 +- arch/alpha/lib/ev67-strlen.S | 2 +- arch/alpha/lib/ev67-strncat.S | 2 +- arch/alpha/lib/ev67-strrchr.S | 2 +- arch/alpha/lib/memchr.S | 2 +- arch/alpha/lib/memmove.S | 2 +- arch/alpha/lib/memset.S | 2 +- arch/alpha/lib/strcat.S | 2 +- arch/alpha/lib/strchr.S | 2 +- arch/alpha/lib/strcpy.S | 2 +- arch/alpha/lib/strlen.S | 2 +- arch/alpha/lib/strncat.S | 2 +- arch/alpha/lib/strncpy.S | 2 +- arch/alpha/lib/strrchr.S | 2 +- arch/alpha/lib/udiv-qrnnd.S | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) diff --git a/arch/alpha/lib/callback_srm.S b/arch/alpha/lib/callback_srm.S index b13c4a231f1b..36b63f295170 100644 --- a/arch/alpha/lib/callback_srm.S +++ b/arch/alpha/lib/callback_srm.S @@ -3,8 +3,8 @@ * arch/alpha/lib/callback_srm.S */ +#include #include -#include .text #define HWRPB_CRB_OFFSET 0xc0 diff --git a/arch/alpha/lib/clear_page.S b/arch/alpha/lib/clear_page.S index ce02de7b0493..af70ee309a33 100644 --- a/arch/alpha/lib/clear_page.S +++ b/arch/alpha/lib/clear_page.S @@ -4,7 +4,7 @@ * * Zero an entire page. */ -#include +#include .text .align 4 .global clear_page diff --git a/arch/alpha/lib/clear_user.S b/arch/alpha/lib/clear_user.S index db6c6ca45896..848eb60a0010 100644 --- a/arch/alpha/lib/clear_user.S +++ b/arch/alpha/lib/clear_user.S @@ -10,7 +10,7 @@ * a successful copy). There is also some rather minor exception setup * stuff. */ -#include +#include /* Allow an exception for an insn; exit if we get one. */ #define EX(x,y...) \ diff --git a/arch/alpha/lib/copy_page.S b/arch/alpha/lib/copy_page.S index 5439a30c77d0..1c444fdad9a5 100644 --- a/arch/alpha/lib/copy_page.S +++ b/arch/alpha/lib/copy_page.S @@ -4,7 +4,7 @@ * * Copy an entire page. */ -#include +#include .text .align 4 .global copy_page diff --git a/arch/alpha/lib/copy_user.S b/arch/alpha/lib/copy_user.S index 32ab0344b185..ef18faafcad6 100644 --- a/arch/alpha/lib/copy_user.S +++ b/arch/alpha/lib/copy_user.S @@ -12,7 +12,7 @@ * exception setup stuff.. */ -#include +#include /* Allow an exception for an insn; exit if we get one. */ #define EXI(x,y...) \ diff --git a/arch/alpha/lib/csum_ipv6_magic.S b/arch/alpha/lib/csum_ipv6_magic.S index c7b213ab01ab..273c426c3859 100644 --- a/arch/alpha/lib/csum_ipv6_magic.S +++ b/arch/alpha/lib/csum_ipv6_magic.S @@ -13,7 +13,7 @@ * added by Ivan Kokshaysky */ -#include +#include .globl csum_ipv6_magic .align 4 .ent csum_ipv6_magic diff --git a/arch/alpha/lib/divide.S b/arch/alpha/lib/divide.S index 2b60eb45e50b..db01840d76ec 100644 --- a/arch/alpha/lib/divide.S +++ b/arch/alpha/lib/divide.S @@ -46,7 +46,7 @@ * $28 - compare status */ -#include +#include #define halt .long 0 /* diff --git a/arch/alpha/lib/ev6-clear_page.S b/arch/alpha/lib/ev6-clear_page.S index 325864c81586..a534d9ff7161 100644 --- a/arch/alpha/lib/ev6-clear_page.S +++ b/arch/alpha/lib/ev6-clear_page.S @@ -4,7 +4,7 @@ * * Zero an entire page. */ -#include +#include .text .align 4 .global clear_page diff --git a/arch/alpha/lib/ev6-clear_user.S b/arch/alpha/lib/ev6-clear_user.S index 7e644f83cdf2..af776cc45f91 100644 --- a/arch/alpha/lib/ev6-clear_user.S +++ b/arch/alpha/lib/ev6-clear_user.S @@ -29,7 +29,7 @@ * want to leave a hole (and we also want to avoid repeating lots of work) */ -#include +#include /* Allow an exception for an insn; exit if we get one. */ #define EX(x,y...) \ 99: x,##y; \ diff --git a/arch/alpha/lib/ev6-copy_page.S b/arch/alpha/lib/ev6-copy_page.S index fd7212c8dcf1..36be5113b7b7 100644 --- a/arch/alpha/lib/ev6-copy_page.S +++ b/arch/alpha/lib/ev6-copy_page.S @@ -57,7 +57,7 @@ destination pages are in the dcache, but it is my guess that this is less important than the dcache miss case. */ -#include +#include .text .align 4 .global copy_page diff --git a/arch/alpha/lib/ev6-copy_user.S b/arch/alpha/lib/ev6-copy_user.S index f3e433754397..b9b19710c364 100644 --- a/arch/alpha/lib/ev6-copy_user.S +++ b/arch/alpha/lib/ev6-copy_user.S @@ -23,7 +23,7 @@ * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 */ -#include +#include /* Allow an exception for an insn; exit if we get one. */ #define EXI(x,y...) \ 99: x,##y; \ diff --git a/arch/alpha/lib/ev6-csum_ipv6_magic.S b/arch/alpha/lib/ev6-csum_ipv6_magic.S index 9a73f90700a1..2ee548be98e3 100644 --- a/arch/alpha/lib/ev6-csum_ipv6_magic.S +++ b/arch/alpha/lib/ev6-csum_ipv6_magic.S @@ -53,7 +53,7 @@ * may cause additional delay in rare cases (load-load replay traps). */ -#include +#include .globl csum_ipv6_magic .align 4 .ent csum_ipv6_magic diff --git a/arch/alpha/lib/ev6-divide.S b/arch/alpha/lib/ev6-divide.S index 137ff1a07356..b73a6d26362e 100644 --- a/arch/alpha/lib/ev6-divide.S +++ b/arch/alpha/lib/ev6-divide.S @@ -56,7 +56,7 @@ * Try not to change the actual algorithm if possible for consistency. */ -#include +#include #define halt .long 0 /* diff --git a/arch/alpha/lib/ev6-memchr.S b/arch/alpha/lib/ev6-memchr.S index 56bf9e14eeee..f75ba43e61e3 100644 --- a/arch/alpha/lib/ev6-memchr.S +++ b/arch/alpha/lib/ev6-memchr.S @@ -28,7 +28,7 @@ * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 * Try not to change the actual algorithm if possible for consistency. */ -#include +#include .set noreorder .set noat diff --git a/arch/alpha/lib/ev6-memcpy.S b/arch/alpha/lib/ev6-memcpy.S index ffbd056b6eb2..3ef43c26c8af 100644 --- a/arch/alpha/lib/ev6-memcpy.S +++ b/arch/alpha/lib/ev6-memcpy.S @@ -20,7 +20,7 @@ * Temp usage notes: * $1,$2, - scratch */ -#include +#include .set noreorder .set noat diff --git a/arch/alpha/lib/ev6-memset.S b/arch/alpha/lib/ev6-memset.S index 1cfcfbbea6f0..89d7809da4cc 100644 --- a/arch/alpha/lib/ev6-memset.S +++ b/arch/alpha/lib/ev6-memset.S @@ -27,7 +27,7 @@ * as fixes will need to be made in multiple places. The performance gain * is worth it. */ -#include +#include .set noat .set noreorder .text diff --git a/arch/alpha/lib/ev67-strcat.S b/arch/alpha/lib/ev67-strcat.S index ec3096a9e8d4..f8c7305b11d6 100644 --- a/arch/alpha/lib/ev67-strcat.S +++ b/arch/alpha/lib/ev67-strcat.S @@ -20,7 +20,7 @@ * string once. */ -#include +#include .text .align 4 diff --git a/arch/alpha/lib/ev67-strchr.S b/arch/alpha/lib/ev67-strchr.S index fbf89e0b6dc3..97a7cb475309 100644 --- a/arch/alpha/lib/ev67-strchr.S +++ b/arch/alpha/lib/ev67-strchr.S @@ -16,7 +16,7 @@ * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 * Try not to change the actual algorithm if possible for consistency. */ -#include +#include #include .set noreorder diff --git a/arch/alpha/lib/ev67-strlen.S b/arch/alpha/lib/ev67-strlen.S index b73106ffbbc7..3d9078807ab4 100644 --- a/arch/alpha/lib/ev67-strlen.S +++ b/arch/alpha/lib/ev67-strlen.S @@ -18,7 +18,7 @@ * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1 * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 */ -#include +#include .set noreorder .set noat diff --git a/arch/alpha/lib/ev67-strncat.S b/arch/alpha/lib/ev67-strncat.S index ceb0ca528789..8f313233e3a7 100644 --- a/arch/alpha/lib/ev67-strncat.S +++ b/arch/alpha/lib/ev67-strncat.S @@ -21,7 +21,7 @@ * Try not to change the actual algorithm if possible for consistency. */ -#include +#include .text .align 4 diff --git a/arch/alpha/lib/ev67-strrchr.S b/arch/alpha/lib/ev67-strrchr.S index 7f80e398530f..ae7355f9ec56 100644 --- a/arch/alpha/lib/ev67-strrchr.S +++ b/arch/alpha/lib/ev67-strrchr.S @@ -19,7 +19,7 @@ * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 */ -#include +#include #include .set noreorder diff --git a/arch/alpha/lib/memchr.S b/arch/alpha/lib/memchr.S index c13d3eca2e05..45366e32feee 100644 --- a/arch/alpha/lib/memchr.S +++ b/arch/alpha/lib/memchr.S @@ -31,7 +31,7 @@ For correctness consider that: - only minimum number of quadwords may be accessed - the third argument is an unsigned long */ -#include +#include .set noreorder .set noat diff --git a/arch/alpha/lib/memmove.S b/arch/alpha/lib/memmove.S index 42d1922d0edf..3a27689e3390 100644 --- a/arch/alpha/lib/memmove.S +++ b/arch/alpha/lib/memmove.S @@ -7,7 +7,7 @@ * This is hand-massaged output from the original memcpy.c. We defer to * memcpy whenever possible; the backwards copy loops are not unrolled. */ -#include +#include .set noat .set noreorder .text diff --git a/arch/alpha/lib/memset.S b/arch/alpha/lib/memset.S index 00393e30df25..9075d6918346 100644 --- a/arch/alpha/lib/memset.S +++ b/arch/alpha/lib/memset.S @@ -14,7 +14,7 @@ * The scheduling comments are according to the EV5 documentation (and done by * hand, so they might well be incorrect, please do tell me about it..) */ -#include +#include .set noat .set noreorder .text diff --git a/arch/alpha/lib/strcat.S b/arch/alpha/lib/strcat.S index 055877dccd27..62b90ebbcf44 100644 --- a/arch/alpha/lib/strcat.S +++ b/arch/alpha/lib/strcat.S @@ -5,7 +5,7 @@ * * Append a null-terminated string from SRC to DST. */ -#include +#include .text diff --git a/arch/alpha/lib/strchr.S b/arch/alpha/lib/strchr.S index 17871dd00280..68c54ff50dfe 100644 --- a/arch/alpha/lib/strchr.S +++ b/arch/alpha/lib/strchr.S @@ -6,7 +6,7 @@ * Return the address of a given character within a null-terminated * string, or null if it is not found. */ -#include +#include #include .set noreorder diff --git a/arch/alpha/lib/strcpy.S b/arch/alpha/lib/strcpy.S index cb74ad23a90d..d8773ba77525 100644 --- a/arch/alpha/lib/strcpy.S +++ b/arch/alpha/lib/strcpy.S @@ -6,7 +6,7 @@ * Copy a null-terminated string from SRC to DST. Return a pointer * to the null-terminator in the source. */ -#include +#include .text .align 3 diff --git a/arch/alpha/lib/strlen.S b/arch/alpha/lib/strlen.S index dd882fe4d7e3..4fc6a6ff24cd 100644 --- a/arch/alpha/lib/strlen.S +++ b/arch/alpha/lib/strlen.S @@ -12,7 +12,7 @@ * do this instead of the 9 instructions that * binary search needs). */ -#include +#include .set noreorder .set noat diff --git a/arch/alpha/lib/strncat.S b/arch/alpha/lib/strncat.S index 522fee3e26ac..a913a7c84a39 100644 --- a/arch/alpha/lib/strncat.S +++ b/arch/alpha/lib/strncat.S @@ -10,7 +10,7 @@ * past count, whereas libc may write to count+1. This follows the generic * implementation in lib/string.c and is, IMHO, more sensible. */ -#include +#include .text .align 3 diff --git a/arch/alpha/lib/strncpy.S b/arch/alpha/lib/strncpy.S index cc57fad8b7ca..cb90cf022df3 100644 --- a/arch/alpha/lib/strncpy.S +++ b/arch/alpha/lib/strncpy.S @@ -11,7 +11,7 @@ * version has cropped that bit o' nastiness as well as assuming that * __stxncpy is in range of a branch. */ -#include +#include .set noat .set noreorder diff --git a/arch/alpha/lib/strrchr.S b/arch/alpha/lib/strrchr.S index 7650ba99b7e2..dd8e073b6cf2 100644 --- a/arch/alpha/lib/strrchr.S +++ b/arch/alpha/lib/strrchr.S @@ -6,7 +6,7 @@ * Return the address of the last occurrence of a given character * within a null-terminated string, or null if it is not found. */ -#include +#include #include .set noreorder diff --git a/arch/alpha/lib/udiv-qrnnd.S b/arch/alpha/lib/udiv-qrnnd.S index b887aa5428e5..96f05918bffe 100644 --- a/arch/alpha/lib/udiv-qrnnd.S +++ b/arch/alpha/lib/udiv-qrnnd.S @@ -25,7 +25,7 @@ # along with GCC; see the file COPYING. If not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, # MA 02111-1307, USA. -#include +#include .set noreorder .set noat From e930d97f6d3ea4f43cb2c465d02e834d675c5274 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 20 Aug 2023 08:33:53 +0900 Subject: [PATCH 47/62] alpha: remove All *.S files under arch/alpha/ have been converted to include instead of . Remove . Signed-off-by: Masahiro Yamada --- arch/alpha/include/asm/Kbuild | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/alpha/include/asm/Kbuild b/arch/alpha/include/asm/Kbuild index dd31e97edae8..396caece6d6d 100644 --- a/arch/alpha/include/asm/Kbuild +++ b/arch/alpha/include/asm/Kbuild @@ -3,6 +3,5 @@ generated-y += syscall_table.h generic-y += agp.h generic-y += asm-offsets.h -generic-y += export.h generic-y += kvm_para.h generic-y += mcs_spinlock.h From ed79c34d3cf8539589257189bf4a08418d7f2abf Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 21 Aug 2023 07:18:02 +0900 Subject: [PATCH 48/62] 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(-) 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 From 2429742e506a2b5939a62c629c4a46d91df0ada8 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:41 +0900 Subject: [PATCH 49/62] kbuild: do not run depmod for 'make modules_sign' Commit 961ab4a3cd66 ("kbuild: merge scripts/Makefile.modsign to scripts/Makefile.modinst") started to run depmod at the end of 'make modules_sign'. Move the depmod rule to scripts/Makefile.modinst and run it only when $(modules_sign_only) is empty. Fixes: 961ab4a3cd66 ("kbuild: merge scripts/Makefile.modsign to scripts/Makefile.modinst") Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 64c114e9ce5f..9075ad851b46 100644 --- a/Makefile +++ b/Makefile @@ -1877,7 +1877,9 @@ quiet_cmd_depmod = DEPMOD $(MODLIB) modules_install: $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst +ifndef modules_sign_only $(call cmd,depmod) +endif else # CONFIG_MODULES From eb931e12194b69b59e6badb06cf1b53e6106ccee Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:42 +0900 Subject: [PATCH 50/62] kbuild: add modules_sign to no-{compiler,sync-config}-targets Like modules_install, modules_sign should avoid the syncconfig. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9075ad851b46..ba35ba14a974 100644 --- a/Makefile +++ b/Makefile @@ -280,8 +280,8 @@ no-dot-config-targets := $(clean-targets) \ # Installation targets should not require compiler. Unfortunately, vdso_install # is an exception where build artifacts may be updated. This must be fixed. no-compiler-targets := $(no-dot-config-targets) install dtbs_install \ - headers_install modules_install kernelrelease image_name -no-sync-config-targets := $(no-dot-config-targets) %install kernelrelease \ + headers_install modules_install modules_sign kernelrelease image_name +no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \ image_name single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %.symtypes %/ From 79b96c332241c06b4c63cfa0e23a539558b79b90 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:43 +0900 Subject: [PATCH 51/62] 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 --- Makefile | 8 -------- scripts/Makefile.modinst | 9 +++++++++ scripts/depmod.sh | 12 +++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index ba35ba14a974..ac11e6893ed1 100644 --- a/Makefile +++ b/Makefile @@ -509,7 +509,6 @@ LEX = flex YACC = bison AWK = awk INSTALLKERNEL := installkernel -DEPMOD = depmod PERL = perl PYTHON3 = python3 CHECK = sparse @@ -1871,15 +1870,8 @@ PHONY += modules_check modules_check: $(MODORDER) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< -quiet_cmd_depmod = DEPMOD $(MODLIB) - cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ - $(KERNELRELEASE) - modules_install: $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst -ifndef modules_sign_only - $(call cmd,depmod) -endif else # CONFIG_MODULES 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 From d8131c2965d5ee59bfa4d548641e52a13cbe17c9 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:44 +0900 Subject: [PATCH 52/62] kbuild: remove $(MODLIB)/source symlink This reverts the old commit "kbuild: Introduce source symlink in /lib/modules/.../". [1] The current Kbuild does not require $(MODLIB)/source. If the kernel was built in a separate output directory, $(MODLIB)/build/Makefile wraps the Makefile in the source tree. It is enough for building external modules. [1] https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=e09e58867154b8aae0a3ac26a9b1c05962f5a355 Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index ac11e6893ed1..f61ad7ff0057 100644 --- a/Makefile +++ b/Makefile @@ -1486,14 +1486,10 @@ modules_install: $(modinst_pre) PHONY += __modinst_pre __modinst_pre: @rm -rf $(MODLIB)/kernel - @rm -f $(MODLIB)/source + @rm -f $(MODLIB)/build @mkdir -p $(MODLIB) ifdef CONFIG_MODULES - @ln -s $(abspath $(srctree)) $(MODLIB)/source - @if [ ! $(objtree) -ef $(MODLIB)/build ]; then \ - rm -f $(MODLIB)/build ; \ - ln -s $(CURDIR) $(MODLIB)/build ; \ - fi + @ln -s $(CURDIR) $(MODLIB)/build @sed 's:^\(.*\)\.o$$:kernel/\1.ko:' modules.order > $(MODLIB)/modules.order endif @cp -f modules.builtin $(MODLIB)/ From 2dfec887c0fd7d25d26b2ba7e60479208f9b6fb8 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:45 +0900 Subject: [PATCH 53/62] 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(-) 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) From 5e02797b8eb093ba73fcbdc6048d02a3f9fb7379 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:46 +0900 Subject: [PATCH 54/62] 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 --- Makefile | 34 +++++++--------------------------- scripts/Makefile.modinst | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index f61ad7ff0057..ceffb582bd0a 100644 --- a/Makefile +++ b/Makefile @@ -1477,24 +1477,6 @@ endif endif # CONFIG_MODULES -modinst_pre := -ifneq ($(filter modules_install,$(MAKECMDGOALS)),) -modinst_pre := __modinst_pre -endif - -modules_install: $(modinst_pre) -PHONY += __modinst_pre -__modinst_pre: - @rm -rf $(MODLIB)/kernel - @rm -f $(MODLIB)/build - @mkdir -p $(MODLIB) -ifdef CONFIG_MODULES - @ln -s $(CURDIR) $(MODLIB)/build - @sed 's:^\(.*\)\.o$$:kernel/\1.ko:' modules.order > $(MODLIB)/modules.order -endif - @cp -f modules.builtin $(MODLIB)/ - @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/ - ### # Cleaning is done on three levels. # make clean Delete most generated files @@ -1836,12 +1818,15 @@ help: @echo ' clean - remove generated files in module directory only' @echo '' +ifndef CONFIG_MODULES +modules modules_install: __external_modules_error __external_modules_error: @echo >&2 '***' @echo >&2 '*** The present kernel disabled CONFIG_MODULES.' @echo >&2 '*** You cannot build or install external modules.' @echo >&2 '***' @false +endif endif # KBUILD_EXTMOD @@ -1850,6 +1835,9 @@ endif # KBUILD_EXTMOD PHONY += modules modules_install modules_prepare +modules_install: + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst + ifdef CONFIG_MODULES $(MODORDER): $(build-dir) @@ -1866,17 +1854,9 @@ PHONY += modules_check modules_check: $(MODORDER) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< -modules_install: - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst - else # CONFIG_MODULES -# Modules not configured -# --------------------------------------------------------------------------- - -PHONY += __external_modules_error - -modules modules_install: __external_modules_error +modules: @: KBUILD_MODULES := 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 From 02e8487bbf1b68b29f7759154728071af08091cb Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:47 +0900 Subject: [PATCH 55/62] 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(-) 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)))) From 151aeca2179290fb9eb63bb3ee60c47fffd86c5e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 23 Aug 2023 20:50:48 +0900 Subject: [PATCH 56/62] 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 --- Makefile | 32 ++++++++++++++++---------------- scripts/Makefile.modinst | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index ceffb582bd0a..e21bf66af6fd 100644 --- a/Makefile +++ b/Makefile @@ -1461,20 +1461,6 @@ modules: modules_prepare modules_prepare: prepare $(Q)$(MAKE) $(build)=scripts scripts/module.lds -export modules_sign_only := - -ifeq ($(CONFIG_MODULE_SIG),y) -PHONY += modules_sign -modules_sign: modules_install - @: - -# modules_sign is a subset of modules_install. -# 'make modules_install modules_sign' is equivalent to 'make modules_install'. -ifeq ($(filter modules_install,$(MAKECMDGOALS)),) -modules_sign_only := y -endif -endif - endif # CONFIG_MODULES ### @@ -1833,10 +1819,24 @@ endif # KBUILD_EXTMOD # --------------------------------------------------------------------------- # Modules -PHONY += modules modules_install modules_prepare +PHONY += modules modules_install modules_sign modules_prepare modules_install: - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \ + sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y) + +ifeq ($(CONFIG_MODULE_SIG),y) +# modules_sign is a subset of modules_install. +# 'make modules_install modules_sign' is equivalent to 'make modules_install'. +modules_sign: modules_install + @: +else +modules_sign: + @echo >&2 '***' + @echo >&2 '*** CONFIG_MODULE_SIG is disabled. You cannot sign modules.' + @echo >&2 '***' + @false +endif ifdef CONFIG_MODULES 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 From 1ef061a4e2648f23ab9bd996a7656675933f1c1f Mon Sep 17 00:00:00 2001 From: Denis Nikitin Date: Fri, 25 Aug 2023 00:27:43 -0700 Subject: [PATCH 57/62] 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(+) 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 }; From a3c6bfba4429123533e9ae96ee50ba45ff8a63f2 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Fri, 25 Aug 2023 10:38:01 -0700 Subject: [PATCH 58/62] Documentation/llvm: refresh docs Recent fixes for an embargoed hardware security vulnerability failed to link with ld.lld (LLVM's linker). [0] To be fair, our documentation mentions ``CC=clang`` foremost with ``LLVM=1`` being buried "below the fold." We want to encourage the use of ``LLVM=1`` rather than just ``CC=clang``. Make that suggestion "above the fold" and "front and center" in our docs. While here, the following additional changes were made: - remove the bit about CROSS_COMPILE setting --target=, that's no longer true. - Add ARCH=loongarch to the list of maintained targets (though we're still working on getting defconfig building cleanly at the moment; we're pretty close). - Bump ARCH=powerpc from CC=clang to LLVM=1 status. - Promote ARCH=riscv from being Maintained to being Supported. Android is working towards supporting RISC-V, and we have excellent support from multiple companies in this regard. - Note that the toolchain distribution on kernel.org has been built with profile data from kernel builds. - Note how to use ccache with clang. Link: https://github.com/ClangBuiltLinux/linux/issues/1907 [0] Reviewed-by: Nathan Chancellor Signed-off-by: Nick Desaulniers Signed-off-by: Masahiro Yamada --- Documentation/kbuild/llvm.rst | 124 ++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 44 deletions(-) diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst index c3851fe1900d..b1d97fafddcf 100644 --- a/Documentation/kbuild/llvm.rst +++ b/Documentation/kbuild/llvm.rst @@ -25,50 +25,38 @@ objects `_. Clang is a front-end to LLVM that supports C and the GNU C extensions required by the kernel, and is pronounced "klang," not "see-lang." -Clang ------ +Building with LLVM +------------------ -The compiler used can be swapped out via ``CC=`` command line argument to ``make``. -``CC=`` should be set when selecting a config and during a build. :: +Invoke ``make`` via:: - make CC=clang defconfig + make LLVM=1 - make CC=clang +to compile for the host target. For cross compiling:: -Cross Compiling ---------------- + make LLVM=1 ARCH=arm64 -A single Clang compiler binary will typically contain all supported backends, -which can help simplify cross compiling. :: +The LLVM= argument +------------------ - make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-gnu- - -``CROSS_COMPILE`` is not used to prefix the Clang compiler binary, instead -``CROSS_COMPILE`` is used to set a command line flag: ``--target=``. For -example: :: - - clang --target=aarch64-linux-gnu foo.c - -LLVM Utilities --------------- - -LLVM has substitutes for GNU binutils utilities. They can be enabled individually. -The full list of supported make variables:: +LLVM has substitutes for GNU binutils utilities. They can be enabled +individually. The full list of supported make variables:: make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \ OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump READELF=llvm-readelf \ HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar HOSTLD=ld.lld -To simplify the above command, Kbuild supports the ``LLVM`` variable:: - - make LLVM=1 +``LLVM=1`` expands to the above. If your LLVM tools are not available in your PATH, you can supply their location using the LLVM variable with a trailing slash:: make LLVM=/path/to/llvm/ -which will use ``/path/to/llvm/clang``, ``/path/to/llvm/ld.lld``, etc. +which will use ``/path/to/llvm/clang``, ``/path/to/llvm/ld.lld``, etc. The +following may also be used:: + + PATH=/path/to/llvm:$PATH make LLVM=1 If your LLVM tools have a version suffix and you want to test with that explicit version rather than the unsuffixed executables like ``LLVM=1``, you @@ -78,31 +66,72 @@ can pass the suffix using the ``LLVM`` variable:: which will use ``clang-14``, ``ld.lld-14``, etc. +To support combinations of out of tree paths with version suffixes, we +recommend:: + + PATH=/path/to/llvm/:$PATH make LLVM=-14 + ``LLVM=0`` is not the same as omitting ``LLVM`` altogether, it will behave like -``LLVM=1``. If you only wish to use certain LLVM utilities, use their respective -make variables. +``LLVM=1``. If you only wish to use certain LLVM utilities, use their +respective make variables. -The integrated assembler is enabled by default. You can pass ``LLVM_IAS=0`` to -disable it. +The same value used for ``LLVM=`` should be set for each invocation of ``make`` +if configuring and building via distinct commands. ``LLVM=`` should also be set +as an environment variable when running scripts that will eventually run +``make``. -Omitting CROSS_COMPILE +Cross Compiling +--------------- + +A single Clang compiler binary (and corresponding LLVM utilities) will +typically contain all supported back ends, which can help simplify cross +compiling especially when ``LLVM=1`` is used. If you use only LLVM tools, +``CROSS_COMPILE`` or target-triple-prefixes become unnecessary. Example:: + + make LLVM=1 ARCH=arm64 + +As an example of mixing LLVM and GNU utilities, for a target like ``ARCH=s390`` +which does not yet have ``ld.lld`` or ``llvm-objcopy`` support, you could +invoke ``make`` via:: + + make LLVM=1 ARCH=s390 LD=s390x-linux-gnu-ld.bfd \ + OBJCOPY=s390x-linux-gnu-objcopy + +This example will invoke ``s390x-linux-gnu-ld.bfd`` as the linker and +``s390x-linux-gnu-objcopy``, so ensure those are reachable in your ``$PATH``. + +``CROSS_COMPILE`` is not used to prefix the Clang compiler binary (or +corresponding LLVM utilities) as is the case for GNU utilities when ``LLVM=1`` +is not set. + +The LLVM_IAS= argument ---------------------- -As explained above, ``CROSS_COMPILE`` is used to set ``--target=``. +Clang can assemble assembler code. You can pass ``LLVM_IAS=0`` to disable this +behavior and have Clang invoke the corresponding non-integrated assembler +instead. Example:: -If ``CROSS_COMPILE`` is not specified, the ``--target=`` is inferred -from ``ARCH``. + make LLVM=1 LLVM_IAS=0 -That means if you use only LLVM tools, ``CROSS_COMPILE`` becomes unnecessary. +``CROSS_COMPILE`` is necessary when cross compiling and ``LLVM_IAS=0`` +is used in order to set ``--prefix=`` for the compiler to find the +corresponding non-integrated assembler (typically, you don't want to use the +system assembler when targeting another architecture). Example:: -For example, to cross-compile the arm64 kernel:: + make LLVM=1 ARCH=arm LLVM_IAS=0 CROSS_COMPILE=arm-linux-gnueabi- - make ARCH=arm64 LLVM=1 -If ``LLVM_IAS=0`` is specified, ``CROSS_COMPILE`` is also used to derive -``--prefix=`` to search for the GNU assembler and linker. :: +Ccache +------ - make ARCH=arm64 LLVM=1 LLVM_IAS=0 CROSS_COMPILE=aarch64-linux-gnu- +``ccache`` can be used with ``clang`` to improve subsequent builds, (though +KBUILD_BUILD_TIMESTAMP_ should be set to a deterministic value between builds +in order to avoid 100% cache misses, see Reproducible_builds_ for more info): + + KBUILD_BUILD_TIMESTAMP='' make LLVM=1 CC="ccache clang" + +.. _KBUILD_BUILD_TIMESTAMP: kbuild.html#kbuild-build-timestamp +.. _Reproducible_builds: reproducible-builds.html#timestamps Supported Architectures ----------------------- @@ -135,14 +164,17 @@ yet. Bug reports are always welcome at the issue tracker below! * - hexagon - Maintained - ``LLVM=1`` + * - loongarch + - Maintained + - ``LLVM=1`` * - mips - Maintained - ``LLVM=1`` * - powerpc - Maintained - - ``CC=clang`` + - ``LLVM=1`` * - riscv - - Maintained + - Supported - ``LLVM=1`` * - s390 - Maintained @@ -171,7 +203,11 @@ Getting Help Getting LLVM ------------- -We provide prebuilt stable versions of LLVM on `kernel.org `_. +We provide prebuilt stable versions of LLVM on `kernel.org +`_. These have been optimized with profile +data for building Linux kernels, which should improve kernel build times +relative to other distributions of LLVM. + Below are links that may be useful for building LLVM from source or procuring it through a distribution's package manager. From bfb41e46d0b040ae83c1c4a50292298208b10f73 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Tue, 29 Aug 2023 12:51:06 +0200 Subject: [PATCH 59/62] 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(-) 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 From 7cd343008b967423b06af8f6d3236749c67d12e8 Mon Sep 17 00:00:00 2001 From: Sergey Senozhatsky Date: Wed, 30 Aug 2023 09:49:36 +0900 Subject: [PATCH 60/62] 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 --- Documentation/kbuild/kconfig.rst | 9 +++++++++ scripts/kconfig/confdata.c | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/kconfig.rst b/Documentation/kbuild/kconfig.rst index 463914a7fdec..b8327e89ea51 100644 --- a/Documentation/kbuild/kconfig.rst +++ b/Documentation/kbuild/kconfig.rst @@ -54,6 +54,15 @@ KCONFIG_OVERWRITECONFIG If you set KCONFIG_OVERWRITECONFIG in the environment, Kconfig will not break symlinks when .config is a symlink to somewhere else. +KCONFIG_WARN_UNKNOWN_SYMBOLS +---------------------------- +This environment variable makes Kconfig warn about all unrecognized +symbols in the config input. + +KCONFIG_WERROR +-------------- +If set, Kconfig treats warnings as errors. + `CONFIG_` --------- If you set `CONFIG_` in the environment, Kconfig will prefix all symbols 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; } From feec5e1f74f5b735c0c5c02ec70673db1334173f Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Thu, 31 Aug 2023 12:13:39 -0700 Subject: [PATCH 61/62] 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 --- Makefile | 1 - arch/arm/configs/dram_0x00000000.config | 1 + arch/arm/configs/dram_0xc0000000.config | 1 + arch/arm/configs/dram_0xd0000000.config | 1 + arch/arm/configs/lpae.config | 1 + arch/arm64/configs/virt.config | 1 + arch/powerpc/configs/disable-werror.config | 1 + arch/powerpc/configs/security.config | 4 +++- arch/riscv/configs/32-bit.config | 1 + arch/riscv/configs/64-bit.config | 1 + arch/s390/configs/btf.config | 1 + arch/s390/configs/kasan.config | 1 + arch/x86/Makefile | 4 ---- kernel/configs/debug.config | 2 ++ kernel/configs/kvm_guest.config | 1 + kernel/configs/nopm.config | 2 ++ kernel/configs/rust.config | 1 + kernel/configs/x86_debug.config | 1 + kernel/configs/xen.config | 2 ++ scripts/kconfig/Makefile | 15 ++++++++++++--- 20 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index e21bf66af6fd..23cd62a5ff05 100644 --- a/Makefile +++ b/Makefile @@ -1552,7 +1552,6 @@ help: @echo ' mrproper - Remove all generated files + config + various backup files' @echo ' distclean - mrproper + remove editor backup and patch files' @echo '' - @echo 'Configuration targets:' @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help @echo '' @echo 'Other generic targets:' diff --git a/arch/arm/configs/dram_0x00000000.config b/arch/arm/configs/dram_0x00000000.config index db96dcb420ce..8803a0f58343 100644 --- a/arch/arm/configs/dram_0x00000000.config +++ b/arch/arm/configs/dram_0x00000000.config @@ -1 +1,2 @@ +# Help: DRAM base at 0x00000000 CONFIG_DRAM_BASE=0x00000000 diff --git a/arch/arm/configs/dram_0xc0000000.config b/arch/arm/configs/dram_0xc0000000.config index 343d5333d973..aab8f864686b 100644 --- a/arch/arm/configs/dram_0xc0000000.config +++ b/arch/arm/configs/dram_0xc0000000.config @@ -1 +1,2 @@ +# Help: DRAM base at 0xc0000000 CONFIG_DRAM_BASE=0xc0000000 diff --git a/arch/arm/configs/dram_0xd0000000.config b/arch/arm/configs/dram_0xd0000000.config index 61ba7045f8a1..4aabce4ea3d4 100644 --- a/arch/arm/configs/dram_0xd0000000.config +++ b/arch/arm/configs/dram_0xd0000000.config @@ -1 +1,2 @@ +# Help: DRAM base at 0xd0000000 CONFIG_DRAM_BASE=0xd0000000 diff --git a/arch/arm/configs/lpae.config b/arch/arm/configs/lpae.config index a6d6f7ab3c01..1ab94da8345d 100644 --- a/arch/arm/configs/lpae.config +++ b/arch/arm/configs/lpae.config @@ -1,2 +1,3 @@ +# Help: Enable Large Physical Address Extension mode CONFIG_ARM_LPAE=y CONFIG_VMSPLIT_2G=y diff --git a/arch/arm64/configs/virt.config b/arch/arm64/configs/virt.config index 6865d54e68f8..c47c36f8f67b 100644 --- a/arch/arm64/configs/virt.config +++ b/arch/arm64/configs/virt.config @@ -1,3 +1,4 @@ +# Help: Virtualization guest # # Base options for platforms # diff --git a/arch/powerpc/configs/disable-werror.config b/arch/powerpc/configs/disable-werror.config index 6ea12a12432c..7776b91da37f 100644 --- a/arch/powerpc/configs/disable-werror.config +++ b/arch/powerpc/configs/disable-werror.config @@ -1 +1,2 @@ +# Help: Disable -Werror CONFIG_PPC_DISABLE_WERROR=y diff --git a/arch/powerpc/configs/security.config b/arch/powerpc/configs/security.config index 1c91a35c6a73..0d54e29e2cdf 100644 --- a/arch/powerpc/configs/security.config +++ b/arch/powerpc/configs/security.config @@ -1,3 +1,5 @@ +# Help: Common security options for PowerPC builds + # This is the equivalent of booting with lockdown=integrity CONFIG_SECURITY=y CONFIG_SECURITYFS=y @@ -12,4 +14,4 @@ CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y # UBSAN bounds checking is very cheap and good for hardening CONFIG_UBSAN=y -# CONFIG_UBSAN_MISC is not set \ No newline at end of file +# CONFIG_UBSAN_MISC is not set diff --git a/arch/riscv/configs/32-bit.config b/arch/riscv/configs/32-bit.config index f6af0f708df4..16ee163847b4 100644 --- a/arch/riscv/configs/32-bit.config +++ b/arch/riscv/configs/32-bit.config @@ -1,3 +1,4 @@ +# Help: Build a 32-bit image CONFIG_ARCH_RV32I=y CONFIG_32BIT=y # CONFIG_PORTABLE is not set diff --git a/arch/riscv/configs/64-bit.config b/arch/riscv/configs/64-bit.config index 313edc554d84..d872a2d533f2 100644 --- a/arch/riscv/configs/64-bit.config +++ b/arch/riscv/configs/64-bit.config @@ -1,2 +1,3 @@ +# Help: Build a 64-bit image CONFIG_ARCH_RV64I=y CONFIG_64BIT=y diff --git a/arch/s390/configs/btf.config b/arch/s390/configs/btf.config index 39227b4511af..eb7f84f5925c 100644 --- a/arch/s390/configs/btf.config +++ b/arch/s390/configs/btf.config @@ -1 +1,2 @@ +# Help: Enable BTF debug info CONFIG_DEBUG_INFO_BTF=y diff --git a/arch/s390/configs/kasan.config b/arch/s390/configs/kasan.config index 700a8b25c3ff..84c2b551e992 100644 --- a/arch/s390/configs/kasan.config +++ b/arch/s390/configs/kasan.config @@ -1,3 +1,4 @@ +# Help: Enable KASan for debugging CONFIG_KASAN=y CONFIG_KASAN_INLINE=y CONFIG_KASAN_VMALLOC=y diff --git a/arch/x86/Makefile b/arch/x86/Makefile index fdc2e3abd615..c4b2a8a19fc8 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -335,9 +335,5 @@ define archhelp echo ' bzdisk/fdimage*/hdimage/isoimage also accept:' echo ' FDARGS="..." arguments for the booted kernel' echo ' FDINITRD=file initrd for the booted kernel' - echo '' - echo ' kvm_guest.config - Enable Kconfig items for running this kernel as a KVM guest' - echo ' xen.config - Enable Kconfig items for running this kernel as a Xen guest' - echo ' x86_debug.config - Enable tip tree debugging options for testing' endef diff --git a/kernel/configs/debug.config b/kernel/configs/debug.config index e8db8d938661..4722b998a324 100644 --- a/kernel/configs/debug.config +++ b/kernel/configs/debug.config @@ -1,3 +1,5 @@ +# Help: Debugging for CI systems and finding regressions +# # The config is based on running daily CI for enterprise Linux distros to # seek regressions on linux-next builds on different bare-metal and virtual # platforms. It can be used for example, diff --git a/kernel/configs/kvm_guest.config b/kernel/configs/kvm_guest.config index 208481d91090..d0877063d925 100644 --- a/kernel/configs/kvm_guest.config +++ b/kernel/configs/kvm_guest.config @@ -1,3 +1,4 @@ +# Help: Bootable as a KVM guest CONFIG_NET=y CONFIG_NET_CORE=y CONFIG_NETDEVICES=y diff --git a/kernel/configs/nopm.config b/kernel/configs/nopm.config index 81ff07863576..ebfdc3d8aa9a 100644 --- a/kernel/configs/nopm.config +++ b/kernel/configs/nopm.config @@ -1,3 +1,5 @@ +# Help: Disable Power Management + CONFIG_PM=n CONFIG_SUSPEND=n CONFIG_HIBERNATION=n diff --git a/kernel/configs/rust.config b/kernel/configs/rust.config index 38a7c5362c9c..2c6e001a7284 100644 --- a/kernel/configs/rust.config +++ b/kernel/configs/rust.config @@ -1 +1,2 @@ +# Help: Enable Rust CONFIG_RUST=y diff --git a/kernel/configs/x86_debug.config b/kernel/configs/x86_debug.config index 6fac5b405334..35f48671b8d5 100644 --- a/kernel/configs/x86_debug.config +++ b/kernel/configs/x86_debug.config @@ -1,3 +1,4 @@ +# Help: Debugging options for tip tree testing CONFIG_X86_DEBUG_FPU=y CONFIG_LOCK_STAT=y CONFIG_DEBUG_VM=y diff --git a/kernel/configs/xen.config b/kernel/configs/xen.config index 436f806aa1ed..6878b9a49be8 100644 --- a/kernel/configs/xen.config +++ b/kernel/configs/xen.config @@ -1,3 +1,5 @@ +# Help: Bootable as a Xen guest +# # global stuff - these enable us to allow some # of the not so generic stuff below for xen CONFIG_PARAVIRT=y 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 From a3b7039bb2b22fcd2ad20d59c00ed4e606ce3754 Mon Sep 17 00:00:00 2001 From: Konstantin Meskhidze Date: Tue, 5 Sep 2023 17:59:14 +0800 Subject: [PATCH 62/62] 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(+) 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; /*