From: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
To: Arnd Bergmann <arnd@arndb.de>, <linux-kernel@vger.kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Subject: [PATCH 2/2] recordmcount: fix mcount recording with -ffunction-sections
Date: Thu, 22 Dec 2016 09:51:47 +0100 [thread overview]
Message-ID: <1482396707-14349-3-git-send-email-marcin.nowakowski@imgtec.com> (raw)
In-Reply-To: <1482396707-14349-1-git-send-email-marcin.nowakowski@imgtec.com>
When CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled, each function is
added to its own new section called .text.functionname.
As described in vmlinux.lds.h, "those enabling
LD_DEAD_CODE_DATA_ELIMINATION must ensure they don't have conflicting
section names, and must pull in .text.[0-9a-zA-Z_]*", add a similar
pattern matching to recordmcount script for section detection.
To simplify the basic C implementation, replace the regex with a string
match on the prefix and a single character match following the '.text.'
prefix.
Signed-off-by: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
Acked-by: Nicholas Piggin <npiggin@gmail.com>
---
scripts/Makefile | 5 +++++
scripts/recordmcount.c | 26 +++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/scripts/Makefile b/scripts/Makefile
index 1d80897..9b88250 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -23,6 +23,11 @@ hostprogs-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert
HOSTCFLAGS_sortextable.o = -I$(srctree)/tools/include
HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include
+
+ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
+HOSTCFLAGS_recordmcount.o = -DMCOUNT_INCLUDE_FUNCTION_SECTIONS
+endif
+
HOSTLOADLIBES_sign-file = -lcrypto
HOSTLOADLIBES_extract-cert = -lcrypto
diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
index aeb3422..bb517ef 100644
--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
/*
* glibc synced up and added the metag number but didn't add the relocations.
@@ -408,9 +409,31 @@ static uint32_t (*w)(uint32_t);
static uint32_t (*w2)(uint16_t);
/* Names of the sections that could contain calls to mcount. */
+#ifdef MCOUNT_INCLUDE_FUNCTION_SECTIONS
+static int
+is_mcounted_function_section_name(char const *const txtname)
+{
+ const size_t len = strlen(".text.");
+
+ return strncmp(".text.", txtname, len) == 0 &&
+ strlen(txtname) > len &&
+ (isalnum(txtname[len]) || txtname[len] == '_');
+}
+#else
+static int
+is_mcounted_function_section_name(char const *const txtname)
+{
+ return 0;
+}
+#endif
+
+
static int
is_mcounted_section_name(char const *const txtname)
{
+ int ffunc_section =
+ is_mcounted_function_section_name(txtname);
+
return strcmp(".text", txtname) == 0 ||
strcmp(".ref.text", txtname) == 0 ||
strcmp(".sched.text", txtname) == 0 ||
@@ -419,7 +442,8 @@ is_mcounted_section_name(char const *const txtname)
strcmp(".softirqentry.text", txtname) == 0 ||
strcmp(".kprobes.text", txtname) == 0 ||
strcmp(".cpuidle.text", txtname) == 0 ||
- strcmp(".text.unlikely", txtname) == 0;
+ strcmp(".text.unlikely", txtname) == 0 ||
+ ffunc_section;
}
/* 32 bit and 64 bit are very similar */
--
2.7.4
next prev parent reply other threads:[~2016-12-22 9:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-22 8:51 [PATCH RESEND 0/2] kbuild: dead code elimination: ftrace fixes Marcin Nowakowski
2016-12-22 8:51 ` [PATCH 1/2] kbuild: keep __mcount_loc table through dead code elimination Marcin Nowakowski
2016-12-22 8:51 ` Marcin Nowakowski [this message]
2016-12-22 9:08 ` [PATCH RESEND 0/2] kbuild: dead code elimination: ftrace fixes Nicholas Piggin
2016-12-22 9:15 ` Marcin Nowakowski
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=1482396707-14349-3-git-send-email-marcin.nowakowski@imgtec.com \
--to=marcin.nowakowski@imgtec.com \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=npiggin@gmail.com \
/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
all inboxes | Powered by JetHome®