[llvm-bugs] [Bug 42082] Defaults output file permissions to 0775 unlike GNU objcopy which mirrors the input file's permissions

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 9 21:07:36 PDT 2019


Fangrui Song <i at maskray.me> changed:

           What    |Removed                     |Added
                 CC|                            |i at maskray.me
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #4 from Fangrui Song <i at maskray.me> ---
Fixed by D62718/r365162 and follow-ups. The description of r365162 is

GNU objcopy has some tricky rules to decide the output permission.

  if (i_ehdrp->e_type == ET_EXEC)
    abfd->flags |= EXEC_P;
  else if (i_ehdrp->e_type == ET_DYN)
    abfd->flags |= DYNAMIC;

// bfd/opncls.c
static inline void
_maybe_make_executable (bfd * abfd)
  /* If the file was open for writing and is now executable,
     make it so.  */
  if (abfd->direction == write_direction
      && (abfd->flags & (EXEC_P | DYNAMIC)) != 0)
      struct stat buf;

      if (stat (abfd->filename, &buf) == 0
          /* Do not attempt to change non-regular files.  This is
             here especially for configure scripts and kernel builds
             which run tests with "ld [...] -o /dev/null".  */
          && S_ISREG(buf.st_mode))
          unsigned int mask = umask (0);

          umask (mask);
          chmod (abfd->filename,
                  & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));

llvm-objcopy simply copies the permission of the input to the output.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190910/2e85a1a9/attachment.html>

More information about the llvm-bugs mailing list