Commit d55571c0 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull Kbuild updates from Masahiro Yamada:

 - Refactor scripts/kallsyms to make it faster and easier to maintain

 - Clean up menuconfig

 - Provide Clang with hard-coded target triple instead of CROSS_COMPILE

 - Use -z pack-relative-relocs flags instead of --use-android-relr-tags
   for arm64 CONFIG_RELR

 - Add srcdeb-pkg target to build only a Debian source package

 - Add KDEB_SOURCE_COMPRESS option to specify the compression for a
   Debian source package

 - Misc cleanups and fixes

* tag 'kbuild-v6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
  kbuild: deb-pkg: specify targets in debian/rules as .PHONY
  sparc: unify sparc32/sparc64 archhelp
  kbuild: rpm-pkg: remove kernel-drm PROVIDES
  kbuild: deb-pkg: add KDEB_SOURCE_COMPRESS to specify source compression
  kbuild: add srcdeb-pkg target
  Makefile: use -z pack-relative-relocs
  kbuild: clang: do not use CROSS_COMPILE for target triple
  kconfig: menuconfig: reorder functions to remove forward declarations
  kconfig: menuconfig: remove unused M_EVENT macro
  kconfig: menuconfig: remove OLD_NCURSES macro
  kbuild: builddeb: Eliminate debian/arch use
  scripts/kallsyms: update the usage in the comment block
  scripts/kallsyms: decrease expand_symbol() / cleanup_symbol_name() calls
  scripts/kallsyms: change the output order
  scripts/kallsyms: move compiler-generated symbol patterns to mksysmap
  scripts/kallsyms: exclude symbols generated by itself dynamically
  scripts/mksysmap: use sed with in-line comments
  scripts/mksysmap: remove comments described in nm(1)
  scripts/kallsyms: remove redundant code for omitting U and N
  kallsyms: expand symbol name into comment for debugging
parents 31089765 9892bd72
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1113,7 +1113,8 @@ LDFLAGS_vmlinux += -X
endif

ifeq ($(CONFIG_RELR),y)
LDFLAGS_vmlinux	+= --pack-dyn-relocs=relr --use-android-relr-tags
# ld.lld before 15 did not support -z pack-relative-relocs.
LDFLAGS_vmlinux	+= $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs)
endif

# We never want expected sections to be placed heuristically by the
+4 −11
Original line number Diff line number Diff line
@@ -83,18 +83,11 @@ vdso_install:
KBUILD_IMAGE := $(boot)/zImage

# Don't use tabs in echo arguments.
ifeq ($(ARCH),sparc)
define archhelp
  echo  '* image        - kernel image ($(boot)/image)'
  echo  '* zImage       - stripped kernel image ($(boot)/zImage)'
  echo  '* vmlinux      - standard SPARC kernel'
  echo  '  image        - kernel image ($(boot)/image)'
  echo  '* zImage       - stripped/compressed kernel image ($(boot)/zImage)'
  echo  '  uImage       - U-Boot SPARC32 Image (only for LEON)'
  echo  '  vmlinux.aout - a.out kernel for SPARC64'
  echo  '  tftpboot.img - image prepared for tftp'
endef
else
define archhelp
  echo  '* vmlinux      - standard sparc64 kernel'
  echo  '* zImage       - stripped and compressed sparc64 kernel ($(boot)/zImage)'
  echo  '  vmlinux.aout - a.out kernel for sparc64'
  echo  '  tftpboot.img - image prepared for tftp'
endef
endif
+2 −6
Original line number Diff line number Diff line
@@ -13,15 +13,11 @@ CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
CLANG_TARGET_FLAGS_um		:= $(CLANG_TARGET_FLAGS_$(SUBARCH))
CLANG_TARGET_FLAGS		:= $(CLANG_TARGET_FLAGS_$(SRCARCH))

ifeq ($(CROSS_COMPILE),)
ifeq ($(CLANG_TARGET_FLAGS),)
$(error Specify CROSS_COMPILE or add '--target=' option to scripts/Makefile.clang)
$(error add '--target=' option to scripts/Makefile.clang)
else
CLANG_FLAGS	+= --target=$(CLANG_TARGET_FLAGS)
endif # CLANG_TARGET_FLAGS
else
CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
endif # CROSS_COMPILE
endif

ifeq ($(LLVM_IAS),0)
CLANG_FLAGS	+= -fno-integrated-as
+47 −14
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ include $(srctree)/scripts/Kbuild.include
include $(srctree)/scripts/Makefile.lib

KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
KBUILD_PKG_ROOTCMD ?="fakeroot -u"
# Include only those top-level files that are needed by make, plus the GPL copy
TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
               include init io_uring ipc kernel lib mm net rust \
@@ -44,6 +43,7 @@ check-git:

git-config-tar.gz   = -c tar.tar.gz.command="$(KGZIP)"
git-config-tar.bz2  = -c tar.tar.bz2.command="$(KBZIP2)"
git-config-tar.lzma = -c tar.tar.lzma.command="$(LZMA)"
git-config-tar.xz   = -c tar.tar.xz.command="$(XZ)"
git-config-tar.zst  = -c tar.tar.zst.command="$(ZSTD)"

@@ -51,10 +51,15 @@ quiet_cmd_archive = ARCHIVE $@
      cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
                    --output=$$(realpath $@) $(archive-args)

suffix-gzip  := .gz
suffix-bzip2 := .bz2
suffix-lzma  := .lzma
suffix-xz    := .xz

# Linux source tarball
# ---------------------------------------------------------------------------

linux-tarballs := $(addprefix linux, .tar.gz)
linux-tarballs := $(addprefix linux, .tar.gz .tar.bz2 .tar.lzma .tar.xz)

targets += $(linux-tarballs)
$(linux-tarballs): archive-args = --prefix=linux/ $$(cat $<)
@@ -86,6 +91,22 @@ binrpm-pkg:
	+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
		$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec

# deb-pkg srcdeb-pkg bindeb-pkg
# ---------------------------------------------------------------------------

KDEB_SOURCE_COMPRESS ?= gzip

supported-deb-source-compress := gzip bzip2 lzma xz

PHONY += linux.tar.unsupported-deb-src-compress
linux.tar.unsupported-deb-src-compress:
	@echo "error: KDEB_SOURCE_COMPRESS=$(KDEB_SOURCE_COMPRESS) is not supported. The supported values are: $(supported-deb-source-compress)" >&2
	@false

debian-orig-suffix := \
    $(strip $(if $(filter $(supported-deb-source-compress), $(KDEB_SOURCE_COMPRESS)), \
    $(suffix-$(KDEB_SOURCE_COMPRESS)),.unsupported-deb-src-compress))

quiet_cmd_debianize = GEN     $@
      cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)

@@ -95,23 +116,34 @@ debian: FORCE
PHONY += debian-orig
debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
debian-orig: private orig-name = $(source)_$(version).orig.tar$(debian-orig-suffix)
debian-orig: mkdebian-opts = --need-source
debian-orig: linux.tar.gz debian
debian-orig: linux.tar$(debian-orig-suffix) debian
	$(Q)if [ "$(df  --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
		ln -f $< ../$(orig-name); \
	else \
		cp $< ../$(orig-name); \
	fi

PHONY += deb-pkg
deb-pkg: debian-orig
	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
		--build=source,binary -nc -us -uc
KBUILD_PKG_ROOTCMD ?= 'fakeroot -u'

PHONY += deb-pkg srcdeb-pkg bindeb-pkg

deb-pkg:    private build-type := source,binary
srcdeb-pkg: private build-type := source
bindeb-pkg: private build-type := binary

PHONY += bindeb-pkg
deb-pkg srcdeb-pkg: debian-orig
bindeb-pkg: debian
	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
deb-pkg srcdeb-pkg bindeb-pkg:
	+$(strip dpkg-buildpackage \
	--build=$(build-type) --no-pre-clean --unsigned-changes \
	$(if $(findstring source, $(build-type)), \
		--unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \
	$(if $(findstring binary, $(build-type)), \
		-r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \
		--no-check-builddeps) \
	$(DPKG_FLAGS))

PHONY += intdeb-pkg
intdeb-pkg:
@@ -208,6 +240,7 @@ help:
	@echo '  srcrpm-pkg          - Build only the source kernel RPM package'
	@echo '  binrpm-pkg          - Build only the binary kernel RPM package'
	@echo '  deb-pkg             - Build both source and binary deb kernel packages'
	@echo '  srcdeb-pkg          - Build only the source kernel deb package'
	@echo '  bindeb-pkg          - Build only the binary kernel deb package'
	@echo '  snap-pkg            - Build only the binary kernel snap package'
	@echo '                        (will connect to external hosts)'
+74 −155
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
 * of the GNU General Public License, incorporated herein by reference.
 *
 * Usage: kallsyms [--all-symbols] [--absolute-percpu]
 *                         [--base-relative] in.map > out.S
 *                         [--base-relative] [--lto-clang] in.map > out.S
 *
 *      Table compression uses all the unused char codes on the symbols and
 *  maps these to the most used substrings (tokens). For instance, it might
@@ -102,86 +102,7 @@ static char *sym_name(const struct sym_entry *s)

static bool is_ignored_symbol(const char *name, char type)
{
	/* Symbol names that exactly match to the following are ignored.*/
	static const char * const ignored_symbols[] = {
		/*
		 * Symbols which vary between passes. Passes 1 and 2 must have
		 * identical symbol lists. The kallsyms_* symbols below are
		 * only added after pass 1, they would be included in pass 2
		 * when --all-symbols is specified so exclude them to get a
		 * stable symbol list.
		 */
		"kallsyms_addresses",
		"kallsyms_offsets",
		"kallsyms_relative_base",
		"kallsyms_num_syms",
		"kallsyms_names",
		"kallsyms_markers",
		"kallsyms_token_table",
		"kallsyms_token_index",
		"kallsyms_seqs_of_names",
		/* Exclude linker generated symbols which vary between passes */
		"_SDA_BASE_",		/* ppc */
		"_SDA2_BASE_",		/* ppc */
		NULL
	};

	/* Symbol names that begin with the following are ignored.*/
	static const char * const ignored_prefixes[] = {
		"__efistub_",		/* arm64 EFI stub namespace */
		"__kvm_nvhe_$",		/* arm64 local symbols in non-VHE KVM namespace */
		"__kvm_nvhe_.L",	/* arm64 local symbols in non-VHE KVM namespace */
		"__AArch64ADRPThunk_",	/* arm64 lld */
		"__ARMV5PILongThunk_",	/* arm lld */
		"__ARMV7PILongThunk_",
		"__ThumbV7PILongThunk_",
		"__LA25Thunk_",		/* mips lld */
		"__microLA25Thunk_",
		"__kcfi_typeid_",	/* CFI type identifiers */
		NULL
	};

	/* Symbol names that end with the following are ignored.*/
	static const char * const ignored_suffixes[] = {
		"_from_arm",		/* arm */
		"_from_thumb",		/* arm */
		"_veneer",		/* arm */
		NULL
	};

	/* Symbol names that contain the following are ignored.*/
	static const char * const ignored_matches[] = {
		".long_branch.",	/* ppc stub */
		".plt_branch.",		/* ppc stub */
		NULL
	};

	const char * const *p;

	for (p = ignored_symbols; *p; p++)
		if (!strcmp(name, *p))
			return true;

	for (p = ignored_prefixes; *p; p++)
		if (!strncmp(name, *p, strlen(*p)))
			return true;

	for (p = ignored_suffixes; *p; p++) {
		int l = strlen(name) - strlen(*p);

		if (l >= 0 && !strcmp(name + l, *p))
			return true;
	}

	for (p = ignored_matches; *p; p++) {
		if (strstr(name, *p))
			return true;
	}

	if (type == 'U' || type == 'u')
		return true;
	/* exclude debugging symbols */
	if (type == 'N' || type == 'n')
	if (type == 'u' || type == 'n')
		return true;

	if (toupper(type) == 'A') {
@@ -414,19 +335,10 @@ static int symbol_absolute(const struct sym_entry *s)
	return s->percpu_absolute;
}

static char * s_name(char *buf)
{
	/* Skip the symbol type */
	return buf + 1;
}

static void cleanup_symbol_name(char *s)
{
	char *p;

	if (!lto_clang)
		return;

	/*
	 * ASCII[.]   = 2e
	 * ASCII[0-9] = 30,39
@@ -445,16 +357,10 @@ static void cleanup_symbol_name(char *s)
static int compare_names(const void *a, const void *b)
{
	int ret;
	char sa_namebuf[KSYM_NAME_LEN];
	char sb_namebuf[KSYM_NAME_LEN];
	const struct sym_entry *sa = *(const struct sym_entry **)a;
	const struct sym_entry *sb = *(const struct sym_entry **)b;

	expand_symbol(sa->sym, sa->len, sa_namebuf);
	expand_symbol(sb->sym, sb->len, sb_namebuf);
	cleanup_symbol_name(s_name(sa_namebuf));
	cleanup_symbol_name(s_name(sb_namebuf));
	ret = strcmp(s_name(sa_namebuf), s_name(sb_namebuf));
	ret = strcmp(sym_name(sa), sym_name(sb));
	if (!ret) {
		if (sa->addr > sb->addr)
			return 1;
@@ -491,55 +397,6 @@ static void write_src(void)

	printf("\t.section .rodata, \"a\"\n");

	if (!base_relative)
		output_label("kallsyms_addresses");
	else
		output_label("kallsyms_offsets");

	for (i = 0; i < table_cnt; i++) {
		if (base_relative) {
			/*
			 * Use the offset relative to the lowest value
			 * encountered of all relative symbols, and emit
			 * non-relocatable fixed offsets that will be fixed
			 * up at runtime.
			 */

			long long offset;
			int overflow;

			if (!absolute_percpu) {
				offset = table[i]->addr - relative_base;
				overflow = (offset < 0 || offset > UINT_MAX);
			} else if (symbol_absolute(table[i])) {
				offset = table[i]->addr;
				overflow = (offset < 0 || offset > INT_MAX);
			} else {
				offset = relative_base - table[i]->addr - 1;
				overflow = (offset < INT_MIN || offset >= 0);
			}
			if (overflow) {
				fprintf(stderr, "kallsyms failure: "
					"%s symbol value %#llx out of range in relative mode\n",
					symbol_absolute(table[i]) ? "absolute" : "relative",
					table[i]->addr);
				exit(EXIT_FAILURE);
			}
			printf("\t.long\t%#x\n", (int)offset);
		} else if (!symbol_absolute(table[i])) {
			output_address(table[i]->addr);
		} else {
			printf("\tPTR\t%#llx\n", table[i]->addr);
		}
	}
	printf("\n");

	if (base_relative) {
		output_label("kallsyms_relative_base");
		output_address(relative_base);
		printf("\n");
	}

	output_label("kallsyms_num_syms");
	printf("\t.long\t%u\n", table_cnt);
	printf("\n");
@@ -592,6 +449,15 @@ static void write_src(void)
	}
	printf("\n");

	/*
	 * Now that we wrote out the compressed symbol names, restore the
	 * original names, which are needed in some of the later steps.
	 */
	for (i = 0; i < table_cnt; i++) {
		expand_symbol(table[i]->sym, table[i]->len, buf);
		strcpy((char *)table[i]->sym, buf);
	}

	output_label("kallsyms_markers");
	for (i = 0; i < ((table_cnt + 255) >> 8); i++)
		printf("\t.long\t%u\n", markers[i]);
@@ -599,15 +465,6 @@ static void write_src(void)

	free(markers);

	sort_symbols_by_name();
	output_label("kallsyms_seqs_of_names");
	for (i = 0; i < table_cnt; i++)
		printf("\t.byte 0x%02x, 0x%02x, 0x%02x\n",
			(unsigned char)(table[i]->seq >> 16),
			(unsigned char)(table[i]->seq >> 8),
			(unsigned char)(table[i]->seq >> 0));
	printf("\n");

	output_label("kallsyms_token_table");
	off = 0;
	for (i = 0; i < 256; i++) {
@@ -622,6 +479,68 @@ static void write_src(void)
	for (i = 0; i < 256; i++)
		printf("\t.short\t%d\n", best_idx[i]);
	printf("\n");

	if (!base_relative)
		output_label("kallsyms_addresses");
	else
		output_label("kallsyms_offsets");

	for (i = 0; i < table_cnt; i++) {
		if (base_relative) {
			/*
			 * Use the offset relative to the lowest value
			 * encountered of all relative symbols, and emit
			 * non-relocatable fixed offsets that will be fixed
			 * up at runtime.
			 */

			long long offset;
			int overflow;

			if (!absolute_percpu) {
				offset = table[i]->addr - relative_base;
				overflow = (offset < 0 || offset > UINT_MAX);
			} else if (symbol_absolute(table[i])) {
				offset = table[i]->addr;
				overflow = (offset < 0 || offset > INT_MAX);
			} else {
				offset = relative_base - table[i]->addr - 1;
				overflow = (offset < INT_MIN || offset >= 0);
			}
			if (overflow) {
				fprintf(stderr, "kallsyms failure: "
					"%s symbol value %#llx out of range in relative mode\n",
					symbol_absolute(table[i]) ? "absolute" : "relative",
					table[i]->addr);
				exit(EXIT_FAILURE);
			}
			printf("\t.long\t%#x	/* %s */\n", (int)offset, table[i]->sym);
		} else if (!symbol_absolute(table[i])) {
			output_address(table[i]->addr);
		} else {
			printf("\tPTR\t%#llx\n", table[i]->addr);
		}
	}
	printf("\n");

	if (base_relative) {
		output_label("kallsyms_relative_base");
		output_address(relative_base);
		printf("\n");
	}

	if (lto_clang)
		for (i = 0; i < table_cnt; i++)
			cleanup_symbol_name((char *)table[i]->sym);

	sort_symbols_by_name();
	output_label("kallsyms_seqs_of_names");
	for (i = 0; i < table_cnt; i++)
		printf("\t.byte 0x%02x, 0x%02x, 0x%02x\n",
			(unsigned char)(table[i]->seq >> 16),
			(unsigned char)(table[i]->seq >> 8),
			(unsigned char)(table[i]->seq >> 0));
	printf("\n");
}


Loading