Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3466883imu; Wed, 7 Nov 2018 10:44:51 -0800 (PST) X-Google-Smtp-Source: AJdET5dWSWFLYpjTA1UTxEbAtjSi+V8Sh1ksZcKKDhcLo46g5l+g4LJg9GTX8Q5S46/lBr1NNpD/ X-Received: by 2002:a63:d604:: with SMTP id q4mr1119915pgg.175.1541616291430; Wed, 07 Nov 2018 10:44:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541616291; cv=none; d=google.com; s=arc-20160816; b=VG9JMiip2Zz5IRk1GDVOfe/Idjn73Wtt6OEp5A4HFsWYqOPX0HmpBYoPLz8o4fP+lv JJ8W/ZLAP1Kpp4mQt2Dj0VV//aOjKUBwIJew4+LN9BQ+UsTn1eISYpstiCcrT2MV0bZ5 kWyUToB/Ux1l3SJYSTMaSlP+5pwPgxFXPQXF4qgAL+dCAaOA9kQrB7RMTosZCS5W1KpP 4rTnx6tKhiRAFOZ5nIBwMi1ix9PzdZ69jr82DiFboLbfbHdyYqt1q3f/TUM7T5UqeLB5 9vugWUJfv76V1/mGX5DE3/i+FE6sAG27ReGk/m615FOK2oP6u+pzvAHe0nZhWbb+VsGe rc6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=I50WRanm2l9fdkvfUMCkwoM4MahFuAfDiAPrm4i0vhQ=; b=0V+hFOmWILoH4CXr5AuKlrl3wiV+0OM57u7CDwq/K3+wRrp8cmuBJ7tpulpR6J24dt rBty1uy1hEel2DowxqGY3QZBl9ATAKs1FmTc4fr2RTyhbHKk76mf5eyNAkd22FMkmscD 4mn2VUARb0Q4vY33dAVpXsuTqJ10L6V2GnwKj/982qRfLDKtO+cqvZR94yOUoTDDIcmZ uD5AO6D4cBlX//KDjTx9hilmC6YDnrN91I277jgXVZtUf1E5SRs8RRmQUZhO3lgOq59Q vow7/Sm9kuf4Wd/jSNHTeEUVsQMyYsHOrFhmvjNmvZ5NCoojfoExTTb91wMCQBf9BW1m djPw== 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 t75-v6si1438282pfi.221.2018.11.07.10.44.36; Wed, 07 Nov 2018 10:44:51 -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 S1728913AbeKHEOY (ORCPT + 99 others); Wed, 7 Nov 2018 23:14:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49964 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726915AbeKHEOY (ORCPT ); Wed, 7 Nov 2018 23:14:24 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 97D063001DCC; Wed, 7 Nov 2018 18:42:47 +0000 (UTC) Received: from shodan.usersys.redhat.com (unknown [10.43.17.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F12F5D6A6; Wed, 7 Nov 2018 18:42:47 +0000 (UTC) Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id B1BF42C1A13; Wed, 7 Nov 2018 19:42:46 +0100 (CET) Date: Wed, 7 Nov 2018 19:42:46 +0100 From: Artem Savkov To: Josh Poimboeuf Cc: Peter Zijlstra , linux-kernel@vger.kernel.org Subject: Re: [PATCH] objtool: fix .cold. functions parent symbols search Message-ID: <20181107184246.GC11183@shodan.usersys.redhat.com> References: <20181107140559.28504-1-asavkov@redhat.com> <20181107170856.usgyzckfirem5qh7@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181107170856.usgyzckfirem5qh7@treble> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 07 Nov 2018 18:42:47 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 07, 2018 at 11:08:56AM -0600, Josh Poimboeuf wrote: > On Wed, Nov 07, 2018 at 03:05:59PM +0100, Artem Savkov wrote: > > The way it is currently done it is possible for read_symbols() to find the > > same symbol as parent for ".cold" functions. > > I seem to remember having this discussion for kpatch-build, but I forget > the details. Can you explain how this can happen (and also add that > detail to the commit message)? find_symbol_by_name() traverses the same lists as read_symbols and when we change sym->name in place without copying it it changes in the list as well. So if child function is before parent in sec->symbol_list the same function will be returned as "parent". It is hard for me to put it into words worthy to be included into commit message. > I haven't seen any bug reports, is it purely theoretical? No, 4.20-rc1 (actually anything after 4a60aa05a063 "objtool: Support per-function rodata sections", before that add_switch_table() doesn't seem to be called for those .cold. funcs) fails to build for mewith KCFLAGS="-ffunction-sections -fdata-sections" because objtool is segfaulting. > > 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 > > > > -- > Josh -- Regards, Artem