[PATCH] D62718: [llvm-objcopy] Change handling of output file permissions
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 19 01:10:14 PDT 2019
MaskRay requested changes to this revision.
MaskRay added a comment.
This revision now requires changes to proceed.
I believe GNU objcopy has the following logic:
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,
(0777
& (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));
}
}
}
I would not suggest copying this behavior (if ET_EXEC or ET_DYN, chmod +x).
Instead, mirroring the input file's permissions is much more reasonable and gives the least surprise.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62718/new/
https://reviews.llvm.org/D62718
More information about the llvm-commits
mailing list