Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3158583imu; Wed, 7 Nov 2018 06:06:46 -0800 (PST) X-Google-Smtp-Source: AJdET5fj+X8ye6rmdGzV+UBkRXa9tt54myfXssJzrJBmTXzbGVh2OhEb/AXovdaoQhMyyMv/zaxI X-Received: by 2002:a17:902:2702:: with SMTP id c2-v6mr366397plb.314.1541599606615; Wed, 07 Nov 2018 06:06:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541599606; cv=none; d=google.com; s=arc-20160816; b=BHtwHTeNHpB5Uw0cGF/Gz4tjb09RGV0BXdegnwp1lHhGX71xRKZzlINGQgFGy4dMD7 mHBTnCrG9ZbfUaSN9HvbOTK1V4jDlahYs6P9A9OYhtKq2k8CHP/F8BE6Lix1enFXEiOW ILqF9ufAVgy3fOvj4arHj6SXk+UvQ6XXSdA0ub0mD2eZ2yfXDOwDPwTwzqULn240eulD wOgIb8vDZoG5LZOYShlikQiEc63l9nEYB7zaoqNr3iyQtuNCuTm1Gzf4yTQn6frzGkmj z2CEKw/hRZS+49y0hauxHDjyTXTrxrwcpFufCI1cG+pCpXT+cIcSIAOIkpVfJKQLS3Qm yunA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=U28oyGpOGFKMA/07G8Zzk88hBX0EHvKJzwbxdfEmj9o=; b=MW31eXiPVJhLmu8f64+MBDgks2++ZV1zedp91Q3NRaQH/ij2M92C71iC3OtNQulHpu xaOJRBGvk5L2ULfI+Jw8Ni/ZUgy6vjL/9KQ6Xm4zGuBRVPZIfYUE/GqgwvwPmnMnlRYA thghQLli+qwJfKa8q53rU5weumlGcu+MHTRTxAr6wuHZfgLsQeA3ScRfDhhew4VqAbgw mM36NIALm/X8MW31DKorx+vlcQ/m1b89n9yjeOBM1apQaZxCuo+8qB7wTSTXFuojLQji ah455N4uEVp5aAWIuBSRIJGkOup15lTL+dBVNBmzG2VGOdXByfxtm+7zlxcTk7vXbNiQ 10iQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p91-v6si756416plb.374.2018.11.07.06.06.32; Wed, 07 Nov 2018 06:06:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727693AbeKGXgj (ORCPT + 99 others); Wed, 7 Nov 2018 18:36:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33608 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726635AbeKGXgj (ORCPT ); Wed, 7 Nov 2018 18:36:39 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04C43C05D3F7; Wed, 7 Nov 2018 14:06:08 +0000 (UTC) Received: from shodan.usersys.redhat.com (unknown [10.43.17.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEAC31001F4C; Wed, 7 Nov 2018 14:06:07 +0000 (UTC) Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id 171732C1A0C; Wed, 7 Nov 2018 15:06:07 +0100 (CET) From: Artem Savkov To: Josh Poimboeuf Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Artem Savkov Subject: [PATCH] objtool: fix .cold. functions parent symbols search Date: Wed, 7 Nov 2018 15:05:59 +0100 Message-Id: <20181107140559.28504-1-asavkov@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 07 Nov 2018 14:06:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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