Skip to content

Commit

Permalink
Merge tag 'kbuild-fixes-v6.14' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/masahiroy/linux-kbuild

Pull Kbuild fixes from Masahiro Yamada:

 - Suppress false-positive -Wformat-{overflow,truncation}-non-kprintf
   warnings regardless of the W= option

 - Avoid CONFIG_TRIM_UNUSED_KSYMS dropping symbols passed to symbol_get()

 - Fix a build regression of the Debian linux-headers package

* tag 'kbuild-fixes-v6.14' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
  kbuild: install-extmod-build: add missing quotation marks for CC variable
  kbuild: fix misspelling in scripts/Makefile.lib
  kbuild: keep symbols for symbol_get() even with CONFIG_TRIM_UNUSED_KSYMS
  scripts/Makefile.extrawarn: Do not show clang's non-kprintf warnings at W=1
  • Loading branch information
Linus Torvalds committed Feb 9, 2025
2 parents 146339d + f354fc8 commit 69b5431
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/asm-generic/vmlinux.lds.h
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
*(.discard) \
*(.discard.*) \
*(.export_symbol) \
*(.no_trim_symbol) \
*(.modinfo) \
/* ld.bfd warns about .gnu.version* even when not emitted */ \
*(.gnu.version*) \
Expand Down
5 changes: 4 additions & 1 deletion include/linux/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ extern int modules_disabled; /* for sysctl */
/* Get/put a kernel symbol (calls must be symmetric) */
void *__symbol_get(const char *symbol);
void *__symbol_get_gpl(const char *symbol);
#define symbol_get(x) ((typeof(&x))(__symbol_get(__stringify(x))))
#define symbol_get(x) ({ \
static const char __notrim[] \
__used __section(".no_trim_symbol") = __stringify(x); \
(typeof(&x))(__symbol_get(__stringify(x))); })

/* modules using other modules: kdb wants to see this. */
struct module_use {
Expand Down
10 changes: 5 additions & 5 deletions scripts/Makefile.extrawarn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ 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

# Clang checks for overflow/truncation with '%p', while GCC does not:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111219
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)
else

# gcc inanely warns about local variables called 'main'
Expand Down Expand Up @@ -105,11 +110,6 @@ KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
ifdef CONFIG_CC_IS_GCC
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
else
# Clang checks for overflow/truncation with '%p', while GCC does not:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111219
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)
endif
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)

Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.lib
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ endef
# These are shared by some Makefile.* files.

ifdef CONFIG_LTO_CLANG
# Run $(LD) here to covert LLVM IR to ELF in the following cases:
# Run $(LD) here to convert LLVM IR to ELF in the following cases:
# - when this object needs objtool processing, as objtool cannot process LLVM IR
# - when this is a single-object module, as modpost cannot process LLVM IR
cmd_ld_single = $(if $(objtool-enabled)$(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
Expand Down
35 changes: 35 additions & 0 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ static int parse_elf(struct elf_info *info, const char *filename)
info->modinfo_len = sechdrs[i].sh_size;
} else if (!strcmp(secname, ".export_symbol")) {
info->export_symbol_secndx = i;
} else if (!strcmp(secname, ".no_trim_symbol")) {
info->no_trim_symbol = (void *)hdr + sechdrs[i].sh_offset;
info->no_trim_symbol_len = sechdrs[i].sh_size;
}

if (sechdrs[i].sh_type == SHT_SYMTAB) {
Expand Down Expand Up @@ -1566,6 +1569,14 @@ static void read_symbols(const char *modname)
/* strip trailing .o */
mod = new_module(modname, strlen(modname) - strlen(".o"));

/* save .no_trim_symbol section for later use */
if (info.no_trim_symbol_len) {
mod->no_trim_symbol = xmalloc(info.no_trim_symbol_len);
memcpy(mod->no_trim_symbol, info.no_trim_symbol,
info.no_trim_symbol_len);
mod->no_trim_symbol_len = info.no_trim_symbol_len;
}

if (!mod->is_vmlinux) {
license = get_modinfo(&info, "license");
if (!license)
Expand Down Expand Up @@ -1728,6 +1739,28 @@ static void handle_white_list_exports(const char *white_list)
free(buf);
}

/*
* Keep symbols recorded in the .no_trim_symbol section. This is necessary to
* prevent CONFIG_TRIM_UNUSED_KSYMS from dropping EXPORT_SYMBOL because
* symbol_get() relies on the symbol being present in the ksymtab for lookups.
*/
static void keep_no_trim_symbols(struct module *mod)
{
unsigned long size = mod->no_trim_symbol_len;

for (char *s = mod->no_trim_symbol; s; s = next_string(s , &size)) {
struct symbol *sym;

/*
* If find_symbol() returns NULL, this symbol is not provided
* by any module, and symbol_get() will fail.
*/
sym = find_symbol(s);
if (sym)
sym->used = true;
}
}

static void check_modname_len(struct module *mod)
{
const char *mod_name;
Expand Down Expand Up @@ -2254,6 +2287,8 @@ int main(int argc, char **argv)
read_symbols_from_files(files_source);

list_for_each_entry(mod, &modules, list) {
keep_no_trim_symbols(mod);

if (mod->dump_file || mod->is_vmlinux)
continue;

Expand Down
6 changes: 6 additions & 0 deletions scripts/mod/modpost.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ struct module_alias {
*
* @dump_file: path to the .symvers file if loaded from a file
* @aliases: list head for module_aliases
* @no_trim_symbol: .no_trim_symbol section data
* @no_trim_symbol_len: length of the .no_trim_symbol section
*/
struct module {
struct list_head list;
Expand All @@ -128,6 +130,8 @@ struct module {
// Actual imported namespaces
struct list_head imported_namespaces;
struct list_head aliases;
char *no_trim_symbol;
unsigned int no_trim_symbol_len;
char name[];
};

Expand All @@ -141,6 +145,8 @@ struct elf_info {
char *strtab;
char *modinfo;
unsigned int modinfo_len;
char *no_trim_symbol;
unsigned int no_trim_symbol_len;

/* support for 32bit section numbers */

Expand Down
1 change: 1 addition & 0 deletions scripts/module.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SECTIONS {
*(.discard)
*(.discard.*)
*(.export_symbol)
*(.no_trim_symbol)
}

__ksymtab 0 : ALIGN(8) { *(SORT(___ksymtab+*)) }
Expand Down
2 changes: 1 addition & 1 deletion scripts/package/install-extmod-build
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if [ "${CC}" != "${HOSTCC}" ]; then
# Clear VPATH and srcroot because the source files reside in the output
# directory.
# shellcheck disable=SC2016 # $(MAKE), $(CC), and $(build) will be expanded by Make
"${MAKE}" run-command KBUILD_RUN_COMMAND='+$(MAKE) HOSTCC=$(CC) VPATH= srcroot=. $(build)='"${destdir}"/scripts
"${MAKE}" run-command KBUILD_RUN_COMMAND='+$(MAKE) HOSTCC="$(CC)" VPATH= srcroot=. $(build)='"${destdir}"/scripts

rm -f "${destdir}/scripts/Kbuild"
fi
Expand Down

0 comments on commit 69b5431

Please sign in to comment.