Commit Graph

1807 Commits

Author SHA1 Message Date
jusito
7b9fa2146e
[cmake] Option to create Ninja job pools depending on available resources (#65274)
This PR adds options to let CMake calculate the ninja job pools
depending on free memory and available cores.
You can provide memory requirements for each compile and link job which
is checked against CMake AVAILABLE_PHYSICAL_MEMORY and
NUMBER_OF_LOGICAL_CORES. [This information are available since CMake
3.0](https://cmake.org/cmake/help/v3.0/command/cmake_host_system_information.html).

This is very helpful in CI environments with multiple jobs per
environment or a VM with multiple users.
Its different to LLVM_PARALLEL_LINK_JOBS / LLVM_PARALLEL_COMPILE_JOBS
(or ninja -j 1) because it tries to use the resources more efficient
without being terminated. Only downside currently is that compile and
link jobs can run at the same time so there is an offset for link job
memory suggested which is added to the documentation.

The definitions aren't added as cache because if I understand it
correctly this would break it because values could be outdated.
2023-10-20 22:37:51 +05:30
Vincent Lee
6362ef1fb1
[CMake] Avoid build spam by switching to Debug message (#69497)
This is primarily only useful when debugging. It's generally assumed
that users
will have their custom flags applied if it's specified in their CMake
cache files.

Addresses
https://github.com/llvm/llvm-project/pull/68393#discussion_r1363399029
2023-10-19 23:52:18 -07:00
Eric Kilmer
e3ae2a52d2
[llvm][CMake] Check dependency cxx source compiles (#68549)
If a CMake project doesn't enable the C language, then the CMake FFI and
Terminfo find modules will fail their checks for compilation and
linking.

This commit allows projects to enable only C++ by first checking if a C
compiler is set before testing C source compilation; if not, it checks
whether C++ compilation succeeds.

Fixes #53950
2023-10-18 09:03:04 -07:00
Vincent Lee
e90ec58b13
[CMake] Support per-target linker flags (#68393)
`CMAKE_{C/CXX}_FLAGS` affects all targets in LLVM. This can
be undesirable in situations, like the case of enabling thinLTO,
where `-flto` is added to every source file. In reality, we only 
care about optimizing a select few of binaries, such as clang or lld,
that dominate the compilation pipeline. Auxiliary binaries in a 
distribution and not on the critical path can be kept non-optimized. 
This PR adds support of per-target linker flags, which can solve the
thinLTO problem by negating the effects of LTO via targeted linker 
flags on the targets. The example of negating thinLTO 
above can be done by doing the following:

```
set(LLVM_llvm-dwarfdump_LINKER_FLAGS "-Wl,--lto-O0" CACHE STRING "Custom linker flags to llvm-dwarfdump")
set(LLVM_lldb_LINKER_FLAGS "-Wl,--lto-O0" CACHE STRING "Custom linker flags to lldb")
```

There's other applications where this could be used (e.g. avoid
optimizing host tools for build speed improvement etc.). 
I've generalized this so that users can apply their desired flags to
targets that are generated by `llvm_add_library` or
`add_llvm_executable`.

Internally, our toolchain builds were on average 1.4x faster when
selectively choosing the binaries that we want optimized.
2023-10-17 14:05:01 -07:00
Jeremy Morse
088d272e83 [ADT][DebugInfo][RemoveDIs] Add extra bits to ilist_iterator for debug-info
...behind an experimental CMAKE option that's off by default.

This patch adds a new ilist-iterator-like class that can carry two extra bits
as well as the usual node pointer. This is part of the project to remove
debug-intrinsics from LLVM: see the rationale here [0], they're needed to
signal whether a "position" in a BasicBlock includes any debug-info before or
after the iterator.

This entirely duplicates ilist_iterator, attempting re-use showed it to be a
false economy. It's enable-able through the existing ilist_node options
interface, hence a few sites where the instruction-list type needs to be
updated. The actual main feature, the extra bits in the class, aren't part of
the class unless the cmake flag is given: this is because there's a
compile-time cost associated with it, and I'd like to get everything in-tree
but off-by-default so that we can do proper comparisons.

Nothing actually makes use of this yet, but will do soon, see the Phab patch
stack.

[0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939

Differential Revision: https://reviews.llvm.org/D153777
2023-10-17 15:24:44 +01:00
George Lyon
d5e91ca563
[CMake] Limit -gsplit-dwarf option to C and C++ compilers
Currently, If the C or C++ compiler supports the `-gsplit-dwarf` option it is added to _all_ compilers.
If a project decides to use another  language, such as Swift, this option will be sent to that compiler as well, regardless whether that compiler supports it or not (Swift doesnot).
This patch uses [generator expressions](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html) to limit the `-gsplit-dwarf` option to only those compilers that support it (C and C++).
2023-10-15 19:59:00 +03:00
Juergen Ributzka
eb601430d3
[llvm][objdump] Remove support for printing the embedded Bitcode section in MachO files. (#68457)
It's no longer possible to submit bitcode apps to the Apple App Store.
The tools
used to create xar archived bitcode sections inside MachO files have
been
discontinued. Additionally, the xar APIs have been deprecated since
macOS 12,
so this change removes unnecessary code from objdump and all
dependencies on
libxar.

This fixes rdar://116600767
2023-10-09 15:03:29 -07:00
David Spickett
864beb1792
[llvm][CMake] Expand error message shown when -fuse-ld= test fails (#66778)
This is one of the most common issues new users face, especially as so
many reccomended CMake configurations include `-DLLVM_ENABLE_LLD=ON`.

I don't want the error message to get too long but let's at least say
that there are 2 main reasons for the failure. If it's not those then
maybe folks will find the actual problem while trying to discount them.

The new message looks like:
```
CMake Error at cmake/modules/HandleLLVMOptions.cmake:330 (message):
  Host compiler does not support '-fuse-ld=not_a_linker'.  Please make sure
  that 'not_a_linker' is installed and that your host compiler can compile a
  simple program when given the option '-fuse-ld=not_a_linker'.
Call Stack (most recent call first):
  CMakeLists.txt:910 (include)
```
2023-10-03 09:08:50 +01:00
David Truby
247b7d0684
[cmake] Add LLVM_FORCE_VC_REVISION option (#67125)
This patch adds a LLVM_FORCE_VC_REVISION option to force a custom
VC revision to be included instead of trying to fetch one from a
git command. This is helpful in environments where git is not
available or is non-functional but the vc revision is available
through some other means.
2023-09-25 14:32:52 +01:00
Justin Lebar
36b87d8043
Set -rpath-link only if the path is nonempty.
This cmake rule is used by external clients, who may or may not have
the LLVM_LIBRARY_OUTPUT_INTDIR variable set.

If it is not set, then we pass `-Wl,-rpath-link,` to the compiler.  It
turns out that gcc and clang interpret this differently.

  * gcc passes `-rpath-link ""` to the linker, which is what we want.

  * clang passes `-rpath-link` to the linker.  This is not what we want,
    because then the linker gobbles the next command-line argument,
    whatever it happens to be, and uses it as the -rpath-link target.

Fix this by passing -rpath-link only if we actually have a path we want.
2023-09-21 10:13:51 -07:00
Zhang
618e5d2c2d
[CMake] Fully delete the deprecated LLVM_USE_CRT* (#66850)
This has been deprecated in favor of CMake's CMAKE_MSVC_RUNTIME_LIBRARY
in c6bd873403 .
Current release branch still contains it in deprecated status so no
existing end-users will be affected.
2023-09-21 13:25:06 +03:00
Zhang
5664b56043
[CMake][Z3]Don't attempt to compile / run if cross-compiling (#66355)
Otherwise CMake might throw and error:
CMake Error: try_run() invoked in cross-compiling mode, please set the
following cache variables appropriately:
   Z3_RETURNCODE (advanced)
   Z3_RETURNCODE__TRYRUN_OUTPUT (advanced)
2023-09-15 12:57:33 +02:00
Petr Hosek
7b03a55ce2
[CMake] Remove SetTargetTriple (#66464)
This module is only used in two places and its logic can be inlined and
simplified.
2023-09-14 23:44:13 -07:00
Carlo Bramini
e873280e61 [flang/mlir] Fix "file too big" build error on CYGWIN.
Attached patch fixes issues #63582 and #57718 when building my port to CYGWIN of llvm-project.
https://github.com/llvm/llvm-project/issues/63582
https://github.com/llvm/llvm-project/issues/57718

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D159404
2023-09-14 12:41:40 +03:00
Rainer Orth
d39a9e3b4d [Driver] Support GNU ld on Solaris
This patch supports GNU ld on Solaris in addition to Solaris ld, the
default.

- Linker selection is dynamic: one can switch between Solaris ld and GNU ld
  at runtime, with the default selectable with `-DCLANG_DEFAULT_LINKER`.

- Testcases have been adjusted to test both variants in case there are
  differences.

- The `compiler-rt/cmake/config-ix.cmake` and
  `llvm/cmake/modules/AddLLVM.cmake` changes to restrict the tests to
  Solaris ld are necessary because GNU accepts unknown `-z` options, but
  warns every time they are used, creating a lot of noise.  Since there
  seems to be no way to check for those warnings in
  `llvm_check_compiler_linker_flag` or `llvm_check_compiler_linker_flag`, I
  restrict the cmake tests to Solaris ld in the first place.

- The changes to `clang/test/Driver/hip-link-bundle-archive.hip` and
  `flang/test/Driver/linker-flags.f90` are required when LLVM is built with
  `-DCLANG_DEFAULT_LINKER=gld` on Solaris: `MSVC.cpp`
  `visualstudio::Linker::ConstructJob` ultimately calls
  `GetProgramPath("gld")`, resulting in a search for `gld`, which exists in
  `/usr/bin/gld` on Solaris.  With `-fuse-ld=`, this doesn't happen and the
  expected `link` is returned.

- `compiler-rt/test/asan/TestCases/global-location-nodebug.cpp` needs to
  enforce the Solaris ld, otherwise the test would `XPASS` with GNU ld
  which has the `-S` semantics expected by the test.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11` with both
`-DCLANG_DEFAULT_LINKER=gld` and the default, and `x86_64-pc-linux-gnu`.
No regressions in either case.

Differential Revision: https://reviews.llvm.org/D85309
2023-09-01 21:42:05 +02:00
Saleem Abdulrasool
05d613ea93 [lit][clang] Avoid realpath on Windows due to MAX_PATH limitations
Running lit tests on Windows can fail because its use of
`os.path.realpath` expands substitute drives, which are used to keep
paths short and avoid hitting MAX_PATH limitations.

Changes lit logic to:

Use `os.path.abspath` on Windows, where `MAX_PATH` is a concern that we
can work around using substitute drives, which `os.path.realpath` would
resolve.

Use `os.path.realpath` on Unix, where the current directory always has
symlinks resolved, so it is impossible to preserve symlinks in the
presence of relative paths, and so we must make sure that all code paths
use real paths.

Also updates clang's `FileManager::getCanonicalName` and `ExtractAPI`
code to avoid resolving substitute drives (i.e. resolving to a path
under a different root).

How tested: built with `-DLLVM_ENABLE_PROJECTS=clang` and built `check-all` on both Windows

Differential Revision: https://reviews.llvm.org/D154130
Reviewed By: @benlangmuir

Patch by Tristan Labelle <tristan@thebrowser.company>!
2023-08-01 11:00:27 -07:00
Fangrui Song
1e06b82bde [docs] Bump minimum GCC version to 7.4
GCC 7.3 cannot build 16.x releases.
```
In file included from /tmp/llvm-16/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:14:0:
/tmp/llvm-16/llvm/include/llvm/Transforms/IPO/Attributor.h:1137:32: error: duplicate initialization of ‘llvm::AnalysisGetter::HasLegacyWrapper<Analysis, std::void_t<typename Analysis::Lega
cyWrapper> >’
 constexpr bool AnalysisGetter::HasLegacyWrapper<
                                ^~~~~~~~~~~~~~~~~
       Analysis, std::void_t<typename Analysis::LegacyWrapper>> = true;
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/llvm-16/llvm/include/llvm/Transforms/IPO/Attributor.h:1137:32: error: got 1 template parameters for ‘constexpr const bool llvm::AnalysisGetter::HasLegacyWrapper< <template-parameter-1
-1>, <template-parameter-1-2> >’
/tmp/llvm-16/llvm/include/llvm/Transforms/IPO/Attributor.h:1137:32: error:   but 2 required
```

The 17.x and main branches have more failures, e.g.

```
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp: `error: cannot decompose class type ‘std::pair<llvm::Value*, const llvm::SCEV*>’: ...`
```

We probably should just give up 7.1 and say that GCC<=7.3 is unsupported.
There is evidence that GCC 7.4 works.
I have verified that GCC 7.5 is able to build `check-{llvm,clang,clang-tools,lldb,lld,polly,mlir,bolt}`,
but not flang due to at least `flang/Common/enum-class.h` and a `<charconv`> in a unittest.

Link: https://discourse.llvm.org/t/require-gcc-7-5-as-gcc-7-3-cannot-build-llvm/72310

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156286
2023-07-31 13:10:08 -07:00
Konstantin Varlamov
194e2ba125 [CMake] Use LLVM_ENABLE_ASSERTIONS to enable the hardened mode in libc++.
Use the new libc++ hardened mode instead of the deprecated safe mode.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D156377
2023-07-26 23:09:23 -07:00
Shivam Gupta
64d19542e7 [LIT] Added an option to llvm-lit to emit the necessary test coverage data, divided per test case
This patch is the first part of https://llvm.org/OpenProjects.html#llvm_patch_coverage.

We have first define a new variable LLVM_TEST_COVERAGE which when set, pass --per-test-coverage option to
llvm-lit which will help in setting a unique value to LLVM_PROFILE_FILE for each RUN. So for example
coverage data for test case llvm/test/Analysis/AliasSet/memtransfer.ll will be emitted as
build/test/Analysis/AliasSet/memtransfer0.profraw

Reviewed By: hnrklssn

Differential Revision: https://reviews.llvm.org/D154280
2023-07-26 16:47:17 +05:30
Farid Zakaria
1f8f8760b5 [CMake] Disable GCC -Wnonnull
I noticed during the build that GCC would emit a ton of nonnull
warnings.

Example:
```
/usr/local/google/home/fmzakari/code/github.com/llvm/llvm-project/clang/include/clang/AST/ExternalASTSource.h:378:54: warning: ‘this’ pointer is null [-Wnonnull]
  378 |       Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1));
      |                                        ~~~~~~~~~~~~~~^~~~~~~~~~
```

Reviewed By: MaskRay, rsmith

Differential Revision: https://reviews.llvm.org/D155857
2023-07-23 20:19:42 -07:00
Shivam Gupta
db04f018bb Revert "[LIT] Added an option to llvm-lit to emit the necessary test coverage data, divided per test case"
This reverts commit d8e26bccb3.
Test case are meant to run only when LLVM_INDIVIDUAL_TEST_COVERAGE is set.
2023-07-21 15:59:56 +05:30
Shivam Gupta
d8e26bccb3 [LIT] Added an option to llvm-lit to emit the necessary test coverage data, divided per test case
This patch is the first part of https://llvm.org/OpenProjects.html#llvm_patch_coverage.

We have first define a new variable LLVM_TEST_COVERAGE which when set, pass --emit-coverage option to
llvm-lit which will help in setting a unique value to LLVM_PROFILE_FILE for each RUN. So for example
coverage data for test case llvm/test/Analysis/AliasSet/memtransfer.ll will be emitted as
build/test/Analysis/AliasSet/memtransfer.profraw

Reviewed By: hnrklssn

Differential Revision: https://reviews.llvm.org/D154280
2023-07-21 15:23:01 +05:30
Martin Storsjö
9f4dfcb795 [CMake] Clean up old code for handling MSVC runtime setting the old way
This was left in place to reduce the risk of breaking anything,
and to keep the diff smaller, in D155233.

Differential Revision: https://reviews.llvm.org/D155431
2023-07-19 11:25:28 +03:00
Alex MacLean
621d1d07d9 [cmake] Add -Wcast-qual to C flags if LLVM_ENABLE_WARNINGS is defined.
Disable this warning for specific cast in llvm_regcomp().

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D153911
2023-07-18 23:44:55 +00:00
Martin Storsjö
c6bd873403 [CMake] Switch the CMP0091 policy (MSVC_RUNTIME_LIBRARY) to the new behaviour
With the new behaviour, the /MD or similar options aren't added to
e.g. CMAKE_CXX_FLAGS_RELEASE, but are added separately by CMake.
They can be changed by the cmake variable
CMAKE_MSVC_RUNTIME_LIBRARY or with the target property
MSVC_RUNTIME_LIBRARY.

LLVM has had its own custom CMake flags, e.g. LLVM_USE_CRT_RELEASE,
which affects which CRT is used for release mode builds. Deprecate
these and direct users to use CMAKE_MSVC_RUNTIME_LIBRARY directly
instead (and do a best effort attempt at setting CMAKE_MSVC_RUNTIME_LIBRARY
based on the existing LLVM_USE_CRT_ flags). This only handles the
simple cases, it doesn't handle multi-config generators with
different LLVM_USE_CRT_* variables for different configs though,
but that's probably fine - we should move over to the new upstream
CMake mechanism anyway, and push users towards that.

Change code in compiler-rt, that previously tried to override the
CRT choice to /MT, to set CMAKE_MSVC_RUNTIME_LIBRARY instead of
meddling in the old variables.

This resolves the policy issue in
https://github.com/llvm/llvm-project/issues/63286, and should
handle the issues that were observed originally when the
minimum CMake version was bumped, in
https://github.com/llvm/llvm-project/issues/62719 and
https://github.com/llvm/llvm-project/issues/62739.

Differential Revision: https://reviews.llvm.org/D155233
2023-07-17 09:59:05 +03:00
Arthur Eubanks
9efbb67939 [CMake] Add /winsysroot to lld-link when LLVM_WINSYSROOT is specified
So that the linker can find libraries in the winsysroot.

Reviewed By: hans, rnk

Differential Revision: https://reviews.llvm.org/D151946
2023-07-05 09:58:48 -07:00
Nikita Popov
c0011f027d [cmake] Add LLVM_UNITTEST_LINK_FLAGS option
Add an option to specify additional linker flags for unit tests only.
For example, this allows using something like
-DLLVM_UNITTEST_LINK_FLAGS="-Wl,-plugin-opt=O0" if you're doing LTO
builds, or -DLLVM_UNITTEST_LINK_FLAGS="-fno-lto" if you're using
fat LTO objects.

The build system already does this itself if the LLVM_ENABLE_LTO
flag is used, but this does not cover all possible LTO configurations.

Differential Revision: https://reviews.llvm.org/D154212
2023-07-05 09:19:33 +02:00
Stella Laurenzo
54db162429 Revert "Define/guard MLIR_STANDALONE_BUILD LLVM_LIBRARY_OUTPUT_INTDIR var."
This reverts commit f55fd19b6b.

As noted on the original thread, other uses of LLVM_LIBRARY_OUTPUT_INTDIR are optional. Will make a separate patch that makes this use optional as well.
2023-06-21 10:20:35 -07:00
Stella Laurenzo
f55fd19b6b Define/guard MLIR_STANDALONE_BUILD LLVM_LIBRARY_OUTPUT_INTDIR var.
It looks like MLIR is using the more modern CMAKE_LIBRARY_OUTPUT_DIRECTORY, but AddLLVM still uses this older LLVM specific alias.

In the specific case I was running into, the empty variable was causing `-Wl,-rpath-link,` on the command line, causing the following argument to be swallowed. This was maddening, because the following argument was the .o file containing `main` and I was getting `main` undefined errors when it was clearly there. This is egregious enough that I chose to guard it.

Differential Revision: https://reviews.llvm.org/D153373
2023-06-20 14:14:15 -07:00
Alexandre Ganea
6f2e92c10c Re-land [LLD] Allow usage of LLD as a library
This reverts commit aa495214b3.

As discussed in https://github.com/llvm/llvm-project/issues/53475 this patch
allows for using LLD-as-a-lib. It also lets clients link only the drivers that
they want (see unit tests).

This also adds the unit test infra as in the other LLVM projects. Among the
test coverage, I've added the original issue from @krzysz00, see:
https://github.com/ROCmSoftwarePlatform/D108850-lld-bug-reproduction

Important note: this doesn't allow (yet) linking in parallel. This will come a
bit later hopefully, in subsequent patches, for COFF at least.

Differential revision: https://reviews.llvm.org/D119049
2023-06-19 07:35:11 -04:00
Mark de Wever
9c39400d1a [CMake] Fixes using CMake 3.27.0.
Testing libc++ with CMake 3.27.0-rc1 fails. It seems some of the modules
used in CMake are not included.

The error before this change was
```
CMake Error at <mono-repo>/llvm/cmake/modules/HandleLLVMOptions.cmake:821 (CHECK_C_SOURCE_COMPILES):
  Unknown CMake command "CHECK_C_SOURCE_COMPILES".
Call Stack (most recent call first):
  CMakeLists.txt:156 (include)
```

Reviewed By: thesamesam

Differential Revision: https://reviews.llvm.org/D152619
2023-06-15 17:31:29 +02:00
Leonard Chan
aa495214b3 Revert "[LLD] Allow usage of LLD as a library"
This reverts commit 2700da5fe2.

Reverting since this causes some test failures on our builders: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8778372807208184913/overview
2023-06-14 20:36:27 +00:00
Alexandre Ganea
2700da5fe2 [LLD] Allow usage of LLD as a library
As discussed in https://github.com/llvm/llvm-project/issues/53475 this patch allows using LLD-as-a-lib. It also lets clients link only the drivers that they want (see unit tests).

This also adds the unit test infra as in the other LLVM projects. Among the test coverage, I've added the original issue from @krzysz00, see: https://github.com/ROCmSoftwarePlatform/D108850-lld-bug-reproduction

Important note: this doesn't allow (yet) linking in parallel. This will come a bit later, in subsequent patches, for COFF at last.

Differential revision: https://reviews.llvm.org/D119049
2023-06-13 16:22:59 -04:00
Pierre Gousseau
56bf960629 [CMake] Enable building with UBSAN + clang-cl on windows.
Currently both ASAN and UBSAN are supported on Windows but only ASAN is enabled in LLVM build system. This patch enables the option to build LLVM with UBSAN on windows.

Tested with clang-cl released in LLVM16.

Submitting on behalf of @dwang.

Reviewed by: andrewng, pgousseau

Differential Revision: https://reviews.llvm.org/D151511
2023-06-13 10:17:49 +01:00
Sam James
e3ad7081ac [CMake] Add missing CheckCSourceCompiles include
Fails with cmake-3.27_rc1 otherwise:
```

CMake Error at /var/tmp/portage/sys-libs/libcxxabi-17.0.0_pre20230609/work/llvm/cmake/modules/HandleLLVMOptions.cmake:821 (CHECK_C_SOURCE_COMPILES):
  Unknown CMake command "CHECK_C_SOURCE_COMPILES".
Call Stack (most recent call first):
  CMakeLists.txt:156 (include)
```

Needed for CHECK_C_SOURCE_COMPILES.

Bug: https://bugs.gentoo.org/908233

Reviewed By: mgorny

Differential Revision: https://reviews.llvm.org/D152622
2023-06-10 19:20:59 +01:00
Alison Zhang
ab00b10d72 [AIX] Update CMake linker flags to use large glink code
Building clang/llvm as a debug build results in TOC overflow even when
using large code model on AIX. This review updates the
llvm/cmake/modules/HandleLLVMOptions.cmake file to use large glink code
in addition to building as a large code model.

Differential Revision: https://reviews.llvm.org/D151733
2023-06-08 13:17:24 -04:00
Aiden Grossman
8df5841c25 [CMake] Add option to link LLVM/subproject executables against LLVM libc
This patch adds in CMake option LLVM_ENABLE_LLVM_LIBC which when set to
true automatically builds LLVM libc in overlay mode and links all
generated executables against the libc overlay. This is intended to
somewhat mirror the LLVM_ENABLE_LIBCXX flag.

Differential Revision: https://reviews.llvm.org/D151013
2023-06-07 07:27:53 +00:00
Sam James
ab8d4f5a12 [CMake] Quote variables where "TARGET" may be a value
In CMake, "TARGET" is a special keyword. But it's also an LLVM component, which
means downstreams may request "target" or "TARGET" from CMake. Quote such input
so "TARGET" is interpreted as a string rather than a keyword.

This is a followup to 75a0502fe0 (D150884).

Fixes Meson's test suite and an issue which manifested identically to #61436
but appears to have been a slightly different problem.

Bug: https://github.com/mesonbuild/meson/issues/11642
Bug: https://github.com/llvm/llvm-project/issues/61436

Reviewed By: tstellar

Differential Revision: https://reviews.llvm.org/D152121
2023-06-06 02:08:45 +01:00
paperchalice
0beffb8542 [CMake] Ensure CLANG_RESOURCE_DIR is respected.
re-commit of 39aa0f5c43 with missing file:
cmake/Modules/GetClangResourceDir.cmake.
2023-06-03 04:21:35 -07:00
Martin Storsjö
d072d11022 Revert "[CMake] Ensure CLANG_RESOURCE_DIR is respected."
This reverts commit 39aa0f5c43.

This is missing the new GetClangResourceDir.cmake that is being included,
so all clang builds are broken.
2023-06-03 11:47:57 +03:00
paperchalice
39aa0f5c43 [CMake] Ensure CLANG_RESOURCE_DIR is respected. 2023-06-02 23:29:44 -07:00
Petr Hosek
f3269a94e7 [BOLT][CMake] Redo the build and install targets
The existing BOLT install targets are broken on Windows becase they
don't properly handle the output extension. We cannot use the existing
LLVM macros since those make assumptions that don't hold for BOLT. This
change instead implements custom macros following the approach used by
Clang and LLD.

Differential Revision: https://reviews.llvm.org/D151595
2023-06-01 14:48:01 +00:00
Petr Hosek
1d6a2c5357 Revert "[BOLT][CMake] Redo the build and install targets"
This reverts commit f99a7d3e38 since it
broke the bolt-aarch64-ubuntu-clang-shared bot.
2023-06-01 08:03:50 +00:00
Petr Hosek
f99a7d3e38 [BOLT][CMake] Redo the build and install targets
The existing BOLT install targets are broken on Windows becase they
don't properly handle the output extension. We cannot use the existing
LLVM macros since those make assumptions that don't hold for BOLT. This
change instead implements custom macros following the approach used by
Clang and LLD.

Differential Revision: https://reviews.llvm.org/D151595
2023-06-01 06:01:39 +00:00
Marcelo Juchem
75a0502fe0
[CMake] Set compatibility policy for lists in LLVM-Config.cmake.
Fixes "dependent projects fail to build with cmake 3.25 and llvm 16-rc4".

When building [latest `iovisor/bcc`](1ea0390725), `cmake` complains about a change in the behavior of operator `IN_LIST`:
```console
CMake Warning (dev) at /usr/local/lib/cmake/llvm/LLVM-Config.cmake:230 (if):
  Policy CMP0057 is not set: Support new IN_LIST if() operator.  Run "cmake
  --help-policy CMP0057" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  IN_LIST will be interpreted as an operator when the policy is set to NEW.
  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  cmake/clang_libs.cmake:32 (llvm_map_components_to_libnames)
  src/cc/CMakeLists.txt:132 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at /usr/local/lib/cmake/llvm/LLVM-Config.cmake:230 (if):
  if given arguments:

    "engine" "IN_LIST" "link_components"

  Unknown arguments specified
Call Stack (most recent call first):
  cmake/clang_libs.cmake:32 (llvm_map_components_to_libnames)
  src/cc/CMakeLists.txt:132 (include)
```

This patch addresses this issue by setting the aforementioned policy in `LLVM-Config.cmake`.

Reviewed By: mgorny, thesamesam

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

Closes: https://github.com/llvm/llvm-project/issues/61436
2023-05-22 20:06:40 +01:00
Igor Kudrin
f649599ea9 [CMake] Use LLVM own tools in extract_symbols.py
As for now, 'extract_symbols.py' can use several tools to extract
symbols from object files and libraries and to guess if the target is
32-bit Windows. The tools are being found via PATH, so in most cases,
they are just system tools. This approach has a number of limitations,
in particular:

* System tools may not be able to handle the target format in case of
  cross-platform builds,
* They cannot read symbols from LLVM bitcode files, so the staged LTO
  build with plugins is not supported,
* The auto-selected tools may be suboptimal (see D113557),
* Support for multiple tools for a single task increases the complexity
  of the script code.

The patch proposes using LLVM's own tools to solve these issues.
Specifically, 'llvm-readobj' detects the target platform, and 'llvm-nm'
reads symbols from all supported formats, including bitcode files. The
tools can be built in Release mode for the host platform or overridden
using CMake settings 'LLVM_READOBJ' and 'LLVM_NM' respectively. The
implementation also supports using precompiled tools via
'LLVM_NATIVE_TOOL_DIR'.

Differential Revision: https://reviews.llvm.org/D149119
2023-05-15 16:20:19 -07:00
Xi Ruoyao
47f5c54f99
[cmake] Disable GCC lifetime DSE
LLVM data structures like llvm::User and llvm::MDNode rely on
the value of object storage persisting beyond the lifetime of the
object (#24952).  This is not standard compliant and causes a runtime
crash if LLVM is built with GCC and LTO enabled (#57740).  Until
these issues are fixed, we need to disable dead store eliminations
eliminations based on object lifetime.

The previous test issues are fixed by 626849c71e.

Bug: https://github.com/llvm/llvm-project/issues/24952
Bug: https://github.com/llvm/llvm-project/issues/57740
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106943

Reviewed By: MaskRay, thesamesam, nikic

Differential Revision: https://reviews.llvm.org/D150505
2023-05-15 04:34:51 +01:00
Sam James
9400c64593
Revert "[cmake] Disable GCC lifetime DSE"
This reverts commit ce990b5426.

This breaks some build bots - specifically when using GCC to build LLVM and
then -fno-lifetime-dse ends up passed to Clang in some tests like at
https://lab.llvm.org/buildbot/#/builders/139/builds/40594.

Bug: https://github.com/llvm/llvm-project/issues/24952
Bug: https://github.com/llvm/llvm-project/issues/57740

Differential Revision: https://reviews.llvm.org/D150505
2023-05-14 07:37:59 +01:00
Xi Ruoyao
ce990b5426 [cmake] Disable GCC lifetime DSE
LLVM data structures like llvm::User and llvm::MDNode rely on
the value of object storage persisting beyond the lifetime of the
object (#24952).  This is not standard compliant and causes a runtime
crash if LLVM is built with GCC and LTO enabled (#57740).  Until
these issues are fixed, we need to disable dead store eliminations
eliminations based on object lifetime.

Bug: https://github.com/llvm/llvm-project/issues/24952
Bug: https://github.com/llvm/llvm-project/issues/57740
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106943

(This was originally committed as 94f7c961c7 but
I reverted it in b974991f4c4457a2104b648d9797a0ed438ecc9 to fix authorship.)

Reviewed By: MaskRay, thesamesam, nikic

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

Signed-off-by: Sam James <sam@gentoo.org>
2023-05-14 03:46:00 +01:00
Sam James
bb974991f4
Revert "[cmake] Disable GCC lifetime DSE" (to fix authorship)
This reverts commit 94f7c961c7.

Differential Revision: https://reviews.llvm.org/D150505
2023-05-14 03:42:27 +01:00