All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections
@ 2016-08-11 10:16 Nicholas Piggin
  2016-08-11 10:16 ` [PATCH 1/6] kbuild: allow architectures to use thin archives instead of ld -r Nicholas Piggin
                   ` (10 more replies)
  0 siblings, 11 replies; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-11 10:16 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Nicholas Piggin, linux-arch, Michal Marek, Sam Ravnborg,
	Stephen Rothwell, Arnd Bergmann, Nicolas Pitre,
	Segher Boessenkool, Alan Modra

Hi,

I would like to submit the kbuild changes in patches 1-3 for
consideration.

I've taken on the feedback, so thanks everybody for that. The
biggest change since last time is a more general way for
architectures to do a post-link pass in patch 3.

On the question of whether to enable thin archives unconditionally,
I prefer to have architectures enable them as they are tested. But
I would like to see everybody moved as soon as possible and the
incremental linking removed.

All patches should be basically noops without arch enablement,
so I include initial powerpc enablement in patches 4-6 for
reference, but I will submit those via powerpc maintainer if
the kbuild changes are merged.

Thanks,
Nick

Nicholas Piggin (4):
  kbuild: allow archs to select build for link dead code/data
    elimination
  kbuild: add arch specific post-link pass
  powerpc/64: use linker dce
  powerpc: use the new post-link pass to check relocations

Stephen Rothwell (2):
  kbuild: allow architectures to use thin archives instead of ld -r
  powerpc: switch to using thin archives

 Documentation/kbuild/makefiles.txt     | 10 +++++
 Makefile                               |  9 ++++
 arch/Kconfig                           | 26 ++++++++++++
 arch/powerpc/Kconfig                   |  1 +
 arch/powerpc/Makefile                  | 17 ++------
 arch/powerpc/Makefile.postlink         | 31 ++++++++++++++
 arch/powerpc/kernel/Makefile           |  3 ++
 arch/powerpc/kernel/vmlinux.lds.S      |  2 +-
 arch/powerpc/platforms/Kconfig.cputype |  2 +
 arch/x86/entry/vdso/Makefile           |  6 +--
 include/asm-generic/vmlinux.lds.h      | 52 ++++++++++++-----------
 include/linux/compiler.h               | 23 +++++++++++
 include/linux/export.h                 | 30 +++++++-------
 include/linux/init.h                   | 38 ++++++-----------
 init/Makefile                          |  2 +
 kernel/Makefile                        |  3 --
 scripts/Makefile.build                 | 25 +++++++++---
 scripts/Makefile.modpost               |  3 ++
 scripts/link-vmlinux.sh                | 75 +++++++++++++++++++++++++++++-----
 19 files changed, 258 insertions(+), 100 deletions(-)
 create mode 100644 arch/powerpc/Makefile.postlink

-- 
2.8.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 1/6] kbuild: allow architectures to use thin archives instead of ld -r
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
@ 2016-08-11 10:16 ` Nicholas Piggin
  2016-08-11 10:16 ` [PATCH 2/6] kbuild: allow archs to select link dead code/data elimination Nicholas Piggin
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-11 10:16 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Nicholas Piggin, linux-arch, Michal Marek, Sam Ravnborg,
	Stephen Rothwell, Arnd Bergmann, Nicolas Pitre,
	Segher Boessenkool, Alan Modra

From: Stephen Rothwell <sfr@canb.auug.org.au>

ld -r is an incremental link used to create built-in.o files in build
subdirectories. It produces relocatable object files containing all
its input files, and these are are then pulled together and relocated
in the final link. Aside from the bloat, this constrains the final
link relocations, which has bitten large powerpc builds with
unresolvable relocations in the final link.

Alan Modra has recommended the kernel use thin archives for linking.
This is an alternative and means that the linker has more information
available to it when it links the kernel.

This patch enables a config option architectures can select, which
causes all built-in.o files to be built as thin archives. built-in.o
files in subdirectories do not get symbol table or index attached,
which improves speed and size. The final link pass creates a
built-in.o archive in the root output directory which includes the
symbol table and index. The linker then uses takes this file to link.

The --whole-archive linker option is required, because the linker now
has visibility to every individual object file, and it will otherwise
just completely avoid including those without external references
(consider a file with EXPORT_SYMBOL or initcall or hardware exceptions
as its only entry points). The traditional built works "by luck" as
built-in.o files are large enough that they're going to get external
references. However this optimisation is unpredictable for the kernel
(due to above external references), ineffective at culling unused, and
costly because the .o files have to be searched for references.
Superior alternatives for link-time culling should be used instead.

Build characteristics for inclink vs thinarc, on a small powerpc64le
pseries VM with a modest .config:

                                  inclink       thinarc
sizes
vmlinux                        15 618 680    15 625 028
sum of all built-in.o          56 091 808     1 054 334
sum excluding root built-in.o                   151 430

find -name built-in.o | xargs rm ; time make vmlinux
real                              22.772s       21.143s
user                              13.280s       13.430s
sys                                4.310s        2.750s

- Final kernel pulled in only about 6K more, which shows how
  ineffective the object file culling is.
- Build performance looks improved due to less pagecache activity.
  On IO constrained systems it could be a bigger win.
- Build size saving is significant.

Side note, the toochain understands archives, so there's some tricks,
$ ar t built-in.o          # list all files you linked with
$ size built-in.o          # and their sizes
$ objdump -d built-in.o    # disassembly (unrelocated) with filenames

Implementation by sfr, minor tweaks by npiggin.

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
Changes since v1
- Fixed um build breakage
- Fixed linking against lib.a archives (add symbol table)
- Tested x86 builds
- Tested arm64 defconfig thin archives cross compile
  inclinc - 385s 2.7GB; thinarc - 377s 1.8G

 arch/Kconfig            |  6 +++++
 scripts/Makefile.build  | 23 +++++++++++++---
 scripts/link-vmlinux.sh | 71 +++++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 85 insertions(+), 15 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index e9c9334..02df9be 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -461,6 +461,12 @@ config CC_STACKPROTECTOR_STRONG
 
 endchoice
 
+config THIN_ARCHIVES
+	bool
+	help
+	  Select this if the architecture wants to use thin archives
+	  instead of ld -r to create the built-in.o files.
+
 config HAVE_ARCH_WITHIN_STACK_FRAMES
 	bool
 	help
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 11602e5..7ce183f 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -358,12 +358,22 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ;
 # Rule to compile a set of .o files into one .o file
 #
 ifdef builtin-target
-quiet_cmd_link_o_target = LD      $@
+
+ifdef CONFIG_THIN_ARCHIVES
+  cmd_make_builtin = rm -f $@; $(AR) rcST$(KBUILD_ARFLAGS)
+  cmd_make_empty_builtin = rm -f $@; $(AR) rcST$(KBUILD_ARFLAGS)
+  quiet_cmd_link_o_target = AR      $@
+else
+  cmd_make_builtin = $(LD) $(ld_flags) -r -o
+  cmd_make_empty_builtin = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS)
+  quiet_cmd_link_o_target = LD      $@
+endif
+
 # If the list of objects to link is empty, just create an empty built-in.o
 cmd_link_o_target = $(if $(strip $(obj-y)),\
-		      $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \
+		      $(cmd_make_builtin) $@ $(filter $(obj-y), $^) \
 		      $(cmd_secanalysis),\
-		      rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@)
+		      $(cmd_make_empty_builtin) $@)
 
 $(builtin-target): $(obj-y) FORCE
 	$(call if_changed,link_o_target)
@@ -389,7 +399,12 @@ $(modorder-target): $(subdir-ym) FORCE
 #
 ifdef lib-target
 quiet_cmd_link_l_target = AR      $@
-cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y)
+
+ifdef CONFIG_THIN_ARCHIVES
+  cmd_link_l_target = rm -f $@; $(AR) rcT$(KBUILD_ARFLAGS) $@ $(lib-y)
+else
+  cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y)
+endif
 
 $(lib-target): $(lib-y) FORCE
 	$(call if_changed,link_l_target)
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 4f727eb..f742c65 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -37,12 +37,40 @@ info()
 	fi
 }
 
+# Thin archive build here makes a final archive with
+# symbol table and indexes from vmlinux objects, which can be
+# used as input to linker.
+#
+# Traditional incremental style of link does not require this step
+#
+# built-in.o output file
+#
+archive_builtin()
+{
+	if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
+		info AR built-in.o
+		rm -f built-in.o;
+		${AR} rcsT${KBUILD_ARFLAGS} built-in.o			\
+					${KBUILD_VMLINUX_INIT}		\
+					${KBUILD_VMLINUX_MAIN}
+	fi
+}
+
 # Link of vmlinux.o used for section mismatch analysis
 # ${1} output file
 modpost_link()
 {
-	${LD} ${LDFLAGS} -r -o ${1} ${KBUILD_VMLINUX_INIT}                   \
-		--start-group ${KBUILD_VMLINUX_MAIN} --end-group
+	local objects
+
+	if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
+		objects="--whole-archive built-in.o"
+	else
+		objects="${KBUILD_VMLINUX_INIT}				\
+			--start-group					\
+			${KBUILD_VMLINUX_MAIN}				\
+			--end-group"
+	fi
+	${LD} ${LDFLAGS} -r -o ${1} ${objects}
 }
 
 # Link of vmlinux
@@ -51,18 +79,36 @@ modpost_link()
 vmlinux_link()
 {
 	local lds="${objtree}/${KBUILD_LDS}"
+	local objects
 
 	if [ "${SRCARCH}" != "um" ]; then
-		${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2}                  \
-			-T ${lds} ${KBUILD_VMLINUX_INIT}                     \
-			--start-group ${KBUILD_VMLINUX_MAIN} --end-group ${1}
+		if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
+			objects="--whole-archive built-in.o ${1}"
+		else
+			objects="${KBUILD_VMLINUX_INIT}			\
+				--start-group				\
+				${KBUILD_VMLINUX_MAIN}			\
+				--end-group				\
+				${1}"
+		fi
+
+		${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2}		\
+			-T ${lds} ${objects}
 	else
-		${CC} ${CFLAGS_vmlinux} -o ${2}                              \
-			-Wl,-T,${lds} ${KBUILD_VMLINUX_INIT}                 \
-			-Wl,--start-group                                    \
-				 ${KBUILD_VMLINUX_MAIN}                      \
-			-Wl,--end-group                                      \
-			-lutil -lrt -lpthread ${1}
+		if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
+			objects="-Wl,--whole-archive built-in.o ${1}"
+		else
+			objects="${KBUILD_VMLINUX_INIT}			\
+				-Wl,--start-group			\
+				${KBUILD_VMLINUX_MAIN}			\
+				-Wl,--end-group				\
+				${1}"
+		fi
+
+		${CC} ${CFLAGS_vmlinux} -o ${2}				\
+			-Wl,-T,${lds}					\
+			${objects}					\
+			-lutil -lrt -lpthread
 		rm -f linux
 	fi
 }
@@ -119,6 +165,7 @@ cleanup()
 	rm -f .tmp_kallsyms*
 	rm -f .tmp_version
 	rm -f .tmp_vmlinux*
+	rm -f built-in.o
 	rm -f System.map
 	rm -f vmlinux
 	rm -f vmlinux.o
@@ -162,6 +209,8 @@ case "${KCONFIG_CONFIG}" in
 	. "./${KCONFIG_CONFIG}"
 esac
 
+archive_builtin
+
 #link vmlinux.o
 info LD vmlinux.o
 modpost_link vmlinux.o
-- 
2.8.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 2/6] kbuild: allow archs to select link dead code/data elimination
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
  2016-08-11 10:16 ` [PATCH 1/6] kbuild: allow architectures to use thin archives instead of ld -r Nicholas Piggin
@ 2016-08-11 10:16 ` Nicholas Piggin
  2016-08-11 10:16 ` [PATCH 3/6] kbuild: add arch specific post-link pass Nicholas Piggin
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-11 10:16 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Nicholas Piggin, linux-arch, Michal Marek, Sam Ravnborg,
	Stephen Rothwell, Arnd Bergmann, Nicolas Pitre,
	Segher Boessenkool, Alan Modra

Introduce LD_DEAD_CODE_DATA_ELIMINATION option for architectures to
select to build with -ffunction-sections, -fdata-sections, and link
with --gc-sections. It requires some work (documented) to ensure all
unreferenced entrypoints are live, and requires toolchain and build
verification, so it is made a per-arch option for now.

On a random powerpc64le build, this yelds a significant size saving,
it boots and runs fine, but there is a lot I haven't tested as yet, so
these savings may be reduced if there are bugs in the link.

    text      data        bss        dec   filename
11169741   1180744    1923176	14273661   vmlinux
10445269   1004127    1919707	13369103   vmlinux.dce

~700K text, ~170K data, 6% removed from kernel image size.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
Since v1
- More descriptive config option name
- Improve some comments
- Tested x86 builds, boot in KVM

 Makefile                          |  9 +++++++
 arch/Kconfig                      | 13 ++++++++++
 arch/x86/entry/vdso/Makefile      |  6 ++---
 include/asm-generic/vmlinux.lds.h | 52 ++++++++++++++++++++++-----------------
 include/linux/compiler.h          | 23 +++++++++++++++++
 include/linux/export.h            | 30 +++++++++++-----------
 include/linux/init.h              | 38 ++++++++++------------------
 init/Makefile                     |  2 ++
 kernel/Makefile                   |  3 ---
 scripts/Makefile.build            |  2 +-
 10 files changed, 107 insertions(+), 71 deletions(-)

diff --git a/Makefile b/Makefile
index 8c504f3..1d26fdb 100644
--- a/Makefile
+++ b/Makefile
@@ -622,6 +622,11 @@ include arch/$(SRCARCH)/Makefile
 KBUILD_CFLAGS	+= $(call cc-option,-fno-delete-null-pointer-checks,)
 KBUILD_CFLAGS	+= $(call cc-disable-warning,maybe-uninitialized,)
 
+ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
+KBUILD_CFLAGS	+= $(call cc-option,-ffunction-sections,)
+KBUILD_CFLAGS	+= $(call cc-option,-fdata-sections,)
+endif
+
 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
 KBUILD_CFLAGS	+= -Os
 else
@@ -802,6 +807,10 @@ LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\
 KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
 LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
 
+ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
+LDFLAGS_vmlinux	+= $(call ld-option, --gc-sections,)
+endif
+
 ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
 LDFLAGS_vmlinux	+= $(call ld-option, -X,)
 endif
diff --git a/arch/Kconfig b/arch/Kconfig
index 02df9be..fc3f9e1 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -467,6 +467,19 @@ config THIN_ARCHIVES
 	  Select this if the architecture wants to use thin archives
 	  instead of ld -r to create the built-in.o files.
 
+config LD_DEAD_CODE_DATA_ELIMINATION
+	bool
+	help
+	  Select this if the architecture wants to do dead code and
+	  data elimination with the linker by compiling with
+	  -ffunction-sections -fdata-sections and linking with
+	  --gc-sections.
+
+	  This requires that the arch annotates or otherwise protects
+	  its external entry points from being discarded. Linker scripts
+	  must also merge .text.*, .data.*, and .bss.* correctly into
+	  output sections.
+
 config HAVE_ARCH_WITHIN_STACK_FRAMES
 	bool
 	help
diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
index d540966..5832225 100644
--- a/arch/x86/entry/vdso/Makefile
+++ b/arch/x86/entry/vdso/Makefile
@@ -2,7 +2,6 @@
 # Building vDSO images for x86.
 #
 
-KBUILD_CFLAGS += $(DISABLE_LTO)
 KASAN_SANITIZE			:= n
 UBSAN_SANITIZE			:= n
 OBJECT_FILES_NON_STANDARD	:= y
@@ -49,8 +48,7 @@ export CPPFLAGS_vdso.lds += -P -C
 
 VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
 			-Wl,--no-undefined \
-			-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \
-			$(DISABLE_LTO)
+			-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
 
 $(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
 	$(call if_changed,vdso)
@@ -171,7 +169,7 @@ quiet_cmd_vdso = VDSO    $@
 		 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
 
 VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=both) \
-	$(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
+	$(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic
 GCOV_PROFILE := n
 
 #
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 2456397..ad9d8f9 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -196,9 +196,14 @@
 	*(.dtb.init.rodata)						\
 	VMLINUX_SYMBOL(__dtb_end) = .;
 
-/* .data section */
+/*
+ * .data section
+ * -fdata-sections generates .data.identifier which needs to be pulled in
+ * with .data, but don't want to pull in .data..stuff which has its own
+ * requirements. Same for bss.
+ */
 #define DATA_DATA							\
-	*(.data)							\
+	*(.data .data.[0-9a-zA-Z_]*)					\
 	*(.ref.data)							\
 	*(.data..shared_aligned) /* percpu related */			\
 	MEM_KEEP(init.data)						\
@@ -320,76 +325,76 @@
 	/* Kernel symbol table: Normal symbols */			\
 	__ksymtab         : AT(ADDR(__ksymtab) - LOAD_OFFSET) {		\
 		VMLINUX_SYMBOL(__start___ksymtab) = .;			\
-		*(SORT(___ksymtab+*))					\
+		KEEP(*(SORT(___ksymtab+*)))				\
 		VMLINUX_SYMBOL(__stop___ksymtab) = .;			\
 	}								\
 									\
 	/* Kernel symbol table: GPL-only symbols */			\
 	__ksymtab_gpl     : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) {	\
 		VMLINUX_SYMBOL(__start___ksymtab_gpl) = .;		\
-		*(SORT(___ksymtab_gpl+*))				\
+		KEEP(*(SORT(___ksymtab_gpl+*)))				\
 		VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .;		\
 	}								\
 									\
 	/* Kernel symbol table: Normal unused symbols */		\
 	__ksymtab_unused  : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) {	\
 		VMLINUX_SYMBOL(__start___ksymtab_unused) = .;		\
-		*(SORT(___ksymtab_unused+*))				\
+		KEEP(*(SORT(___ksymtab_unused+*)))			\
 		VMLINUX_SYMBOL(__stop___ksymtab_unused) = .;		\
 	}								\
 									\
 	/* Kernel symbol table: GPL-only unused symbols */		\
 	__ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
 		VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .;	\
-		*(SORT(___ksymtab_unused_gpl+*))			\
+		KEEP(*(SORT(___ksymtab_unused_gpl+*)))			\
 		VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .;	\
 	}								\
 									\
 	/* Kernel symbol table: GPL-future-only symbols */		\
 	__ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
 		VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .;	\
-		*(SORT(___ksymtab_gpl_future+*))			\
+		KEEP(*(SORT(___ksymtab_gpl_future+*)))			\
 		VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .;	\
 	}								\
 									\
 	/* Kernel symbol table: Normal symbols */			\
 	__kcrctab         : AT(ADDR(__kcrctab) - LOAD_OFFSET) {		\
 		VMLINUX_SYMBOL(__start___kcrctab) = .;			\
-		*(SORT(___kcrctab+*))					\
+		KEEP(*(SORT(___kcrctab+*)))				\
 		VMLINUX_SYMBOL(__stop___kcrctab) = .;			\
 	}								\
 									\
 	/* Kernel symbol table: GPL-only symbols */			\
 	__kcrctab_gpl     : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) {	\
 		VMLINUX_SYMBOL(__start___kcrctab_gpl) = .;		\
-		*(SORT(___kcrctab_gpl+*))				\
+		KEEP(*(SORT(___kcrctab_gpl+*)))				\
 		VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .;		\
 	}								\
 									\
 	/* Kernel symbol table: Normal unused symbols */		\
 	__kcrctab_unused  : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) {	\
 		VMLINUX_SYMBOL(__start___kcrctab_unused) = .;		\
-		*(SORT(___kcrctab_unused+*))				\
+		KEEP(*(SORT(___kcrctab_unused+*)))			\
 		VMLINUX_SYMBOL(__stop___kcrctab_unused) = .;		\
 	}								\
 									\
 	/* Kernel symbol table: GPL-only unused symbols */		\
 	__kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \
 		VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .;	\
-		*(SORT(___kcrctab_unused_gpl+*))			\
+		KEEP(*(SORT(___kcrctab_unused_gpl+*)))			\
 		VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .;	\
 	}								\
 									\
 	/* Kernel symbol table: GPL-future-only symbols */		\
 	__kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
 		VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .;	\
-		*(SORT(___kcrctab_gpl_future+*))			\
+		KEEP(*(SORT(___kcrctab_gpl_future+*)))			\
 		VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .;	\
 	}								\
 									\
 	/* Kernel symbol table: strings */				\
         __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) {	\
-		*(__ksymtab_strings)					\
+		KEEP(*(__ksymtab_strings))				\
 	}								\
 									\
 	/* __*init sections */						\
@@ -424,7 +429,7 @@
 #define SECURITY_INIT							\
 	.security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
 		VMLINUX_SYMBOL(__security_initcall_start) = .;		\
-		*(.security_initcall.init) 				\
+		KEEP(*(.security_initcall.init))			\
 		VMLINUX_SYMBOL(__security_initcall_end) = .;		\
 	}
 
@@ -432,7 +437,7 @@
  * during second ld run in second ld pass when generating System.map */
 #define TEXT_TEXT							\
 		ALIGN_FUNCTION();					\
-		*(.text.hot .text .text.fixup .text.unlikely)		\
+		*(.text.hot .text .text.fixup .text.unlikely .text.*)	\
 		*(.ref.text)						\
 	MEM_KEEP(init.text)						\
 	MEM_KEEP(exit.text)						\
@@ -527,6 +532,7 @@
 
 /* init and exit section handling */
 #define INIT_DATA							\
+	KEEP(*(SORT(___kentry+*)))					\
 	*(.init.data)							\
 	MEM_DISCARD(init.data)						\
 	KERNEL_CTORS()							\
@@ -593,7 +599,7 @@
 		BSS_FIRST_SECTIONS					\
 		*(.bss..page_aligned)					\
 		*(.dynbss)						\
-		*(.bss)							\
+		*(.bss .bss.[0-9a-zA-Z_]*)				\
 		*(COMMON)						\
 	}
 
@@ -676,12 +682,12 @@
 
 #define INIT_CALLS_LEVEL(level)						\
 		VMLINUX_SYMBOL(__initcall##level##_start) = .;		\
-		*(.initcall##level##.init)				\
-		*(.initcall##level##s.init)				\
+		KEEP(*(.initcall##level##.init))			\
+		KEEP(*(.initcall##level##s.init))			\
 
 #define INIT_CALLS							\
 		VMLINUX_SYMBOL(__initcall_start) = .;			\
-		*(.initcallearly.init)					\
+		KEEP(*(.initcallearly.init))				\
 		INIT_CALLS_LEVEL(0)					\
 		INIT_CALLS_LEVEL(1)					\
 		INIT_CALLS_LEVEL(2)					\
@@ -695,21 +701,21 @@
 
 #define CON_INITCALL							\
 		VMLINUX_SYMBOL(__con_initcall_start) = .;		\
-		*(.con_initcall.init)					\
+		KEEP(*(.con_initcall.init))				\
 		VMLINUX_SYMBOL(__con_initcall_end) = .;
 
 #define SECURITY_INITCALL						\
 		VMLINUX_SYMBOL(__security_initcall_start) = .;		\
-		*(.security_initcall.init)				\
+		KEEP(*(.security_initcall.init))			\
 		VMLINUX_SYMBOL(__security_initcall_end) = .;
 
 #ifdef CONFIG_BLK_DEV_INITRD
 #define INIT_RAM_FS							\
 	. = ALIGN(4);							\
 	VMLINUX_SYMBOL(__initramfs_start) = .;				\
-	*(.init.ramfs)							\
+	KEEP(*(.init.ramfs))						\
 	. = ALIGN(8);							\
-	*(.init.ramfs.info)
+	KEEP(*(.init.ramfs.info))
 #else
 #define INIT_RAM_FS
 #endif
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 1bb9548..86130cd 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -182,6 +182,29 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
 # define unreachable() do { } while (1)
 #endif
 
+/*
+ * KENTRY - kernel entry point
+ * This can be used to annotate symbols (functions or data) that are used
+ * without their linker symbol being referenced explicitly. For example,
+ * interrupt vector handlers, or functions in the kernel image that are found
+ * programatically.
+ *
+ * Not required for symbols exported with EXPORT_SYMBOL, or initcalls. Those
+ * are handled in their own way (with KEEP() in linker scripts).
+ *
+ * KENTRY can be avoided if the symbols in question are marked as KEEP() in the
+ * linker script. For example an architecture could KEEP() its entire
+ * boot/exception vector code rather than annotate each function and data.
+ */
+#ifndef KENTRY
+# define KENTRY(sym)						\
+	extern typeof(sym) sym;					\
+	static const unsigned long __kentry_##sym		\
+	__used							\
+	__attribute__((section("___kentry" "+" #sym ), used))	\
+	= (unsigned long)&sym;
+#endif
+
 #ifndef RELOC_HIDE
 # define RELOC_HIDE(ptr, off)					\
   ({ unsigned long __ptr;					\
diff --git a/include/linux/export.h b/include/linux/export.h
index c565f87..337cb90 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -1,5 +1,6 @@
 #ifndef _LINUX_EXPORT_H
 #define _LINUX_EXPORT_H
+
 /*
  * Export symbols from the kernel to modules.  Forked from module.h
  * to reduce the amount of pointless cruft we feed to gcc when only
@@ -42,27 +43,26 @@ extern struct module __this_module;
 #ifdef CONFIG_MODVERSIONS
 /* Mark the CRC weak since genksyms apparently decides not to
  * generate a checksums for some symbols */
-#define __CRC_SYMBOL(sym, sec)					\
-	extern __visible void *__crc_##sym __attribute__((weak));		\
-	static const unsigned long __kcrctab_##sym		\
-	__used							\
-	__attribute__((section("___kcrctab" sec "+" #sym), unused))	\
+#define __CRC_SYMBOL(sym, sec)						\
+	extern __visible void *__crc_##sym __attribute__((weak));	\
+	static const unsigned long __kcrctab_##sym			\
+	__used								\
+	__attribute__((section("___kcrctab" sec "+" #sym), used))	\
 	= (unsigned long) &__crc_##sym;
 #else
 #define __CRC_SYMBOL(sym, sec)
 #endif
 
 /* For every exported symbol, place a struct in the __ksymtab section */
-#define ___EXPORT_SYMBOL(sym, sec)				\
-	extern typeof(sym) sym;					\
-	__CRC_SYMBOL(sym, sec)					\
-	static const char __kstrtab_##sym[]			\
-	__attribute__((section("__ksymtab_strings"), aligned(1))) \
-	= VMLINUX_SYMBOL_STR(sym);				\
-	extern const struct kernel_symbol __ksymtab_##sym;	\
-	__visible const struct kernel_symbol __ksymtab_##sym	\
-	__used							\
-	__attribute__((section("___ksymtab" sec "+" #sym), unused))	\
+#define ___EXPORT_SYMBOL(sym, sec)					\
+	extern typeof(sym) sym;						\
+	__CRC_SYMBOL(sym, sec)						\
+	static const char __kstrtab_##sym[]				\
+	__attribute__((section("__ksymtab_strings"), aligned(1)))	\
+	= VMLINUX_SYMBOL_STR(sym);					\
+	static const struct kernel_symbol __ksymtab_##sym		\
+	__used								\
+	__attribute__((section("___ksymtab" sec "+" #sym), used))	\
 	= { (unsigned long)&sym, __kstrtab_##sym }
 
 #if defined(__KSYM_DEPS__)
diff --git a/include/linux/init.h b/include/linux/init.h
index 6935d02..e571fec 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -150,24 +150,8 @@ extern bool initcall_debug;
 
 #ifndef __ASSEMBLY__
 
-#ifdef CONFIG_LTO
-/* Work around a LTO gcc problem: when there is no reference to a variable
- * in a module it will be moved to the end of the program. This causes
- * reordering of initcalls which the kernel does not like.
- * Add a dummy reference function to avoid this. The function is
- * deleted by the linker.
- */
-#define LTO_REFERENCE_INITCALL(x) \
-	; /* yes this is needed */			\
-	static __used __exit void *reference_##x(void)	\
-	{						\
-		return &x;				\
-	}
-#else
-#define LTO_REFERENCE_INITCALL(x)
-#endif
-
-/* initcalls are now grouped by functionality into separate 
+/*
+ * initcalls are now grouped by functionality into separate
  * subsections. Ordering inside the subsections is determined
  * by link order. 
  * For backwards compatibility, initcall() puts the call in 
@@ -175,12 +159,16 @@ extern bool initcall_debug;
  *
  * The `id' arg to __define_initcall() is needed so that multiple initcalls
  * can point at the same handler without causing duplicate-symbol build errors.
+ *
+ * Initcalls are run by placing pointers in initcall sections that the
+ * kernel iterates at runtime. The linker can do dead code / data elimination
+ * and remove that completely, so the initcall sections have to be marked
+ * as KEEP() in the linker script.
  */
 
 #define __define_initcall(fn, id) \
 	static initcall_t __initcall_##fn##id __used \
-	__attribute__((__section__(".initcall" #id ".init"))) = fn; \
-	LTO_REFERENCE_INITCALL(__initcall_##fn##id)
+	__attribute__((__section__(".initcall" #id ".init"))) = fn;
 
 /*
  * Early initcalls run before initializing SMP.
@@ -216,15 +204,15 @@ extern bool initcall_debug;
 
 #define __initcall(fn) device_initcall(fn)
 
-#define __exitcall(fn) \
+#define __exitcall(fn)						\
 	static exitcall_t __exitcall_##fn __exit_call = fn
 
-#define console_initcall(fn) \
-	static initcall_t __initcall_##fn \
+#define console_initcall(fn)					\
+	static initcall_t __initcall_##fn			\
 	__used __section(.con_initcall.init) = fn
 
-#define security_initcall(fn) \
-	static initcall_t __initcall_##fn \
+#define security_initcall(fn)					\
+	static initcall_t __initcall_##fn			\
 	__used __section(.security_initcall.init) = fn
 
 struct obs_kernel_param {
diff --git a/init/Makefile b/init/Makefile
index 7bc47ee..c4fb455 100644
--- a/init/Makefile
+++ b/init/Makefile
@@ -2,6 +2,8 @@
 # Makefile for the linux kernel.
 #
 
+ccflags-y := -fno-function-sections -fno-data-sections
+
 obj-y                          := main.o version.o mounts.o
 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
 obj-y                          += noinitramfs.o
diff --git a/kernel/Makefile b/kernel/Makefile
index e2ec54e..f80ce82 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -29,9 +29,6 @@ KCOV_INSTRUMENT_extable.o := n
 KCOV_INSTRUMENT_kcov.o := n
 KASAN_SANITIZE_kcov.o := n
 
-# cond_syscall is currently not LTO compatible
-CFLAGS_sys_ni.o = $(DISABLE_LTO)
-
 obj-y += sched/
 obj-y += locking/
 obj-y += power/
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 7ce183f..83f304e 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -147,7 +147,7 @@ $(multi-objs-y:.o=.s)   : modname = $(modname-multi)
 $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
 
 quiet_cmd_cc_s_c = CC $(quiet_modtag)  $@
-cmd_cc_s_c       = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
+cmd_cc_s_c       = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
 
 $(obj)/%.s: $(src)/%.c FORCE
 	$(call if_changed_dep,cc_s_c)
-- 
2.8.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 3/6] kbuild: add arch specific post-link pass
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
  2016-08-11 10:16 ` [PATCH 1/6] kbuild: allow architectures to use thin archives instead of ld -r Nicholas Piggin
  2016-08-11 10:16 ` [PATCH 2/6] kbuild: allow archs to select link dead code/data elimination Nicholas Piggin
@ 2016-08-11 10:16 ` Nicholas Piggin
  2016-08-16  9:23   ` Michal Marek
  2016-08-11 10:16 ` [PATCH 4/6] powerpc: switch to using thin archives Nicholas Piggin
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-11 10:16 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Nicholas Piggin, linux-arch, Michal Marek, Sam Ravnborg,
	Stephen Rothwell, Arnd Bergmann, Nicolas Pitre,
	Segher Boessenkool, Alan Modra

Add an option for architectures to pass over modules after they are
linked. powerpc will use this to check linker relocations for sanity,
and possibly to fix up alternate instruction patch relocations.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
Since v1,
- Switched to a more flexible arch makefile invocation.
- Provide a powerpc patch to use it to help existing build issue
  (rather than only justification being out-of-tree patch).

 Documentation/kbuild/makefiles.txt | 10 ++++++++++
 arch/Kconfig                       |  7 +++++++
 scripts/Makefile.modpost           |  3 +++
 scripts/link-vmlinux.sh            |  4 ++++
 4 files changed, 24 insertions(+)

diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 385a5ef..8581e38 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -41,6 +41,7 @@ This document describes the Linux kernel Makefiles.
 	   --- 6.8 Custom kbuild commands
 	   --- 6.9 Preprocessing linker scripts
 	   --- 6.10 Generic header files
+	   --- 6.11 Post-link pass
 
 	=== 7 Kbuild syntax for exported headers
 		--- 7.1 header-y
@@ -1237,6 +1238,15 @@ When kbuild executes, the following steps are followed (roughly):
 	to list the file in the Kbuild file.
 	See "7.4 generic-y" for further info on syntax etc.
 
+--- 6.11 Post-link pass
+
+	CONFIG_BUILD_ARCH_POSTLINK can be selected in order to have
+	arch/?/Makefile.postlink invoked on vmlinux and module.ko
+	files after final link.
+
+	For example, powerpc uses this to check relocations on the
+	linked vmlinux file.
+
 === 7 Kbuild syntax for exported headers
 
 The kernel includes a set of headers that is exported to userspace.
diff --git a/arch/Kconfig b/arch/Kconfig
index fc3f9e1..3a36ea8 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -461,6 +461,13 @@ config CC_STACKPROTECTOR_STRONG
 
 endchoice
 
+config BUILD_ARCH_POSTLINK
+	bool
+	help
+	  Select this if the architecture wants to have a Makefile invoked
+	  on modules and vmlinux after they are linked. The architecture
+	  must provide arch/?/Makefile.postlink
+
 config THIN_ARCHIVES
 	bool
 	help
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 1366a94..1acaa20 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -123,6 +123,9 @@ quiet_cmd_ld_ko_o = LD [M]  $@
 
 $(modules): %.ko :%.o %.mod.o FORCE
 	$(call if_changed,ld_ko_o)
+ifdef CONFIG_BUILD_ARCH_POSTLINK
+	$(Q)$(MAKE) -f $(srctree)/arch/$(SRCARCH)/Makefile.postlink $@
+endif
 
 targets += $(modules)
 
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index f742c65..ec84b33 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -279,6 +279,10 @@ fi
 info LD vmlinux
 vmlinux_link "${kallsymso}" vmlinux
 
+if [ -n "${CONFIG_BUILD_ARCH_POSTLINK}" ]; then
+	${MAKE} -f ${srctree}/arch/${SRCARCH}/Makefile.postlink vmlinux
+fi
+
 if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then
 	info SORTEX vmlinux
 	sortextable vmlinux
-- 
2.8.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 4/6] powerpc: switch to using thin archives
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
                   ` (2 preceding siblings ...)
  2016-08-11 10:16 ` [PATCH 3/6] kbuild: add arch specific post-link pass Nicholas Piggin
@ 2016-08-11 10:16 ` Nicholas Piggin
  2016-08-11 10:16 ` [PATCH 5/6] powerpc/64: use linker dead code elimination Nicholas Piggin
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-11 10:16 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Nicholas Piggin, linux-arch, Michal Marek, Sam Ravnborg,
	Stephen Rothwell, Arnd Bergmann, Nicolas Pitre,
	Segher Boessenkool, Alan Modra

From: Stephen Rothwell <sfr@canb.auug.org.au>

Some change to the way we invoke ar is required so it can be used
by scripts/link-vmlinux.sh

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Makefile                  | 6 ++++--
 arch/powerpc/platforms/Kconfig.cputype | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index ca25454..04a1332 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -23,7 +23,8 @@ CROSS32AR		:= $(CROSS32_COMPILE)ar
 ifeq ($(HAS_BIARCH),y)
 ifeq ($(CROSS32_COMPILE),)
 CROSS32CC	:= $(CC) -m32
-CROSS32AR	:= GNUTARGET=elf32-powerpc $(AR)
+CROSS32AR	:= $(AR)
+KBUILD_ARFLAGS	+= --target elf32-powerpc
 endif
 endif
 
@@ -93,7 +94,8 @@ ifeq ($(HAS_BIARCH),y)
 override AS	+= -a$(CONFIG_WORD_SIZE)
 override LD	+= -m elf$(CONFIG_WORD_SIZE)$(LDEMULATION)
 override CC	+= -m$(CONFIG_WORD_SIZE)
-override AR	:= GNUTARGET=elf$(CONFIG_WORD_SIZE)-$(GNUTARGET) $(AR)
+override AR	:= $(AR)
+KBUILD_ARFLAGS	+= --target elf$(CONFIG_WORD_SIZE)-$(GNUTARGET)
 endif
 
 LDFLAGS_vmlinux-y := -Bstatic
diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
index f32edec..b5fc6cb 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -1,6 +1,7 @@
 config PPC64
 	bool "64-bit kernel"
 	default n
+	select THIN_ARCHIVES
 	select ZLIB_DEFLATE
 	help
 	  This option selects whether a 32-bit or a 64-bit kernel
-- 
2.8.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 5/6] powerpc/64: use linker dead code elimination
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
                   ` (3 preceding siblings ...)
  2016-08-11 10:16 ` [PATCH 4/6] powerpc: switch to using thin archives Nicholas Piggin
@ 2016-08-11 10:16 ` Nicholas Piggin
  2016-08-11 10:16 ` [PATCH 6/6] powerpc: use the new post-link pass to check relocations Nicholas Piggin
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-11 10:16 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Nicholas Piggin, linux-arch, Michal Marek, Sam Ravnborg,
	Stephen Rothwell, Arnd Bergmann, Nicolas Pitre,
	Segher Boessenkool, Alan Modra

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/Makefile           | 3 +++
 arch/powerpc/kernel/vmlinux.lds.S      | 2 +-
 arch/powerpc/platforms/Kconfig.cputype | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index b2027a5..974a068 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -4,7 +4,10 @@
 
 CFLAGS_ptrace.o		+= -DUTS_MACHINE='"$(UTS_MACHINE)"'
 
+ccflags-y		+= -fno-function-sections -fno-data-sections
+
 subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror
+subdir-ccflags-y	+= -fno-function-sections -fno-data-sections
 
 ifeq ($(CONFIG_PPC64),y)
 CFLAGS_prom_init.o	+= $(NO_MINIMAL_TOC)
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index b5fba68..baad2af 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -50,7 +50,7 @@ SECTIONS
 		HEAD_TEXT
 		_text = .;
 		/* careful! __ftr_alt_* sections need to be close to .text */
-		*(.text .fixup __ftr_alt_* .ref.text)
+		*(.text .text.* .fixup __ftr_alt_* .ref.text)
 		SCHED_TEXT
 		LOCK_TEXT
 		KPROBES_TEXT
diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
index b5fc6cb..59c9097 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -2,6 +2,7 @@ config PPC64
 	bool "64-bit kernel"
 	default n
 	select THIN_ARCHIVES
+	select LD_DEAD_CODE_DATA_ELIMINATION
 	select ZLIB_DEFLATE
 	help
 	  This option selects whether a 32-bit or a 64-bit kernel
-- 
2.8.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 6/6] powerpc: use the new post-link pass to check relocations
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
                   ` (4 preceding siblings ...)
  2016-08-11 10:16 ` [PATCH 5/6] powerpc/64: use linker dead code elimination Nicholas Piggin
@ 2016-08-11 10:16 ` Nicholas Piggin
  2016-08-11 12:31 ` [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Stephen Rothwell
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-11 10:16 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Nicholas Piggin, linux-arch, Michal Marek, Sam Ravnborg,
	Stephen Rothwell, Arnd Bergmann, Nicolas Pitre,
	Segher Boessenkool, Alan Modra

Currently powerpc has to introduce a dependency on its default
build target zImage in order to run a relocation check pass
over the linked vmlinux. This is deficient because the check
is not run if the plain vmlinux target is built, or if one of
the other boot targets is built.

Switch to using the kbuild post-link pass in order to run this
check. In future powerpc will use this to do more complicated
operations, but initially using it for something simple is a
good first step.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Kconfig           |  1 +
 arch/powerpc/Makefile          | 11 -----------
 arch/powerpc/Makefile.postlink | 31 +++++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 11 deletions(-)
 create mode 100644 arch/powerpc/Makefile.postlink

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 927d2ab..74be094 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -85,6 +85,7 @@ config ARCH_HAS_DMA_SET_COHERENT_MASK
 config PPC
 	bool
 	default y
+	select BUILD_ARCH_POSTLINK
 	select ARCH_MIGHT_HAVE_PC_PARPORT
 	select ARCH_MIGHT_HAVE_PC_SERIO
 	select BINFMT_ELF
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 04a1332..e7e0f5e 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -270,17 +270,6 @@ PHONY += $(BOOT_TARGETS1) $(BOOT_TARGETS2)
 
 boot := arch/$(ARCH)/boot
 
-ifeq ($(CONFIG_RELOCATABLE),y)
-quiet_cmd_relocs_check = CALL    $<
-      cmd_relocs_check = $(CONFIG_SHELL) $< "$(OBJDUMP)" "$(obj)/vmlinux"
-
-PHONY += relocs_check
-relocs_check: arch/powerpc/relocs_check.sh vmlinux
-	$(call cmd,relocs_check)
-
-zImage: relocs_check
-endif
-
 $(BOOT_TARGETS1): vmlinux
 	$(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
 $(BOOT_TARGETS2): vmlinux
diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postlink
new file mode 100644
index 0000000..67a0864
--- /dev/null
+++ b/arch/powerpc/Makefile.postlink
@@ -0,0 +1,31 @@
+# ===========================================================================
+# Post-link powerpc pass
+# ===========================================================================
+#
+# 1. Check that vmlinux relocations look sane
+
+PHONY := __archpost
+__archpost:
+
+include include/config/auto.conf
+include scripts/Kbuild.include
+
+quiet_cmd_relocs_check = CHKREL  $@
+      cmd_relocs_check = $(CONFIG_SHELL) arch/powerpc/relocs_check.sh "$(OBJDUMP)" "$@"
+
+# Prevent complainints about nothing to be done
+vmlinux: FORCE
+	@echo -n
+ifeq ($(CONFIG_RELOCATABLE),y)
+	$(call if_changed,relocs_check)
+endif
+
+%.ko: FORCE
+	@echo -n
+
+
+PHONY += FORCE
+
+FORCE:
+
+.PHONY: $(PHONY)
-- 
2.8.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
                   ` (5 preceding siblings ...)
  2016-08-11 10:16 ` [PATCH 6/6] powerpc: use the new post-link pass to check relocations Nicholas Piggin
@ 2016-08-11 12:31 ` Stephen Rothwell
  2016-08-11 12:39 ` [PATCH] Xen: remove -fshort-wchar gcc flag Arnd Bergmann
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Stephen Rothwell @ 2016-08-11 12:31 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: linux-kbuild, linux-arch, Michal Marek, Sam Ravnborg,
	Arnd Bergmann, Nicolas Pitre, Segher Boessenkool, Alan Modra

Hi Nicholas,

On Thu, 11 Aug 2016 20:16:14 +1000 Nicholas Piggin <npiggin@gmail.com> wrote:
>
> I would like to submit the kbuild changes in patches 1-3 for
> consideration.

I would just like to thank Nick for taking my preliminary patches and
running with them.  There was a lot more to do than I suspected :-)

> All patches should be basically noops without arch enablement,
> so I include initial powerpc enablement in patches 4-6 for
> reference, but I will submit those via powerpc maintainer if
> the kbuild changes are merged.

In this case, if patches 1-3 are merged via the kbuild tree, can I
ask that they be put in a separate non-rebaseing topic branch so
that they can also be merged into relevant architecture trees.

-- 
Cheers,
Stephen Rothwell

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
                   ` (6 preceding siblings ...)
  2016-08-11 12:31 ` [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Stephen Rothwell
@ 2016-08-11 12:39 ` Arnd Bergmann
  2016-08-11 12:51   ` Jan Beulich
                     ` (3 more replies)
  2016-08-11 12:39 ` Arnd Bergmann
                   ` (2 subsequent siblings)
  10 siblings, 4 replies; 28+ messages in thread
From: Arnd Bergmann @ 2016-08-11 12:39 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: linux-kbuild, linux-arch, Michal Marek, Sam Ravnborg,
	Stephen Rothwell, Nicolas Pitre, Segher Boessenkool, Alan Modra,
	Boris Ostrovsky, David Vrabel, Juergen Gross, xen-devel

A previous patch added the --no-wchar-size-warning to the Makefile to
avoid this harmless warning:

arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail

Changing kbuild to use thin archives instead of recursive linking
unfortunately brings the same warning back during the final link.

This time, we remove the -fshort-wchar flag that originally caused
the warning, hopefully fixing the problem for good. I don't see
any reason for having the flag in the first place, as the Xen code
does not use wchar_t at all.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 971a69db7dc0 ("Xen: don't warn about 2-byte wchar_t in efi")
---
On Thursday, August 11, 2016 8:16:14 PM CEST Nicholas Piggin wrote:
> Hi,
> 
> I would like to submit the kbuild changes in patches 1-3 for
> consideration.
> 
> I've taken on the feedback, so thanks everybody for that. The
> biggest change since last time is a more general way for
> architectures to do a post-link pass in patch 3.
> 
> On the question of whether to enable thin archives unconditionally,
> I prefer to have architectures enable them as they are tested. But
> I would like to see everybody moved as soon as possible and the
> incremental linking removed.

It would be nice to get this patch merged along with the thin
archive conversion, either by merging it through the xen
Tree, or by making it part of Nick's series with an Ack
from the xen maintainers.

diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index 8feab810aed9..7f188b8d0c67 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -7,9 +7,6 @@ obj-y	+= xenbus/
 nostackp := $(call cc-option, -fno-stack-protector)
 CFLAGS_features.o			:= $(nostackp)
 
-CFLAGS_efi.o				+= -fshort-wchar
-LDFLAGS					+= $(call ld-option, --no-wchar-size-warning)
-
 dom0-$(CONFIG_ARM64) += arm-device.o
 dom0-$(CONFIG_PCI) += pci.o
 dom0-$(CONFIG_USB_SUPPORT) += dbgp.o


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
                   ` (7 preceding siblings ...)
  2016-08-11 12:39 ` [PATCH] Xen: remove -fshort-wchar gcc flag Arnd Bergmann
@ 2016-08-11 12:39 ` Arnd Bergmann
  2016-08-11 13:55 ` [EXPERIMENTAL] enable thin archives and --gc-sections on ARM Arnd Bergmann
  2016-08-23  6:17 ` [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
  10 siblings, 0 replies; 28+ messages in thread
From: Arnd Bergmann @ 2016-08-11 12:39 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: linux-arch, Stephen Rothwell, Juergen Gross, Segher Boessenkool,
	Nicolas Pitre, linux-kbuild, Alan Modra, Michal Marek,
	David Vrabel, xen-devel, Boris Ostrovsky, Sam Ravnborg

A previous patch added the --no-wchar-size-warning to the Makefile to
avoid this harmless warning:

arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail

Changing kbuild to use thin archives instead of recursive linking
unfortunately brings the same warning back during the final link.

This time, we remove the -fshort-wchar flag that originally caused
the warning, hopefully fixing the problem for good. I don't see
any reason for having the flag in the first place, as the Xen code
does not use wchar_t at all.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 971a69db7dc0 ("Xen: don't warn about 2-byte wchar_t in efi")
---
On Thursday, August 11, 2016 8:16:14 PM CEST Nicholas Piggin wrote:
> Hi,
> 
> I would like to submit the kbuild changes in patches 1-3 for
> consideration.
> 
> I've taken on the feedback, so thanks everybody for that. The
> biggest change since last time is a more general way for
> architectures to do a post-link pass in patch 3.
> 
> On the question of whether to enable thin archives unconditionally,
> I prefer to have architectures enable them as they are tested. But
> I would like to see everybody moved as soon as possible and the
> incremental linking removed.

It would be nice to get this patch merged along with the thin
archive conversion, either by merging it through the xen
Tree, or by making it part of Nick's series with an Ack
from the xen maintainers.

diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index 8feab810aed9..7f188b8d0c67 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -7,9 +7,6 @@ obj-y	+= xenbus/
 nostackp := $(call cc-option, -fno-stack-protector)
 CFLAGS_features.o			:= $(nostackp)
 
-CFLAGS_efi.o				+= -fshort-wchar
-LDFLAGS					+= $(call ld-option, --no-wchar-size-warning)
-
 dom0-$(CONFIG_ARM64) += arm-device.o
 dom0-$(CONFIG_PCI) += pci.o
 dom0-$(CONFIG_USB_SUPPORT) += dbgp.o


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 12:39 ` [PATCH] Xen: remove -fshort-wchar gcc flag Arnd Bergmann
  2016-08-11 12:51   ` Jan Beulich
@ 2016-08-11 12:51   ` Jan Beulich
  2016-08-11 14:01     ` Arnd Bergmann
  2016-08-11 14:01     ` Arnd Bergmann
  2016-08-24 17:18   ` [Xen-devel] " David Vrabel
  2016-08-24 17:18   ` David Vrabel
  3 siblings, 2 replies; 28+ messages in thread
From: Jan Beulich @ 2016-08-11 12:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Stephen Rothwell, David Vrabel, Alan Modra, Nicholas Piggin,
	Segher Boessenkool, Nicolas Pitre, xen-devel, Boris Ostrovsky,
	Sam Ravnborg, Juergen Gross, Michal Marek, linux-arch,
	linux-kbuild

>>> On 11.08.16 at 14:39, <arnd@arndb.de> wrote:
> A previous patch added the --no-wchar-size-warning to the Makefile to
> avoid this harmless warning:
> 
> arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the 
> output is to use 4-byte wchar_t; use of wchar_t values across objects may 
> fail
> 
> Changing kbuild to use thin archives instead of recursive linking
> unfortunately brings the same warning back during the final link.
> 
> This time, we remove the -fshort-wchar flag that originally caused
> the warning, hopefully fixing the problem for good. I don't see
> any reason for having the flag in the first place, as the Xen code
> does not use wchar_t at all.

It uses efi_char16_t, and by dropping -fshort-wchar you'd open
up a trap for anyone to fall into who were to add wide string
literals to that same file. EFI using 16-bit characters requires
code interfacing with EFI to do so too.

Jan


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 12:39 ` [PATCH] Xen: remove -fshort-wchar gcc flag Arnd Bergmann
@ 2016-08-11 12:51   ` Jan Beulich
  2016-08-11 12:51   ` [Xen-devel] " Jan Beulich
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 28+ messages in thread
From: Jan Beulich @ 2016-08-11 12:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Juergen Gross, Stephen Rothwell, Segher Boessenkool,
	Nicolas Pitre, Alan Modra, Nicholas Piggin, Michal Marek,
	David Vrabel, linux-arch, xen-devel, Boris Ostrovsky,
	Sam Ravnborg, linux-kbuild

>>> On 11.08.16 at 14:39, <arnd@arndb.de> wrote:
> A previous patch added the --no-wchar-size-warning to the Makefile to
> avoid this harmless warning:
> 
> arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the 
> output is to use 4-byte wchar_t; use of wchar_t values across objects may 
> fail
> 
> Changing kbuild to use thin archives instead of recursive linking
> unfortunately brings the same warning back during the final link.
> 
> This time, we remove the -fshort-wchar flag that originally caused
> the warning, hopefully fixing the problem for good. I don't see
> any reason for having the flag in the first place, as the Xen code
> does not use wchar_t at all.

It uses efi_char16_t, and by dropping -fshort-wchar you'd open
up a trap for anyone to fall into who were to add wide string
literals to that same file. EFI using 16-bit characters requires
code interfacing with EFI to do so too.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [EXPERIMENTAL] enable thin archives and --gc-sections on ARM
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
                   ` (8 preceding siblings ...)
  2016-08-11 12:39 ` Arnd Bergmann
@ 2016-08-11 13:55 ` Arnd Bergmann
  2016-08-11 20:01   ` Nicolas Pitre
  2016-08-23  6:17 ` [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
  10 siblings, 1 reply; 28+ messages in thread
From: Arnd Bergmann @ 2016-08-11 13:55 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: linux-kbuild, linux-arch, Michal Marek, Sam Ravnborg,
	Stephen Rothwell, Nicolas Pitre, Segher Boessenkool, Alan Modra

This goes on top of Nick's latest version of "[PATCH 0/6 v2] kbuild changes,
thin archives, --gc-sections" and enables both features on ARM.

It's a bit half-baked, these are known problems:

- as big-endian support is still broken, I disable it in Kconfig
  so an allyesconfig build ends up as little-endian

- I've thrown in a change to include/asm-generic/vmlinux.lds.h
  but don't know whether this is the right way or not. We have
  to keep .text.fixup linked together with .text, but I separate
  out .text.unlikely and .text.hot again. This has not caused
  any link failures for me (yet).

- I mark a ton of sections as KEEP() in vmlinux.lds.S. Some of
  them might not actually be needed, and I have not spent much
  time checking what they actually are. However, I did build
  a few hundred randconfigs without new issues.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b62ae32f8a1e..9bf37a6e7384 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -83,6 +83,7 @@ config ARM
 	select HAVE_UID16
 	select HAVE_VIRT_CPU_ACCOUNTING_GEN
 	select IRQ_FORCED_THREADING
+	select LD_DEAD_CODE_DATA_ELIMINATION
 	select MODULES_USE_ELF_REL
 	select NO_BOOTMEM
 	select OF_EARLY_FLATTREE if OF
@@ -92,6 +93,7 @@ config ARM
 	select PERF_USE_VMALLOC
 	select RTC_LIB
 	select SYS_SUPPORTS_APM_EMULATION
+	select THIN_ARCHIVES
 	# Above selects are sorted alphabetically; please add new ones
 	# according to that.  Thanks.
 	help
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index ad325a8c7e1e..b7f2a41fd940 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -13,6 +13,9 @@ endif
 
 CFLAGS_REMOVE_return_address.o = -pg
 
+ccflags-y              += -fno-function-sections -fno-data-sections
+subdir-ccflags-y       += -fno-function-sections -fno-data-sections
+
 # Object file lists.
 
 obj-y		:= elf.o entry-common.o irq.o opcodes.o \
diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S
index 56c8bdf776bd..77c2c607cdd9 100644
--- a/arch/arm/kernel/vmlinux-xip.lds.S
+++ b/arch/arm/kernel/vmlinux-xip.lds.S
@@ -12,17 +12,17 @@
 #define PROC_INFO							\
 	. = ALIGN(4);							\
 	VMLINUX_SYMBOL(__proc_info_begin) = .;				\
-	*(.proc.info.init)						\
+	KEEP(*(.proc.info.init))					\
 	VMLINUX_SYMBOL(__proc_info_end) = .;
 
 #define IDMAP_TEXT							\
 	ALIGN_FUNCTION();						\
 	VMLINUX_SYMBOL(__idmap_text_start) = .;				\
-	*(.idmap.text)							\
+	KEEP(*(.idmap.text))						\
 	VMLINUX_SYMBOL(__idmap_text_end) = .;				\
 	. = ALIGN(PAGE_SIZE);						\
 	VMLINUX_SYMBOL(__hyp_idmap_text_start) = .;			\
-	*(.hyp.idmap.text)						\
+	KEEP(*(.hyp.idmap.text))					\
 	VMLINUX_SYMBOL(__hyp_idmap_text_end) = .;
 
 #ifdef CONFIG_HOTPLUG_CPU
@@ -93,7 +93,7 @@ SECTIONS
 		_stext = .;		/* Text and read-only data	*/
 			IDMAP_TEXT
 			__exception_text_start = .;
-			*(.exception.text)
+			KEEP(*(.exception.text))
 			__exception_text_end = .;
 			IRQENTRY_TEXT
 			TEXT_TEXT
@@ -114,7 +114,7 @@ SECTIONS
 	__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
 		__start___ex_table = .;
 #ifdef CONFIG_MMU
-		*(__ex_table)
+		KEEP(*(__ex_table))
 #endif
 		__stop___ex_table = .;
 	}
@@ -126,12 +126,12 @@ SECTIONS
 	. = ALIGN(8);
 	.ARM.unwind_idx : {
 		__start_unwind_idx = .;
-		*(.ARM.exidx*)
+		KEEP(*(.ARM.exidx*))
 		__stop_unwind_idx = .;
 	}
 	.ARM.unwind_tab : {
 		__start_unwind_tab = .;
-		*(.ARM.extab*)
+		KEEP(*(.ARM.extab*))
 		__stop_unwind_tab = .;
 	}
 #endif
@@ -146,14 +146,14 @@ SECTIONS
 	 */
 	__vectors_start = .;
 	.vectors 0xffff0000 : AT(__vectors_start) {
-		*(.vectors)
+		KEEP(*(.vectors))
 	}
 	. = __vectors_start + SIZEOF(.vectors);
 	__vectors_end = .;
 
 	__stubs_start = .;
 	.stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) {
-		*(.stubs)
+		KEEP(*(.stubs))
 	}
 	. = __stubs_start + SIZEOF(.stubs);
 	__stubs_end = .;
@@ -169,24 +169,24 @@ SECTIONS
 	}
 	.init.arch.info : {
 		__arch_info_begin = .;
-		*(.arch.info.init)
+		KEEP(*(.arch.info.init))
 		__arch_info_end = .;
 	}
 	.init.tagtable : {
 		__tagtable_begin = .;
-		*(.taglist.init)
+		KEEP(*(.taglist.init))
 		__tagtable_end = .;
 	}
 #ifdef CONFIG_SMP_ON_UP
 	.init.smpalt : {
 		__smpalt_begin = .;
-		*(.alt.smp.init)
+		KEEP(*(.alt.smp.init))
 		__smpalt_end = .;
 	}
 #endif
 	.init.pv_table : {
 		__pv_table_begin = .;
-		*(.pv_table)
+		KEEP(*(.pv_table))
 		__pv_table_end = .;
 	}
 	.init.data : {
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index 7396a5f00c5f..61b9b8784036 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -17,7 +17,7 @@
 #define PROC_INFO							\
 	. = ALIGN(4);							\
 	VMLINUX_SYMBOL(__proc_info_begin) = .;				\
-	*(.proc.info.init)						\
+	KEEP(*(.proc.info.init))					\
 	VMLINUX_SYMBOL(__proc_info_end) = .;
 
 #define HYPERVISOR_TEXT							\
@@ -104,7 +104,7 @@ SECTIONS
 		_stext = .;		/* Text and read-only data	*/
 			IDMAP_TEXT
 			__exception_text_start = .;
-			*(.exception.text)
+			KEEP(*(.exception.text))
 			__exception_text_end = .;
 			IRQENTRY_TEXT
 			SOFTIRQENTRY_TEXT
@@ -169,14 +169,14 @@ SECTIONS
 	 */
 	__vectors_start = .;
 	.vectors 0xffff0000 : AT(__vectors_start) {
-		*(.vectors)
+		KEEP(*(.vectors))
 	}
 	. = __vectors_start + SIZEOF(.vectors);
 	__vectors_end = .;
 
 	__stubs_start = .;
 	.stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) {
-		*(.stubs)
+		KEEP(*(.stubs))
 	}
 	. = __stubs_start + SIZEOF(.stubs);
 	__stubs_end = .;
@@ -192,24 +192,24 @@ SECTIONS
 	}
 	.init.arch.info : {
 		__arch_info_begin = .;
-		*(.arch.info.init)
+		KEEP(*(.arch.info.init))
 		__arch_info_end = .;
 	}
 	.init.tagtable : {
 		__tagtable_begin = .;
-		*(.taglist.init)
+		KEEP(*(.taglist.init))
 		__tagtable_end = .;
 	}
 #ifdef CONFIG_SMP_ON_UP
 	.init.smpalt : {
 		__smpalt_begin = .;
-		*(.alt.smp.init)
+		KEEP(*(.alt.smp.init))
 		__smpalt_end = .;
 	}
 #endif
 	.init.pv_table : {
 		__pv_table_begin = .;
-		*(.pv_table)
+		KEEP(*(.pv_table))
 		__pv_table_end = .;
 	}
 	.init.data : {
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index 6a09cc204b07..7117b8e99de8 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -717,6 +717,7 @@ config SWP_EMULATE
 config CPU_BIG_ENDIAN
 	bool "Build big-endian kernel"
 	depends on ARCH_SUPPORTS_BIG_ENDIAN
+	depends on !THIN_ARCHIVES
 	help
 	  Say Y if you plan on running a kernel in big-endian mode.
 	  Note that your board must be properly built and your board
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 9136c3afd3c6..e01f0b00a678 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -433,7 +433,9 @@
  * during second ld run in second ld pass when generating System.map */
 #define TEXT_TEXT							\
 		ALIGN_FUNCTION();					\
-		*(.text.hot .text .text.fixup .text.unlikely .text.*)	\
+		*(.text.hot .text.hot.*)				\
+		*(.text.unlikely .text.unlikely.*)			\
+		*(.text .text.*)					\
 		*(.ref.text)						\
 	MEM_KEEP(init.text)						\
 	MEM_KEEP(exit.text)						\


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 12:51   ` [Xen-devel] " Jan Beulich
@ 2016-08-11 14:01     ` Arnd Bergmann
  2016-08-11 14:06       ` Jan Beulich
  2016-08-11 14:06       ` Jan Beulich
  2016-08-11 14:01     ` Arnd Bergmann
  1 sibling, 2 replies; 28+ messages in thread
From: Arnd Bergmann @ 2016-08-11 14:01 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Stephen Rothwell, David Vrabel, Alan Modra, Nicholas Piggin,
	Segher Boessenkool, Nicolas Pitre, xen-devel, Boris Ostrovsky,
	Sam Ravnborg, Juergen Gross, Michal Marek, linux-arch,
	linux-kbuild

On Thursday, August 11, 2016 6:51:33 AM CEST Jan Beulich wrote:
> >>> On 11.08.16 at 14:39, <arnd@arndb.de> wrote:
> > A previous patch added the --no-wchar-size-warning to the Makefile to
> > avoid this harmless warning:
> > 
> > arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the 
> > output is to use 4-byte wchar_t; use of wchar_t values across objects may 
> > fail
> > 
> > Changing kbuild to use thin archives instead of recursive linking
> > unfortunately brings the same warning back during the final link.
> > 
> > This time, we remove the -fshort-wchar flag that originally caused
> > the warning, hopefully fixing the problem for good. I don't see
> > any reason for having the flag in the first place, as the Xen code
> > does not use wchar_t at all.
> 
> It uses efi_char16_t, and by dropping -fshort-wchar you'd open
> up a trap for anyone to fall into who were to add wide string
> literals to that same file. EFI using 16-bit characters requires
> code interfacing with EFI to do so too.

I don't understand. How is this different from other source files
that use efi_char16_t or the wchar_t definition from include/linux/nls.h?

As far as I can tell, they all use 16-bit characters, but none of the
others sets the flag. Maybe we should just always build with -fshort-wchar
from the top-level Makefile?

	Arnd

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 12:51   ` [Xen-devel] " Jan Beulich
  2016-08-11 14:01     ` Arnd Bergmann
@ 2016-08-11 14:01     ` Arnd Bergmann
  1 sibling, 0 replies; 28+ messages in thread
From: Arnd Bergmann @ 2016-08-11 14:01 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Juergen Gross, Stephen Rothwell, Segher Boessenkool,
	Nicolas Pitre, Alan Modra, Nicholas Piggin, Michal Marek,
	David Vrabel, linux-arch, xen-devel, Boris Ostrovsky,
	Sam Ravnborg, linux-kbuild

On Thursday, August 11, 2016 6:51:33 AM CEST Jan Beulich wrote:
> >>> On 11.08.16 at 14:39, <arnd@arndb.de> wrote:
> > A previous patch added the --no-wchar-size-warning to the Makefile to
> > avoid this harmless warning:
> > 
> > arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the 
> > output is to use 4-byte wchar_t; use of wchar_t values across objects may 
> > fail
> > 
> > Changing kbuild to use thin archives instead of recursive linking
> > unfortunately brings the same warning back during the final link.
> > 
> > This time, we remove the -fshort-wchar flag that originally caused
> > the warning, hopefully fixing the problem for good. I don't see
> > any reason for having the flag in the first place, as the Xen code
> > does not use wchar_t at all.
> 
> It uses efi_char16_t, and by dropping -fshort-wchar you'd open
> up a trap for anyone to fall into who were to add wide string
> literals to that same file. EFI using 16-bit characters requires
> code interfacing with EFI to do so too.

I don't understand. How is this different from other source files
that use efi_char16_t or the wchar_t definition from include/linux/nls.h?

As far as I can tell, they all use 16-bit characters, but none of the
others sets the flag. Maybe we should just always build with -fshort-wchar
from the top-level Makefile?

	Arnd

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 14:01     ` Arnd Bergmann
@ 2016-08-11 14:06       ` Jan Beulich
  2016-08-11 14:06       ` Jan Beulich
  1 sibling, 0 replies; 28+ messages in thread
From: Jan Beulich @ 2016-08-11 14:06 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Stephen Rothwell, David Vrabel, Alan Modra, Nicholas Piggin,
	Segher Boessenkool, Nicolas Pitre, xen-devel, Boris Ostrovsky,
	Sam Ravnborg, Juergen Gross, Michal Marek, linux-arch,
	linux-kbuild

>>> On 11.08.16 at 16:01, <arnd@arndb.de> wrote:
> On Thursday, August 11, 2016 6:51:33 AM CEST Jan Beulich wrote:
>> >>> On 11.08.16 at 14:39, <arnd@arndb.de> wrote:
>> > A previous patch added the --no-wchar-size-warning to the Makefile to
>> > avoid this harmless warning:
>> > 
>> > arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the 
>> > output is to use 4-byte wchar_t; use of wchar_t values across objects may 
>> > fail
>> > 
>> > Changing kbuild to use thin archives instead of recursive linking
>> > unfortunately brings the same warning back during the final link.
>> > 
>> > This time, we remove the -fshort-wchar flag that originally caused
>> > the warning, hopefully fixing the problem for good. I don't see
>> > any reason for having the flag in the first place, as the Xen code
>> > does not use wchar_t at all.
>> 
>> It uses efi_char16_t, and by dropping -fshort-wchar you'd open
>> up a trap for anyone to fall into who were to add wide string
>> literals to that same file. EFI using 16-bit characters requires
>> code interfacing with EFI to do so too.
> 
> I don't understand. How is this different from other source files
> that use efi_char16_t or the wchar_t definition from include/linux/nls.h?

Perhaps they didn't run into the issue yet?

> As far as I can tell, they all use 16-bit characters, but none of the
> others sets the flag. Maybe we should just always build with -fshort-wchar
> from the top-level Makefile?

Quite possible, unless elsewhere in the tree 4-byte characters are
needed.

Jan


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 14:01     ` Arnd Bergmann
  2016-08-11 14:06       ` Jan Beulich
@ 2016-08-11 14:06       ` Jan Beulich
  1 sibling, 0 replies; 28+ messages in thread
From: Jan Beulich @ 2016-08-11 14:06 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Juergen Gross, Stephen Rothwell, Segher Boessenkool,
	Nicolas Pitre, Alan Modra, Nicholas Piggin, Michal Marek,
	David Vrabel, linux-arch, xen-devel, Boris Ostrovsky,
	Sam Ravnborg, linux-kbuild

>>> On 11.08.16 at 16:01, <arnd@arndb.de> wrote:
> On Thursday, August 11, 2016 6:51:33 AM CEST Jan Beulich wrote:
>> >>> On 11.08.16 at 14:39, <arnd@arndb.de> wrote:
>> > A previous patch added the --no-wchar-size-warning to the Makefile to
>> > avoid this harmless warning:
>> > 
>> > arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the 
>> > output is to use 4-byte wchar_t; use of wchar_t values across objects may 
>> > fail
>> > 
>> > Changing kbuild to use thin archives instead of recursive linking
>> > unfortunately brings the same warning back during the final link.
>> > 
>> > This time, we remove the -fshort-wchar flag that originally caused
>> > the warning, hopefully fixing the problem for good. I don't see
>> > any reason for having the flag in the first place, as the Xen code
>> > does not use wchar_t at all.
>> 
>> It uses efi_char16_t, and by dropping -fshort-wchar you'd open
>> up a trap for anyone to fall into who were to add wide string
>> literals to that same file. EFI using 16-bit characters requires
>> code interfacing with EFI to do so too.
> 
> I don't understand. How is this different from other source files
> that use efi_char16_t or the wchar_t definition from include/linux/nls.h?

Perhaps they didn't run into the issue yet?

> As far as I can tell, they all use 16-bit characters, but none of the
> others sets the flag. Maybe we should just always build with -fshort-wchar
> from the top-level Makefile?

Quite possible, unless elsewhere in the tree 4-byte characters are
needed.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [EXPERIMENTAL] enable thin archives and --gc-sections on ARM
  2016-08-11 13:55 ` [EXPERIMENTAL] enable thin archives and --gc-sections on ARM Arnd Bergmann
@ 2016-08-11 20:01   ` Nicolas Pitre
  2016-08-11 20:37     ` Arnd Bergmann
  0 siblings, 1 reply; 28+ messages in thread
From: Nicolas Pitre @ 2016-08-11 20:01 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Nicholas Piggin, linux-kbuild, linux-arch, Michal Marek,
	Sam Ravnborg, Stephen Rothwell, Segher Boessenkool, Alan Modra

On Thu, 11 Aug 2016, Arnd Bergmann wrote:

> This goes on top of Nick's latest version of "[PATCH 0/6 v2] kbuild changes,
> thin archives, --gc-sections" and enables both features on ARM.
> 
[...]
> 
> - I mark a ton of sections as KEEP() in vmlinux.lds.S. Some of
>   them might not actually be needed, and I have not spent much
>   time checking what they actually are. However, I did build
>   a few hundred randconfigs without new issues.
> 
> index 7396a5f00c5f..61b9b8784036 100644
> --- a/arch/arm/kernel/vmlinux.lds.S
> +++ b/arch/arm/kernel/vmlinux.lds.S
> @@ -17,7 +17,7 @@
>  #define PROC_INFO							\
>  	. = ALIGN(4);							\
>  	VMLINUX_SYMBOL(__proc_info_begin) = .;				\
> -	*(.proc.info.init)						\
> +	KEEP(*(.proc.info.init))					\

OK.

>  	VMLINUX_SYMBOL(__proc_info_end) = .;
>  
>  #define HYPERVISOR_TEXT							\
> @@ -104,7 +104,7 @@ SECTIONS
>  		_stext = .;		/* Text and read-only data	*/
>  			IDMAP_TEXT
>  			__exception_text_start = .;
> -			*(.exception.text)
> +			KEEP(*(.exception.text))

No need here. The code there has to be referenced from somewhere. If not 
it should not be kept.

>  			__exception_text_end = .;
>  			IRQENTRY_TEXT
>  			SOFTIRQENTRY_TEXT
> @@ -169,14 +169,14 @@ SECTIONS
>  	 */
>  	__vectors_start = .;
>  	.vectors 0xffff0000 : AT(__vectors_start) {
> -		*(.vectors)
> +		KEEP(*(.vectors))

OK.

>  	}
>  	. = __vectors_start + SIZEOF(.vectors);
>  	__vectors_end = .;
>  
>  	__stubs_start = .;
>  	.stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) {
> -		*(.stubs)
> +		KEEP(*(.stubs))

This is referenced from .vectors entries and therefore the KEEP() is not 
needed.  There is nothing to be saved either ways though.

>  	}
>  	. = __stubs_start + SIZEOF(.stubs);
>  	__stubs_end = .;
> @@ -192,24 +192,24 @@ SECTIONS
>  	}
>  	.init.arch.info : {
>  		__arch_info_begin = .;
> -		*(.arch.info.init)
> +		KEEP(*(.arch.info.init))

OK.

>  		__arch_info_end = .;
>  	}
>  	.init.tagtable : {
>  		__tagtable_begin = .;
> -		*(.taglist.init)
> +		KEEP(*(.taglist.init))

OK.

>  		__tagtable_end = .;
>  	}
>  #ifdef CONFIG_SMP_ON_UP
>  	.init.smpalt : {
>  		__smpalt_begin = .;
> -		*(.alt.smp.init)
> +		KEEP(*(.alt.smp.init))

Yes unfortunately this needs a KEEP() right now as there is no explicit 
references to those entries. But by doing so you force a reference from 
those entries to all functions they annotate, preventing those functions 
from being discarded if there isn't any reference to that code 
otherwise. That's a case that falls into the "missing forward reference" 
category in my slides.

>  		__smpalt_end = .;
>  	}
>  #endif
>  	.init.pv_table : {
>  		__pv_table_begin = .;
> -		*(.pv_table)
> +		KEEP(*(.pv_table))

Ditto here.


Nicolas

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [EXPERIMENTAL] enable thin archives and --gc-sections on ARM
  2016-08-11 20:01   ` Nicolas Pitre
@ 2016-08-11 20:37     ` Arnd Bergmann
  2016-08-11 21:05       ` Nicolas Pitre
  0 siblings, 1 reply; 28+ messages in thread
From: Arnd Bergmann @ 2016-08-11 20:37 UTC (permalink / raw)
  To: Nicolas Pitre
  Cc: Nicholas Piggin, linux-kbuild, linux-arch, Michal Marek,
	Sam Ravnborg, Stephen Rothwell, Segher Boessenkool, Alan Modra

On Thursday, August 11, 2016 4:01:33 PM CEST Nicolas Pitre wrote:
> >  #ifdef CONFIG_SMP_ON_UP
> >       .init.smpalt : {
> >               __smpalt_begin = .;
> > -             *(.alt.smp.init)
> > +             KEEP(*(.alt.smp.init))
> 
> Yes unfortunately this needs a KEEP() right now as there is no explicit 
> references to those entries. But by doing so you force a reference from 
> those entries to all functions they annotate, preventing those functions 
> from being discarded if there isn't any reference to that code 
> otherwise. That's a case that falls into the "missing forward reference" 
> category in my slides.

I see. This actually relates to an existing problem with SMP alternatives
in exit sections, which cause a linker error. I've done a patch for
this at some point, but didn't feel confident enough to send it out

commit 0c598e53b3a0ad7daf077603618001edcf9bface
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Sun Mar 16 20:14:30 2014 +0100

    ARM: don't discard exit sections for spinlock debugging
    
    This avoids lots of warnings like this one:
    
    `.exit.text' referenced in section `.alt.smp.init' of drivers/built-in.o: defined in discarded section `.exit.text' of drivers/built-in.o
    
    for each spinlock that is used in an __exit function, because
    the smp alternatives try to patch out the spinlock locations.
    
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>

diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index d24e5dd2aa7a..1f5eeeb4c8d0 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -43,8 +43,7 @@
 #define ARM_CPU_KEEP(x)
 #endif
 
-#if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
-	defined(CONFIG_GENERIC_BUG) || defined(CONFIG_JUMP_LABEL)
+#if defined(CONFIG_SMP_ON_UP) || defined(CONFIG_GENERIC_BUG) || defined(CONFIG_JUMP_LABEL)
 #define ARM_EXIT_KEEP(x)	x
 #define ARM_EXIT_DISCARD(x)
 #else


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [EXPERIMENTAL] enable thin archives and --gc-sections on ARM
  2016-08-11 20:37     ` Arnd Bergmann
@ 2016-08-11 21:05       ` Nicolas Pitre
  0 siblings, 0 replies; 28+ messages in thread
From: Nicolas Pitre @ 2016-08-11 21:05 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Nicholas Piggin, linux-kbuild, linux-arch, Michal Marek,
	Sam Ravnborg, Stephen Rothwell, Segher Boessenkool, Alan Modra

On Thu, 11 Aug 2016, Arnd Bergmann wrote:

> On Thursday, August 11, 2016 4:01:33 PM CEST Nicolas Pitre wrote:
> > >  #ifdef CONFIG_SMP_ON_UP
> > >       .init.smpalt : {
> > >               __smpalt_begin = .;
> > > -             *(.alt.smp.init)
> > > +             KEEP(*(.alt.smp.init))
> > 
> > Yes unfortunately this needs a KEEP() right now as there is no explicit 
> > references to those entries. But by doing so you force a reference from 
> > those entries to all functions they annotate, preventing those functions 
> > from being discarded if there isn't any reference to that code 
> > otherwise. That's a case that falls into the "missing forward reference" 
> > category in my slides.
> 
> I see. This actually relates to an existing problem with SMP alternatives
> in exit sections, which cause a linker error. I've done a patch for
> this at some point, but didn't feel confident enough to send it out

The only sane way I found to solve this implied a patch to gas, and it 
was accepted upstream. Please see:

http://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=451133cefa

The example given is for .init sections, but that would solve the 
link-time discarding of .exit sections just as well.


Nicolas

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/6] kbuild: add arch specific post-link pass
  2016-08-11 10:16 ` [PATCH 3/6] kbuild: add arch specific post-link pass Nicholas Piggin
@ 2016-08-16  9:23   ` Michal Marek
  2016-08-17  4:43     ` Nicholas Piggin
  0 siblings, 1 reply; 28+ messages in thread
From: Michal Marek @ 2016-08-16  9:23 UTC (permalink / raw)
  To: Nicholas Piggin, linux-kbuild
  Cc: linux-arch, Sam Ravnborg, Stephen Rothwell, Arnd Bergmann,
	Nicolas Pitre, Segher Boessenkool, Alan Modra

Dne 11.8.2016 v 12:16 Nicholas Piggin napsal(a):
> Add an option for architectures to pass over modules after they are
> linked. powerpc will use this to check linker relocations for sanity,
> and possibly to fix up alternate instruction patch relocations.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> Since v1,
> - Switched to a more flexible arch makefile invocation.
> - Provide a powerpc patch to use it to help existing build issue
>   (rather than only justification being out-of-tree patch).
> 
>  Documentation/kbuild/makefiles.txt | 10 ++++++++++
>  arch/Kconfig                       |  7 +++++++
>  scripts/Makefile.modpost           |  3 +++
>  scripts/link-vmlinux.sh            |  4 ++++
>  4 files changed, 24 insertions(+)
> 
> diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
> index 385a5ef..8581e38 100644
> --- a/Documentation/kbuild/makefiles.txt
> +++ b/Documentation/kbuild/makefiles.txt
> @@ -41,6 +41,7 @@ This document describes the Linux kernel Makefiles.
>  	   --- 6.8 Custom kbuild commands
>  	   --- 6.9 Preprocessing linker scripts
>  	   --- 6.10 Generic header files
> +	   --- 6.11 Post-link pass
>  
>  	=== 7 Kbuild syntax for exported headers
>  		--- 7.1 header-y
> @@ -1237,6 +1238,15 @@ When kbuild executes, the following steps are followed (roughly):
>  	to list the file in the Kbuild file.
>  	See "7.4 generic-y" for further info on syntax etc.
>  
> +--- 6.11 Post-link pass
> +
> +	CONFIG_BUILD_ARCH_POSTLINK can be selected in order to have
> +	arch/?/Makefile.postlink invoked on vmlinux and module.ko
> +	files after final link.
> +
> +	For example, powerpc uses this to check relocations on the
> +	linked vmlinux file.
> +
>  === 7 Kbuild syntax for exported headers
>  
>  The kernel includes a set of headers that is exported to userspace.
> diff --git a/arch/Kconfig b/arch/Kconfig
> index fc3f9e1..3a36ea8 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -461,6 +461,13 @@ config CC_STACKPROTECTOR_STRONG
>  
>  endchoice
>  
> +config BUILD_ARCH_POSTLINK
> +	bool
> +	help
> +	  Select this if the architecture wants to have a Makefile invoked
> +	  on modules and vmlinux after they are linked. The architecture
> +	  must provide arch/?/Makefile.postlink
> +
>  config THIN_ARCHIVES
>  	bool
>  	help
> diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
> index 1366a94..1acaa20 100644
> --- a/scripts/Makefile.modpost
> +++ b/scripts/Makefile.modpost
> @@ -123,6 +123,9 @@ quiet_cmd_ld_ko_o = LD [M]  $@
>  
>  $(modules): %.ko :%.o %.mod.o FORCE
>  	$(call if_changed,ld_ko_o)
> +ifdef CONFIG_BUILD_ARCH_POSTLINK
> +	$(Q)$(MAKE) -f $(srctree)/arch/$(SRCARCH)/Makefile.postlink $@
> +endif

Why not simply branch off the existence of arch/*/Makefile.postlink and
drop the kconfig option?

Thanks,
Michal

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/6] kbuild: add arch specific post-link pass
  2016-08-16  9:23   ` Michal Marek
@ 2016-08-17  4:43     ` Nicholas Piggin
  2016-08-17  9:05       ` Michal Marek
  2016-08-17  9:56       ` Sam Ravnborg
  0 siblings, 2 replies; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-17  4:43 UTC (permalink / raw)
  To: Michal Marek
  Cc: linux-kbuild, linux-arch, Sam Ravnborg, Stephen Rothwell,
	Arnd Bergmann, Nicolas Pitre, Segher Boessenkool, Alan Modra

On Tue, 16 Aug 2016 11:23:45 +0200
Michal Marek <mmarek@suse.com> wrote:

> Dne 11.8.2016 v 12:16 Nicholas Piggin napsal(a):
> >  $(modules): %.ko :%.o %.mod.o FORCE
> >  	$(call if_changed,ld_ko_o)
> > +ifdef CONFIG_BUILD_ARCH_POSTLINK
> > +	$(Q)$(MAKE) -f $(srctree)/arch/$(SRCARCH)/Makefile.postlink $@
> > +endif  
> 
> Why not simply branch off the existence of arch/*/Makefile.postlink and
> drop the kconfig option?

I just did not think of it. That does seem nicer, thanks. What do
you think of this?


Allow architectures to create arch/xxx/Makefile.postlink with targets
for vmlinux, modules.ko, and clean, which will be invoked after final
linking of vmlinux and modules.

powerpc will use this to check vmlinux linker relocations for sanity,
and may use it to fix up alternate instruction patch branch addresses.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>

---
Since v1,
- Switched to a more flexible arch makefile invocation.
- Provide a powerpc patch to use it to help existing build issue
  (rather than only justification being out-of-tree patch).

Since v2
- Depend on existence of Makefile.modpost, rather than config option.
- Move post-vmlinux invocation into Makefile rather than link-vmlinux.sh
- Add a clean target

---
 Documentation/kbuild/makefiles.txt | 16 ++++++++++++++++
 Makefile                           |  7 +++++++
 scripts/Makefile.modpost           |  6 ++++++
 3 files changed, 29 insertions(+)

diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 385a5ef..ce93dc7 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -41,6 +41,7 @@ This document describes the Linux kernel Makefiles.
 	   --- 6.8 Custom kbuild commands
 	   --- 6.9 Preprocessing linker scripts
 	   --- 6.10 Generic header files
+	   --- 6.11 Post-link pass
 
 	=== 7 Kbuild syntax for exported headers
 		--- 7.1 header-y
@@ -1237,6 +1238,21 @@ When kbuild executes, the following steps are followed (roughly):
 	to list the file in the Kbuild file.
 	See "7.4 generic-y" for further info on syntax etc.
 
+--- 6.11 Post-link pass
+
+	If the file arch/xxx/Makefile.postlink exists, this makefile
+	will be invoked for post-link objects (vmlinux and modules.ko)
+	for architectures to run post-link passes on. Must also handle
+	the clean target.
+
+	This pass runs after kallsyms generation. If the architecture
+	needs to modify symbol locations, rather than manipulate the
+	kallsyms, it may be easier to add another postlink target for
+        .tmp_vmlinux? targets to be called from link-vmlinux.sh.
+
+	For example, powerpc uses this to check relocation sanity of
+	the linked vmlinux file.
+
 === 7 Kbuild syntax for exported headers
 
 The kernel includes a set of headers that is exported to userspace.
diff --git a/Makefile b/Makefile
index 1d26fdb..20d3bfd 100644
--- a/Makefile
+++ b/Makefile
@@ -954,8 +954,14 @@ include/generated/autoksyms.h: FORCE
       cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux)
 quiet_cmd_link-vmlinux = LINK    $@
 
+# Optional arch pass after final link
+ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
+      cmd_postlink-vmlinux = \
+          $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+
 vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE
 	+$(call if_changed,link-vmlinux)
+	+$(call if_changed,postlink-vmlinux)
 
 # Build samples along the rest of the kernel
 ifdef CONFIG_SAMPLES
@@ -1279,6 +1285,7 @@ $(clean-dirs):
 
 vmlinuxclean:
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
+	$(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
 
 clean: archclean vmlinuxclean
 
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 1366a94..a3e862e 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -121,8 +121,14 @@ quiet_cmd_ld_ko_o = LD [M]  $@
                              $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
                              -o $@ $(filter-out FORCE,$^)
 
+# Optional arch pass after final link
+ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
+      cmd_postlink-ko = \
+          $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+
 $(modules): %.ko :%.o %.mod.o FORCE
 	$(call if_changed,ld_ko_o)
+	+$(call if_changed,postlink-ko)
 
 targets += $(modules)
 
-- 
2.8.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/6] kbuild: add arch specific post-link pass
  2016-08-17  4:43     ` Nicholas Piggin
@ 2016-08-17  9:05       ` Michal Marek
  2016-08-17  9:56       ` Sam Ravnborg
  1 sibling, 0 replies; 28+ messages in thread
From: Michal Marek @ 2016-08-17  9:05 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: linux-kbuild, linux-arch, Sam Ravnborg, Stephen Rothwell,
	Arnd Bergmann, Nicolas Pitre, Segher Boessenkool, Alan Modra

On 2016-08-17 06:43, Nicholas Piggin wrote:
> On Tue, 16 Aug 2016 11:23:45 +0200
> Michal Marek <mmarek@suse.com> wrote:
> 
>> Dne 11.8.2016 v 12:16 Nicholas Piggin napsal(a):
>>>  $(modules): %.ko :%.o %.mod.o FORCE
>>>  	$(call if_changed,ld_ko_o)
>>> +ifdef CONFIG_BUILD_ARCH_POSTLINK
>>> +	$(Q)$(MAKE) -f $(srctree)/arch/$(SRCARCH)/Makefile.postlink $@
>>> +endif  
>>
>> Why not simply branch off the existence of arch/*/Makefile.postlink and
>> drop the kconfig option?
> 
> I just did not think of it. That does seem nicer, thanks. What do
> you think of this?
[...]

This looks cleaner, thanks!

Michal


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/6] kbuild: add arch specific post-link pass
  2016-08-17  4:43     ` Nicholas Piggin
  2016-08-17  9:05       ` Michal Marek
@ 2016-08-17  9:56       ` Sam Ravnborg
  2016-08-18  0:17         ` Nicholas Piggin
  1 sibling, 1 reply; 28+ messages in thread
From: Sam Ravnborg @ 2016-08-17  9:56 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: Michal Marek, linux-kbuild, linux-arch, Stephen Rothwell,
	Arnd Bergmann, Nicolas Pitre, Segher Boessenkool, Alan Modra

> diff --git a/Makefile b/Makefile
> index 1d26fdb..20d3bfd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -954,8 +954,14 @@ include/generated/autoksyms.h: FORCE
>        cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux)
>  quiet_cmd_link-vmlinux = LINK    $@
>  
> +# Optional arch pass after final link
> +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
> +      cmd_postlink-vmlinux = \
> +          $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
> +
>  vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE
>  	+$(call if_changed,link-vmlinux)
> +	+$(call if_changed,postlink-vmlinux)
>  
>  # Build samples along the rest of the kernel
>  ifdef CONFIG_SAMPLES
> @@ -1279,6 +1285,7 @@ $(clean-dirs):
>  
>  vmlinuxclean:
>  	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
> +	$(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
>  
>  clean: archclean vmlinuxclean
>  
Another option would be to embed the logic in the link-vmlinux shell script.
It is much simpler for normal humans to read and understand shell scripts,
and it would be simpler too.


> diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
> index 1366a94..a3e862e 100644
> --- a/scripts/Makefile.modpost
> +++ b/scripts/Makefile.modpost
> @@ -121,8 +121,14 @@ quiet_cmd_ld_ko_o = LD [M]  $@
>                               $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
>                               -o $@ $(filter-out FORCE,$^)
>  
> +# Optional arch pass after final link
> +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
> +      cmd_postlink-ko = \
> +          $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
> +
>  $(modules): %.ko :%.o %.mod.o FORCE
>  	$(call if_changed,ld_ko_o)
> +	+$(call if_changed,postlink-ko)
For modules we have no script, so here we need this.

	Sam

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/6] kbuild: add arch specific post-link pass
  2016-08-17  9:56       ` Sam Ravnborg
@ 2016-08-18  0:17         ` Nicholas Piggin
  0 siblings, 0 replies; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-18  0:17 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: Michal Marek, linux-kbuild, linux-arch, Stephen Rothwell,
	Arnd Bergmann, Nicolas Pitre, Segher Boessenkool, Alan Modra

On Wed, 17 Aug 2016 11:56:33 +0200
Sam Ravnborg <sam@ravnborg.org> wrote:

> > diff --git a/Makefile b/Makefile
> > index 1d26fdb..20d3bfd 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -954,8 +954,14 @@ include/generated/autoksyms.h: FORCE
> >        cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux)
> >  quiet_cmd_link-vmlinux = LINK    $@
> >  
> > +# Optional arch pass after final link
> > +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
> > +      cmd_postlink-vmlinux = \
> > +          $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
> > +
> >  vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE
> >  	+$(call if_changed,link-vmlinux)
> > +	+$(call if_changed,postlink-vmlinux)
> >  
> >  # Build samples along the rest of the kernel
> >  ifdef CONFIG_SAMPLES
> > @@ -1279,6 +1285,7 @@ $(clean-dirs):
> >  
> >  vmlinuxclean:
> >  	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
> > +	$(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
> >  
> >  clean: archclean vmlinuxclean
> >    
> Another option would be to embed the logic in the link-vmlinux shell script.
> It is much simpler for normal humans to read and understand shell scripts,
> and it would be simpler too.

I did that in the previous patch. I struggle with Makefiles too, but
considering that we need the same recipe for modules, I thought just
doing it the same for both was a bit nicer. But I really can go either
way on it so whatever maintainers prefer I can respin.

Thanks,
Nick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections
  2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
                   ` (9 preceding siblings ...)
  2016-08-11 13:55 ` [EXPERIMENTAL] enable thin archives and --gc-sections on ARM Arnd Bergmann
@ 2016-08-23  6:17 ` Nicholas Piggin
  10 siblings, 0 replies; 28+ messages in thread
From: Nicholas Piggin @ 2016-08-23  6:17 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-arch, Michal Marek, Sam Ravnborg, Stephen Rothwell,
	Arnd Bergmann, Nicolas Pitre, Segher Boessenkool, Alan Modra

On Thu, 11 Aug 2016 20:16:14 +1000
Nicholas Piggin <npiggin@gmail.com> wrote:

> Hi,
> 
> I would like to submit the kbuild changes in patches 1-3 for
> consideration.
> 
> I've taken on the feedback, so thanks everybody for that. The
> biggest change since last time is a more general way for
> architectures to do a post-link pass in patch 3.
> 
> On the question of whether to enable thin archives unconditionally,
> I prefer to have architectures enable them as they are tested. But
> I would like to see everybody moved as soon as possible and the
> incremental linking removed.
> 
> All patches should be basically noops without arch enablement,
> so I include initial powerpc enablement in patches 4-6 for
> reference, but I will submit those via powerpc maintainer if
> the kbuild changes are merged.

Hi Michal,

I'm wondering what your thoughts are with this series?

Sam had some other comment on patch 3, but I think it has come to a
matter of preference. I don't mind too much, so I can change it to
whatever people prefer (sh or makefile).

And did you want me to re-post the series, or are you happy to take
updated patches from replies?

The ARM slowness with allyesconfig builds with thin archives was a
linker workaround for a processor bug that they don't need to enable
for allyesconfig build anyway. I provided them a patch to avoid that.
For usual sized builds, it's not noticeable.

Thanks,
Nick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 12:39 ` [PATCH] Xen: remove -fshort-wchar gcc flag Arnd Bergmann
  2016-08-11 12:51   ` Jan Beulich
  2016-08-11 12:51   ` [Xen-devel] " Jan Beulich
@ 2016-08-24 17:18   ` David Vrabel
  2016-08-24 17:18   ` David Vrabel
  3 siblings, 0 replies; 28+ messages in thread
From: David Vrabel @ 2016-08-24 17:18 UTC (permalink / raw)
  To: Arnd Bergmann, Nicholas Piggin
  Cc: linux-arch, Stephen Rothwell, Juergen Gross, Segher Boessenkool,
	Nicolas Pitre, linux-kbuild, Alan Modra, Michal Marek,
	David Vrabel, xen-devel, Boris Ostrovsky, Sam Ravnborg

On 11/08/16 13:39, Arnd Bergmann wrote:
> A previous patch added the --no-wchar-size-warning to the Makefile to
> avoid this harmless warning:
> 
> arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
> 
> Changing kbuild to use thin archives instead of recursive linking
> unfortunately brings the same warning back during the final link.
> 
> This time, we remove the -fshort-wchar flag that originally caused
> the warning, hopefully fixing the problem for good. I don't see
> any reason for having the flag in the first place, as the Xen code
> does not use wchar_t at all.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Fixes: 971a69db7dc0 ("Xen: don't warn about 2-byte wchar_t in efi")

Acked-by: David Vrabel <david.vrabel@citrix.com>

David

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] Xen: remove -fshort-wchar gcc flag
  2016-08-11 12:39 ` [PATCH] Xen: remove -fshort-wchar gcc flag Arnd Bergmann
                     ` (2 preceding siblings ...)
  2016-08-24 17:18   ` [Xen-devel] " David Vrabel
@ 2016-08-24 17:18   ` David Vrabel
  3 siblings, 0 replies; 28+ messages in thread
From: David Vrabel @ 2016-08-24 17:18 UTC (permalink / raw)
  To: Arnd Bergmann, Nicholas Piggin
  Cc: linux-arch, Stephen Rothwell, Juergen Gross, Segher Boessenkool,
	linux-kbuild, Nicolas Pitre, Alan Modra, Michal Marek,
	David Vrabel, xen-devel, Boris Ostrovsky, Sam Ravnborg

On 11/08/16 13:39, Arnd Bergmann wrote:
> A previous patch added the --no-wchar-size-warning to the Makefile to
> avoid this harmless warning:
> 
> arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
> 
> Changing kbuild to use thin archives instead of recursive linking
> unfortunately brings the same warning back during the final link.
> 
> This time, we remove the -fshort-wchar flag that originally caused
> the warning, hopefully fixing the problem for good. I don't see
> any reason for having the flag in the first place, as the Xen code
> does not use wchar_t at all.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Fixes: 971a69db7dc0 ("Xen: don't warn about 2-byte wchar_t in efi")

Acked-by: David Vrabel <david.vrabel@citrix.com>

David

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2016-08-24 17:19 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-11 10:16 [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin
2016-08-11 10:16 ` [PATCH 1/6] kbuild: allow architectures to use thin archives instead of ld -r Nicholas Piggin
2016-08-11 10:16 ` [PATCH 2/6] kbuild: allow archs to select link dead code/data elimination Nicholas Piggin
2016-08-11 10:16 ` [PATCH 3/6] kbuild: add arch specific post-link pass Nicholas Piggin
2016-08-16  9:23   ` Michal Marek
2016-08-17  4:43     ` Nicholas Piggin
2016-08-17  9:05       ` Michal Marek
2016-08-17  9:56       ` Sam Ravnborg
2016-08-18  0:17         ` Nicholas Piggin
2016-08-11 10:16 ` [PATCH 4/6] powerpc: switch to using thin archives Nicholas Piggin
2016-08-11 10:16 ` [PATCH 5/6] powerpc/64: use linker dead code elimination Nicholas Piggin
2016-08-11 10:16 ` [PATCH 6/6] powerpc: use the new post-link pass to check relocations Nicholas Piggin
2016-08-11 12:31 ` [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Stephen Rothwell
2016-08-11 12:39 ` [PATCH] Xen: remove -fshort-wchar gcc flag Arnd Bergmann
2016-08-11 12:51   ` Jan Beulich
2016-08-11 12:51   ` [Xen-devel] " Jan Beulich
2016-08-11 14:01     ` Arnd Bergmann
2016-08-11 14:06       ` Jan Beulich
2016-08-11 14:06       ` Jan Beulich
2016-08-11 14:01     ` Arnd Bergmann
2016-08-24 17:18   ` [Xen-devel] " David Vrabel
2016-08-24 17:18   ` David Vrabel
2016-08-11 12:39 ` Arnd Bergmann
2016-08-11 13:55 ` [EXPERIMENTAL] enable thin archives and --gc-sections on ARM Arnd Bergmann
2016-08-11 20:01   ` Nicolas Pitre
2016-08-11 20:37     ` Arnd Bergmann
2016-08-11 21:05       ` Nicolas Pitre
2016-08-23  6:17 ` [PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections Nicholas Piggin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.