From patchwork Fri Jun 9 07:47:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 105329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp780199vqr; Fri, 9 Jun 2023 00:55:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ59NCGANIg0zffB4poiRiNiY5JGyNAai7mPf7I8n1oCFlB4NzWqiYRLEBPAEk7tVlFL7Rku X-Received: by 2002:a05:6808:210f:b0:39b:8121:4e32 with SMTP id r15-20020a056808210f00b0039b81214e32mr753538oiw.4.1686297354420; Fri, 09 Jun 2023 00:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686297354; cv=none; d=google.com; s=arc-20160816; b=VE95q929aJJ6f35/PVkhRBi5Uifx8GCoI7aE/k4ez/kpRwKFcq4njjIidQecb23Ipl fHLw5WblQS1YxTNw3f5Y0mihGOvrz17Tn3lsZj8t9dy9TEoY0kWXcBzHSU6DZspH4GvZ DKcxiCsEkn2FKyAe4UfWdeWtLSTauDmlTO6nkLXDk/g9GsqsNSFcvoY/XBsH9dldTG3u l5LYwgvYgk3oNFApwds94zBOJzz7XaC6ww2MsR83PTN/xonwo/Zqflej5Fk6PhJ9DBzY 7hJcM1olNmBMtC2i+e89qDaH7KPnF8uMgj3nPASFAo+2/1uzLnqBxLvbBBZH92d121kg H0aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=FMLOC9+JcExYQXo480vdAW5+Y3vcBAhxA0RE2WfX4O8=; b=ZqL7n4Ex6H+ur4I83QF+2kGQvTU/fR83yI6vGIPP9DVTGTI6FdwyjA9M1Hlp0y9+xx taRpA3V57BmdCWP0+byA8UK/+XFd0AUUGFgsz8ZKiH8qQUIhhpzFuJJg3w+I1eo7OTmQ QU88wbATJwdxYxwjMb/kqQHIDndeiWRaQwOOFoyPdbYXvKrllmkE5YiFjDEcPFhRayvg ATlftv/7sSdk3vw12cx1Dd+h9WiKrV/6RNM7Mj2AVT5LoPCGUvuxZQ6kIq+dv+ND3ZSq zFH0iCWnmjpa8HnTBuVKuymWKmlu2UAsXUmcGVxZKtfUcG1LKR/BMKwGJ8Do3YlNdXlu wJdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="v1+/jUJi"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ng17-20020a17090b1a9100b0025645cd3909si2372525pjb.161.2023.06.09.00.55.41; Fri, 09 Jun 2023 00:55:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="v1+/jUJi"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239213AbjFIHs6 (ORCPT + 99 others); Fri, 9 Jun 2023 03:48:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239037AbjFIHrp (ORCPT ); Fri, 9 Jun 2023 03:47:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0C871FEB; Fri, 9 Jun 2023 00:47:41 -0700 (PDT) Date: Fri, 09 Jun 2023 07:47:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686296856; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FMLOC9+JcExYQXo480vdAW5+Y3vcBAhxA0RE2WfX4O8=; b=v1+/jUJiUrSlPjG3J/oWtNZa1q1L2TbW4GPGn8UcG/lp/PWSXfGkGDZZKkD6Xxzicc9Zas 3Msmcwace+oKxWcJXRc9MQNJ/UI4Mc0iaVCQ5s65IVBE6fI3MvB3MJtgHol6rkFuoIjVeN eGAk2Kk6dcO0BQ6TbUOnQybUuCt8pxu76JlLyjlCpVYFrfm9LTwLkrGOrld+VTDUiMrzty ug+qK5fca5Am9IvobjqigyqV8FIe+0CYT56o6LtXvDOJ4p3CkBodMMyF7bzWITNbpC/cUq MR+23bwdeT/9uTzWS13Pqp79BqVUqqORKbkfAATGCqQifyPIwH32gxZOM3k2iw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686296856; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FMLOC9+JcExYQXo480vdAW5+Y3vcBAhxA0RE2WfX4O8=; b=qw4o68jpjQ3DozaCo3xigiSo1g2h1k7N5BEER8fxBsS8WTsgwIFtcszaIRMcO6s5v3Ep9T iu0lVBQm/o8mzJAA== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Add mark_sec_changed() Cc: Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <9a810a8d2e28af6ba07325362d0eb4703bb09d3a.1685464332.git.jpoimboe@kernel.org> References: <9a810a8d2e28af6ba07325362d0eb4703bb09d3a.1685464332.git.jpoimboe@kernel.org> MIME-Version: 1.0 Message-ID: <168629685608.404.5335907781714907060.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767341177898379074?= X-GMAIL-MSGID: =?utf-8?q?1768210934633864472?= The following commit has been merged into the objtool/core branch of tip: Commit-ID: ff4082730c2aaff3706232266e09d1ae4b350521 Gitweb: https://git.kernel.org/tip/ff4082730c2aaff3706232266e09d1ae4b350521 Author: Josh Poimboeuf AuthorDate: Tue, 30 May 2023 10:20:58 -07:00 Committer: Josh Poimboeuf CommitterDate: Wed, 07 Jun 2023 10:03:16 -07:00 objtool: Add mark_sec_changed() Ensure elf->changed always gets set when sec->changed gets set. Link: https://lore.kernel.org/r/9a810a8d2e28af6ba07325362d0eb4703bb09d3a.1685464332.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 31 ++++++++++++++-------------- tools/objtool/include/objtool/elf.h | 14 ++++++++++++- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index f72ec6d..67967c2 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -562,7 +562,8 @@ int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); sec->rsec->sh.sh_size += sec->rsec->sh.sh_entsize; - sec->rsec->changed = true; + + mark_sec_changed(elf, sec->rsec, true); return 0; } @@ -577,7 +578,7 @@ static void elf_dirty_reloc_sym(struct elf *elf, struct symbol *sym) struct reloc *reloc; list_for_each_entry(reloc, &sym->reloc_list, sym_reloc_entry) - reloc->sec->changed = true; + mark_sec_changed(elf, reloc->sec, true); } /* @@ -654,7 +655,7 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab, symtab_data->d_align = 1; symtab_data->d_type = ELF_T_SYM; - symtab->changed = true; + mark_sec_changed(elf, symtab, true); symtab->truncate = true; if (t) { @@ -669,7 +670,7 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab, shndx_data->d_align = sizeof(Elf32_Word); shndx_data->d_type = ELF_T_WORD; - symtab_shndx->changed = true; + mark_sec_changed(elf, symtab_shndx, true); symtab_shndx->truncate = true; } @@ -773,11 +774,11 @@ non_local: } symtab->sh.sh_size += symtab->sh.sh_entsize; - symtab->changed = true; + mark_sec_changed(elf, symtab, true); if (symtab_shndx) { symtab_shndx->sh.sh_size += sizeof(Elf32_Word); - symtab_shndx->changed = true; + mark_sec_changed(elf, symtab_shndx, true); } return sym; @@ -1040,7 +1041,8 @@ static int elf_add_string(struct elf *elf, struct section *strtab, char *str) len = strtab->sh.sh_size; strtab->sh.sh_size += data->d_size; - strtab->changed = true; + + mark_sec_changed(elf, strtab, true); return len; } @@ -1075,7 +1077,6 @@ struct section *elf_create_section(struct elf *elf, const char *name, } sec->idx = elf_ndxscn(s); - sec->changed = true; sec->data = elf_newdata(s); if (!sec->data) { @@ -1122,7 +1123,7 @@ struct section *elf_create_section(struct elf *elf, const char *name, elf_hash_add(section, &sec->hash, sec->idx); elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); - elf->changed = true; + mark_sec_changed(elf, sec, true); return sec; } @@ -1208,9 +1209,8 @@ int elf_write_insn(struct elf *elf, struct section *sec, } memcpy(data->d_buf + offset, insn, len); - elf_flagdata(data, ELF_C_SET, ELF_F_DIRTY); - elf->changed = true; + mark_sec_changed(elf, sec, true); return 0; } @@ -1235,7 +1235,7 @@ int elf_write_reloc(struct elf *elf, struct reloc *reloc) return -1; } - elf->changed = true; + mark_sec_changed(elf, rsec, true); return 0; } @@ -1307,12 +1307,14 @@ int elf_write(struct elf *elf) if (sec->truncate) elf_truncate_section(elf, sec); - if (sec->changed) { + if (sec_changed(sec)) { s = elf_getscn(elf->elf, sec->idx); if (!s) { WARN_ELF("elf_getscn"); return -1; } + + /* Note this also flags the section dirty */ if (!gelf_update_shdr(s, &sec->sh)) { WARN_ELF("gelf_update_shdr"); return -1; @@ -1324,8 +1326,7 @@ int elf_write(struct elf *elf) return -1; } - sec->changed = false; - elf->changed = true; + mark_sec_changed(elf, sec, false); } } diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index b81d78b..56b66ff 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -39,7 +39,7 @@ struct section { Elf_Data *data; char *name; int idx; - bool changed, text, rodata, noinstr, init, truncate; + bool _changed, text, rodata, noinstr, init, truncate; struct reloc *reloc_data; }; @@ -164,6 +164,18 @@ static inline bool is_reloc_sec(struct section *sec) return sec->sh.sh_type == SHT_RELA || sec->sh.sh_type == SHT_REL; } +static inline bool sec_changed(struct section *sec) +{ + return sec->_changed; +} + +static inline void mark_sec_changed(struct elf *elf, struct section *sec, + bool changed) +{ + sec->_changed = changed; + elf->changed |= changed; +} + #define for_each_sec(file, sec) \ list_for_each_entry(sec, &file->elf->sections, list)