Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1438818ybg; Thu, 4 Jun 2020 09:42:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKMy/9OdurMZKyFPx+cB9DAMEkaNuMnj7fuAn2i8ftlClcux0ckS2eJ7IjMtt5ZvWG04EP X-Received: by 2002:aa7:d698:: with SMTP id d24mr5256593edr.56.1591288925852; Thu, 04 Jun 2020 09:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591288925; cv=none; d=google.com; s=arc-20160816; b=LHLoIQ7lrc5slWP9eedIe53LFsfw0rkC9TYuBo5BuCSK38EYMkdeC6L7vzImYijCK+ Z4mpSrtR29MSfTfs8xZOtwt07xBGSkSz99MmaJrXnWdZSP+k9K+euhBg7RGqr8kmeyZF 5rRx1aBct9FJ/yGVhyR2KQUiVkjsc+alINA7/vS8S43ObQ0cFi7AmVt2z6G0KVYPEsfY w9r+Nj8OP5UqIcJ8FTSJeFqa1px+vQ2QociwgLor/s+4wre3WdHfX3mMm7gyM53mOEHe KCFWV2VHTVYz/MvgJ613AWVLrGKb8ji9Tmi9CNWfA6uFnDZyAUTQUQsmHIRViqjDGRSv EnvQ== 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=NF2VWmtkVvO+oeaxQB5cRYXlRd5YODZUpdBaRJJyuxY=; b=R9vZ7VvCT7h2n/KIVLIQVQj41wOqkvK/Swzj/jnbPVM1ZtgdOPeFVNxyqDod0k87bO 7m8ASkf9n1ecYWBSCfz/336cpv1UJxehwXi6+pgrvhMRWJ+tfay+At/wckCwQyPAWgfS UAiU7BMWWBHFV82kO+P3Dx9I1o7iYCztGwA9weos/3tWxRRDKhB/dg/GO38ywBFqNbCE b6iiponpqUcSidNZCkpg0scOMelDQHTGGx+MZmFu+LJ4C2rqbjw1VcezI3fClzBqyM9V O27EW6xlW6SxGiNICmv5gaq2Q2N+UOel47e0RT1XS7Z+YyIASXFQX5FHlSdJDi1WAMMw PfTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="JA/AYhCv"; 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 w26si2165460eds.339.2020.06.04.09.41.42; Thu, 04 Jun 2020 09:42:05 -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="JA/AYhCv"; 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 S1729888AbgFDQjy (ORCPT + 99 others); Thu, 4 Jun 2020 12:39:54 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56065 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729870AbgFDQjw (ORCPT ); Thu, 4 Jun 2020 12:39:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591288789; 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=NF2VWmtkVvO+oeaxQB5cRYXlRd5YODZUpdBaRJJyuxY=; b=JA/AYhCv1gpJh2cxF/SNevytUgNeqFOCGgKREap3x1HvAPmSIzOTBua88ip8dwpCQk45hJ ggLf/PpJocLQHBzFAgBKswjRuQ9EcpM8wfA9GMFiDalAgddTGNP1s4E8VuRM7bGi7RFldq 1yLq5a53xrEUsnM2g39NZG8/agqQ+6A= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-240-bxUu6voQPoCX2Yz43unlkA-1; Thu, 04 Jun 2020 12:39:48 -0400 X-MC-Unique: bxUu6voQPoCX2Yz43unlkA-1 Received: by mail-wm1-f70.google.com with SMTP id l26so2177393wmh.3 for ; Thu, 04 Jun 2020 09:39:48 -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=NF2VWmtkVvO+oeaxQB5cRYXlRd5YODZUpdBaRJJyuxY=; b=qffWlaLUF3oqoVd+VFB5nI8SaWtfgRsov7Q7JlciHBzhZTVthE4QexRpFCo7os4xOQ TwbVGKVIilkIeIH2qSPUcjoZYF/S5RGez6MpbKdC68oFNr0GYjLhyxzpa/eAHhzlr41j grY2WjIdavkvT2AtWo1d+buCkczUqzlOOZ3PQ1wL+wttTfP3mZpzW+/c7a8KgLLdSSJm zPXTuUz/I7fe0h1kFJpyb7rvvd9MRtUvoW1NqOrfIIqR9pYg2xeaiRjquntn/JZsbvvP NxEcyaz8nNgqZmCCcjw2+ErJpYG2fmpzytN7ICXCasPoiZpm43eyuQsGzX2iszhpWFHk o52A== X-Gm-Message-State: AOAM532MoJpI91zGXlZmM82YVv6fW2PdqvQ2m8bsJ5DF2WwmfWVwdxOd P2R2pHh18atP4kRetjksKjjYcnv12UF5F7WDpTl/zyH4PP0MWYEDT1pGdYt07pjNUR3vtE3sLaM rBZPAX57723AUHD5SF75W3LUv X-Received: by 2002:a7b:cae2:: with SMTP id t2mr4885319wml.150.1591288787127; Thu, 04 Jun 2020 09:39:47 -0700 (PDT) X-Received: by 2002:a7b:cae2:: with SMTP id t2mr4885299wml.150.1591288786889; Thu, 04 Jun 2020 09:39:46 -0700 (PDT) Received: from redfedo.redhat.com ([2a01:cb14:499:3d00:cd47:f651:9d80:157a]) by smtp.gmail.com with ESMTPSA id p9sm7881636wma.48.2020.06.04.09.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 09:39:45 -0700 (PDT) From: Julien Thierry To: linux-kernel@vger.kernel.org Cc: jpoimboe@redhat.com, peterz@infradead.org, mhelsley@vmware.com, Julien Thierry Subject: [PATCH 4/4] objtool: orc_gen: Move orc_entry out of instruction structure Date: Thu, 4 Jun 2020 17:39:38 +0100 Message-Id: <20200604163938.21660-5-jthierry@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200604163938.21660-1-jthierry@redhat.com> References: <20200604163938.21660-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 One orc_entry is associated with each instruction in the object file, but having the orc_entry contained by the instruction structure forces architectures not implementing the orc subcommands to provide a dummy definition of the orc_entry. Avoid that by having orc_entries in a separate list, part of the objtool_file. Signed-off-by: Julien Thierry --- tools/objtool/check.h | 1 - tools/objtool/objtool.c | 1 + tools/objtool/objtool.h | 1 + tools/objtool/orc_gen.c | 83 +++++++++++++++++++++++------------------ 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/tools/objtool/check.h b/tools/objtool/check.h index 906b5210f7ca..49f9a5cc4228 100644 --- a/tools/objtool/check.h +++ b/tools/objtool/check.h @@ -42,7 +42,6 @@ struct instruction { struct symbol *func; struct list_head stack_ops; struct cfi_state cfi; - struct orc_entry orc; }; struct instruction *find_insn(struct objtool_file *file, diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index 71c4122cf491..4b2e8013edb8 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -61,6 +61,7 @@ struct objtool_file *objtool_setup_file(const char *_objname, bool writable) INIT_LIST_HEAD(&file.insn_list); hash_init(file.insn_hash); + INIT_LIST_HEAD(&file.orc_data_list); file.c_file = find_section_by_name(file.elf, ".comment"); file.ignore_unreachables = no_unreachable; file.hints = false; diff --git a/tools/objtool/objtool.h b/tools/objtool/objtool.h index be526f3d294d..e782c4206cb2 100644 --- a/tools/objtool/objtool.h +++ b/tools/objtool/objtool.h @@ -16,6 +16,7 @@ struct objtool_file { struct elf *elf; struct list_head insn_list; DECLARE_HASHTABLE(insn_hash, 20); + struct list_head orc_data_list; bool ignore_unreachables, c_file, hints, rodata; }; diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c index e74578640705..b8d199682530 100644 --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -9,14 +9,32 @@ #include "check.h" #include "warn.h" +struct orc_data { + struct list_head list; + struct instruction *insn; + struct orc_entry orc; +}; + int create_orc(struct objtool_file *file) { struct instruction *insn; for_each_insn(file, insn) { - struct orc_entry *orc = &insn->orc; struct cfi_reg *cfa = &insn->cfi.cfa; struct cfi_reg *bp = &insn->cfi.regs[CFI_BP]; + struct orc_entry *orc; + struct orc_data *od; + + if (!insn->sec->text) + continue; + + od = calloc(1, sizeof(*od)); + if (!od) + return -1; + od->insn = insn; + list_add_tail(&od->list, &file->orc_data_list); + + orc = &od->orc; if (!insn->sec->text) continue; @@ -139,7 +157,7 @@ static int create_orc_entry(struct elf *elf, struct section *u_sec, struct secti int create_orc_sections(struct objtool_file *file) { - struct instruction *insn, *prev_insn; + struct orc_data *od, *prev_od; struct section *sec, *u_sec, *ip_relasec; unsigned int idx; @@ -157,23 +175,21 @@ int create_orc_sections(struct objtool_file *file) /* count the number of needed orcs */ idx = 0; - for_each_sec(file, sec) { - if (!sec->text) - continue; - - prev_insn = NULL; - sec_for_each_insn(file, sec, insn) { - if (!prev_insn || - memcmp(&insn->orc, &prev_insn->orc, - sizeof(struct orc_entry))) { - idx++; - } - prev_insn = insn; + prev_od = NULL; + list_for_each_entry(od, &file->orc_data_list, list) { + if (!prev_od || + memcmp(&od->orc, &prev_od->orc, sizeof(struct orc_entry))) { + idx++; } + prev_od = od; + /* section terminator */ - if (prev_insn) + if (list_is_last(&od->insn->list, &file->insn_list) || + list_next_entry(od->insn, list)->sec != od->insn->sec) { + prev_od = NULL; idx++; + } } if (!idx) return -1; @@ -194,33 +210,28 @@ int create_orc_sections(struct objtool_file *file) /* populate sections */ idx = 0; - for_each_sec(file, sec) { - if (!sec->text) - continue; - - prev_insn = NULL; - sec_for_each_insn(file, sec, insn) { - if (!prev_insn || memcmp(&insn->orc, &prev_insn->orc, - sizeof(struct orc_entry))) { - - if (create_orc_entry(file->elf, u_sec, ip_relasec, idx, - insn->sec, insn->offset, - &insn->orc)) - return -1; - - idx++; - } - prev_insn = insn; + prev_od = NULL; + list_for_each_entry(od, &file->orc_data_list, list) { + if (!prev_od || + memcmp(&od->orc, &prev_od->orc, sizeof(struct orc_entry))) { + if (create_orc_entry(file->elf, u_sec, ip_relasec, idx, + od->insn->sec, od->insn->offset, + &od->orc)) + return -1; + idx++; } + prev_od = od; + /* section terminator */ - if (prev_insn) { + if (list_is_last(&od->insn->list, &file->insn_list) || + list_next_entry(od->insn, list)->sec != od->insn->sec) { if (create_orc_entry(file->elf, u_sec, ip_relasec, idx, - prev_insn->sec, - prev_insn->offset + prev_insn->len, + prev_od->insn->sec, + prev_od->insn->offset + prev_od->insn->len, &empty)) return -1; - + prev_od = NULL; idx++; } } -- 2.21.1