Commit Graph

451 Commits

Author SHA1 Message Date
Zachary Turner
2811bb8f72 Make home_directory look in the password database in addition to $HOME.
This is something of an edge case, but when the $HOME environment
variable is not set, we can still look in the password database
to get the current user's home directory.

Added a test for this by getting the value of $HOME, then unsetting
it, then calling home_directory() and verifying that it succeeds
and that the value is the same as what we originally read from
the environment.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298513 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-22 15:24:59 +00:00
Zachary Turner
254674aa55 [Support] Fill the file_status struct with link count.
Differential Revision: https://reviews.llvm.org/D31110

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298326 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-20 23:55:20 +00:00
Zachary Turner
5ff37746b3 Fix linux build.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298007 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-16 22:34:18 +00:00
James Henderson
8276800d3c [Support] Add support for getting file system permissions on Windows and implement sys::fs::set/getPermissions to work with them
This change adds support for functions to set and get file permissions, in a similar manner to the C++17 permissions() function in <filesystem>. The setter uses chmod on Unix systems and SetFileAttributes on Windows, setting the permissions as passed in. The getter simply uses the existing status() function.

Prior to this change, status() would always return an unknown value for the permissions on a Windows file, making it impossible to test the new function on Windows. I have therefore added support for this as well. On Linux, prior to this change, the permissions included the file type, which should actually be accessed via a different member of the file_status class.

Note that on Windows, only the *_write permission bits have any affect - if any are set, the file is writable, and if not, the file is read-only. This is in common with what MSDN describes for their behaviour of std::filesystem::permissions(), and also what boost::filesystem does.

The motivation behind this change is so that we can easily test behaviour on read-only files in LLVM unit tests, but I am sure that others may find it useful in some situations.

Reviewers: zturner, amccarth, aaron.ballman

Differential Revision: https://reviews.llvm.org/D30736

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297945 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-16 11:22:09 +00:00
Aaron Ballman
61d9d49df6 Reverting r297617 because it broke some bots:
http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/49970

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297618 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-13 12:24:51 +00:00
Aaron Ballman
565edc0441 Add support for getting file system permissions and implement sys::fs::permissions to set them.
Patch by James Henderson.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297617 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-13 12:17:14 +00:00
Zachary Turner
ad31712bf4 Add llvm::sys::fs::real_path.
LLVM already has real_path like functionality, but it is
cumbersome to use and involves clean up after (e.g. you have
to call openFileForRead, then close the resulting FD).

Furthermore, on Windows it doesn't work for directories since
opening a directory and opening a file require slightly
different flags.

So I add a simple function `real_path` which works for all
paths on all platforms and has a simple to use interface.

In doing so, I add the ability to opt in to resolving tilde
expressions (e.g. ~/foo), which are normally handled by
the shell.

Differential Revision: https://reviews.llvm.org/D30668

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297483 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-10 17:39:21 +00:00
Nuno Lopes
844a69f35e fix build on Cygwin
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297378 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-09 13:43:31 +00:00
Zachary Turner
c036eebbeb [Support] Add llvm::sys::fs::remove_directories.
We already have a function create_directories() which can create
an entire tree, and remove() which can remove an empty directory,
but we do not have remove_directories() which can remove an entire
tree.  This patch adds such a function.

Because removing a directory tree can have dangerous consequences
when the tree contains a directory symlink, the patch here updates
the existing directory_iterator construct to optionally not follow
symlinks (previously it would always follow symlinks).  The delete
algorithm uses this flag so that for symlinks, only the links are
removed, and not the targets.

On Windows this is implemented with SHFileOperation, which also
does not recurse into symbolic links or junctions.

Differential Revision: https://reviews.llvm.org/D30676

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297314 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-08 22:49:32 +00:00
Zachary Turner
e00955f15c [fs] Make sure to check S_ISLNK() in fillStatus.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297167 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-07 17:48:47 +00:00
Zachary Turner
6a2cb8131e [Support] Add the option to not follow symlinks on stat.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297154 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-07 16:10:10 +00:00
Zachary Turner
6a33d44017 Try to fix thread name truncation on non-Windows.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296976 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-04 18:53:09 +00:00
Kamil Rytarowski
8fa74750a3 Improve the Threading code on NetBSD
Do not include <sys/user.h> on NetBSD. It's dead file and will be removed.

No need to include <sys/sysctl.h> in this code context on NetBSD.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296973 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-04 17:42:46 +00:00
Zachary Turner
7d7a5d9b46 Truncate thread names if they're too long.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296972 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-04 16:42:25 +00:00
Krzysztof Parzyszek
5a2cc6062f Silence a warning, NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296917 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-03 22:21:02 +00:00
Krzysztof Parzyszek
2b465546ec Detect the existence of pthread_{s,g}etname_np in libpthread on Linux
Older Linux distributions may not have those functions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296915 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-03 21:53:12 +00:00
Zachary Turner
9465dcab37 Add missing #includes for FreeBSD.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296902 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-03 18:38:22 +00:00
Zachary Turner
d19fe96ac9 Try again to appease the FreeBSD bot.
The actual logic was wrong, not just the type conversion.
This should get it correct.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296899 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-03 18:21:04 +00:00
Zachary Turner
cda7ea0056 Try to appease the FreeBSD bots.
pthread_self() returns a pthread_t, but we were setting it to
an int.  It seems the cast to int when calling sysctl is still
the correct thing to do, though.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296892 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-03 17:56:14 +00:00
Zachary Turner
154b43a9b7 Add #include for unistd.h on Linux.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296890 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-03 17:24:55 +00:00
Zachary Turner
50d14e63e0 [Support] Provide access to current thread name/thread id.
Applications often need the current thread id when making
system calls, and some operating systems provide the notion
of a thread name, which can be useful in enabling better
diagnostics when debugging or logging.

This patch adds an accessor for the thread id, and "best effort"
getters and setters for the thread name.  Since this is
non critical functionality, no error is returned to indicate
that a platform doesn't support thread names.

Differential Revision: https://reviews.llvm.org/D30526

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296887 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-03 17:15:17 +00:00
Zachary Turner
a6cf40b584 [Support] Re-add the special OSX flags on mmap.
The problem appears to be that these flags can only be used
when mapping a file for read-only, not for readwrite.  So
we do that here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295880 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-22 21:24:06 +00:00
Michal Gorny
39b10e911b [Support] Provide linux/magic.h fallback for older kernels
The function for distinguishing local and remote files added in r295768
unconditionally uses linux/magic.h header to provide necessary
filesystem magic numbers. However, in kernel headers predating 2.6.18
the magic numbers are spread throughout multiple include files.
Furthermore, LLVM did not require kernel headers being installed so far.

To increase the portability across different versions of Linux kernel
and different Linux systems, add CMake header checks for linux/magic.h
and -- if it is missing -- the linux/nfs_fs.h and linux/smb.h headers
which contained the numbers previously.

Furthermore, since the numbers are static and the feature does not seem
critical enough to make LLVM require kernel headers at all, add fallback
constants for the case when none of the necessary headers is available.

Differential Revision: https://reviews.llvm.org/D30261

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295854 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-22 18:09:15 +00:00
Zachary Turner
0f341e41e5 Try to fix the buildbot on OSX.
Since I'm only seeing failures on OSX, and it's saying
permission denied, I'm suspecting this is due to the addition
of the MAP_RESILIENT_CODESIGN and/or MAP_RESILIENT_MEDIA flags.
Speculatively trying to remove those to get the bots working.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295770 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-21 21:31:28 +00:00
Zachary Turner
83fbeaf3ba Try to fix Android build.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295769 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-21 21:13:10 +00:00
Zachary Turner
167b16d8fb [Support] Add a function to check if a file resides locally.
Differential Revision: https://reviews.llvm.org/D30010

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295768 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-21 20:55:47 +00:00
Omair Javaid
367ed08f22 Fix LLDB Android AArch64 GCC debug info build
Committing after fixing suggested changes and tested release/debug builds on 
x86_64-linux and arm/aarch64 builds.

Differential revision: https://reviews.llvm.org/D29042



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293850 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02 01:17:49 +00:00
Pavel Labath
c5e1c4de45 [Support] Use O_CLOEXEC only when declared
Summary:
Use the O_CLOEXEC flag only when it is available. Some old systems (e.g.
SLES10) do not support this flag. POSIX explicitly guarantees that this
flag can be checked for using #if, so there is no need for a CMake
check.

In case O_CLOEXEC is not supported, fall back to fcntl(FD_CLOEXEC)
instead.

Reviewers: rnk, rafael, mgorny

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D28894

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292912 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24 10:57:01 +00:00
Pavel Labath
f61f422e4e [Support] Add sys::fs::set_current_path() (aka chdir)
Summary:
This adds a cross-platform way of setting the current working directory
analogous to the existing current_path() function used for retrieving
it. The function will be used in lldb.

Reviewers: rafael, silvas, zturner

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D29035

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292907 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24 10:32:03 +00:00
Pavel Labath
7990fabccf raw_fd_ostream: Make file handles non-inheritable by default
Summary:
This makes the file descriptors on unix platform non-inheritable (O_CLOEXEC).

There is no change in behavior on windows, as the handles were already
non-inheritable there.

Reviewers: rnk, rafael

Subscribers: llvm-commits, mgorny

Differential Revision: https://reviews.llvm.org/D28854

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292401 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 15:46:50 +00:00
Bob Wilson
9ffd2e44bf Revert "Use _Unwind_Backtrace on Apple platforms."
This reverts commit 63165f6ae3.

After making this change, I discovered that _Unwind_Backtrace is
unable to unwind past a signal handler after an assertion failure.
I filed a bug report about that issue in rdar://29866587 but even if
we get a fix soon, it will be awhile before it get released.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291207 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-06 02:26:33 +00:00
Mehdi Amini
dbca62ee4e [ThinLTO] Add an API to trigger file-based API for returning objects to the linker
Summary:
The motivation is to support better the -object_path_lto option on
Darwin. The linker needs to write down the generate object files on
disk for later use by lldb or dsymutil (debug info are not present
in the final binary). We're moving this into libLTO so that we can
be smarter when a cache is enabled and hard-link when possible
instead of duplicating the files.

Reviewers: tejohnson, deadalnix, pcc

Subscribers: dexonsmith, llvm-commits

Differential Revision: https://reviews.llvm.org/D27507

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289631 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-14 04:56:42 +00:00
Simon Pilgrim
84d1e9104a Fix comment typos. NFC.
Identified by Pedro Giffuni in PR27636.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287490 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-20 13:47:59 +00:00
Bob Wilson
63165f6ae3 Use _Unwind_Backtrace on Apple platforms.
Darwin's backtrace() function does not work with sigaltstack (which was
enabled when available with r270395) — it does a sanity check to make
sure that the current frame pointer is within the expected stack area
(which it is not when using an alternate stack) and gives up otherwise.
The alternative of _Unwind_Backtrace seems to work fine on macOS, so use
that when backtrace() fails. Note that we then use backtrace_symbols_fd()
with the addresses from _Unwind_Backtrace, but I’ve tested that and it
also seems to work fine. rdar://problem/28646552

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286851 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-14 17:56:18 +00:00
Pavel Labath
517cd170c3 Zero-initialize chrono duration objects
The default duration constructor does not zero-initialize the object, we need to
do that manually.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286359 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 11:43:57 +00:00
Alina Sbirlea
1aa9c9ac56 Correct mprotect page boundries to round up end page. Fixes PR30905.
Summary:
Update the boundries for mprotect.
Patch by Andrew Adams. Fixes PR30905.

Reviewers: loladiro, andrew.w.kaylor, chandlerc

Subscribers: abadams, llvm-commits

Differential Revision: https://reviews.llvm.org/D26312

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286032 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-05 04:22:15 +00:00
Pavel Labath
f62fc7a377 [Chrono] Fix !HAVE_FUTIMENS build
If we don't have futimens(), we fall back to futimes(), which only supports
microsecond timestamps. In that case, we need to explicitly cast away the extra
precision in setLastModificationAndAccessTime().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284977 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-24 14:19:28 +00:00
Pavel Labath
2864c2ae90 Remove TimeValue usage from llvm/Support
Summary:
This is a follow-up to D25416. It removes all usages of TimeValue from
llvm/Support library (except for the actual TimeValue declaration), and replaces
them with appropriate usages of std::chrono. To facilitate this, I have added
small utility functions for converting time points and durations into appropriate
OS-specific types (FILETIME, struct timespec, ...).

Reviewers: zturner, mehdi_amini

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D25730

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284966 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-24 10:59:17 +00:00
Pavel Labath
911bb941ce Reapply "Add Chrono.h - std::chrono support header"
This is a resubmission of r284590. The mingw build should be fixed now. The
problem was we were matching time_t with _localtime_64s, which was incorrect on
_USE_32BIT_TIME_T systems. Instead I use localtime_s, which should always
evaluate to the correct function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284720 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-20 12:05:50 +00:00
Pavel Labath
b40b8e3413 Revert "Add Chrono.h - std::chrono support header"
This reverts commit r284590 as it fails on the mingw buildbot. I think I know the
fix, but I cannot test it right now. Will reapply when I verify it works ok.

This reverts r284590.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284615 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-19 17:17:53 +00:00
Pavel Labath
bca3cda284 Add Chrono.h - std::chrono support header
Summary:
std::chrono mostly covers the functionality of llvm::sys::TimeValue and
lldb_private::TimeValue. This header adds a bit of utility functions and
typedefs, which make the usage of the library and porting code from TimeValues
easier.

Rationale:
- TimePoint typedef - precision of system_clock is implementation defined -
  using a well-defined precision helps maintain consistency between platforms,
  makes it interact better with existing TimeValue classes, and avoids cases
  there a time point is implicitly convertible to a specific precision on some
  platforms but not on others.
- system_clock::to_time_t only accepts time_points with the default system
  precision (even though time_t has only second precision on all platforms we
  support). To avoid the need for explicit casts, I have added a toTimeT()
  wrapper function. toTimePoint(time_t) was not strictly necessary, but I have
  added it for symmetry.

Reviewers: zturner, mehdi_amini

Subscribers: beanz, mgorny, llvm-commits, modocache

Differential Revision: https://reviews.llvm.org/D25416

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284590 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-19 13:58:55 +00:00
Nuno Lopes
9f79578305 fix build on cygwin
Cygwin has dlfcn.h, but no Dl_info

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283427 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-06 09:32:16 +00:00
Joerg Sonnenberger
593505d39e Deal with the (historic) MAP_ANONYMOUS vs MAP_ANON directly by using CPP
to check for the former, don't depend on (dangling) HAVE_MMAP_ANONYMOUS.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282925 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-30 20:17:23 +00:00
Joerg Sonnenberger
f1086ea04d Retire NEED_DEV_ZERO_FOR_MMAP. It should be needed only on outdated
systems. It wasn't even hooked up in cmake, so problems on such systems
would be visible with 3.9 release already.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282924 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-30 20:16:01 +00:00
Joerg Sonnenberger
d8588ac73f Turn ENABLE_CRASH_OVERRIDES into a 0/1 definition.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282919 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-30 20:06:19 +00:00
Joerg Sonnenberger
2bf78b4d6c Convert ENABLE_BACKTRACES into a 0/1 definition.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282918 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-30 20:04:24 +00:00
Joerg Sonnenberger
5a47084235 Make HAVE_DECL_ARC4RANDOM always defined. Sort the entry correctly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282768 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-29 21:10:38 +00:00
Joerg Sonnenberger
422655d988 HAVE_UNWIND_BACKTRACE -> HAVE__UNWIND_BACKTRACE
Check for existance and not truth value.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282767 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-29 21:07:57 +00:00
Rafael Espindola
ec44cfdaf0 Add an c++ itanium demangler to llvm.
This adds a copy of the demangler in libcxxabi.

The code also has no dependencies on anything else in LLVM. To enforce
that I added it as another library. That way a BUILD_SHARED_LIBS will
fail if anyone adds an use of StringRef for example.

The no llvm dependency combined with the fact that this has to build
on linux, OS X and Windows required a few changes to the code. In
particular:

    No constexpr.
    No alignas

On OS X at least this library has only one global symbol:
__ZN4llvm16itanium_demangleEPKcPcPmPi

My current plan is:

    Commit something like this
    Change lld to use it
    Change lldb to use it as the fallback

    Add a few #ifdefs so that exactly the same file can be used in
    libcxxabi to export abi::__cxa_demangle.

Once the fast demangler in lldb can handle any names this
implementation can be replaced with it and we will have the one true
demangler.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280732 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-06 19:16:48 +00:00
Eugene Leviant
e21267a9a4 Implement getRandomBytes() function
This function allows getting arbitrary sized block of random bytes.
Primary motivation is support for --build-id=uuid in lld.

Differential revision: https://reviews.llvm.org/D23671


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279807 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26 08:14:54 +00:00