Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4165159ybg; Mon, 8 Jun 2020 00:15:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUUL18DromI5ueaVhmCBLJl+G4Z/h3e87VNGEo5oJVEBu8Xd8zxOnx7q+UEJEhuM/pnpSl X-Received: by 2002:aa7:cd4b:: with SMTP id v11mr21455246edw.356.1591600549591; Mon, 08 Jun 2020 00:15:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591600549; cv=none; d=google.com; s=arc-20160816; b=AWkXIxJDlO95NXJvAv2ucvMKh8PA3QBcZg3WBAE5fv/oe3VegeJk2rDIN8Gw/JdpkZ 2Ss+UjgYylJ1SsiFS4Rm3Qq2nrH3ZbKb5NXmktTT2RNk1+yCDo5hq2HBmNUka2NtwXJU aWZ9Owc8vy+rDEAHT12w0Ta6OoC2c9PHiAPMVHNo73aUaE83EyHnYlfhnonPlx9+B0gx ZskFJPfC53Y/KZeqKETCS+SCPHg1tMYDqNDIkbl4HlavdbACcrOP9Evoc0Qaw3QJmP0F KLpTWhbHpeH5bvnUxGVIbjpPbSd5a0YUqbXDnIFmddiOpJJ6UOF+1VH0kwizUF/xc0Bu RZxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VGXzotyGQ0uS8DSLgpA4BDR+heUxDbWEeeYOwit4OjY=; b=EBcvx3FEmRxtgTWpju3GuZwRf8GiCyVtYqLRUiEw30Wjq7gSJBlhzXUimNo3PkgGY3 24LbsXTGp/X/wWAJweQniT69Gy2Xp2Hbqr+el+y3wpOtdohiThN87YEJ0ABAEOwqyQSy g9idNj9IzAyMWIFQUV13OwuhbG7gyDphBrK3qgwnuG2mosR86Z3DnEksE5xWYdK3RzzB izpqauQhcqSIdGLc7yGhitjCHU2x256ScgFgdVbdhQUCY10EkQ7zwzOsiu1wq6cv7UBw 4Kc289Bs0dP+GaRV/qAIneiHCt6VYFyOYei2dEP2vrVp7X4o5RRQ0zn1fRoSBgbboGDH Hz4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SeulnYlo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y1si7831008ejq.726.2020.06.08.00.15.27; Mon, 08 Jun 2020 00:15:49 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SeulnYlo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729085AbgFHHMd (ORCPT + 99 others); Mon, 8 Jun 2020 03:12:33 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:52632 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728053AbgFHHMQ (ORCPT ); Mon, 8 Jun 2020 03:12:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591600334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VGXzotyGQ0uS8DSLgpA4BDR+heUxDbWEeeYOwit4OjY=; b=SeulnYloSzSnp5n8GQkYB2SvZu931Dp8cCbC8YToab+HGwvbZVz9Ea/IFFOs1/wwZ2USow lmuG3Oi1mlPtE0oHP3Y47eFFo2W9okUg94BwdIOWrm35+jLejCxBzLAtktFe9a242a3b82 b6LkvGXRS93Lkr0LNPMRFfK3iFICNqk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-43-qeA2l6hNO1SPocw6jEDWGw-1; Mon, 08 Jun 2020 03:12:10 -0400 X-MC-Unique: qeA2l6hNO1SPocw6jEDWGw-1 Received: by mail-wm1-f69.google.com with SMTP id v24so1406248wmh.3 for ; Mon, 08 Jun 2020 00:12:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VGXzotyGQ0uS8DSLgpA4BDR+heUxDbWEeeYOwit4OjY=; b=Q1McAIoPYHIXP+FUMjJo3kXqKP7ivlmrQ8KSo1g2pA3dtCQljElv88thwgscvlWq08 l44NkJWpTGwyjhfCCNvvrThat8L7GJ+KhkMRyTkOSXt9MlkHBt5nJ5T12Qhn1Rnmi3aG a1QRXoGS9fRvr6fIzXK0l/+gvJchPoPsfPws/dxt9Ku8DIx80ZPjAu6MSqvcBxKvmba+ /xBSmQbyZcZOx0VtDdDMqPwK6BMV676zr8PynrWUyRFuXwz8cxOWgkK+5Yo3ol71XNfR nwzlwm+FfHEyFNOwTNHU5hLexmfNhzSC8S4YzgGAwatasedPp6dyn/eiH/uHncqpALs1 3QVQ== X-Gm-Message-State: AOAM532EB5blkMIl2gBskLGisgzC1erCJs4QKoghbOY09W2Qvm2DDGTQ IwdzK332+2WxtH/awGmNCp9cgAdaSrQojNeVwoqN/F6deOboZipQ6ORD0GMo6vRJHghHTX6nFGJ 0Bk9OS6aovwlMv3hCEbozTIEx X-Received: by 2002:adf:a51a:: with SMTP id i26mr21493354wrb.406.1591600328211; Mon, 08 Jun 2020 00:12:08 -0700 (PDT) X-Received: by 2002:adf:a51a:: with SMTP id i26mr21493334wrb.406.1591600327976; Mon, 08 Jun 2020 00:12:07 -0700 (PDT) Received: from redfedo.redhat.com ([2a01:cb14:499:3d00:cd47:f651:9d80:157a]) by smtp.gmail.com with ESMTPSA id w17sm22908254wra.71.2020.06.08.00.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2020 00:12:07 -0700 (PDT) From: Julien Thierry To: linux-kernel@vger.kernel.org Cc: jpoimboe@redhat.com, peterz@infradead.org, mhelsley@vmware.com, mbenes@suse.cz, Julien Thierry Subject: [PATCH v2 1/4] objtool: Move object file loading out of check Date: Mon, 8 Jun 2020 08:12:00 +0100 Message-Id: <20200608071203.4055-2-jthierry@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200608071203.4055-1-jthierry@redhat.com> References: <20200608071203.4055-1-jthierry@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Structure objtool_file can be used by different subcommands. In fact it already is, by check and orc. Provide a function that allows to initialize objtool_file, that builtin can call, without relying on check to do the correct setup for them and explicitly hand the objtool_file to them. Signed-off-by: Julien Thierry --- tools/objtool/builtin-check.c | 7 ++++++- tools/objtool/builtin-orc.c | 8 +++++++- tools/objtool/check.c | 37 +++++++++++------------------------ tools/objtool/objtool.c | 29 +++++++++++++++++++++++++++ tools/objtool/objtool.h | 4 +++- tools/objtool/weak.c | 4 +--- 6 files changed, 57 insertions(+), 32 deletions(-) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 7a44174967b5..9f525d497308 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -41,6 +41,7 @@ const struct option check_options[] = { int cmd_check(int argc, const char **argv) { const char *objname, *s; + struct objtool_file *file; argc = parse_options(argc, argv, check_options, check_usage, 0); @@ -53,5 +54,9 @@ int cmd_check(int argc, const char **argv) if (s && !s[9]) vmlinux = true; - return check(objname, false); + file = objtool_setup_file(objname, false); + if (!file) + return 1; + + return check(file, false); } diff --git a/tools/objtool/builtin-orc.c b/tools/objtool/builtin-orc.c index b1dfe2007962..3b700f477a11 100644 --- a/tools/objtool/builtin-orc.c +++ b/tools/objtool/builtin-orc.c @@ -31,13 +31,19 @@ int cmd_orc(int argc, const char **argv) usage_with_options(orc_usage, check_options); if (!strncmp(argv[0], "gen", 3)) { + struct objtool_file *file; + argc = parse_options(argc, argv, check_options, orc_usage, 0); if (argc != 1) usage_with_options(orc_usage, check_options); objname = argv[0]; - return check(objname, true); + file = objtool_setup_file(objname, true); + if (!file) + return 1; + + return check(file, true); } if (!strcmp(argv[0], "dump")) { diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 63d65a702900..1638428df454 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -26,7 +26,6 @@ struct alternative { bool skip_orig; }; -const char *objname; struct cfi_init_state initial_func_cfi; struct instruction *find_insn(struct objtool_file *file, @@ -2710,36 +2709,22 @@ static int validate_reachable_instructions(struct objtool_file *file) return 0; } -static struct objtool_file file; - -int check(const char *_objname, bool orc) +int check(struct objtool_file *file, bool orc) { int ret, warnings = 0; - objname = _objname; - - file.elf = elf_open_read(objname, orc ? O_RDWR : O_RDONLY); - if (!file.elf) - return 1; - - INIT_LIST_HEAD(&file.insn_list); - hash_init(file.insn_hash); - file.c_file = find_section_by_name(file.elf, ".comment"); - file.ignore_unreachables = no_unreachable; - file.hints = false; - arch_initial_func_cfi_state(&initial_func_cfi); - ret = decode_sections(&file); + ret = decode_sections(file); if (ret < 0) goto out; warnings += ret; - if (list_empty(&file.insn_list)) + if (list_empty(&file->insn_list)) goto out; if (vmlinux && !validate_dup) { - ret = validate_vmlinux_functions(&file); + ret = validate_vmlinux_functions(file); if (ret < 0) goto out; @@ -2748,39 +2733,39 @@ int check(const char *_objname, bool orc) } if (retpoline) { - ret = validate_retpoline(&file); + ret = validate_retpoline(file); if (ret < 0) return ret; warnings += ret; } - ret = validate_functions(&file); + ret = validate_functions(file); if (ret < 0) goto out; warnings += ret; - ret = validate_unwind_hints(&file, NULL); + ret = validate_unwind_hints(file, NULL); if (ret < 0) goto out; warnings += ret; if (!warnings) { - ret = validate_reachable_instructions(&file); + ret = validate_reachable_instructions(file); if (ret < 0) goto out; warnings += ret; } if (orc) { - ret = create_orc(&file); + ret = create_orc(file); if (ret < 0) goto out; - ret = create_orc_sections(&file); + ret = create_orc_sections(file); if (ret < 0) goto out; - ret = elf_write(file.elf); + ret = elf_write(file->elf); if (ret < 0) goto out; } diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index 58fdda510653..71c4122cf491 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -22,6 +22,8 @@ #include #include "builtin.h" +#include "objtool.h" +#include "warn.h" struct cmd_struct { const char *name; @@ -39,6 +41,33 @@ static struct cmd_struct objtool_cmds[] = { bool help; +const char *objname; +static struct objtool_file file; + +struct objtool_file *objtool_setup_file(const char *_objname, bool writable) +{ + if (objname) { + if (strcmp(objname, _objname)) { + WARN("won't handle more than one file at a time"); + return NULL; + } + return &file; + } + objname = _objname; + + file.elf = elf_open_read(objname, writable ? O_RDWR : O_RDONLY); + if (!file.elf) + return NULL; + + INIT_LIST_HEAD(&file.insn_list); + hash_init(file.insn_hash); + file.c_file = find_section_by_name(file.elf, ".comment"); + file.ignore_unreachables = no_unreachable; + file.hints = false; + + return &file; +} + static void cmd_usage(void) { unsigned int i, longest = 0; diff --git a/tools/objtool/objtool.h b/tools/objtool/objtool.h index 528028a66816..e4f0ab5a4094 100644 --- a/tools/objtool/objtool.h +++ b/tools/objtool/objtool.h @@ -19,7 +19,9 @@ struct objtool_file { bool ignore_unreachables, c_file, hints, rodata; }; -int check(const char *objname, bool orc); +struct objtool_file *objtool_setup_file(const char *_objname, bool writable); + +int check(struct objtool_file *file, bool orc); int orc_dump(const char *objname); int create_orc(struct objtool_file *file); int create_orc_sections(struct objtool_file *file); diff --git a/tools/objtool/weak.c b/tools/objtool/weak.c index 942ea5e8ac36..82698319f008 100644 --- a/tools/objtool/weak.c +++ b/tools/objtool/weak.c @@ -17,9 +17,7 @@ return ENOSYS; \ }) -const char __weak *objname; - -int __weak check(const char *_objname, bool orc) +int __weak check(struct objtool_file *file, bool orc) { UNSUPPORTED("check subcommand"); } -- 2.21.1