Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1336401ybt; Thu, 25 Jun 2020 03:42:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5nciupMvCzNCDCYfeapnfR/73Yl1xOBmD/7Jp6tnwJh+gG+bFLjsBNj11qYCe3iN/u0xp X-Received: by 2002:a05:6402:796:: with SMTP id d22mr21492890edy.78.1593081765721; Thu, 25 Jun 2020 03:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593081765; cv=none; d=google.com; s=arc-20160816; b=F4TKf+VqlGqMUEzYIK9RzeC0qyHwI2f+Y5gaRCu5t4bRhHuqmY2wJ/11AcU4m+vqm2 PpiAiV3qG7tNSm33btzNgRm20TAhswARVxQz4/uj4oD1/OjtZvab1ZGE+Q08a9RwCNAT RPS75fXzryesPF/Ps6J5ZCNK+GJEOoKZ25o3ZZHtS/vmU3HjW2d6wxjiAOwDLPTJS0Hp EIVmIISoe0E6Av7XAgB3Ou1Y9TcSFgUF/jIW8ugoH+3G5JK70IjhShfCLUtRrOS83o0G fnZP0Q6uRAxqDHL6g8QE1R+IHgwb+Tvl6xy0Ovt5A+GhRdQNY5oxH4+AupP7BykXyWdg hX5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=59FA3sOL3ldJjWD9irSMs8Y/s1MXLMA4i63/0PdJ6yc=; b=O8as17vhtpkhfgw+lCETfXbByn8Wrz/poQlh2RCtrqgujTo23pmzcf4TLTfie3os6C 3g7jxsAqEXBajbSaeu95UsuzL/0ZDaYZEu/kPeu7BpwHHqVrHPQHg8BmBwZYSHWMzbXg zzPyeeMQUIG2dOWVVvLkn7ppL1q7GymKkFGrhDY+K5RXJ2ZRcobbjqVnnA+6Bqu96CS1 rMOTadXZNIr3gsRsg5kDeXCFRXs/UFkop4dse4RdG+55k2256eRSexyAGP/LBgcK39zK BeOgLNw05LvVyjcXjwzs6Y3cONeULmypvjvmZkyafdr93M1hM/qDAbUmVOJ2RYfT5JTv UEEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp14si19130295ejc.412.2020.06.25.03.42.20; Thu, 25 Jun 2020 03:42:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403972AbgFYKjh (ORCPT + 99 others); Thu, 25 Jun 2020 06:39:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:55892 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403816AbgFYKjh (ORCPT ); Thu, 25 Jun 2020 06:39:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 161D6AD39; Thu, 25 Jun 2020 10:39:35 +0000 (UTC) Date: Thu, 25 Jun 2020 12:39:34 +0200 (CEST) From: Miroslav Benes To: Matt Helsley cc: linux-kernel@vger.kernel.org, Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Julien Thierry , Kamalesh Babulal Subject: Re: [RFC][PATCH v5 03/51] objtool: Make recordmcount into mcount subcmd In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 18 Jun 2020, Matt Helsley wrote: > Rather than a standalone executable merge recordmcount as a sub command > of objtool. This is a small step towards cleaning up recordmcount and > eventually sharing ELF code with objtool. > > For the initial step all that's required is a bit of Makefile changes > and invoking the former main() function from recordmcount.c because the > subcommand code uses similar function arguments as main when dispatching. > > objtool ignores some object files that tracing does not, specifically > those with OBJECT_FILES_NON_STANDARD Makefile variables. For this reason > we keep the recordmcount_dep separate from the objtool_dep. When using > objtool mcount we can also, like the other objtool invocations, just > depend on the binary rather than the source the binary is built from. > > Subsequent patches will gradually convert recordmcount to use > more and more of libelf/objtool's ELF accessor code. This will both > clean up recordmcount to be more easily readable and remove > recordmcount's crude accessor wrapping code. I'll try to leave only relevant parts for a question below... > sub_cmd_record_mcount = \ > if [ $(@) != "scripts/mod/empty.o" ]; then \ > - $(objtree)/tools/objtool/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \ > + $(objtree)/tools/objtool/objtool mcount record $(RECORDMCOUNT_FLAGS) "$(@)"; \ > fi; > +int cmd_mcount(int argc, const char **argv) > +{ > + argc--; argv++; > + if (argc <= 0) > + usage_with_options(mcount_usage, mcount_options); > + > + if (!strncmp(argv[0], "record", 6)) { > + argc = parse_options(argc, argv, > + mcount_options, mcount_usage, 0); > + if (argc < 1) > + usage_with_options(mcount_usage, mcount_options); > + > + return record_mcount(argc, argv); > + } > + > + usage_with_options(mcount_usage, mcount_options); > + > + return 0; > +} > -int main(int argc, char *argv[]) > +int record_mcount(int argc, const char **argv) > { > const char ftrace[] = "/ftrace.o"; > int ftrace_size = sizeof(ftrace) - 1; > int n_error = 0; /* gcc-4.3.0 false positive complaint */ > - int c; > int i; > > - while ((c = getopt(argc, argv, "w")) >= 0) { > - switch (c) { > - case 'w': > - warn_on_notrace_sect = 1; > - break; > - default: > - fprintf(stderr, "usage: recordmcount [-w] file.o...\n"); > - return 0; > - } > - } > - > - if ((argc - optind) < 1) { > - fprintf(stderr, "usage: recordmcount [-w] file.o...\n"); > - return 0; > - } > - > /* Process each file in turn, allowing deep failure. */ > - for (i = optind; i < argc; i++) { > - char *file = argv[i]; > + for (i = 0; i < argc; i++) { > + const char *file = argv[i]; > int len; Do you expect that mcount subcmd would be called on more than one object file at a time? I don't see a reason for that with all the Makefile changes, but I may be missing something (Kbuild is a maze for me). Because if not, I think it would be nice to make record_mcount() more similar to what we have for check(). After Julien's changes (20200608071203.4055-1-jthierry@redhat.com) at least. So that record_mcount() could accept struct objtool_file and work directly on that. It would also impact several other patches in the series. For example, is there a need for a private 'struct elf *lf' in mcount.c? Thanks Miroslav