linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] objtool: fix .cold. functions parent symbols search
@ 2018-11-07 14:05 Artem Savkov
  2018-11-07 17:08 ` Josh Poimboeuf
  0 siblings, 1 reply; 17+ messages in thread
From: Artem Savkov @ 2018-11-07 14:05 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: Peter Zijlstra, linux-kernel, Artem Savkov

The way it is currently done it is possible for read_symbols() to find the
same symbol as parent for ".cold" functions. This leads to a bunch of
complications such as func length being set to 0 and a segfault in
add_switch_table(). Fix by copying the search string instead of modifying
it in place.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 tools/objtool/elf.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 6dbb9fae0f9d..781c8afb29b9 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -298,6 +298,7 @@ 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;
 			if (sym->type != STT_FUNC)
 				continue;
 			sym->pfunc = sym->cfunc = sym;
@@ -305,9 +306,9 @@ static int read_symbols(struct elf *elf)
 			if (!coldstr)
 				continue;
 
-			coldstr[0] = '\0';
-			pfunc = find_symbol_by_name(elf, sym->name);
-			coldstr[0] = '.';
+			pname = strndup(sym->name, coldstr - sym->name);
+			pfunc = find_symbol_by_name(elf, pname);
+			free(pname);
 
 			if (!pfunc) {
 				WARN("%s(): can't find parent function",
-- 
2.17.2


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

end of thread, other threads:[~2018-11-20 14:12 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-07 14:05 [PATCH] objtool: fix .cold. functions parent symbols search Artem Savkov
2018-11-07 17:08 ` Josh Poimboeuf
2018-11-07 18:42   ` Artem Savkov
2018-11-07 20:29     ` Josh Poimboeuf
2018-11-07 21:45       ` [PATCH v2] " Artem Savkov
2018-11-09 17:23         ` Josh Poimboeuf
2018-11-10 12:18           ` Artem Savkov
2018-11-12  3:38             ` Josh Poimboeuf
2018-11-12 12:55               ` [PATCH v3 0/2] objtool: read_symbols() fixes Artem Savkov
2018-11-12 12:55                 ` [PATCH v3 1/2] objtool: fix failed cold symbol doublefree Artem Savkov
2018-11-19 17:57                   ` Josh Poimboeuf
2018-11-12 12:55                 ` [PATCH v3 2/2] objtool: fix .cold functions parent symbols search Artem Savkov
2018-11-19 18:02                   ` Josh Poimboeuf
2018-11-20  8:05                 ` [PATCH v4 0/2] objtool: read_symbols() fixes Artem Savkov
2018-11-20  8:05                   ` [PATCH v4 1/2] objtool: fix failed cold symbol doublefree Artem Savkov
2018-11-20  8:05                   ` [PATCH v4 2/2] objtool: fix .cold functions parent symbols search Artem Savkov
2018-11-20 14:12                   ` [PATCH v4 0/2] objtool: read_symbols() fixes Josh Poimboeuf

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).