Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1726031rwd; Fri, 9 Jun 2023 00:56:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4tMnP+eo0BdRM3H1m/RTs1wl4jbe/y34fPmE4NzT7l+e4XamTP23b0Lj/0wV7xLER+hgHN X-Received: by 2002:a05:6a20:a108:b0:10b:8221:3348 with SMTP id q8-20020a056a20a10800b0010b82213348mr536468pzk.50.1686297390931; Fri, 09 Jun 2023 00:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686297390; cv=none; d=google.com; s=arc-20160816; b=vZxxTDYnj3XxPCRrPaaGDlYoY6t3CJQwmrgZnefzSWhXzNcOgVdl/j/fUZNrSBvHDJ 0YpGKvGdlt+zw19lB9vqmtPQko+TyjiIwe7gs0DafGyRp9zPlMi/062xhigmZJA8Ditg EBR0+HuV8/jfdl22nbWeVtUPmvLc0yrLKk83UjwZiOtBgK2+x5G0i29AHXjBAUF156Nx iwn5SomjNBvWWbOlo+qPIFfGY0U8jzSvKcLFYWV/Alk+YOyPtOGQNMYi1ChrlHtpzp6x hVC55bKTeyEkmHHR4VSvAoyOzBTYtOqnIaP/SRy+PYKDaBEHbrrmUWlEytIu4bMLyBnD GrJA== 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 header.b=qw4o68jp; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a633c4e000000b00543fcc59429si2405409pgn.60.2023.06.09.00.56.17; Fri, 09 Jun 2023 00:56:30 -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 header.b=qw4o68jp; 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 S239211AbjFIHs5 (ORCPT + 99 others); Fri, 9 Jun 2023 03:48:57 -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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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)