linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Sami Tolvanen <samitolvanen@google.com>,
	Sedat Dilek <sedat.dilek@gmail.com>,
	Kees Cook <keescook@chromium.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	clang-built-linux@googlegroups.com,
	Miroslav Benes <mbenes@suse.cz>
Subject: [PATCH v2 10/20] objtool: Move unsuffixed symbol conversion to a helper function
Date: Thu, 21 Jan 2021 15:29:26 -0600	[thread overview]
Message-ID: <693bc87431d1fb498e93a43ea2640e4512c39144.1611263462.git.jpoimboe@redhat.com> (raw)
In-Reply-To: <cover.1611263461.git.jpoimboe@redhat.com>

This logic will also be needed for the CONFIG_CFI_CLANG support.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/objtool/elf.c | 60 ++++++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 23 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 43714ecd09f7..e7d9c29fe78c 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -262,6 +262,38 @@ struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, uns
 	return find_reloc_by_dest_range(elf, sec, offset, 1);
 }
 
+static int find_unsuffixed_func(const struct elf *elf, struct symbol *sym,
+				const char *suffix, struct symbol **func)
+{
+	char name[MAX_NAME_LEN + 1];
+	const char *loc;
+	size_t len;
+
+	*func = NULL;
+
+	loc = strstr(sym->name, suffix);
+	if (!loc)
+		return 0;
+
+	len = loc - sym->name;
+	if (len > MAX_NAME_LEN) {
+		WARN("%s(): unsuffixed function name exceeds maximum length of %d characters",
+		     sym->name, MAX_NAME_LEN);
+		return -1;
+	}
+
+	strncpy(name, sym->name, len);
+	name[len] = '\0';
+
+	*func = find_symbol_by_name(elf, name);
+	if (!*func || (*func)->type != STT_FUNC) {
+		WARN("%s(): can't find unsuffixed function", sym->name);
+		return -1;
+	}
+
+	return 0;
+}
+
 void insn_to_reloc_sym_addend(struct section *sec, unsigned long offset,
 			      struct reloc *reloc)
 {
@@ -374,7 +406,6 @@ static int read_symbols(struct elf *elf)
 	struct list_head *entry;
 	struct rb_node *pnode;
 	int symbols_nr, i;
-	char *coldstr;
 	Elf_Data *shndx_data = NULL;
 	Elf32_Word shndx;
 
@@ -456,37 +487,20 @@ static int read_symbols(struct elf *elf)
 	/* Create parent/child links for any cold subfunctions */
 	list_for_each_entry(sec, &elf->sections, list) {
 		list_for_each_entry(sym, &sec->symbol_list, list) {
-			char pname[MAX_NAME_LEN + 1];
-			size_t pnamelen;
 			if (sym->type != STT_FUNC)
 				continue;
 
-			if (sym->pfunc == NULL)
+			if (!sym->pfunc)
 				sym->pfunc = sym;
 
-			if (sym->cfunc == NULL)
+			if (!sym->cfunc)
 				sym->cfunc = sym;
 
-			coldstr = strstr(sym->name, ".cold");
-			if (!coldstr)
-				continue;
-
-			pnamelen = coldstr - sym->name;
-			if (pnamelen > MAX_NAME_LEN) {
-				WARN("%s(): parent function name exceeds maximum length of %d characters",
-				     sym->name, MAX_NAME_LEN);
+			if (find_unsuffixed_func(elf, sym, ".cold", &pfunc))
 				return -1;
-			}
 
-			strncpy(pname, sym->name, pnamelen);
-			pname[pnamelen] = '\0';
-			pfunc = find_symbol_by_name(elf, pname);
-
-			if (!pfunc) {
-				WARN("%s(): can't find parent function",
-				     sym->name);
-				return -1;
-			}
+			if (!pfunc)
+				continue;
 
 			sym->pfunc = pfunc;
 			pfunc->cfunc = sym;
-- 
2.29.2


  parent reply	other threads:[~2021-01-21 21:37 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 21:29 [PATCH v2 00/20] objtool: vmlinux.o and CLANG LTO support Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 01/20] objtool: Fix error handling for STD/CLD warnings Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 02/20] objtool: Fix retpoline detection in asm code Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 03/20] objtool: Fix ".cold" section suffix check for newer versions of GCC Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 04/20] objtool: Support retpoline jump detection for vmlinux.o Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 05/20] x86/ftrace: Add UNWIND_HINT_FUNC annotation for ftrace_stub Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 06/20] objtool: Assume only ELF functions do sibling calls Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 07/20] objtool: Add asm version of STACK_FRAME_NON_STANDARD Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 08/20] objtool: Combine UNWIND_HINT_RET_OFFSET and UNWIND_HINT_FUNC Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 09/20] objtool: Add xen_start_kernel() to noreturn list Josh Poimboeuf
2021-01-21 21:29 ` Josh Poimboeuf [this message]
2021-01-21 21:29 ` [PATCH v2 11/20] objtool: Add CONFIG_CFI_CLANG support Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 12/20] x86/xen: Support objtool validation in xen-asm.S Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 13/20] x86/xen: Support objtool vmlinux.o validation in xen-head.S Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 14/20] x86/xen/pvh: Annotate indirect branch as safe Josh Poimboeuf
2021-01-22  5:17   ` Jürgen Groß
2021-01-21 21:29 ` [PATCH v2 15/20] x86/ftrace: Support objtool vmlinux.o validation in ftrace_64.S Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 16/20] x86/acpi: Annotate indirect branch as safe Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 17/20] x86/acpi: Support objtool validation in wakeup_64.S Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 18/20] x86/power: Annotate indirect branches as safe Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 19/20] x86/power: Move restore_registers() to top of the file Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 20/20] x86/power: Support objtool validation in hibernate_asm_64.S Josh Poimboeuf
2021-01-21 22:38 ` [PATCH v2 00/20] objtool: vmlinux.o and CLANG LTO support Sedat Dilek
2021-01-22 15:41   ` Josh Poimboeuf
2021-01-22 21:17     ` Sami Tolvanen
2021-01-23  1:32       ` Nick Desaulniers
2021-01-23  2:26         ` Josh Poimboeuf
2021-01-23  2:31           ` Sedat Dilek
2021-01-23  2:46             ` Josh Poimboeuf
2021-01-23  2:50               ` Sedat Dilek
2021-01-25 22:43           ` Sami Tolvanen

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=693bc87431d1fb498e93a43ea2640e4512c39144.1611263462.git.jpoimboe@redhat.com \
    --to=jpoimboe@redhat.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=samitolvanen@google.com \
    --cc=sedat.dilek@gmail.com \
    --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).