bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/30016] New: strip/objcopy should do atomic renames


From: thiago at kde dot org
Subject: [Bug binutils/30016] New: strip/objcopy should do atomic renames
Date: Tue, 17 Jan 2023 19:16:37 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=30016

            Bug ID: 30016
           Summary: strip/objcopy should do atomic renames
           Product: binutils
           Version: 2.40
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: thiago at kde dot org
  Target Milestone: ---

I noticed this while building binutils itself because, after ./binutils got
installed, the installed strip was in $PATH and that caused errors later on.

strace shows that strip/objcopy create a temporary file to write contents to,
but later truncate the target file and do a manual copy of everything:

$ strace strip toolname
newfstatat(AT_FDCWD, "toolname", {st_mode=S_IFREG|0755, st_size=1772072, ...},
0) = 0
openat(AT_FDCWD, "stA2UbOD", O_RDWR|O_CREAT|O_EXCL, 0600) = 3            //
creates temporary file
dup(3)                                  = 4
newfstatat(AT_FDCWD, "toolname", {st_mode=S_IFREG|0755, st_size=1772072, ...},
0) = 0
openat(AT_FDCWD, "toolname", O_RDONLY) = 5                               //
opens source file
fcntl(5, F_GETFD)                       = 0
fcntl(5, F_SETFD, FD_CLOEXEC)           = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=512*1024}) = 0
newfstatat(5, "", {st_mode=S_IFREG|0755, st_size=27183920, ...}, AT_EMPTY_PATH)
= 0
newfstatat(5, "", {st_mode=S_IFREG|0755, st_size=27183920, ...}, AT_EMPTY_PATH)
= 0

[lots of read, lseek and stat]
mmap(NULL, 978944, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x55b46f311000
munmap(0x55b46f311000, 978944)          = 0
brk(0x55b470f37000)                     = 0x55b470f37000
[read,lseek and writes of different sizes here]
close(3)                                = 0

newfstatat(AT_FDCWD, "stA2UbOD", {st_mode=S_IFREG|0600, st_size=1772072, ...},
0) = 0  // stat() on the temporary file instead of fstat() on the still-open
file descriptor 4
umask(000)                              = 022
umask(022)                              = 000
chmod("stA2UbOD", 0711)         = 0                 // unnecessary chmod() on
the temporary file; fchmod() preferred

close(5)                                = 0
openat(AT_FDCWD, "toolname", O_WRONLY|O_TRUNC) = 3           // reopens the
output file, truncating
[read & write of the exact same size]
read(4, "", 8192)                       = 0
fchmod(3, 0100755)                      = 0
close(4)                                = 0
close(3)                                = 0
unlink("stA2UbOD")              = 0

The last block is wasteful and problematic. objcopy/strip should have simply
renamed the temporary file "stA2UbOD" to the target "toolname" instead of
copying 1.7 MB.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]