linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org
Cc: sam@ravnborg.org, x86@kernel.org, linux-kbuild@vger.kernel.org,
	Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 15/20] Kbuild, lto: Fix single pass kallsyms for LTO
Date: Tue, 18 Feb 2014 15:28:53 +0100	[thread overview]
Message-ID: <1392733738-8290-16-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1392733738-8290-1-git-send-email-andi@firstfloor.org>

From: Andi Kleen <ak@linux.intel.com>

gcc-nm on slim LTO objects does not output static functions or variables.

This causes the first pass estimation of the kallsyms table
to be off too much. Add a hack using the LTO function sections
to retrieve all functions instead. I wrote that hack in perl,
as it exceeded my awk-fu (this adds a build dependency on perl,
but only if LTO is active). The hack also doesn't support
variables, but we handle that by disable KALLSYMS_ALL with LTO.
The hack is also somewhat depending on the internal LTO
object format.

Hopefully at some future point gcc-nm will be fixed and this
won't be necessary anymore.

One issue is that LTO can generate new symbols in the
final link, for example when cloning functions. These clones
are just copies of existing names with a postfix (which
we remove), so they compress well in the kallsyms compression.

With that we can get away by just adding a 5% safety factor
to the first pass kallsyms estimation, and hope all clones
fit into that.  If some obscure build has more clones than that
the PAD_RATIO value in kallsyms.c can be lowered to increase it.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 init/Kconfig            |  5 ++++-
 scripts/link-vmlinux.sh | 24 +++++++++++++++++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/init/Kconfig b/init/Kconfig
index 009a797..ea00c0e 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1317,7 +1317,10 @@ config KALLSYMS
 
 config KALLSYMS_ALL
 	bool "Include all symbols in kallsyms"
-	depends on DEBUG_KERNEL && KALLSYMS
+	# the method LTO uses to predict the symbol table
+	# only supports functions for now
+	# This can be removed once http://gcc.gnu.org/PR60016 is fixed
+	depends on DEBUG_KERNEL && KALLSYMS && !LTO
 	help
 	   Normally kallsyms only contains the symbols of functions for nicer
 	   OOPS messages and backtraces (i.e., symbols from the text and inittext
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index b299fdd..5a28f2a 100644
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -90,10 +90,28 @@ kallsyms()
 	local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL}               \
 		      ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"
 
-	${NM} -n ${1} | \
-		awk 'NF == 3 { print}' |
-		scripts/kallsyms ${kallsymopt} | \
+	# workaround for slim LTO gcc-nm not outputing static symbols
+	# http://gcc.gnu.org/PR60016
+	# generate a fake symbol table based on the LTO function sections.
+	# This unfortunately "knows" about the internal LTO file format
+	# and only works for functions
+	# needs perl for now when building for LTO
+	(
+	if $OBJDUMP --section-headers ${1} | grep -q \.gnu\.lto_ ; then
+		${OBJDUMP} --section-headers ${1} |
+		perl -ne '
+@n = split;
+next unless $n[1] =~ /\.gnu\.lto_([_a-zA-Z][^.]+)/;
+next if $n[1] eq $prev;
+$prev = $n[1];
+print "0 T ",$1,"\n"'
+	fi
+	${NM} -n ${1} | awk 'NF == 3 { print }'
+	)  > ${2}_sym
+	# run without pipe to make kallsyms errors stop the script
+	./scripts/kallsyms ${kallsymopt} < ${2}_sym |
 		${CC} ${aflags} -c -o ${2} -x assembler-with-cpp -
+
 }
 
 # Create map file with all symbols from ${1}
-- 
1.8.5.2


  parent reply	other threads:[~2014-02-18 14:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-18 14:28 Link Time Optimization patchkit v3 Andi Kleen
2014-02-18 14:28 ` [PATCH 01/20] x86, lto: Disable LTO for the x86 VDSO Andi Kleen
2014-02-18 14:28 ` [PATCH 02/20] lto: Disable LTO for hweight functions Andi Kleen
2014-02-18 14:28 ` [PATCH 03/20] lto: Make asmlinkage __visible Andi Kleen
2014-02-18 14:28 ` [PATCH 04/20] lto, workaround: Add workaround for initcall reordering Andi Kleen
2014-02-18 14:28 ` [PATCH 05/20] lto: Handle LTO common symbols in module loader Andi Kleen
2014-02-18 14:53   ` Konrad Rzeszutek Wilk
2014-02-18 14:28 ` [PATCH 06/20] lto: Disable LTO for sys_ni Andi Kleen
2014-02-18 14:28 ` [PATCH 07/20] lto: Don't let LATENCYTOP and LOCKDEP select KALLSYMS_ALL Andi Kleen
2014-02-18 14:28 ` [PATCH 08/20] Kbuild, lto, workaround: Don't warn for initcall_reference in modpost Andi Kleen
2014-02-18 14:28 ` [PATCH 09/20] Kbuild, lto: Drop .number postfixes " Andi Kleen
2014-02-18 14:28 ` [PATCH 10/20] Kbuild, lto: add ld-version and ld-ifversion macros Andi Kleen
2014-02-18 14:28 ` [PATCH 11/20] Kbuild, lto: Add a gcc-ld script to let run gcc as ld Andi Kleen
2014-02-18 14:28 ` [PATCH 12/20] Kbuild, lto: Disable LTO for asm-offsets.c Andi Kleen
2014-02-18 14:28 ` [PATCH 13/20] Kbuild, lto: Set TMPDIR for LTO v2 Andi Kleen
2014-02-18 14:35   ` H. Peter Anvin
2014-02-18 14:28 ` [PATCH 14/20] Kbuild, lto: Handle basic LTO in modpost Andi Kleen
2014-02-18 14:28 ` Andi Kleen [this message]
2014-02-18 14:28 ` [PATCH 16/20] Kbuild, lto: Add Link Time Optimization support v2 Andi Kleen
2014-02-18 14:28 ` [PATCH 17/20] Kbuild, bloat-o-meter: Ignore .lto_priv postfix Andi Kleen
2014-02-18 14:51   ` Konrad Rzeszutek Wilk
2014-02-18 14:28 ` [PATCH 18/20] lto: Mark spinlocks noinline when inline spinlocks are disabled Andi Kleen
2014-02-18 14:28 ` [PATCH 19/20] lto, module: Warn about modules that are not fully LTOed Andi Kleen
2014-02-18 14:50   ` Konrad Rzeszutek Wilk
2014-02-18 18:52     ` Andi Kleen
2014-02-18 14:28 ` [PATCH 20/20] lto: Don't inline __const_udelay Andi Kleen
2014-02-18 14:34 ` Link Time Optimization patchkit v3 H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392733738-8290-16-git-send-email-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam@ravnborg.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).