summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog15
-rw-r--r--libdwfl/argp-std.c2
-rw-r--r--libdwfl/dwfl_build_id_find_elf.c4
-rw-r--r--libdwfl/dwfl_module_getdwarf.c2
-rw-r--r--libdwfl/dwfl_report_elf.c2
-rw-r--r--libdwfl/dwfl_segment_report_module.c2
-rw-r--r--libdwfl/find-debuginfo.c2
-rw-r--r--libdwfl/link_map.c4
-rw-r--r--libdwfl/linux-kernel-modules.c20
-rw-r--r--libdwfl/linux-pid-attach.c6
-rw-r--r--libdwfl/linux-proc-maps.c10
-rw-r--r--libdwfl/offline.c2
12 files changed, 43 insertions, 28 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 26a3599b..6f3a5611 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,18 @@
+2017-05-04 Ulf Hermann <[email protected]>
+
+ * argp-std.c: Open files in O_BINARY.
+ * dwfl_build_id_find_elf.c: Likewise.
+ * dwfl_build_id_find_elf.c: Likewise.
+ * dwfl_module_getdwarf.c: Likewise.
+ * dwfl_report_elf.c: Likewise.
+ * dwfl_segment_report_module.c: Likewise.
+ * find-debuginfo.c: Likewise.
+ * link_map.c: Likewise.
+ * linux-kernel-modules.c: Likewise.
+ * linux-pid-attach.c: Likewise.
+ * linux-proc-maps.c: Likewise.
+ * offline.c: Likewise.
+
2017-04-27 Ulf Hermann <[email protected]>
* linux-kernel-modules.c: Don't include system.h.
diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
index 347a05b4..012eb0c7 100644
--- a/libdwfl/argp-std.c
+++ b/libdwfl/argp-std.c
@@ -277,7 +277,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
if (opt->core)
{
- int fd = open (opt->core, O_RDONLY);
+ int fd = open (opt->core, O_RDONLY | O_BINARY);
if (fd < 0)
{
int code = errno;
diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c
index ee0c1646..6ce2c1cc 100644
--- a/libdwfl/dwfl_build_id_find_elf.c
+++ b/libdwfl/dwfl_build_id_find_elf.c
@@ -94,7 +94,7 @@ __libdwfl_open_by_build_id (Dwfl_Module *mod, bool debug, char **file_name,
break;
memcpy (mempcpy (name, dir, dirlen), id_name, sizeof id_name);
- fd = TEMP_FAILURE_RETRY (open (name, O_RDONLY));
+ fd = TEMP_FAILURE_RETRY (open (name, O_RDONLY | O_BINARY));
if (fd >= 0)
{
if (*file_name != NULL)
@@ -154,7 +154,7 @@ dwfl_build_id_find_elf (Dwfl_Module *mod,
recorded executable file when MOD was identified as main executable
(which then triggers opening and reporting of the executable). */
const char *executable = mod->dwfl->user_core->executable_for_core;
- int fd = open (executable, O_RDONLY);
+ int fd = open (executable, O_RDONLY | O_BINARY);
if (fd >= 0)
{
*file_name = strdup (executable);
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 9775aced..f6380934 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -51,7 +51,7 @@ open_elf_file (Elf **elf, int *fd, char **name)
/* If there was a pre-primed file name left that the callback left
behind, try to open that file name. */
if (*fd < 0 && *name != NULL)
- *fd = TEMP_FAILURE_RETRY (open (*name, O_RDONLY));
+ *fd = TEMP_FAILURE_RETRY (open (*name, O_RDONLY | O_BINARY));
if (*fd < 0)
return CBFAIL;
diff --git a/libdwfl/dwfl_report_elf.c b/libdwfl/dwfl_report_elf.c
index 6950a37b..d4d3feb9 100644
--- a/libdwfl/dwfl_report_elf.c
+++ b/libdwfl/dwfl_report_elf.c
@@ -295,7 +295,7 @@ dwfl_report_elf (Dwfl *dwfl, const char *name, const char *file_name, int fd,
if (fd < 0)
{
closefd = true;
- fd = open (file_name, O_RDONLY);
+ fd = open (file_name, O_RDONLY | O_BINARY);
if (fd < 0)
{
__libdwfl_seterrno (DWFL_E_ERRNO);
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 207a2573..cd8f6135 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -688,7 +688,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
name = file_note_name;
name_is_final = true;
bool invalid = false;
- fd = open (name, O_RDONLY);
+ fd = open (name, O_RDONLY | O_BINARY);
if (fd >= 0)
{
Dwfl_Error error = __libdw_open_file (&fd, &elf, true, false);
diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c
index 6d5a42a6..7f7e1081 100644
--- a/libdwfl/find-debuginfo.c
+++ b/libdwfl/find-debuginfo.c
@@ -58,7 +58,7 @@ try_open (const struct stat *main_stat,
return -1;
struct stat st;
- int fd = TEMP_FAILURE_RETRY (open (fname, O_RDONLY));
+ int fd = TEMP_FAILURE_RETRY (open (fname, O_RDONLY | O_BINARY));
if (fd < 0)
free (fname);
else if (fstat (fd, &st) == 0
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 794668fc..4a50c441 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -393,7 +393,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
{
/* This code is mostly inlined dwfl_report_elf. */
// XXX hook for sysroot
- int fd = open (name, O_RDONLY);
+ int fd = open (name, O_RDONLY | O_BINARY);
if (fd >= 0)
{
Elf *elf;
@@ -808,7 +808,7 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
EXECUTABLE_FOR_CORE to find where DYNAMIC is located in the
core file. */
- int fd = open (dwfl->user_core->executable_for_core, O_RDONLY);
+ int fd = open (dwfl->user_core->executable_for_core, O_RDONLY | O_BINARY);
Elf *elf;
Dwfl_Error error = DWFL_E_ERRNO;
if (fd != -1)
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index 5f132b46..139a4774 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -97,7 +97,7 @@ try_kernel_name (Dwfl *dwfl, char **fname, bool try_debug)
int fd = ((((dwfl->callbacks->debuginfo_path
? *dwfl->callbacks->debuginfo_path : NULL)
?: DEFAULT_DEBUGINFO_PATH)[0] == ':') ? -1
- : TEMP_FAILURE_RETRY (open (*fname, O_RDONLY)));
+ : TEMP_FAILURE_RETRY (open (*fname, O_RDONLY | O_BINARY)));
if (fd < 0)
{
@@ -132,7 +132,7 @@ try_kernel_name (Dwfl *dwfl, char **fname, bool try_debug)
char *zname;
if (asprintf (&zname, "%s%s", *fname, vmlinux_suffixes[i]) > 0)
{
- fd = TEMP_FAILURE_RETRY (open (zname, O_RDONLY));
+ fd = TEMP_FAILURE_RETRY (open (zname, O_RDONLY | O_BINARY));
if (fd < 0)
free (zname);
else
@@ -488,7 +488,7 @@ intuit_kernel_bounds (Dwarf_Addr *start, Dwarf_Addr *end, Dwarf_Addr *notes)
{
struct read_address_state state = { NULL, NULL, 0, 0, NULL, NULL };
- state.f = fopen (KSYMSFILE, "r");
+ state.f = fopen (KSYMSFILE, "rb");
if (state.f == NULL)
return errno;
@@ -531,7 +531,7 @@ static int
check_notes (Dwfl_Module *mod, const char *notesfile,
Dwarf_Addr vaddr, const char *secname)
{
- int fd = open (notesfile, O_RDONLY);
+ int fd = open (notesfile, O_RDONLY | O_BINARY);
if (fd < 0)
return 1;
@@ -789,7 +789,7 @@ dwfl_linux_kernel_find_elf (Dwfl_Module *mod,
&& (!memcmp (f->fts_name, module_name, namelen)
|| !memcmp (f->fts_name, alternate_name, namelen)))
{
- int fd = open (f->fts_accpath, O_RDONLY);
+ int fd = open (f->fts_accpath, O_RDONLY | O_BINARY);
*file_name = strdup (f->fts_path);
fts_close (fts);
free (modulesdir[0]);
@@ -842,7 +842,7 @@ dwfl_linux_kernel_module_section_address
if (asprintf (&sysfile, SECADDRDIRFMT "%s", modname, secname) < 0)
return DWARF_CB_ABORT;
- FILE *f = fopen (sysfile, "r");
+ FILE *f = fopen (sysfile, "rb");
free (sysfile);
if (f == NULL)
@@ -876,7 +876,7 @@ dwfl_linux_kernel_module_section_address
if (asprintf (&sysfile, SECADDRDIRFMT "_%s",
modname, &secname[1]) < 0)
return ENOMEM;
- f = fopen (sysfile, "r");
+ f = fopen (sysfile, "rb");
free (sysfile);
if (f != NULL)
goto ok;
@@ -896,11 +896,11 @@ dwfl_linux_kernel_module_section_address
do
{
*--end = '\0';
- f = fopen (sysfile, "r");
+ f = fopen (sysfile, "rb");
if (is_init && f == NULL && errno == ENOENT)
{
sysfile[len - namelen] = '_';
- f = fopen (sysfile, "r");
+ f = fopen (sysfile, "rb");
sysfile[len - namelen] = '.';
}
}
@@ -934,7 +934,7 @@ INTDEF (dwfl_linux_kernel_module_section_address)
int
dwfl_linux_kernel_report_modules (Dwfl *dwfl)
{
- FILE *f = fopen (MODULELIST, "r");
+ FILE *f = fopen (MODULELIST, "rb");
if (f == NULL)
return errno;
diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c
index e6a5c419..1def7f16 100644
--- a/libdwfl/linux-pid-attach.c
+++ b/libdwfl/linux-pid-attach.c
@@ -52,7 +52,7 @@ linux_proc_pid_is_stopped (pid_t pid)
bool retval, have_state;
snprintf (buffer, sizeof (buffer), "/proc/%ld/status", (long) pid);
- procfile = fopen (buffer, "r");
+ procfile = fopen (buffer, "rb");
if (procfile == NULL)
return false;
@@ -302,7 +302,7 @@ dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid, bool assume_ptrace_stopped)
/* Make sure to report the actual PID (thread group leader) to
dwfl_attach_state. */
snprintf (buffer, sizeof (buffer), "/proc/%ld/status", (long) pid);
- procfile = fopen (buffer, "r");
+ procfile = fopen (buffer, "rb");
if (procfile == NULL)
{
err = errno;
@@ -352,7 +352,7 @@ dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid, bool assume_ptrace_stopped)
Elf *elf;
i = snprintf (name, sizeof (name), "/proc/%ld/exe", (long) pid);
assert (i > 0 && i < (ssize_t) sizeof (name) - 1);
- int elf_fd = open (name, O_RDONLY);
+ int elf_fd = open (name, O_RDONLY | O_BINARY);
if (elf_fd >= 0)
{
elf = elf_begin (elf_fd, ELF_C_READ_MMAP, NULL);
diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c
index c4438c0f..78f472a8 100644
--- a/libdwfl/linux-proc-maps.c
+++ b/libdwfl/linux-proc-maps.c
@@ -63,7 +63,7 @@ get_pid_class (pid_t pid)
if (asprintf (&fname, PROCEXEFMT, pid) < 0)
return ELFCLASSNONE;
- int fd = open (fname, O_RDONLY);
+ int fd = open (fname, O_RDONLY | O_BINARY);
free (fname);
if (fd < 0)
return ELFCLASSNONE;
@@ -99,7 +99,7 @@ grovel_auxv (pid_t pid, Dwfl *dwfl, GElf_Addr *sysinfo_ehdr)
if (asprintf (&fname, PROCAUXVFMT, pid) < 0)
return ENOMEM;
- int fd = open (fname, O_RDONLY);
+ int fd = open (fname, O_RDONLY | O_BINARY);
free (fname);
if (fd < 0)
return errno == ENOENT ? 0 : errno;
@@ -306,7 +306,7 @@ dwfl_linux_proc_report (Dwfl *dwfl, pid_t pid)
if (asprintf (&fname, PROCMAPSFMT, pid) < 0)
return ENOMEM;
- FILE *f = fopen (fname, "r");
+ FILE *f = fopen (fname, "rb");
free (fname);
if (f == NULL)
return errno;
@@ -380,7 +380,7 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute__ ((unused)),
if (pid == -1)
{
- int fd = open (module_name, O_RDONLY);
+ int fd = open (module_name, O_RDONLY | O_BINARY);
if (fd >= 0)
{
*file_name = strdup (module_name);
@@ -417,7 +417,7 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute__ ((unused)),
if (asprintf (&fname, PROCMEMFMT, pid) < 0)
goto detach;
- int fd = open (fname, O_RDONLY);
+ int fd = open (fname, O_RDONLY | O_BINARY);
free (fname);
if (fd < 0)
goto detach;
diff --git a/libdwfl/offline.c b/libdwfl/offline.c
index 80c80a16..7666358f 100644
--- a/libdwfl/offline.c
+++ b/libdwfl/offline.c
@@ -302,7 +302,7 @@ dwfl_report_offline (Dwfl *dwfl, const char *name,
if (fd < 0)
{
closefd = true;
- fd = open (file_name, O_RDONLY);
+ fd = open (file_name, O_RDONLY | O_BINARY);
if (fd < 0)
{
__libdwfl_seterrno (DWFL_E_ERRNO);