objtool: Do not assume order of parent/child functions
authorKristen Carlson Accardi <kristen@linux.intel.com>
Wed, 15 Apr 2020 21:04:43 +0000 (14:04 -0700)
committerJosh Poimboeuf <jpoimboe@redhat.com>
Thu, 28 May 2020 16:06:05 +0000 (11:06 -0500)
If a .cold function is examined prior to it's parent, the link
to the parent/child function can be overwritten when the parent
is examined. Only update pfunc and cfunc if they were previously
nil to prevent this from happening.

This fixes an issue seen when compiling with -ffunction-sections.

Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
tools/objtool/elf.c

index 84225679f96dae65d5f9af3b29bc07e0fc6a9b34..f953d3a15612a8f88675444e4b8d20d53a44ab81 100644 (file)
@@ -434,7 +434,13 @@ static int read_symbols(struct elf *elf)
                        size_t pnamelen;
                        if (sym->type != STT_FUNC)
                                continue;
-                       sym->pfunc = sym->cfunc = sym;
+
+                       if (sym->pfunc == NULL)
+                               sym->pfunc = sym;
+
+                       if (sym->cfunc == NULL)
+                               sym->cfunc = sym;
+
                        coldstr = strstr(sym->name, ".cold");
                        if (!coldstr)
                                continue;