Skip to content

Commit bca7532

Browse files
captain5050acmel
authored andcommitted
perf dso: Clean up read_symbol() error handling
Ensure errno is set and return to caller for error handling. Unusually for perf the value isn't negated as expected by symbol__strerror_disassemble(). Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Ghiti <alexghiti@rivosinc.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.ibm.com> Cc: Bill Wendling <morbo@google.com> Cc: Charlie Jenkins <charlie@rivosinc.com> Cc: Collin Funk <collin.funk1@gmail.com> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Dr. David Alan Gilbert <linux@treblig.org> Cc: Eric Biggers <ebiggers@kernel.org> Cc: Haibo Xu <haibo1.xu@intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Justin Stitt <justinstitt@google.com> Cc: Li Huafei <lihuafei1@huawei.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <song@kernel.org> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent aa04707 commit bca7532

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

tools/perf/util/capstone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "print_insn.h"
1212
#include "symbol.h"
1313
#include "thread.h"
14+
#include <errno.h>
1415
#include <fcntl.h>
1516
#include <string.h>
1617

@@ -245,7 +246,7 @@ int symbol__disassemble_capstone(const char *filename __maybe_unused,
245246
buf = dso__read_symbol(dso, filename, map, sym,
246247
&code_buf, &buf_len, &is_64bit);
247248
if (buf == NULL)
248-
return -1;
249+
return errno;
249250

250251
/* add the function address and name */
251252
scnprintf(disasm_buf, sizeof(disasm_buf), "%#"PRIx64" <%s>:",

tools/perf/util/dso.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,26 +1827,33 @@ static const u8 *__dso__read_symbol(struct dso *dso, const char *symfs_filename,
18271827
.ip = start,
18281828
};
18291829
u8 *code_buf = NULL;
1830+
int saved_errno;
18301831

18311832
nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
18321833
fd = open(symfs_filename, O_RDONLY);
1834+
saved_errno = errno;
18331835
nsinfo__mountns_exit(&nsc);
1834-
if (fd < 0)
1836+
if (fd < 0) {
1837+
errno = saved_errno;
18351838
return NULL;
1836-
1837-
if (file__read_maps(fd, /*exe=*/true, find_file_offset, &data, is_64bit) == 0) {
1839+
}
1840+
if (file__read_maps(fd, /*exe=*/true, find_file_offset, &data, is_64bit) <= 0) {
18381841
close(fd);
1842+
errno = ENOENT;
18391843
return NULL;
18401844
}
18411845
code_buf = malloc(len);
18421846
if (code_buf == NULL) {
18431847
close(fd);
1848+
errno = ENOMEM;
18441849
return NULL;
18451850
}
18461851
count = pread(fd, code_buf, len, data.offset);
1852+
saved_errno = errno;
18471853
close(fd);
18481854
if ((u64)count != len) {
18491855
free(code_buf);
1856+
errno = saved_errno;
18501857
return NULL;
18511858
}
18521859
*out_buf = code_buf;
@@ -1875,6 +1882,7 @@ const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
18751882
* Note, there is fallback BPF image disassembly in the objdump
18761883
* version but it currently does nothing.
18771884
*/
1885+
errno = EOPNOTSUPP;
18781886
return NULL;
18791887
}
18801888
if (dso__binary_type(dso) == DSO_BINARY_TYPE__BPF_PROG_INFO) {
@@ -1895,6 +1903,7 @@ const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
18951903
return (const u8 *)(uintptr_t)(info_linear->info.jited_prog_insns);
18961904
#else
18971905
pr_debug("No BPF program disassembly support\n");
1906+
errno = EOPNOTSUPP;
18981907
return NULL;
18991908
#endif
19001909
}

tools/perf/util/llvm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "namespaces.h"
88
#include "srcline.h"
99
#include "symbol.h"
10+
#include <errno.h>
1011
#include <fcntl.h>
1112
#include <unistd.h>
1213
#include <linux/zalloc.h>
@@ -147,7 +148,7 @@ int symbol__disassemble_llvm(const char *filename, struct symbol *sym,
147148
buf = dso__read_symbol(dso, filename, map, sym,
148149
&code_buf, &buf_len, &is_64bit);
149150
if (buf == NULL)
150-
return -1;
151+
return errno;
151152

152153
init_llvm();
153154
if (arch__is(args->arch, "x86")) {

0 commit comments

Comments
 (0)