From: Matt Helsley <mhelsley@vmware.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
<linux-kernel@vger.kernel.org>, <x86@kernel.org>,
<dvyukov@google.com>, <elver@google.com>, <andreyknvl@google.com>,
<mark.rutland@arm.com>, <rostedt@goodmis.org>,
<jthierry@redhat.com>, <mbenes@suse.cz>
Subject: Re: [RFC][PATCH 2/3] objtool: Provide elf_write_{insn,reloc}()
Date: Tue, 16 Jun 2020 12:51:06 -0700 [thread overview]
Message-ID: <20200616195106.GE25598@rlwimi.vmware.com> (raw)
In-Reply-To: <20200616091253.GN2531@hirez.programming.kicks-ass.net>
On Tue, Jun 16, 2020 at 11:12:53AM +0200, Peter Zijlstra wrote:
> On Fri, Jun 12, 2020 at 04:30:36PM +0200, Peter Zijlstra wrote:
> > +int elf_write_insn(struct elf *elf, struct section *sec,
> > + unsigned long offset, unsigned int len,
> > + const char *insn)
> > +{
> > + Elf_Data *data = sec->data;
> > +
> > + if (data->d_type != ELF_T_BYTE || data->d_off) {
> > + WARN("write to unexpected data for section: %s", sec->name);
> > + return -1;
> > + }
> > +
> > + memcpy(data->d_buf + offset, insn, len);
> > + elf_flagdata(data, ELF_C_SET, ELF_F_DIRTY);
> > +
> > + sec->changed = true;
> > + elf->changed = true;
> > +
> > + return 0;
> > +}
> > +
> > +int elf_write_reloc(struct elf *elf, struct reloc *reloc)
> > +{
> > + struct section *sec = reloc->sec;
> > +
> > + if (sec->sh.sh_type == SHT_REL) {
> > + reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type);
> > + reloc->rel.r_offset = reloc->offset;
> > +
> > + if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) {
> > + WARN_ELF("gelf_update_rel");
> > + return -1;
> > + }
> > + } else {
> > + reloc->rela.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type);
> > + reloc->rela.r_addend = reloc->addend;
> > + reloc->rela.r_offset = reloc->offset;
> > +
> > + if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) {
> > + WARN_ELF("gelf_update_rela");
> > + return -1;
> > + }
> > + }
> > +
> > + sec->changed = true;
> > + elf->changed = true;
> > +
> > + return 0;
> > +}
>
> Doing the change Matt asked for #1, I realized that sec->changed is only
> required if we need to rewrite the section header, neither of these two
> changes requires that, they already mark the elf data dirty so
> elf_update() DTRT.
This is really useful information.
As long as you're adding the elf->changed flag it might make sense to add this
as a comment in the struct section definition or even rename sec->changed
to reflect this (e.g. sec->shdr_changed).
Cheers,
-Matt Helsley
next prev parent reply other threads:[~2020-06-16 19:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-12 14:30 [RFC][PATCH 0/3] objtool: KCOV vs noinstr Peter Zijlstra
2020-06-12 14:30 ` [RFC][PATCH 1/3] objtool: Clean up elf_write() condition Peter Zijlstra
2020-06-15 18:34 ` Matt Helsley
2020-06-15 18:44 ` Peter Zijlstra
2020-06-16 8:32 ` Peter Zijlstra
2020-06-12 14:30 ` [RFC][PATCH 2/3] objtool: Provide elf_write_{insn,reloc}() Peter Zijlstra
2020-06-16 9:12 ` Peter Zijlstra
2020-06-16 19:51 ` Matt Helsley [this message]
2020-06-12 14:30 ` [RFC][PATCH 3/3] objtool: Fix noinstr vs KCOV Peter Zijlstra
2020-06-15 7:41 ` Dmitry Vyukov
2020-06-13 19:54 ` [RFC][PATCH 0/3] objtool: KCOV vs noinstr Matt Helsley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200616195106.GE25598@rlwimi.vmware.com \
--to=mhelsley@vmware.com \
--cc=andreyknvl@google.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=jpoimboe@redhat.com \
--cc=jthierry@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mbenes@suse.cz \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.