From: Giuliano Procida <gprocida@google.com>
To: dwarves@vger.kernel.org
Cc: acme@kernel.org, andrii@kernel.org, ast@kernel.org,
gprocida@google.com, maennich@google.com,
kernel-team@android.com, kernel-team@fb.com, bpf@vger.kernel.org
Subject: [PATCH dwarves 1/4] btf_encoder: Improve ELF error reporting
Date: Mon, 25 Jan 2021 13:06:22 +0000 [thread overview]
Message-ID: <20210125130625.2030186-2-gprocida@google.com> (raw)
In-Reply-To: <20210125130625.2030186-1-gprocida@google.com>
libelf provides an errno/strerror-like facility. This commit updates
various error messages to include helpful error text.
Signed-off-by: Giuliano Procida <gprocida@google.com>
---
libbtf.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/libbtf.c b/libbtf.c
index 7552d8e..9f76283 100644
--- a/libbtf.c
+++ b/libbtf.c
@@ -110,8 +110,8 @@ try_as_raw_btf:
btfe->elf = elf_begin(btfe->in_fd, ELF_C_READ_MMAP, NULL);
if (!btfe->elf) {
- fprintf(stderr, "%s: cannot read %s ELF file.\n",
- __func__, filename);
+ fprintf(stderr, "%s: cannot read %s ELF file: %s.\n",
+ __func__, filename, elf_errmsg(elf_errno()));
goto errout;
}
}
@@ -707,13 +707,15 @@ static int btf_elf__write(const char *filename, struct btf *btf)
}
if (elf_version(EV_CURRENT) == EV_NONE) {
- fprintf(stderr, "Cannot set libelf version.\n");
+ fprintf(stderr, "Cannot set libelf version: %s.\n",
+ elf_errmsg(elf_errno()));
goto out;
}
elf = elf_begin(fd, ELF_C_RDWR, NULL);
if (elf == NULL) {
- fprintf(stderr, "Cannot update ELF file.\n");
+ fprintf(stderr, "Cannot update ELF file: %s.\n",
+ elf_errmsg(elf_errno()));
goto out;
}
@@ -721,7 +723,8 @@ static int btf_elf__write(const char *filename, struct btf *btf)
ehdr = gelf_getehdr(elf, &ehdr_mem);
if (ehdr == NULL) {
- fprintf(stderr, "%s: elf_getehdr failed.\n", __func__);
+ fprintf(stderr, "%s: elf_getehdr failed: %s.\n", __func__,
+ elf_errmsg(elf_errno()));
goto out;
}
@@ -764,6 +767,9 @@ static int btf_elf__write(const char *filename, struct btf *btf)
if (elf_update(elf, ELF_C_NULL) >= 0 &&
elf_update(elf, ELF_C_WRITE) >= 0)
err = 0;
+ else
+ fprintf(stderr, "%s: elf_update failed: %s.\n",
+ __func__, elf_errmsg(elf_errno()));
} else {
const char *llvm_objcopy;
char tmp_fn[PATH_MAX];
--
2.30.0.280.ga3ce27912f-goog
next prev parent reply other threads:[~2021-01-26 5:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 13:06 [PATCH dwarves 0/4] BTF ELF writing changes Giuliano Procida
2021-01-25 13:06 ` Giuliano Procida [this message]
2021-01-25 13:06 ` [PATCH dwarves 2/4] btf_encoder: Add .BTF section using libelf Giuliano Procida
2021-01-27 23:23 ` Jiri Olsa
2021-01-28 13:35 ` Giuliano Procida
2021-02-05 13:40 ` Giuliano Procida
2021-01-25 13:06 ` [PATCH dwarves 3/4] btf_encoder: Manually lay out updated ELF sections Giuliano Procida
2021-01-25 13:06 ` [PATCH dwarves 4/4] btf_encoder: Align .BTF section to 8 bytes Giuliano Procida
2021-01-26 19:55 ` [PATCH dwarves 0/4] BTF ELF writing changes Jiri Olsa
2021-01-27 1:10 ` Giuliano Procida
2021-01-27 1:42 ` Arnaldo Carvalho de Melo
2021-01-27 14:06 ` Arnaldo Carvalho de Melo
2021-01-27 14:36 ` Giuliano Procida
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=20210125130625.2030186-2-gprocida@google.com \
--to=gprocida@google.com \
--cc=acme@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=kernel-team@android.com \
--cc=kernel-team@fb.com \
--cc=maennich@google.com \
/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).