Kbuild updates for 6.18

- Extend modules.builtin.modinfo to include module aliases from
   MODULE_DEVICE_TABLE for builtin modules so that userspace tools (such
   as kmod) can verify that a particular module alias will be handled by
   a builtin module.
 
 - Bump the minimum version of LLVM for building the kernel to 15.0.0.
 
 - Upgrade several userspace API checks in headers_check.pl to errors.
 
 - Unify and consolidate CONFIG_WERROR / W=e handling.
 
 - Turn assembler and linker warnings into errors with CONFIG_WERROR /
   W=e.
 
 - Respect CONFIG_WERROR / W=e when building userspace programs
   (userprogs).
 
 - Enable -Werror unconditionally when building host programs
   (hostprogs).
 
 - Support copy_file_range() and data segment alignment in gen_init_cpio
   to improve performance on filesystems that support reflinks such as
   btrfs and XFS.
 
 - Miscellaneous small changes to scripts and configuration files.
 
 Signed-off-by: Nathan Chancellor <nathan@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQR74yXHMTGczQHYypIdayaRccAalgUCaNrp6QAKCRAdayaRccAa
 ljxRAP4hYocKXeWsiJzkTB199P4QUGWf220a9elBmtdJEed07gD/VBnCbSOxG3RO
 vS8qbJHwxUFL7a+mDV8RIVXSt99NpAg=
 =psG/
 -----END PGP SIGNATURE-----

Merge tag 'kbuild-6.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux

Pull Kbuild updates from Nathan Chancellor:

 - Extend modules.builtin.modinfo to include module aliases from
   MODULE_DEVICE_TABLE for builtin modules so that userspace tools (such
   as kmod) can verify that a particular module alias will be handled by
   a builtin module

 - Bump the minimum version of LLVM for building the kernel to 15.0.0

 - Upgrade several userspace API checks in headers_check.pl to errors

 - Unify and consolidate CONFIG_WERROR / W=e handling

 - Turn assembler and linker warnings into errors with CONFIG_WERROR /
   W=e

 - Respect CONFIG_WERROR / W=e when building userspace programs
   (userprogs)

 - Enable -Werror unconditionally when building host programs
   (hostprogs)

 - Support copy_file_range() and data segment alignment in gen_init_cpio
   to improve performance on filesystems that support reflinks such as
   btrfs and XFS

 - Miscellaneous small changes to scripts and configuration files

* tag 'kbuild-6.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux: (47 commits)
  modpost: Initialize builtin_modname to stop SIGSEGVs
  Documentation: kbuild: note CONFIG_DEBUG_EFI in reproducible builds
  kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o
  modpost: Create modalias for builtin modules
  modpost: Add modname to mod_device_table alias
  scsi: Always define blogic_pci_tbl structure
  kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
  kbuild: keep .modinfo section in vmlinux.unstripped
  kbuild: always create intermediate vmlinux.unstripped
  s390: vmlinux.lds.S: Reorder sections
  KMSAN: Remove tautological checks
  objtool: Drop noinstr hack for KCSAN_WEAK_MEMORY
  lib/Kconfig.debug: Drop CLANG_VERSION check from DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
  riscv: Remove ld.lld version checks from many TOOLCHAIN_HAS configs
  riscv: Unconditionally use linker relaxation
  riscv: Remove version check for LTO_CLANG selects
  powerpc: Drop unnecessary initializations in __copy_inst_from_kernel_nofault()
  mips: Unconditionally select ARCH_HAS_CURRENT_STACK_POINTER
  arm64: Remove tautological LLVM Kconfig conditions
  ARM: Clean up definition of ARM_HAS_GROUP_RELOCS
  ...
This commit is contained in:
Linus Torvalds 2025-10-01 20:58:51 -07:00
commit 7f70725741
40 changed files with 433 additions and 260 deletions

2
.gitignore vendored
View File

@ -176,7 +176,7 @@ x509.genkey
*.kdev4
# Clang's compilation database file
/compile_commands.json
compile_commands.json
# Documentation toolchain
sphinx_*/

View File

@ -86,6 +86,11 @@ c_mtime is ignored unless CONFIG_INITRAMFS_PRESERVE_MTIME=y is set.
The c_filesize should be zero for any file which is not a regular file
or symlink.
c_namesize may account for more than one trailing '\0', as long as the
value doesn't exceed PATH_MAX. This can be useful for ensuring that a
subsequent file data segment is aligned, e.g. to a filesystem block
boundary.
The c_chksum field contains a simple 32-bit unsigned sum of all the
bytes in the data field. cpio(1) refers to this as "crc", which is
clearly incorrect (a cyclic redundancy check is a different and

View File

@ -61,6 +61,9 @@ supported.
The Reproducible Builds web site has more information about these
`prefix-map options`_.
Some CONFIG options such as `CONFIG_DEBUG_EFI` embed absolute paths in
object files. Such options should be disabled.
Generated files in source packages
----------------------------------

View File

@ -30,7 +30,7 @@ you probably needn't concern yourself with pcmciautils.
Program Minimal version Command to check the version
====================== =============== ========================================
GNU C 8.1 gcc --version
Clang/LLVM (optional) 13.0.1 clang --version
Clang/LLVM (optional) 15.0.0 clang --version
Rust (optional) 1.78.0 rustc --version
bindgen (optional) 0.65.1 bindgen --version
GNU make 4.0 make --version

View File

@ -901,9 +901,6 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
KBUILD_CFLAGS += $(stackp-flags-y)
KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y)
ifdef CONFIG_FRAME_POINTER
KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
@ -1138,8 +1135,9 @@ LDFLAGS_vmlinux += --emit-relocs --discard-none
endif
# Align the bit size of userspace programs with the kernel
KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
USERFLAGS_FROM_KERNEL := -m32 -m64 --target=%
KBUILD_USERCFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
# userspace programs are linked via the compiler, use the correct linker
ifdef CONFIG_CC_IS_CLANG

View File

@ -1523,7 +1523,6 @@ config RANDOMIZE_KSTACK_OFFSET
bool "Support for randomizing kernel stack offset on syscall entry" if EXPERT
default y
depends on HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
depends on INIT_STACK_NONE || !CC_IS_CLANG || CLANG_VERSION >= 140000
help
The kernel stack offset can be randomized (after pt_regs) by
roughly 5 bits of entropy, frustrating memory corruption

View File

@ -166,15 +166,12 @@ config ARM
<http://www.arm.linux.org.uk/>.
config ARM_HAS_GROUP_RELOCS
def_bool y
depends on !LD_IS_LLD || LLD_VERSION >= 140000
depends on !COMPILE_TEST
def_bool !COMPILE_TEST
help
Whether or not to use R_ARM_ALU_PC_Gn or R_ARM_LDR_PC_Gn group
relocations, which have been around for a long time, but were not
supported in LLD until version 14. The combined range is -/+ 256 MiB,
which is usually sufficient, but not for allyesconfig, so we disable
this feature when doing compile testing.
relocations. The combined range is -/+ 256 MiB, which is usually
sufficient, but not for allyesconfig, so we disable this feature
when doing compile testing.
config ARM_DMA_USE_IOMMU
bool

View File

@ -1495,8 +1495,7 @@ choice
config CPU_BIG_ENDIAN
bool "Build big-endian kernel"
# https://github.com/llvm/llvm-project/commit/1379b150991f70a5782e9a143c2ba5308da1161c
depends on (AS_IS_GNU || AS_VERSION >= 150000) && BROKEN
depends on BROKEN
help
Say Y if you plan on running a kernel with a big-endian userspace.
@ -2327,8 +2326,7 @@ config STACKPROTECTOR_PER_TASK
config UNWIND_PATCH_PAC_INTO_SCS
bool "Enable shadow call stack dynamically using code patching"
# needs Clang with https://github.com/llvm/llvm-project/commit/de07cde67b5d205d58690be012106022aea6d2b3 incorporated
depends on CC_IS_CLANG && CLANG_VERSION >= 150000
depends on CC_IS_CLANG
depends on ARM64_PTR_AUTH_KERNEL && CC_HAS_BRANCH_PROT_PAC_RET
depends on SHADOW_CALL_STACK
select UNWIND_TABLES

View File

@ -6,7 +6,7 @@ config MIPS
select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT
select ARCH_HAS_CPU_CACHE_ALIASING
select ARCH_HAS_CPU_FINALIZE_INIT
select ARCH_HAS_CURRENT_STACK_POINTER if !CC_IS_CLANG || CLANG_VERSION >= 140000
select ARCH_HAS_CURRENT_STACK_POINTER
select ARCH_HAS_DEBUG_VIRTUAL if !64BIT
select ARCH_HAS_DMA_OPS if MACH_JAZZ
select ARCH_HAS_FORTIFY_SOURCE

View File

@ -143,10 +143,6 @@ static inline int __copy_inst_from_kernel_nofault(ppc_inst_t *inst, u32 *src)
{
unsigned int val, suffix;
/* See https://github.com/ClangBuiltLinux/linux/issues/1521 */
#if defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 140000
val = suffix = 0;
#endif
__get_kernel_nofault(&val, src, u32, Efault);
if (IS_ENABLED(CONFIG_PPC64) && get_op(val) == OP_PREFIX) {
__get_kernel_nofault(&suffix, src + 1, u32, Efault);

View File

@ -66,9 +66,8 @@ config RISCV
select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE
select ARCH_SUPPORTS_HUGETLBFS if MMU
# LLD >= 14: https://github.com/llvm/llvm-project/issues/50505
select ARCH_SUPPORTS_LTO_CLANG if LLD_VERSION >= 140000 && CMODEL_MEDANY
select ARCH_SUPPORTS_LTO_CLANG_THIN if LLD_VERSION >= 140000
select ARCH_SUPPORTS_LTO_CLANG if CMODEL_MEDANY
select ARCH_SUPPORTS_LTO_CLANG_THIN
select ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS if 64BIT && MMU
select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
@ -249,15 +248,9 @@ config HAVE_SHADOW_CALL_STACK
# https://github.com/riscv-non-isa/riscv-elf-psabi-doc/commit/a484e843e6eeb51f0cb7b8819e50da6d2444d769
depends on $(ld-option,--no-relax-gp)
config RISCV_USE_LINKER_RELAXATION
def_bool y
# https://github.com/llvm/llvm-project/commit/6611d58f5bbcbec77262d392e2923e1d680f6985
depends on !LD_IS_LLD || LLD_VERSION >= 150000
# https://github.com/llvm/llvm-project/commit/bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6
config ARCH_HAS_BROKEN_DWARF5
def_bool y
depends on RISCV_USE_LINKER_RELAXATION
# https://github.com/llvm/llvm-project/commit/1df5ea29b43690b6622db2cad7b745607ca4de6a
depends on AS_IS_LLVM && AS_VERSION < 180000
# https://github.com/llvm/llvm-project/commit/7ffabb61a5569444b5ac9322e22e5471cc5e4a77
@ -621,7 +614,7 @@ config TOOLCHAIN_HAS_V
default y
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64imv)
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32imv)
depends on LLD_VERSION >= 140000 || LD_VERSION >= 23800
depends on LD_IS_LLD || LD_VERSION >= 23800
depends on AS_HAS_OPTION_ARCH
config RISCV_ISA_V
@ -721,7 +714,7 @@ config TOOLCHAIN_HAS_ZBB
default y
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbb)
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb)
depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900
depends on LD_IS_LLD || LD_VERSION >= 23900
depends on AS_HAS_OPTION_ARCH
# This symbol indicates that the toolchain supports all v1.0 vector crypto
@ -736,7 +729,7 @@ config TOOLCHAIN_HAS_ZBA
default y
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zba)
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zba)
depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900
depends on LD_IS_LLD || LD_VERSION >= 23900
depends on AS_HAS_OPTION_ARCH
config RISCV_ISA_ZBA
@ -771,7 +764,7 @@ config TOOLCHAIN_HAS_ZBC
default y
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbc)
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbc)
depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900
depends on LD_IS_LLD || LD_VERSION >= 23900
depends on AS_HAS_OPTION_ARCH
config RISCV_ISA_ZBC
@ -794,7 +787,7 @@ config TOOLCHAIN_HAS_ZBKB
default y
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbkb)
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbkb)
depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900
depends on LD_IS_LLD || LD_VERSION >= 23900
depends on AS_HAS_OPTION_ARCH
config RISCV_ISA_ZBKB

View File

@ -46,17 +46,10 @@ else
KBUILD_LDFLAGS += -melf32lriscv
endif
ifndef CONFIG_RISCV_USE_LINKER_RELAXATION
KBUILD_CFLAGS += -mno-relax
KBUILD_AFLAGS += -mno-relax
ifndef CONFIG_AS_IS_LLVM
KBUILD_CFLAGS += -Wa,-mno-relax
KBUILD_AFLAGS += -Wa,-mno-relax
endif
# LLVM has an issue with target-features and LTO: https://github.com/llvm/llvm-project/issues/59350
# Ensure it is aware of linker relaxation with LTO, otherwise relocations may
# be incorrect: https://github.com/llvm/llvm-project/issues/65090
else ifeq ($(CONFIG_LTO_CLANG),y)
ifeq ($(CONFIG_LTO_CLANG),y)
KBUILD_LDFLAGS += -mllvm -mattr=+c -mllvm -mattr=+relax
endif

View File

@ -209,6 +209,11 @@ SECTIONS
. = ALIGN(PAGE_SIZE);
_end = . ;
/* Debugging sections. */
STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS
/*
* uncompressed image info used by the decompressor
* it should match struct vmlinux_info
@ -239,11 +244,6 @@ SECTIONS
#endif
} :NONE
/* Debugging sections. */
STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS
/*
* Make sure that the .got.plt is either completely empty or it
* contains only the three reserved double words.

View File

@ -3715,7 +3715,6 @@ static void __exit blogic_exit(void)
__setup("BusLogic=", blogic_setup);
#ifdef MODULE
/*static const struct pci_device_id blogic_pci_tbl[] = {
{ PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER,
PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
@ -3725,13 +3724,12 @@ __setup("BusLogic=", blogic_setup);
PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
{ }
};*/
static const struct pci_device_id blogic_pci_tbl[] = {
static const struct pci_device_id blogic_pci_tbl[] __maybe_unused = {
{PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER)},
{PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC)},
{PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT)},
{0, },
};
#endif
MODULE_DEVICE_TABLE(pci, blogic_pci_tbl);
module_init(blogic_init);

View File

@ -832,6 +832,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
/* Required sections not related to debugging. */
#define ELF_DETAILS \
.modinfo : { *(.modinfo) } \
.comment 0 : { *(.comment) } \
.symtab 0 : { *(.symtab) } \
.strtab 0 : { *(.strtab) } \
@ -1045,7 +1046,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
*(.discard.*) \
*(.export_symbol) \
*(.no_trim_symbol) \
*(.modinfo) \
/* ld.bfd warns about .gnu.version* even when not emitted */ \
*(.gnu.version*) \

View File

@ -244,14 +244,22 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);
/* What your module does. */
#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
#ifdef MODULE
/*
* Format: __mod_device_table__kmod_<modname>__<type>__<name>
* Parts of the string `__kmod_` and `__` are used as delimiters when parsing
* a symbol in file2alias.c
*/
#define __mod_device_table(type, name) \
__PASTE(__mod_device_table__, \
__PASTE(__KBUILD_MODNAME, \
__PASTE(__, \
__PASTE(type, \
__PASTE(__, name)))))
/* Creates an alias so file2alias.c can find device table. */
#define MODULE_DEVICE_TABLE(type, name) \
static typeof(name) __mod_device_table__##type##__##name \
static typeof(name) __mod_device_table(type, name) \
__attribute__ ((used, alias(__stringify(name))))
#else /* !MODULE */
#define MODULE_DEVICE_TABLE(type, name)
#endif
/* Version of form [<epoch>:]<version>[-<extra-version>].
* Or for CVS/RCS ID version, everything but the number is stripped.

View File

@ -45,8 +45,11 @@ static size_t fill_cpio(struct initramfs_test_cpio *cs, size_t csz, char *out)
c->mtime, c->filesize, c->devmajor, c->devminor,
c->rdevmajor, c->rdevminor, c->namesize, c->csum,
c->fname) + 1;
pr_debug("packing (%zu): %.*s\n", thislen, (int)thislen, pos);
off += thislen;
if (thislen != CPIO_HDRLEN + c->namesize)
pr_debug("padded to: %u\n", CPIO_HDRLEN + c->namesize);
off += CPIO_HDRLEN + c->namesize;
while (off & 3)
out[off++] = '\0';
@ -383,6 +386,67 @@ static void __init initramfs_test_many(struct kunit *test)
kfree(cpio_srcbuf);
}
/*
* An initramfs filename is namesize in length, including the zero-terminator.
* A filename can be zero-terminated prior to namesize, with the remainder used
* as padding. This can be useful for e.g. alignment of file data segments with
* a 4KB filesystem block, allowing for extent sharing (reflinks) between cpio
* source and destination. This hack works with both GNU cpio and initramfs, as
* long as PATH_MAX isn't exceeded.
*/
static void __init initramfs_test_fname_pad(struct kunit *test)
{
char *err;
size_t len;
struct file *file;
char fdata[] = "this file data is aligned at 4K in the archive";
struct test_fname_pad {
char padded_fname[4096 - CPIO_HDRLEN];
char cpio_srcbuf[CPIO_HDRLEN + PATH_MAX + 3 + sizeof(fdata)];
} *tbufs = kzalloc(sizeof(struct test_fname_pad), GFP_KERNEL);
struct initramfs_test_cpio c[] = { {
.magic = "070701",
.ino = 1,
.mode = S_IFREG | 0777,
.uid = 0,
.gid = 0,
.nlink = 1,
.mtime = 1,
.filesize = sizeof(fdata),
.devmajor = 0,
.devminor = 1,
.rdevmajor = 0,
.rdevminor = 0,
/* align file data at 4K archive offset via padded fname */
.namesize = 4096 - CPIO_HDRLEN,
.csum = 0,
.fname = tbufs->padded_fname,
.data = fdata,
} };
memcpy(tbufs->padded_fname, "padded_fname", sizeof("padded_fname"));
len = fill_cpio(c, ARRAY_SIZE(c), tbufs->cpio_srcbuf);
err = unpack_to_rootfs(tbufs->cpio_srcbuf, len);
KUNIT_EXPECT_NULL(test, err);
file = filp_open(c[0].fname, O_RDONLY, 0);
if (IS_ERR(file)) {
KUNIT_FAIL(test, "open failed");
goto out;
}
/* read back file contents into @cpio_srcbuf and confirm match */
len = kernel_read(file, tbufs->cpio_srcbuf, c[0].filesize, NULL);
KUNIT_EXPECT_EQ(test, len, c[0].filesize);
KUNIT_EXPECT_MEMEQ(test, tbufs->cpio_srcbuf, c[0].data, len);
fput(file);
KUNIT_EXPECT_EQ(test, init_unlink(c[0].fname), 0);
out:
kfree(tbufs);
}
/*
* The kunit_case/_suite struct cannot be marked as __initdata as this will be
* used in debugfs to retrieve results after test has run.
@ -394,6 +458,7 @@ static struct kunit_case __refdata initramfs_test_cases[] = {
KUNIT_CASE(initramfs_test_csum),
KUNIT_CASE(initramfs_test_hardlink),
KUNIT_CASE(initramfs_test_many),
KUNIT_CASE(initramfs_test_fname_pad),
{},
};

View File

@ -259,7 +259,7 @@ config DEBUG_INFO_NONE
config DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
bool "Rely on the toolchain's implicit default DWARF version"
select DEBUG_INFO
depends on !CC_IS_CLANG || AS_IS_LLVM || CLANG_VERSION < 140000 || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_ULEB128)
depends on !CC_IS_CLANG || AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_ULEB128)
help
The implicit default version of DWARF debug info produced by a
toolchain changes over time.

View File

@ -185,12 +185,6 @@ config KCSAN_WEAK_MEMORY
bool "Enable weak memory modeling to detect missing memory barriers"
default y
depends on KCSAN_STRICT
# We can either let objtool nop __tsan_func_{entry,exit}() and builtin
# atomics instrumentation in .noinstr.text, or use a compiler that can
# implement __no_kcsan to really remove all instrumentation.
depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \
CC_IS_GCC || CLANG_VERSION >= 140000
select OBJTOOL if HAVE_NOINSTR_HACK
help
Enable support for modeling a subset of weak memory, which allows
detecting a subset of data races due to missing memory barriers.

View File

@ -3,10 +3,7 @@ config HAVE_ARCH_KMSAN
bool
config HAVE_KMSAN_COMPILER
# Clang versions <14.0.0 also support -fsanitize=kernel-memory, but not
# all the features necessary to build the kernel with KMSAN.
depends on CC_IS_CLANG && CLANG_VERSION >= 140000
def_bool $(cc-option,-fsanitize=kernel-memory -mllvm -msan-disable-checks=1)
def_bool CC_IS_CLANG
config KMSAN
bool "KMSAN: detector of uninitialized values use"
@ -28,15 +25,9 @@ config KMSAN
if KMSAN
config HAVE_KMSAN_PARAM_RETVAL
# -fsanitize-memory-param-retval is supported only by Clang >= 14.
depends on HAVE_KMSAN_COMPILER
def_bool $(cc-option,-fsanitize=kernel-memory -fsanitize-memory-param-retval)
config KMSAN_CHECK_PARAM_RETVAL
bool "Check for uninitialized values passed to and returned from functions"
default y
depends on HAVE_KMSAN_PARAM_RETVAL
help
If the compiler supports -fsanitize-memory-param-retval, KMSAN will
eagerly check every function parameter passed by value and every

View File

@ -195,10 +195,10 @@ macro_rules! module_device_table {
($table_type: literal, $module_table_name:ident, $table_name:ident) => {
#[rustfmt::skip]
#[export_name =
concat!("__mod_device_table__", $table_type,
"__", module_path!(),
"_", line!(),
"_", stringify!($table_name))
concat!("__mod_device_table__", line!(),
"__kmod_", module_path!(),
"__", $table_type,
"__", stringify!($table_name))
]
static $module_table_name: [::core::mem::MaybeUninit<u8>; $table_name.raw_ids().size()] =
unsafe { ::core::mem::transmute_copy($table_name.raw_ids()) };

View File

@ -25,8 +25,6 @@ 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
@ -214,10 +212,20 @@ KBUILD_CFLAGS += -Wno-unused-parameter
endif
#
# W=e - error out on warnings
# W=e and CONFIG_WERROR - error out on warnings
#
ifneq ($(findstring e, $(KBUILD_EXTRA_WARN)),)
ifneq ($(findstring e, $(KBUILD_EXTRA_WARN))$(CONFIG_WERROR),)
KBUILD_CFLAGS += -Werror
KBUILD_CPPFLAGS += -Werror
KBUILD_AFLAGS += -Wa,--fatal-warnings
KBUILD_LDFLAGS += --fatal-warnings
KBUILD_USERCFLAGS += -Werror
KBUILD_USERLDFLAGS += -Wl,--fatal-warnings
KBUILD_RUSTFLAGS += -Dwarnings
endif
# Hostprog flags are used during build bootstrapping and can not rely on CONFIG_ symbols.
KBUILD_HOSTCFLAGS += -Werror
KBUILD_HOSTLDFLAGS += -Wl,--fatal-warnings
KBUILD_HOSTRUSTFLAGS += -Dwarnings

View File

@ -9,20 +9,6 @@ include $(srctree)/scripts/Makefile.lib
targets :=
ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS
vmlinux-final := vmlinux.unstripped
quiet_cmd_strip_relocs = RSTRIP $@
cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' --remove-section=!'.rel*.dyn' $< $@
vmlinux: $(vmlinux-final) FORCE
$(call if_changed,strip_relocs)
targets += vmlinux
else
vmlinux-final := vmlinux
endif
%.o: %.c FORCE
$(call if_changed_rule,cc_o_c)
@ -61,19 +47,14 @@ targets += .builtin-dtbs-list
ifdef CONFIG_GENERIC_BUILTIN_DTB
targets += .builtin-dtbs.S .builtin-dtbs.o
$(vmlinux-final): .builtin-dtbs.o
vmlinux.unstripped: .builtin-dtbs.o
endif
# vmlinux
# vmlinux.unstripped
# ---------------------------------------------------------------------------
ifdef CONFIG_MODULES
targets += .vmlinux.export.o
$(vmlinux-final): .vmlinux.export.o
endif
ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX
$(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o
vmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o
arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE
$(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@
@ -86,17 +67,61 @@ cmd_link_vmlinux = \
$< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
targets += $(vmlinux-final)
$(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
targets += vmlinux.unstripped .vmlinux.export.o
vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o .vmlinux.export.o $(KBUILD_LDS) FORCE
+$(call if_changed_dep,link_vmlinux)
ifdef CONFIG_DEBUG_INFO_BTF
$(vmlinux-final): $(RESOLVE_BTFIDS)
vmlinux.unstripped: $(RESOLVE_BTFIDS)
endif
ifdef CONFIG_BUILDTIME_TABLE_SORT
$(vmlinux-final): scripts/sorttable
vmlinux.unstripped: scripts/sorttable
endif
# vmlinux
# ---------------------------------------------------------------------------
remove-section-y := .modinfo
remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
remove-symbols := -w --strip-symbol='__mod_device_table__*'
# To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
# it is necessary to remove the PT_LOAD flag from the segment.
quiet_cmd_strip_relocs = OBJCOPY $@
cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \
$(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $(remove-symbols) $@
targets += vmlinux
vmlinux: vmlinux.unstripped FORCE
$(call if_changed,strip_relocs)
# modules.builtin.modinfo
# ---------------------------------------------------------------------------
OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
targets += modules.builtin.modinfo
modules.builtin.modinfo: vmlinux.unstripped FORCE
$(call if_changed,objcopy)
# modules.builtin
# ---------------------------------------------------------------------------
__default: modules.builtin
# The second line aids cases where multiple modules share the same object.
quiet_cmd_modules_builtin = GEN $@
cmd_modules_builtin = \
tr '\0' '\n' < $< | \
sed -n 's/^[[:alnum:]:_]*\.file=//p' | \
tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@
targets += modules.builtin
modules.builtin: modules.builtin.modinfo FORCE
$(call if_changed,modules_builtin)
# modules.builtin.ranges
# ---------------------------------------------------------------------------
ifdef CONFIG_BUILTIN_MODULE_RANGES
@ -110,7 +135,7 @@ modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \
modules.builtin vmlinux.map vmlinux.o.map FORCE
$(call if_changed,modules_builtin_ranges)
vmlinux.map: $(vmlinux-final)
vmlinux.map: vmlinux.unstripped
@:
endif

View File

@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
PHONY := __default
__default: vmlinux.o modules.builtin.modinfo modules.builtin
__default: vmlinux.o
include include/config/auto.conf
include $(srctree)/scripts/Kbuild.include
@ -73,30 +73,6 @@ vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
targets += vmlinux.o
# modules.builtin.modinfo
# ---------------------------------------------------------------------------
OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
targets += modules.builtin.modinfo
modules.builtin.modinfo: vmlinux.o FORCE
$(call if_changed,objcopy)
# modules.builtin
# ---------------------------------------------------------------------------
# The second line aids cases where multiple modules share the same object.
quiet_cmd_modules_builtin = GEN $@
cmd_modules_builtin = \
tr '\0' '\n' < $< | \
sed -n 's/^[[:alnum:]:_]*\.file=//p' | \
tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@
targets += modules.builtin
modules.builtin: modules.builtin.modinfo FORCE
$(call if_changed,modules_builtin)
# Add FORCE to the prerequisites of a target to force it to be always rebuilt.
# ---------------------------------------------------------------------------

View File

@ -10,12 +10,15 @@
#
# ----------------------------------------------------------------------
me=${0##*/}
check_vmlinux()
{
if file "$1" | grep -q 'Linux kernel.*boot executable' ||
readelf -h "$1" > /dev/null 2>&1
then
cat "$1"
echo "$me: Extracted vmlinux using '$2' from offset $3" >&2
exit 0
fi
}
@ -30,12 +33,11 @@ try_decompress()
do
pos=${pos%%:*}
tail -c+$pos "$img" | $3 > $tmp 2> /dev/null
check_vmlinux $tmp
check_vmlinux $tmp "$3" $pos
done
}
# Check invocation:
me=${0##*/}
img=$1
if [ $# -ne 1 -o ! -s "$img" ]
then
@ -57,7 +59,7 @@ try_decompress '\002!L\030' xxx 'lz4 -d'
try_decompress '(\265/\375' xxx unzstd
# Finally check for uncompressed images or objects:
check_vmlinux $img
check_vmlinux "$img" cat 0
# Bail out:
echo "$me: Cannot find vmlinux." >&2

View File

@ -173,12 +173,10 @@ void fill_window(WINDOW *win, const char *text)
/* do not go over end of line */
total_lines = min(total_lines, y);
for (i = 0; i < total_lines; i++) {
char tmp[x+10];
const char *line = get_line(text, i);
int len = get_line_length(line);
strncpy(tmp, line, min(len, x));
tmp[len] = '\0';
mvwprintw(win, i, 0, "%s", tmp);
int len = min(get_line_length(line), x);
mvwprintw(win, i, 0, "%.*s", len, line);
}
}

View File

@ -1377,6 +1377,19 @@ ConfigMainWindow::ConfigMainWindow(void)
ConfigList::showPromptAction = new QAction("Show Prompt Options", optGroup);
ConfigList::showPromptAction->setCheckable(true);
switch (configList->optMode) {
case allOpt:
ConfigList::showAllAction->setChecked(true);
break;
case promptOpt:
ConfigList::showPromptAction->setChecked(true);
break;
case normalOpt:
default:
ConfigList::showNormalAction->setChecked(true);
break;
}
QAction *showDebugAction = new QAction("Show Debug Info", this);
showDebugAction->setCheckable(true);
connect(showDebugAction, &QAction::toggled,

View File

@ -73,10 +73,7 @@ vmlinux_link()
objs="${objs} .builtin-dtbs.o"
fi
if is_enabled CONFIG_MODULES; then
objs="${objs} .vmlinux.export.o"
fi
objs="${objs} .vmlinux.export.o"
objs="${objs} init/version-timestamp.o"
if [ "${SRCARCH}" = "um" ]; then

View File

@ -24,12 +24,10 @@ gcc)
fi
;;
llvm)
if [ "$SRCARCH" = s390 -o "$SRCARCH" = x86 ]; then
echo 15.0.0
elif [ "$SRCARCH" = loongarch ]; then
if [ "$SRCARCH" = loongarch ]; then
echo 18.0.0
else
echo 13.0.1
echo 15.0.0
fi
;;
rustc)

View File

@ -45,7 +45,7 @@ check_tracked_ignored_files () {
# does not automatically fix it.
check_missing_include_linux_export_h () {
git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_GPL_FOR_MODULES)\(.*\)' \
git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' \
-- '*.[ch]' :^tools/ :^include/linux/export.h |
xargs -r git -C "${srctree:-.}" grep --files-without-match '#include[[:space:]]*<linux/export\.h>' |
xargs -r printf "%s: warning: EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing\n" >&2
@ -58,7 +58,7 @@ check_unnecessary_include_linux_export_h () {
git -C "${srctree:-.}" grep --files-with-matches '#include[[:space:]]*<linux/export\.h>' \
-- '*.[c]' :^tools/ |
xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_GPL_FOR_MODULES)\(.*\)' |
xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' |
xargs -r printf "%s: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present\n" >&2
}

View File

@ -59,6 +59,9 @@
# EXPORT_SYMBOL (namespace)
/ __kstrtabns_/d
# MODULE_DEVICE_TABLE (symbol name)
/ __mod_device_table__/d
# ---------------------------------------------------------------------------
# Ignored suffixes
# (do not forget '$' after each pattern)
@ -79,6 +82,9 @@
/ _SDA_BASE_$/d
/ _SDA2_BASE_$/d
# MODULE_INFO()
/ __UNIQUE_ID_modinfo[0-9]*$/d
# ---------------------------------------------------------------------------
# Ignored patterns
# (symbols that contain the pattern are ignored)

View File

@ -94,6 +94,7 @@ module_alias_printf(struct module *mod, bool append_wildcard,
}
}
new->builtin_modname = NULL;
list_add_tail(&new->node, &mod->aliases);
}
@ -1476,8 +1477,8 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
{
void *symval;
char *zeros = NULL;
const char *type, *name;
size_t typelen;
const char *type, *name, *modname;
size_t typelen, modnamelen;
static const char *prefix = "__mod_device_table__";
/* We're looking for a section relative symbol */
@ -1488,10 +1489,20 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
return;
/* All our symbols are of form __mod_device_table__<type>__<name>. */
/* All our symbols are of form __mod_device_table__kmod_<modname>__<type>__<name>. */
if (!strstarts(symname, prefix))
return;
type = symname + strlen(prefix);
modname = strstr(symname, "__kmod_");
if (!modname)
return;
modname += strlen("__kmod_");
type = strstr(modname, "__");
if (!type)
return;
modnamelen = type - modname;
type += strlen("__");
name = strstr(type, "__");
if (!name)
@ -1517,5 +1528,21 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
}
}
if (mod->is_vmlinux) {
struct module_alias *alias;
/*
* If this is vmlinux, record the name of the builtin module.
* Traverse the linked list in the reverse order, and set the
* builtin_modname unless it has already been set in the
* previous call.
*/
list_for_each_entry_reverse(alias, &mod->aliases, node) {
if (alias->builtin_modname)
break;
alias->builtin_modname = xstrndup(modname, modnamelen);
}
}
free(zeros);
}

View File

@ -2067,11 +2067,26 @@ static void write_if_changed(struct buffer *b, const char *fname)
static void write_vmlinux_export_c_file(struct module *mod)
{
struct buffer buf = { };
struct module_alias *alias, *next;
buf_printf(&buf,
"#include <linux/export-internal.h>\n");
add_exported_symbols(&buf, mod);
buf_printf(&buf,
"#include <linux/module.h>\n"
"#undef __MODULE_INFO_PREFIX\n"
"#define __MODULE_INFO_PREFIX\n");
list_for_each_entry_safe(alias, next, &mod->aliases, node) {
buf_printf(&buf, "MODULE_INFO(%s.alias, \"%s\");\n",
alias->builtin_modname, alias->str);
list_del(&alias->node);
free(alias->builtin_modname);
free(alias);
}
write_if_changed(&buf, ".vmlinux.export.c");
free(buf.p);
}

View File

@ -99,10 +99,12 @@ buf_write(struct buffer *buf, const char *s, int len);
* struct module_alias - auto-generated MODULE_ALIAS()
*
* @node: linked to module::aliases
* @modname: name of the builtin module (only for vmlinux)
* @str: a string for MODULE_ALIAS()
*/
struct module_alias {
struct list_head node;
char *builtin_modname;
char str[];
};

View File

@ -2453,16 +2453,6 @@ static bool is_profiling_func(const char *name)
if (!strncmp(name, "__sanitizer_cov_", 16))
return true;
/*
* Some compilers currently do not remove __tsan_func_entry/exit nor
* __tsan_atomic_signal_fence (used for barrier instrumentation) with
* the __no_sanitize_thread attribute, remove them. Once the kernel's
* minimum Clang version is 14.0, this can be removed.
*/
if (!strncmp(name, "__tsan_func_", 12) ||
!strcmp(name, "__tsan_atomic_signal_fence"))
return true;
return false;
}

View File

@ -27,6 +27,3 @@ debug/i386/intel_gsic
debug/i386/powernow-k8-decode
debug/x86_64/centrino-decode
debug/x86_64/powernow-k8-decode
# Clang's compilation database file
compile_commands.json

View File

@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@ -23,64 +24,72 @@
#define xstr(s) #s
#define str(s) xstr(s)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define CPIO_HDR_LEN 110
#define CPIO_TRAILER "TRAILER!!!"
#define padlen(_off, _align) (((_align) - ((_off) & ((_align) - 1))) % (_align))
/* zero-padding the filename field for data alignment is limited by PATH_MAX */
static char padding[PATH_MAX];
static unsigned int offset;
static unsigned int ino = 721;
static time_t default_mtime;
static bool do_file_mtime;
static bool do_csum = false;
static int outfd = STDOUT_FILENO;
static unsigned int dalign;
struct file_handler {
const char *type;
int (*handler)(const char *line);
};
static void push_string(const char *name)
static int push_buf(const char *name, size_t name_len)
{
unsigned int name_len = strlen(name) + 1;
ssize_t len;
len = write(outfd, name, name_len);
if (len != name_len)
return -1;
fputs(name, stdout);
putchar(0);
offset += name_len;
return 0;
}
static void push_pad (void)
static int push_pad(size_t padlen)
{
while (offset & 3) {
putchar(0);
offset++;
}
ssize_t len = 0;
if (!padlen)
return 0;
if (padlen < sizeof(padding))
len = write(outfd, padding, padlen);
if (len != padlen)
return -1;
offset += padlen;
return 0;
}
static void push_rest(const char *name)
static int push_rest(const char *name, size_t name_len)
{
unsigned int name_len = strlen(name) + 1;
unsigned int tmp_ofs;
ssize_t len;
len = write(outfd, name, name_len);
if (len != name_len)
return -1;
fputs(name, stdout);
putchar(0);
offset += name_len;
tmp_ofs = name_len + 110;
while (tmp_ofs & 3) {
putchar(0);
offset++;
tmp_ofs++;
}
return push_pad(padlen(name_len + CPIO_HDR_LEN, 4));
}
static void push_hdr(const char *s)
static int cpio_trailer(void)
{
fputs(s, stdout);
offset += 110;
}
int len;
unsigned int namesize = sizeof(CPIO_TRAILER);
static void cpio_trailer(void)
{
char s[256];
const char name[] = "TRAILER!!!";
sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
do_csum ? "070702" : "070701", /* magic */
0, /* ino */
@ -94,25 +103,29 @@ static void cpio_trailer(void)
0, /* minor */
0, /* rmajor */
0, /* rminor */
(unsigned)strlen(name)+1, /* namesize */
namesize, /* namesize */
0); /* chksum */
push_hdr(s);
push_rest(name);
offset += len;
while (offset % 512) {
putchar(0);
offset++;
}
if (len != CPIO_HDR_LEN ||
push_rest(CPIO_TRAILER, namesize) < 0 ||
push_pad(padlen(offset, 512)) < 0)
return -1;
return fsync(outfd);
}
static int cpio_mkslink(const char *name, const char *target,
unsigned int mode, uid_t uid, gid_t gid)
{
char s[256];
int len;
unsigned int namesize, targetsize = strlen(target) + 1;
if (name[0] == '/')
name++;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
namesize = strlen(name) + 1;
len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
do_csum ? "070702" : "070701", /* magic */
ino++, /* ino */
@ -121,19 +134,24 @@ static int cpio_mkslink(const char *name, const char *target,
(long) gid, /* gid */
1, /* nlink */
(long) default_mtime, /* mtime */
(unsigned)strlen(target)+1, /* filesize */
targetsize, /* filesize */
3, /* major */
1, /* minor */
0, /* rmajor */
0, /* rminor */
(unsigned)strlen(name) + 1,/* namesize */
namesize, /* namesize */
0); /* chksum */
push_hdr(s);
push_string(name);
push_pad();
push_string(target);
push_pad();
offset += len;
if (len != CPIO_HDR_LEN ||
push_buf(name, namesize) < 0 ||
push_pad(padlen(offset, 4)) < 0 ||
push_buf(target, targetsize) < 0 ||
push_pad(padlen(offset, 4)) < 0)
return -1;
return 0;
}
static int cpio_mkslink_line(const char *line)
@ -157,11 +175,14 @@ static int cpio_mkslink_line(const char *line)
static int cpio_mkgeneric(const char *name, unsigned int mode,
uid_t uid, gid_t gid)
{
char s[256];
int len;
unsigned int namesize;
if (name[0] == '/')
name++;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
namesize = strlen(name) + 1;
len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
do_csum ? "070702" : "070701", /* magic */
ino++, /* ino */
@ -175,10 +196,14 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,
1, /* minor */
0, /* rmajor */
0, /* rminor */
(unsigned)strlen(name) + 1,/* namesize */
namesize, /* namesize */
0); /* chksum */
push_hdr(s);
push_rest(name);
offset += len;
if (len != CPIO_HDR_LEN ||
push_rest(name, namesize) < 0)
return -1;
return 0;
}
@ -246,7 +271,8 @@ static int cpio_mknod(const char *name, unsigned int mode,
uid_t uid, gid_t gid, char dev_type,
unsigned int maj, unsigned int min)
{
char s[256];
int len;
unsigned int namesize;
if (dev_type == 'b')
mode |= S_IFBLK;
@ -255,7 +281,9 @@ static int cpio_mknod(const char *name, unsigned int mode,
if (name[0] == '/')
name++;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
namesize = strlen(name) + 1;
len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
do_csum ? "070702" : "070701", /* magic */
ino++, /* ino */
@ -269,10 +297,14 @@ static int cpio_mknod(const char *name, unsigned int mode,
1, /* minor */
maj, /* rmajor */
min, /* rminor */
(unsigned)strlen(name) + 1,/* namesize */
namesize, /* namesize */
0); /* chksum */
push_hdr(s);
push_rest(name);
offset += len;
if (len != CPIO_HDR_LEN ||
push_rest(name, namesize) < 0)
return -1;
return 0;
}
@ -324,16 +356,15 @@ static int cpio_mkfile(const char *name, const char *location,
unsigned int mode, uid_t uid, gid_t gid,
unsigned int nlinks)
{
char s[256];
struct stat buf;
unsigned long size;
int file;
int retval;
int file, retval, len;
int rc = -1;
time_t mtime;
int namesize;
int namesize, namepadlen;
unsigned int i;
uint32_t csum = 0;
ssize_t this_read;
mode |= S_IFREG;
@ -378,15 +409,28 @@ static int cpio_mkfile(const char *name, const char *location,
}
size = 0;
namepadlen = 0;
for (i = 1; i <= nlinks; i++) {
/* data goes on last link */
if (i == nlinks)
size = buf.st_size;
if (name[0] == '/')
name++;
namesize = strlen(name) + 1;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
/* data goes on last link, after any alignment padding */
if (i == nlinks)
size = buf.st_size;
if (dalign && size > dalign) {
namepadlen = padlen(offset + CPIO_HDR_LEN + namesize,
dalign);
if (namesize + namepadlen > PATH_MAX) {
fprintf(stderr,
"%s: best-effort alignment %u missed\n",
name, dalign);
namepadlen = 0;
}
}
len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08lX%08X%08X%08X%08X%08X%08X",
do_csum ? "070702" : "070701", /* magic */
ino, /* ino */
@ -400,15 +444,28 @@ static int cpio_mkfile(const char *name, const char *location,
1, /* minor */
0, /* rmajor */
0, /* rminor */
namesize, /* namesize */
namesize + namepadlen, /* namesize */
size ? csum : 0); /* chksum */
push_hdr(s);
push_string(name);
push_pad();
offset += len;
if (len != CPIO_HDR_LEN ||
push_buf(name, namesize) < 0 ||
push_pad(namepadlen ? namepadlen : padlen(offset, 4)) < 0)
goto error;
if (size) {
this_read = copy_file_range(file, NULL, outfd, NULL, size, 0);
if (this_read > 0) {
if (this_read > size)
goto error;
offset += this_read;
size -= this_read;
}
/* short or failed copy falls back to read/write... */
}
while (size) {
unsigned char filebuf[65536];
ssize_t this_read;
size_t this_size = MIN(size, sizeof(filebuf));
this_read = read(file, filebuf, this_size);
@ -417,14 +474,15 @@ static int cpio_mkfile(const char *name, const char *location,
goto error;
}
if (fwrite(filebuf, this_read, 1, stdout) != 1) {
if (write(outfd, filebuf, this_read) != this_read) {
fprintf(stderr, "writing filebuf failed\n");
goto error;
}
offset += this_read;
size -= this_read;
}
push_pad();
if (push_pad(padlen(offset, 4)) < 0)
goto error;
name += namesize;
}
@ -509,7 +567,7 @@ static int cpio_mkfile_line(const char *line)
static void usage(const char *prog)
{
fprintf(stderr, "Usage:\n"
"\t%s [-t <timestamp>] [-c] <cpio_list>\n"
"\t%s [-t <timestamp>] [-c] [-o <output_file>] [-a <data_align>] <cpio_list>\n"
"\n"
"<cpio_list> is a file containing newline separated entries that\n"
"describe the files to be included in the initramfs archive:\n"
@ -546,7 +604,11 @@ static void usage(const char *prog)
"as mtime for symlinks, directories, regular and special files.\n"
"The default is to use the current time for all files, but\n"
"preserve modification time for regular files.\n"
"-c: calculate and store 32-bit checksums for file data.\n",
"-c: calculate and store 32-bit checksums for file data.\n"
"<output_file>: write cpio to this file instead of stdout\n"
"<data_align>: attempt to align file data by zero-padding the\n"
"filename field up to data_align. Must be a multiple of 4.\n"
"Alignment is best-effort; PATH_MAX limits filename padding.\n",
prog);
}
@ -588,7 +650,7 @@ int main (int argc, char *argv[])
default_mtime = time(NULL);
while (1) {
int opt = getopt(argc, argv, "t:ch");
int opt = getopt(argc, argv, "t:cho:a:");
char *invalid;
if (opt == -1)
@ -607,6 +669,25 @@ int main (int argc, char *argv[])
case 'c':
do_csum = true;
break;
case 'o':
outfd = open(optarg,
O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC,
0600);
if (outfd < 0) {
fprintf(stderr, "failed to open %s\n", optarg);
usage(argv[0]);
exit(1);
}
break;
case 'a':
dalign = strtoul(optarg, &invalid, 10);
if (!*optarg || *invalid || (dalign & 3)) {
fprintf(stderr, "Invalid data_align: %s\n",
optarg);
usage(argv[0]);
exit(1);
}
break;
case 'h':
case '?':
usage(argv[0]);
@ -691,7 +772,7 @@ int main (int argc, char *argv[])
}
}
if (ec == 0)
cpio_trailer();
ec = cpio_trailer();
exit(ec);
}

View File

@ -193,7 +193,8 @@ root_gid=0
dep_list=
timestamp=
cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)
output="/dev/stdout"
# gen_init_cpio writes to stdout by default
output=""
trap "rm -f $cpio_list" EXIT
@ -207,7 +208,7 @@ while [ $# -gt 0 ]; do
shift
;;
"-o") # generate cpio image named $1
output="$1"
output="-o $1"
shift
;;
"-u") # map $1 to uid=0 (root)
@ -246,4 +247,4 @@ done
# If output_file is set we will generate cpio archive
# we are careful to delete tmp files
usr/gen_init_cpio $timestamp $cpio_list > $output
usr/gen_init_cpio $output $timestamp $cpio_list

View File

@ -80,12 +80,12 @@ always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/
# Include the header twice to detect missing include guard.
quiet_cmd_hdrtest = HDRTEST $<
cmd_hdrtest = \
$(CC) $(c_flags) -fsyntax-only -x c /dev/null \
$(CC) $(c_flags) -fsyntax-only -Werror -x c /dev/null \
$(if $(filter-out $(no-header-test), $*.h), -include $< -include $<); \
$(PERL) $(src)/headers_check.pl $(obj) $<; \
touch $@
$(obj)/%.hdrtest: $(obj)/%.h FORCE
$(obj)/%.hdrtest: $(obj)/%.h $(src)/headers_check.pl FORCE
$(call if_changed_dep,hdrtest)
# Since GNU Make 4.3, $(patsubst $(obj)/%/,%,$(wildcard $(obj)/*/)) works.

View File

@ -74,6 +74,7 @@ sub check_declarations
printf STDERR "$filename:$lineno: " .
"userspace cannot reference function or " .
"variable defined in the kernel\n";
$ret = 1;
}
}
@ -98,9 +99,8 @@ sub check_asm_types
if ($line =~ m/^\s*#\s*include\s+<asm\/types.h>/) {
$linux_asm_types = 1;
printf STDERR "$filename:$lineno: " .
"include of <linux/types.h> is preferred over <asm/types.h>\n"
# Warn until headers are all fixed
#$ret = 1;
"include of <linux/types.h> is preferred over <asm/types.h>\n";
$ret = 1;
}
}
@ -160,7 +160,6 @@ sub check_sizetypes
"found __[us]{8,16,32,64} type " .
"without #include <linux/types.h>\n";
$linux_types = 2;
# Warn until headers are all fixed
#$ret = 1;
$ret = 1;
}
}