public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] strip don't mmap debug output file.
@ 2019-06-18 11:50 Mark Wielaard
  2019-06-24 21:54 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2019-06-18 11:50 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Using ELF_C_WRITE_MMAP sometimes causes unexpected errors when disk
space is low. When writing out the file, the output file is first
extended so that it covers the whole file/mmap size. But it might
be that the file system allowed the extension as a sparse file. In
that case writing to the file through the mmap might still fail and
produce a SIGBUS if the disk is full. This is confusing to the user.

Using ELF_C_WRITE will produce "normal" errors when the file cannot
be written out. It also seems to use less memory because the debug
file is created from scratch. So the memory is first read into the
ELF data structure buffers, then written out as a whole. In this case
the mmap output buffer is just overhead.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog | 5 +++++
 src/strip.c   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 580eea9..2cde63c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-18  Mark Wielaard  <mark@klomp.org>
+
+	* strip.c (handle_elf): Use elf_begin ELF_C_WRITE, instead of
+	ELF_C_WRITE_MMAP.
+
 2019-05-10  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (struct attrcb_args): Rename die to dies.
diff --git a/src/strip.c b/src/strip.c
index 4cd8750..48792a7 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -1097,7 +1097,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
   if (debug_fname != NULL)
     {
       /* Also create an ELF descriptor for the debug file */
-      debugelf = elf_begin (debug_fd, ELF_C_WRITE_MMAP, NULL);
+      debugelf = elf_begin (debug_fd, ELF_C_WRITE, NULL);
       if (unlikely (gelf_newehdr (debugelf, gelf_getclass (elf)) == 0))
 	{
 	  error (0, 0, gettext ("cannot create new ehdr for file '%s': %s"),
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] strip don't mmap debug output file.
  2019-06-18 11:50 [PATCH] strip don't mmap debug output file Mark Wielaard
@ 2019-06-24 21:54 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2019-06-24 21:54 UTC (permalink / raw)
  To: elfutils-devel

On Tue, 2019-06-18 at 13:50 +0200, Mark Wielaard wrote:
> Using ELF_C_WRITE_MMAP sometimes causes unexpected errors when disk
> space is low. When writing out the file, the output file is first
> extended so that it covers the whole file/mmap size. But it might
> be that the file system allowed the extension as a sparse file. In
> that case writing to the file through the mmap might still fail and
> produce a SIGBUS if the disk is full. This is confusing to the user.
> 
> Using ELF_C_WRITE will produce "normal" errors when the file cannot
> be written out. It also seems to use less memory because the debug
> file is created from scratch. So the memory is first read into the
> ELF data structure buffers, then written out as a whole. In this case
> the mmap output buffer is just overhead.

I pushed this to master.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-24 21:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18 11:50 [PATCH] strip don't mmap debug output file Mark Wielaard
2019-06-24 21:54 ` Mark Wielaard

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 read-only IMAP folder(s) and NNTP newsgroup(s).