755 Commits

Author SHA1 Message Date
azhan92
678f19f082
[Support] Report EISDIR when opening a directory (#79880)
The test `llvm/unittests/Support/CommandLineTest.cpp` that handles
errors in expansion of response files was previously disabled for AIX.
Originally the code was dependent on `read` returning `EISDIR` which
occurs on platforms such as Linux. However, other platforms such as AIX
allow use of `read` on file descriptors for directories. This change
updates `readNativeFile` to produce `EISDIR` on AIX and z/OS when used
on a directory (instead of relying on the call to `read` to do so).

---------

Co-authored-by: Alison Zhang <alisonzhang@ibm.com>
Co-authored-by: James Henderson <46713263+jh7370@users.noreply.github.com>
2024-04-17 17:56:42 -04:00
Jeff Niu
f2f01f6b03
[llvm][Support] Use thread_local caching for llvm::get_threadid() query on Apple systems (#87219)
I was profiling our compiler and noticed that `llvm::get_threadid` was
at the top of the hotlist, taking up a surprising 5% (7 seconds) in the
profile trace. It seems that computing this on MacOS systems is
non-trivial, so cache the result in a thread_local.

Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
2024-04-01 22:59:53 +02:00
Michael Spencer
ba13fa2a5d
[llvm][Support] Add and use errnoAsErrorCode (#84423)
LLVM is inconsistent about how it converts `errno` to `std::error_code`.
This can cause problems because values outside of `std::errc` compare
differently if one is system and one is generic on POSIX systems.

This is even more of a problem on Windows where use of the system
category is just wrong, as that is for Windows errors, which have a
completely different mapping than POSIX/generic errors. This patch fixes
one instance of this mistake in `JSONTransport.cpp`.

This patch adds `errnoAsErrorCode()` which makes it so people do not
need to think about this issue in the future. It also cleans up a lot of
usage of `errno` in LLVM and Clang.
2024-03-08 23:30:33 -08:00
Alexander Richardson
abbf1f1882
[Support] Fix Process::PreventCoreFiles() when coredumps are piped
On many current Linux systems, coredumps are no longer dumped in the CWD
but instead piped to a utility such as systemd-coredumpd that stores
them in a deterministic location. This can be done by setting the
kernel.core_pattern sysctl to start with a '|'. However, when using such
a setup the kernel ignores a coredump limit of 0 (since there is no file
being written) and we can end up piping many gigabytes of data to
systemd-coredumpd which causes the test suite to freeze for a long time.
While most piped coredump handlers do respect the crashing processes'
RLIMIT_CORE, this is notable not the case for Debian's systemd-coredump
due to a local patch that changes sysctl.d/50-coredump.conf to ignore
the specified limit and instead use RLIM_INFINITY
(https://salsa.debian.org/systemd-team/systemd/-/commit/64599ffe44f0d).

Fortunately there is a workaround: the kernel recognizes the magic value
of 1 for RLIMIT_CORE to disable coredumps when piping. One byte is also
too small to generate any coredump, so it effectively behaves as if we
had set the value to zero.

The alternative to using RLIMIT_CORE=1 would be to use prctl() with the
PR_SET_DUMPABLE flag, however that also prevents ptrace(), so makes it
impossible to attach a debugger.

See https://github.com/llvm/llvm-project/pull/83701 and
https://github.com/llvm/llvm-project/issues/45797

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/83703
2024-03-08 22:41:04 -08:00
Connor Sughrue
2fcf248ec2
Reland "[llvm][Support] Add support for executing a detached process (#81708)" (#83367)
Relands #81708, which was reverted by
f410f74cd5b26319b5796e0404c6a0f3b5cc00a5, now with a corrected unit
test. Origionally the test failed on Windows when run with lit as
`GetConsoleWindow` could not retrieve a window handle regardless of
whether `DetachProcess` was `true` or `false`. The test now uses
`GetStdHandle(STD_OUTPUT_HANDLE)` which does not rely on a console
window existing. Original commit message below.

Adds a new parameter, `bool DetachProcess` with a default option of
`false`, to `llvm::sys::ExecuteNoWait`, which, when set to `true`,
executes the specified program without a controlling terminal.

Functionality added so that the module build daemon can be run without a
controlling terminal.
2024-03-06 23:45:11 -05:00
cpsughrue
f410f74cd5 Revert "[llvm][Support] Add support for executing a detached process (#81708)"
This reverts commit 86f6caa562255f81b93e72a501a926b17f5ad244. Unit test
was failing on a few windows build bots
2024-02-26 21:40:21 -05:00
Connor Sughrue
86f6caa562
[llvm][Support] Add support for executing a detached process (#81708)
Adds a new parameter, `bool DetachProcess` with a default option of
`false`, to `llvm::sys::ExecuteNoWait`, which, when set to `true`,
executes the specified program without a controlling terminal.

Functionality added so that the module build daemon can be run without a
controlling terminal.
2024-02-26 21:04:11 -05:00
Timm Baeder
24a804101b
[llvm][Support] Support bright colors in raw_ostream (#80017) 2024-01-31 11:14:02 +01:00
Kazu Hirata
7e6482b3d8 [Support] Use SmallString::operator std::string (NFC) 2024-01-17 20:22:58 -08:00
Abhina Sree
ab380c287a
[SystemZ][z/OS] Complete EBCDIC I/O support (#75212)
This patch completes the support for EBCDIC I/O support on z/OS using the autoconversion functions.
2023-12-13 07:46:02 -05:00
Abhina Sree
61ee923256
[SystemZ][z/OS] Fix build errors on z/OS in the Unix .inc files (#74758)
This patch resolves the following errors on z/OS:

error: no member named 'wait4' in the global namespace
error: no member named 'ru_maxrss' in 'rusage'
error: use of undeclared identifier 'strsignal'
error: Cannot get usage times on this platform
error: Cannot get malloc info on this platform
2023-12-12 15:49:11 -05:00
Kazu Hirata
586ecdf205
[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-11 21:01:36 -08:00
Brad Smith
579e721ce9 [Support] Implement getMainExecutable for Haiku
This uses argv[0] on Haiku.
2023-11-24 02:12:39 -05:00
Lu Weining
fb366581e7
[Memory] Call __clear_cache in InvalidateInstructionCache on LoongArch (#67285)
As the comments of `InvalidateInstructionCache`: Before the JIT can run
a block of code that has been emitted it must invalidate the instruction
cache on some platforms. I think it applies to LoongArch as LoongArch
has a weak memory-model. But I'm not able to write a test to demonstrate
this issue. Perhaps self-modifing code should be wrote?
2023-10-19 10:16:13 +08:00
Qiongsi Wu
2cac95ba2b
[AIX][PowerPC] Teach the Threading Library About the Number of Physical Cores on AIX (#67683)
The threading library does not recognize AIX and always returns `-1` for
number of physical cores on AIX. This PR teaches the library to
recognize AIX and obtain the correct value for the number of physical
cores.
2023-09-29 10:23:20 -04:00
Brad Smith
69d79f1f77 [Support] Implement getMainExecutable for OpenBSD
This uses just argv[0] on OpenBSD. OpenBSD does not support the /proc filesystem.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D159168
2023-09-01 19:47:28 -04:00
Brad Smith
24eaf7858b Cleanup remaining bits for Minix, Contiki and Myriad
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D158806
2023-08-25 16:37:55 -04:00
Petr Hosek
7038bed916 [Support] Avoid wait4 on Fuchsia
Fuchsia doesn't provide wait4, use waitpid instead.

Differential Revision: https://reviews.llvm.org/D155793
2023-08-23 23:32:44 +00:00
Daniel Thornburgh
8d3ff601a3 Fix symbolizer markup backtrace build/test.
This corrects a Darwin build failure due to a missing stub and an
environment-specific Linux test failure due to an overly restrictive
test regex. This also backs out of the previous fix attempt; %p is
intended to be printed and parsed with the semantics of #.
2023-08-17 13:53:02 -07:00
Michael Liao
7026a0caca [llvm][Support] Fix backtrace output by removing '#'. NFC
- '#' has the string "0x" prepended for non-zero values. That results in
  inconsistent behavior between zero and non-zero values.
2023-08-17 15:58:12 -04:00
Daniel Thornburgh
22b9404f09 Optionally print symbolizer markup backtraces.
When the environment LLVM_ENABLE_SYMBOLIZER_MARKUP is set, if
llvm-symbolizer fails or is disabled, this change will print a backtrace
in llvm-symbolizer markup instead of falling back to in-process
symbolization mechanisms.

This allows llvm-symbolizer to be run on the output later to produce a
high quality backtrace, even for fully-stripped LLVM utilities.

Reviewed By: mcgrathr

Differential Revision: https://reviews.llvm.org/D139750
2023-08-17 10:54:47 -07:00
Nick Desaulniers
3b01fa264c [Demangle] remove unused status param of itaniumDemangle
No call sites interpreted this value meaningfully. Simplify this
interface.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D149707
2023-05-03 11:51:35 -07:00
Nick Desaulniers
7277a72b90 [Demangle] remove unused params of itaniumDemangle
No call sites use these parameters, so drop them.
Equivalent to D148940.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D149703
2023-05-03 09:57:41 -07:00
Luís Marques
c111fe46a1 [Support] Implement findModulesAndOffsets on Apple 64-bit platforms
To have line number information in stack traces (per stack frame) it's
necessary to implement findModulesAndOffsets.

Differential Revision: https://reviews.llvm.org/D142282
2023-03-05 12:20:47 +00:00
Luís Marques
6190356914 Revert "[Support] Implement findModulesAndOffsets on Apple 64-bit platforms"
This reverts commit b8b8aa6f06458212193c4202291c9f68364b2025.
It broke AIX.
2023-03-02 21:44:34 +00:00
Luís Marques
b8b8aa6f06 [Support] Implement findModulesAndOffsets on Apple 64-bit platforms
To have line number information in stack traces (per stack frame) it's
necessary to implement findModulesAndOffsets.

Differential Revision: https://reviews.llvm.org/D142282
2023-03-02 10:58:56 +00:00
Fangrui Song
1c417da0f0 Remove uses of ATOMIC_VAR_INIT
ATOMIC_VAR_INIT has a trivial definition `#define ATOMIC_VAR_INIT(value) (value)`,
is deprecated in C17/C++20, and will be removed in newer standards.
2023-02-24 13:43:12 -08:00
Alex Brachet
3e57aa304f [llvm-driver] Reinvoke clang as described by llvm driver extra args
Differential Revision: https://reviews.llvm.org/D137800
2023-02-10 19:42:32 +00:00
Owen Anderson
e4e0f93307 Remove the ThreadLocal template from LLVM.
This has been obsoleted by C++ thread_local for a long time.
As far as I know, Xcode was the last supported toolchain to add
support for C++ thread_local in 2016.

As a precaution, use LLVM_THREAD_LOCAL which provides even greater
backwards compatibility, allowing this to function even pre-C++11
versions of GCC.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D141349
2023-01-10 21:07:52 -07:00
Owen Anderson
ef9aa34f02 Revert "Remove the ThreadLocal template from LLVM."
This reverts commit 54d78b639b9c18b42abd4fac5c6e76105f06b3ef.
2023-01-09 21:21:38 -07:00
Owen Anderson
54d78b639b Remove the ThreadLocal template from LLVM.
This has been obsoleted by C++ thread_local for a long time.
As far as I know, Xcode was the last supported toolchain to add
support for C++ thread_local in 2016.

As a precaution, use LLVM_THREAD_LOCAL which provides even greater
backwards compatibility, allowing this to function even pre-C++11
versions of GCC.

Reviewed By: majnemer

Differential Revision: https://reviews.llvm.org/D141347
2023-01-09 21:12:27 -07:00
Matt Arsenault
24e3086c89 Support: Fix broken C++ marker 2022-12-22 14:40:50 -05:00
Matt Arsenault
eb93b8774e Support: Add polling option to sys::Wait
Currently the process is terminated after the timeout. Add an option
to let the process resume after the timeout instead.

https://reviews.llvm.org/D138952
2022-12-22 12:38:59 -05:00
Archibald Elliott
f09cf34d00 [Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
  component into a new LLVM Component called "TargetParser". This
  potentially enables using tablegen to maintain this information, as
  is shown in https://reviews.llvm.org/D137517. This cannot currently
  be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
  information in the TargetParser:
  - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
    the current Host machine for info about it, primarily to support
    getting the host triple, but also for `-mcpu=native` support in e.g.
    Clang. This is fairly tightly intertwined with the information in
    `X86TargetParser.h`, so keeping them in the same component makes
    sense.
  - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
    the target triple parser and representation. This is very intertwined
    with the Arm target parser, because the arm architecture version
    appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.

And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM

Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.

If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.

Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 11:05:50 +00:00
Fangrui Song
b1df3a2c0b [Support] llvm::Optional => std::optional
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-16 08:49:10 +00:00
Matt Arsenault
7fb7c78c46 Support: Try to fix msan error in sys::Wait 2022-12-14 14:09:34 -05:00
Matt Arsenault
15a6e3c636 Support: Make Wait's SecondsToWait be std::optional [NFC]
I found the interaction between SecondsToWait and
WaitUntilChildTerminates confusing. Rather than have a boolean to
ignore the value of SecondsToWait, combine these into one Optional
parameter.
2022-12-14 09:56:10 -05:00
Krzysztof Parzyszek
3c255f679c Process: convert Optional to std::optional
This applies to GetEnv and FindInEnvPath.
2022-12-06 09:56:14 -08:00
Kazu Hirata
aadaaface2 [llvm] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02 21:11:44 -08:00
Jan Svoboda
abf0c6c0c0 Use CTAD on llvm::SaveAndRestore
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D139229
2022-12-02 15:36:12 -08:00
Matt Arsenault
e748db0f7f Support: Convert Program APIs to std::optional 2022-12-01 17:00:44 -05:00
Archibald Elliott
3c97f6cab9 [Support] Move getHostNumPhysicalCores to Threading.h
This change is focussed on simplifying `Support/Host.h` to only do
target detection. In this case, this function is close in usage to
existing functions in `Support/Threading.h`, so I moved it into there.
The function is also renamed to `llvm::get_physical_cores()` to match
the style of threading's functions.

The big change here is that now if you have threading disabled,
`llvm::get_physical_cores()` will return -1, as if it had not been able
to work out the right info. This is due to how Threading.cpp includes
OS-specific code/headers. This seems ok, as if threading is disabled,
LLVM should not need to know the number of physical cores.

Differential Revision: https://reviews.llvm.org/D137836
2022-11-29 13:14:13 +00:00
Alexandre Ganea
f1aa7348d3 [Support] Apply clang-format on .inc files. NFC.
Apply clang-format on llvm/lib/Support/Windows/ and llvm/lib/Support/Unix/ since .inc files in these folders aren't picked up by default. Eventually we need to add this extension in the monorepo .clang-format file.

Differential Revision: https://reviews.llvm.org/D138714
2022-11-26 09:36:43 -05:00
Fangrui Song
875adb4007 Host: Internalize computeHostNumPhysicalCores/computeHostNumHardwareThreads
Windows computeHostNumPhysicalCores is defined by Threading.cpp. Leave it
unchanged.
2022-11-23 21:09:45 -08:00
Fangrui Song
93b553e3f2 Revert "Host: Internalize computeHostNumPhysicalCores/computeHostNumHardwareThreads"
This reverts commit 9969ceb36b440eaafa17c486f29a69c7a7da3b3b.

On Windows:

lld-link: error: undefined symbol: int __cdecl computeHostNumPhysicalCores(void)
>>> referenced by LLVMSupport.lib(Support.Host.obj):(int __cdecl llvm::sys::getHostNumPhysicalCores(void))
2022-11-23 20:12:16 -08:00
Fangrui Song
9969ceb36b Host: Internalize computeHostNumPhysicalCores/computeHostNumHardwareThreads 2022-11-23 17:44:04 -08:00
Bill Wendling
4787efa380 Revert "Reapply: Add an error message to the default SIGPIPE handler"
This patch is spamming compiles with unhelpful and confusing messages.
E.g. the Linux kernel uses "grep -q" in several places. It's meant to
quit with a return code of zero when the first match is found. This can
cause a SIGPIPE signal, but that's expected, and there's no way to turn
this error message off to avoid spurious error messages.

UNIX03 apparently doesn't require printing an error message on SIGPIPE,
but specifically when there's an error on the stdout stream in a normal
program flow, e.g. when SIGPIPE trap is disabled.

A separate patch is planned to address the specific case we care most
about (involving llvm-nm).

This reverts commit b89bcefa6202e310eb3167dd1c37f1807377ec8d.

Link: https://github.com/llvm/llvm-project/issues/59037
Link: https://github.com/ClangBuiltLinux/linux/issues/1651

Differential Revision: https://reviews.llvm.org/D138244
2022-11-18 11:17:25 -08:00
Yabin Cui
22339e52da [Support] Use thread safe version of getpwuid and getpwnam.
OpenGroup specification doesn't require getpwuid and getpwnam
to be thread-safe. And musl libc has a not thread-safe implementation.
When building clang with musl, this can make clang-scan-deps crash.

Reviewed By: pirama

Differential Revision: https://reviews.llvm.org/D137864
2022-11-14 17:48:44 +00:00
Fangrui Song
6c927f2a86 Canonicalize PowerPC detection macros to __powerpc__ 2022-11-06 17:29:45 -08:00
raghavmedicherla
5d3cf8267f Revert "Support: Add mapped_file_region::sync(), equivalent to msync"
This reverts commit 142f51fc2f448845f6a32e767ffaa2b665eea11f.

This shouldn't be committed, it got committed accidentally.
2022-09-08 12:49:52 -04:00