From: Jiri Slaby <jslaby@suse.cz>
To: Josh Poimboeuf <jpoimboe@redhat.com>, x86@kernel.org
Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [RFC PATCH 04/10] objtool: add undwarf debuginfo generation
Date: Wed, 14 Jun 2017 10:42:19 +0200 [thread overview]
Message-ID: <e53f3bde-3528-6c50-e322-0947cfb4dcdc@suse.cz> (raw)
In-Reply-To: <848a1c6a1384ff5dd40ff204e1ace7e07559fde0.1496293620.git.jpoimboe@redhat.com>
On 06/01/2017, 07:44 AM, Josh Poimboeuf wrote:
...
> index 3fb0747..1ca5d9a 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
...
> +int elf_write_to_file(struct elf *elf, char *outfile)
> +{
> + int fd;
> + struct section *sec;
> + Elf *elfout;
> + GElf_Ehdr eh, ehout;
> + Elf_Scn *scn;
> + Elf_Data *data;
> + GElf_Shdr sh;
> +
> + fd = creat(outfile, 0777);
0755 even though it is umasked?
> + if (fd == -1) {
> + perror("creat");
> + return -1;
> + }
> +
> + elfout = elf_begin(fd, ELF_C_WRITE, NULL);
> + if (!elfout) {
> + perror("elf_begin");
> + return -1;
> + }
> +
> + if (!gelf_newehdr(elfout, gelf_getclass(elf->elf))) {
> + perror("gelf_newehdr");
> + return -1;
> + }
> +
> + if (!gelf_getehdr(elfout, &ehout)) {
This does not make much sense to do. You memset(0) it below.
> + perror("gelf_getehdr");
> + return -1;
> + }
> +
> + if (!gelf_getehdr(elf->elf, &eh)) {
> + perror("gelf_getehdr");
> + return -1;
> + }
> +
> + memset(&ehout, 0, sizeof(ehout));
> + ehout.e_ident[EI_DATA] = eh.e_ident[EI_DATA];
> + ehout.e_machine = eh.e_machine;
> + ehout.e_type = eh.e_type;
> + ehout.e_version = EV_CURRENT;
> + ehout.e_shstrndx = find_section_by_name(elf, ".shstrtab")->idx;
> +
> + list_for_each_entry(sec, &elf->sections, list) {
> + if (sec->idx == 0)
> + continue;
> +
> + scn = elf_newscn(elfout);
> + if (!scn) {
> + perror("elf_newscn");
> + return -1;
> + }
> +
> + data = elf_newdata(scn);
> + if (!data) {
> + perror("elf_newdata");
> + return -1;
> + }
> +
> + if (!elf_flagdata(data, ELF_C_SET, ELF_F_DIRTY)) {
> + perror("elf_flagdata");
> + return -1;
> + }
There is not much point setting DIRTY flag here. elf_newdata does so.
> + data->d_type = sec->data->d_type;
> + data->d_buf = sec->data->d_buf;
> + data->d_size = sec->data->d_size;
> +
> + if(!gelf_getshdr(scn, &sh)) {
> + perror("gelf_getshdr");
> + return -1;
> + }
This does not make much sense to do again. You overwrite the content
right away:
> + sh = sec->sh;
> +
> + if (!gelf_update_shdr(scn, &sh)) {
> + perror("gelf_update_shdr");
> + return -1;
> + }
> + }
> +
> + if (!gelf_update_ehdr(elfout, &ehout)) {
> + perror("gelf_update_ehdr");
> + return -1;
> + }
> +
> + if (elf_update(elfout, ELF_C_WRITE) < 0) {
> + perror("elf_update");
> + return -1;
> + }
elf_end() + close() ?
> +
> + return 0;
> +}
> +
> void elf_close(struct elf *elf)
> {
> struct section *sec, *tmpsec;
...
> --- /dev/null
> +++ b/tools/objtool/undwarf.c
> @@ -0,0 +1,308 @@
...
> +int undwarf_dump(const char *_objname)
> +{
> + struct elf *elf;
> + struct section *sec;
> + struct rela *rela;
> + struct undwarf *undwarf;
> + int nr, i;
> +
> + objname = _objname;
> +
> + elf = elf_open(objname);
> + if (!elf) {
> + WARN("error reading elf file %s\n", objname);
> + return 1;
> + }
> +
> + sec = find_section_by_name(elf, ".undwarf");
> + if (!sec || !sec->rela)
> + return 0;
> +
> + nr = sec->len / sizeof(*undwarf);
> + for (i = 0; i < nr; i++) {
...
> + }
elf_close() ?
> +
> + return 0;
> +}
thanks,
--
js
suse labs
next prev parent reply other threads:[~2017-06-14 8:43 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-01 5:44 [RFC PATCH 00/10] x86: undwarf unwinder Josh Poimboeuf
2017-06-01 5:44 ` [RFC PATCH 01/10] objtool: move checking code to check.c Josh Poimboeuf
2017-06-14 7:22 ` Jiri Slaby
2017-06-01 5:44 ` [RFC PATCH 02/10] objtool, x86: add several functions and files to the objtool whitelist Josh Poimboeuf
2017-06-14 7:24 ` Jiri Slaby
2017-06-14 13:03 ` Josh Poimboeuf
2017-06-01 5:44 ` [RFC PATCH 03/10] objtool: stack validation 2.0 Josh Poimboeuf
2017-06-01 5:44 ` [RFC PATCH 04/10] objtool: add undwarf debuginfo generation Josh Poimboeuf
2017-06-14 8:42 ` Jiri Slaby [this message]
2017-06-14 13:27 ` Josh Poimboeuf
2017-06-22 7:47 ` Jiri Slaby
2017-06-22 12:49 ` Josh Poimboeuf
2017-06-01 5:44 ` [RFC PATCH 05/10] objtool, x86: add facility for asm code to provide CFI hints Josh Poimboeuf
2017-06-01 13:57 ` Andy Lutomirski
2017-06-01 14:16 ` Josh Poimboeuf
2017-06-01 14:40 ` Andy Lutomirski
2017-06-01 15:02 ` Josh Poimboeuf
2017-06-01 5:44 ` [RFC PATCH 06/10] x86/entry: add CFI hint undwarf annotations Josh Poimboeuf
2017-06-01 14:03 ` Andy Lutomirski
2017-06-01 14:23 ` Josh Poimboeuf
2017-06-01 14:28 ` Josh Poimboeuf
2017-06-01 14:39 ` Andy Lutomirski
2017-06-01 15:01 ` Josh Poimboeuf
2017-06-01 5:44 ` [RFC PATCH 07/10] x86/asm: add CFI hint annotations to sync_core() Josh Poimboeuf
2017-06-01 5:44 ` [RFC PATCH 08/10] extable: rename 'sortextable' script to 'sorttable' Josh Poimboeuf
2017-06-01 5:44 ` [RFC PATCH 09/10] extable: add undwarf table sorting ability to sorttable script Josh Poimboeuf
2017-06-01 5:44 ` [RFC PATCH 10/10] x86/unwind: add undwarf unwinder Josh Poimboeuf
2017-06-01 11:05 ` Peter Zijlstra
2017-06-01 12:26 ` Josh Poimboeuf
2017-06-01 12:47 ` Jiri Slaby
2017-06-01 13:02 ` Josh Poimboeuf
2017-06-01 13:42 ` Peter Zijlstra
2017-06-01 13:10 ` Peter Zijlstra
2017-06-01 12:13 ` Peter Zijlstra
2017-06-01 12:36 ` Josh Poimboeuf
2017-06-01 13:12 ` Peter Zijlstra
2017-06-01 15:03 ` Josh Poimboeuf
2017-06-14 11:45 ` Jiri Slaby
2017-06-14 13:44 ` Josh Poimboeuf
2017-06-01 6:08 ` [RFC PATCH 00/10] x86: " Ingo Molnar
2017-06-01 11:58 ` Josh Poimboeuf
2017-06-01 12:17 ` Peter Zijlstra
2017-06-01 12:33 ` Jiri Slaby
2017-06-01 12:52 ` Josh Poimboeuf
2017-06-01 12:57 ` Jiri Slaby
2017-06-01 12:47 ` Josh Poimboeuf
2017-06-01 13:25 ` Peter Zijlstra
2017-06-06 14:14 ` Sergey Senozhatsky
2017-06-01 13:50 ` Andy Lutomirski
2017-06-01 13:50 ` Ingo Molnar
2017-06-01 13:58 ` Jiri Slaby
2017-06-02 8:30 ` Jiri Slaby
2017-06-01 14:05 ` Josh Poimboeuf
2017-06-01 14:08 ` Jiri Slaby
2017-06-02 10:40 ` Mel Gorman
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=e53f3bde-3528-6c50-e322-0947cfb4dcdc@suse.cz \
--to=jslaby@suse.cz \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).