Skip to contentSkip to conversation

kbuild: move some helper headers from scripts/kconfig/ to scripts/include/

PATCH New Masahiro Yamada 1 participant 2 messages Jul 20, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kbuild: move some helper headers from scripts/kconfig/ to scripts/include/

Move array_size.h, hashtable.h, list.h, list_types.h from scripts/kconfig/ to scripts/include/.

These headers will be useful for other host programs.

Remove scripts/mod/list.h.

---

 MAINTAINERS                               |   1 +
 Makefile                                  |   6 +-
 scripts/{kconfig => include}/array_size.h |   0
 scripts/{kconfig => include}/hashtable.h  |   0
 scripts/{kconfig => include}/list.h       |   0
 scripts/{kconfig => include}/list_types.h |   0
 scripts/kconfig/expr.h                    |   3 +-
 scripts/kconfig/internal.h                |   2 +-
 scripts/kconfig/mconf.c                   |   2 +-
 scripts/kconfig/menu.c                    |   2 +-
 scripts/kconfig/mnconf-common.c           |   2 +-
 scripts/kconfig/mnconf-common.h           |   2 +
 scripts/kconfig/nconf.c                   |   2 +-
 scripts/kconfig/preprocess.c              |   4 +-
 scripts/kconfig/util.c                    |   2 +-
 scripts/mod/list.h                        | 213 ----------------------
 scripts/mod/modpost.c                     |   2 +
 scripts/mod/modpost.h                     |   2 +-
 18 files changed, 19 insertions(+), 226 deletions(-)
 rename scripts/{kconfig => include}/array_size.h (100%)
 rename scripts/{kconfig => include}/hashtable.h (100%)
 rename scripts/{kconfig => include}/list.h (100%)
 rename scripts/{kconfig => include}/list_types.h (100%)
 delete mode 100644 scripts/mod/list.h
MAINTAINERS +1 -0
index da5352dbd4f3..0fe40cf1929f 100644
@@ -11943,6 +11943,7 @@ F:	scripts/Makefile*
 F:	scripts/basic/
 F:	scripts/clang-tools/
 F:	scripts/dummy-tools/
+F:	scripts/include/
 F:	scripts/mk*
 F:	scripts/mod/
 F:	scripts/package/
Makefile +4 -2
index c97d6404b891..cbad2bbe4561 100644
@@ -458,8 +458,10 @@ export rust_common_flags := --edition=2021 \
 			    -Dclippy::no_mangle_with_rust_abi \
 			    -Wclippy::dbg_macro
 
-KBUILD_HOSTCFLAGS   := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
-KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
+KBUILD_HOSTCFLAGS   := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \
+		       $(HOSTCFLAGS) -I $(srctree)/scripts/include
+KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \
+		       -I $(srctree)/scripts/include
 KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
 			-Zallow-features= $(HOSTRUSTFLAGS)
 KBUILD_HOSTLDFLAGS  := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
scripts/include/array_size.h renamed from scripts/kconfig/array_size.h +0 -0
similarity index 100%
rename from scripts/kconfig/array_size.h
rename to scripts/include/array_size.h
scripts/include/hashtable.h renamed from scripts/kconfig/hashtable.h +0 -0
similarity index 100%
rename from scripts/kconfig/hashtable.h
rename to scripts/include/hashtable.h
scripts/include/list.h renamed from scripts/kconfig/list.h +0 -0
similarity index 100%
rename from scripts/kconfig/list.h
rename to scripts/include/list.h
scripts/include/list_types.h renamed from scripts/kconfig/list_types.h +0 -0
similarity index 100%
rename from scripts/kconfig/list_types.h
rename to scripts/include/list_types.h
scripts/kconfig/expr.h +1 -2
index 6e47e0ad6e6e..2bc96cd28253 100644
@@ -12,12 +12,11 @@ extern "C" {
 
 #include <assert.h>
 #include <stdio.h>
-#include "list_types.h"
 #ifndef __cplusplus
 #include <stdbool.h>
 #endif
 
-#include "list_types.h"
+#include <list_types.h>
 
 typedef enum tristate {
 	no, mod, yes
scripts/kconfig/internal.h +1 -1
index 6c721c4cfd72..02106eb7815e 100644
@@ -2,7 +2,7 @@
 #ifndef INTERNAL_H
 #define INTERNAL_H
 
-#include "hashtable.h"
+#include <hashtable.h>
 
 #define SYMBOL_HASHSIZE		(1U << 14)
 
scripts/kconfig/mconf.c +1 -1
index 4a0a97bb342f..3887eac75289 100644
@@ -19,7 +19,7 @@
 #include <signal.h>
 #include <unistd.h>
 
-#include "list.h"
+#include <list.h>
 #include "lkc.h"
 #include "lxdialog/dialog.h"
 #include "mnconf-common.h"
scripts/kconfig/menu.c +1 -1
index cd34cc5aefcf..323cc0b62be6 100644
@@ -8,9 +8,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <list.h>
 #include "lkc.h"
 #include "internal.h"
-#include "list.h"
 
 static const char nohelp_text[] = "There is no help available for this option.";
 
scripts/kconfig/mnconf-common.c +1 -1
index 18cb9a6c5aaa..8e24b07121df 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#include <list.h>
 #include "expr.h"
-#include "list.h"
 #include "mnconf-common.h"
 
 int jump_key_char;
scripts/kconfig/mnconf-common.h +2 -0
index ab6292cc4bf2..53bd7292e931 100644
@@ -4,6 +4,8 @@
 
 #include <stddef.h>
 
+#include <list_types.h>
+
 struct search_data {
 	struct list_head *head;
 	struct menu *target;
scripts/kconfig/nconf.c +1 -1
index 1456e24969aa..b91ca47e9e9a 100644
@@ -11,7 +11,7 @@
 #include <strings.h>
 #include <stdlib.h>
 
-#include "list.h"
+#include <list.h>
 #include "lkc.h"
 #include "mnconf-common.h"
 #include "nconf.h"
scripts/kconfig/preprocess.c +2 -2
index f0a4a218c4a5..67d1fb95c491 100644
@@ -9,9 +9,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "array_size.h"
+#include <array_size.h>
+#include <list.h>
 #include "internal.h"
-#include "list.h"
 #include "lkc.h"
 #include "preprocess.h"
 
scripts/kconfig/util.c +1 -1
index 1ea78927121d..696ff477671e 100644
@@ -8,7 +8,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "hashtable.h"
+#include <hashtable.h>
 #include "lkc.h"
 
 unsigned int strhash(const char *s)
scripts/mod/list.h deleted +0 -213

213 lines not on this page · raw message

scripts/mod/modpost.c +2 -0
index 3e5313ed6065..9eade18b4388 100644
@@ -20,6 +20,8 @@
 #include <limits.h>
 #include <stdbool.h>
 #include <errno.h>
+
+#include <list.h>
 #include "modpost.h"
 #include "../../include/linux/license.h"
 
scripts/mod/modpost.h +1 -1
index ee43c7950636..58197b34a3c8 100644
@@ -13,7 +13,7 @@
 #include <elf.h>
 #include "../../include/linux/module_symbol.h"
 
-#include "list.h"
+#include <list_types.h>
 #include "elfconfig.h"
 
 /* On BSD-alike OSes elf.h defines these according to host's word size */
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 modpost: use generic macros for hash table implementation

Use macros provided by hashtable.h

---

 scripts/mod/modpost.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
scripts/mod/modpost.c +5 -13
index 9eade18b4388..b78d93919712 100644
@@ -21,6 +21,7 @@
 #include <stdbool.h>
 #include <errno.h>
 
+#include <hashtable.h>
 #include <list.h>
 #include "modpost.h"
 #include "../../include/linux/license.h"
@@ -201,13 +202,8 @@ static struct module *new_module(const char *name, size_t namelen)
 	return mod;
 }
 
-/* A hash of all exported symbols,
- * struct symbol is also used for lists of unresolved symbols */
-
-#define SYMBOL_HASH_SIZE 1024
-
 struct symbol {
-	struct symbol *next;
+	struct hlist_node hnode;/* link to hash table */
 	struct list_head list;	/* link to module::exported_symbols or module::unresolved_symbols */
 	struct module *module;
 	char *namespace;
@@ -220,7 +216,7 @@ struct symbol {
 	char name[];
 };
 
-static struct symbol *symbolhash[SYMBOL_HASH_SIZE];
+static HASHTABLE_DEFINE(symbol_hashtable, 1U << 10);
 
 /* This is based on the hash algorithm from gdbm, via tdb */
 static inline unsigned int tdb_hash(const char *name)
@@ -252,11 +248,7 @@ static struct symbol *alloc_symbol(const char *name)
 /* For the hash of exported symbols */
 static void hash_add_symbol(struct symbol *sym)
 {
-	unsigned int hash;
-
-	hash = tdb_hash(sym->name) % SYMBOL_HASH_SIZE;
-	sym->next = symbolhash[hash];
-	symbolhash[hash] = sym;
+	hash_add(symbol_hashtable, &sym->hnode, tdb_hash(sym->name));
 }
 
 static void sym_add_unresolved(const char *name, struct module *mod, bool weak)
@@ -277,7 +269,7 @@ static struct symbol *sym_find_with_module(const char *name, struct module *mod)
 	if (name[0] == '.')
 		name++;
 
-	for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) {
+	hash_for_each_possible(symbol_hashtable, s, hnode, tdb_hash(name)) {
 		if (strcmp(s->name, name) == 0 && (!mod || s->module == mod))
 			return s;
 	}
Signature · 1 line
2.43.0