Commit Graph

1824 Commits

Author SHA1 Message Date
Petr Hosek
c20811b659
[libc] Fix libc-hdrgen crosscompiling (#78227)
The support introduced in 675702f356b0c3a540fa2e8af4192f7d658b2988 is
not working correctly in all scenarios. Instead of setup_host_tool
function, we can use the existing targets introduced by add_tablegen
macro.
2024-01-16 07:39:06 -06:00
Petr Hosek
b348126b21
[libc] Build native libc-hdrgen when crosscompiling (#77848)
When crosscompiling tools for a different architecture, we need to build
native libc-hdrgen which can be achieved using the existing CMake
support for crosscompiling tablegen tools.
2024-01-12 11:36:01 -08:00
Corentin Jabot
4d467215f1 [Clang] Revert inintentional changes to cmake committed in 33e5db6e0 2024-01-12 10:59:46 +01:00
Alexandre Ganea
3c6f47d6b8
[llvm-driver] Fix usage of InitLLVM on Windows (#76306)
Previously, some tools such as `clang` or `lld` which require strict
order for certain command-line options, such as `clang -cc1` or `lld
-flavor`, would not longer work on Windows, when these tools were linked
as part of `llvm-driver`. This was caused by `InitLLVM` which was part
of the `*_main()` function of these tools, which in turn calls
`windows::GetCommandLineArguments`. That function completly replaces
argc/argv by new UTF-8 contents, so any ajustements to argc/argv made by
`llvm-driver` prior to calling these tools was reset.

`InitLLVM` is now called by the `llvm-driver`. Any tool that
participates in (or is part of) the `llvm-driver` doesn't call
`InitLLVM` anymore.
2024-01-11 19:08:28 -05:00
Corentin Jabot
33e5db6e04 [clang] Improve colors in status tracking web pages.
Use a consistent, more pastel color for unknown status
in papers and issues tracking pages
2024-01-11 10:21:51 +01:00
Brad Smith
49c35f69ac
[CMake] Add support for building on illumos (#74930)
illumos has an older version of the Solaris linker that does not
support the GNU version script compat nor version scripts and does
not support -Bsymbolic-functions. Treat illumos linker separately.

The libclang/CMakeLists part lifted from NetBSD's pkgsrc.

Build tested on Solaris 11.4 and OpenIndiana 2023.10.

/usr/bin/ld --version

ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.3260

ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.1790 (illumos)
2024-01-08 23:28:04 -05:00
Muhammad Omair Javaid
a24c58140f Revert "[mlir] Consider mlir-linalg-ods-gen as a tablegen tool in build (#75093)"
This reverts commit 9191ac0bdb.

Breaks build on following buildbot:
https://lab.llvm.org/buildbot/#/builders/177/builds/27432
2024-01-04 02:01:16 +05:00
Michael Holman
9191ac0bdb
[mlir] Consider mlir-linalg-ods-gen as a tablegen tool in build (#75093)
There is a bit of an issue with how `mlir-linalg-ods-yaml-gen` is
classified in the MLIR build. Due to it being a tool, it is excluded
from the install when using `-DLLVM_BUILD_TOOLS=OFF`. However, it is a
necessary component of the build, so it can cause build issues with
users of the installed LLVM, and so I think it should not be excluded.

It is a tablegen-like tool, so my solution is to reclassify it that way
in the build.
2024-01-02 12:18:21 -08:00
Dimitry Andric
aad5c2f887
[cmake] Honor CMAKE_VERBOSE_MAKEFILE when building external projects (#75749)
When the top-level CMake invocation has `CMAKE_VERBOSE_MAKEFILE=ON`,
indicating the user wants to have verbose builds (i.e. all executed
commands explicitly echoed), some of the subprojects and runtimes (such
as compiler-rt, libcxx, etc) do not build in verbose mode. For example,
with Ninja:

```
[ 99% 6252/6308] cd /build/runtimes/builtins-bins && /usr/local/bin/cmake --build .
[  0% 6/308] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvti2.c.o
[  0% 7/308] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvdi2.c.o
[  0% 8/308] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvsi2.c.o
...
```

This is because `llvm_ExternalProject_Add()` and `add_custom_libcxx()`
use CMake's `ExternalProject_Add()` function to configure such
subproject builds, and do not pass through the `CMAKE_VERBOSE_MAKEFILE`
setting.

Similar to what is done in `clang/CMakeLists.txt`, add
`-DCMAKE_VERBOSE_MAKEFILE=ON` to the `ExternalProject_Add()` invocations
in `llvm_ExternalProject_Add()` and `add_custom_libcxx()`, whenever the
top-level CMake invocation had `CMAKE_VERBOSE_MAKEFILE` turned on.
2023-12-17 22:43:34 +01:00
Duo Wang
4a4804bf70
[CMake][Windows] Turn off lld string tail merging when ASAN is turned on (#74207)
lld string tail merging interacts badly with ASAN on Windows, as is
reported in https://github.com/llvm/llvm-project/issues/62078.
A similar error was found when building LLVM with
`-DLLVM_USE_SANITIZER=Address`:
```console
[2/2] Building GenVT.inc...
FAILED: include/llvm/CodeGen/GenVT.inc C:/Dev/llvm-project/Build_asan/include/llvm/CodeGen/GenVT.inc
cmd.exe /C "cd /D C:\Dev\llvm-project\Build_asan && C:\Dev\llvm-project\Build_asan\bin\llvm-min-tblgen.exe -gen-vt -I C:/Dev/llvm-project/llvm/include/llvm/CodeGen -IC:/Dev/llvm-project/Build_asan/include -IC:/Dev/llvm-project/llvm/include C:/Dev/llvm-project/llvm/include/llvm/CodeGen/ValueTypes.td --write-if-changed -o include/llvm/CodeGen/GenVT.inc -d include/llvm/CodeGen/GenVT.inc.d"       
=================================================================
==31944==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7ff6cff80d20 at pc 0x7ff6cfcc7378 bp 0x00e8bcb8e990 sp 0x00e8bcb8e9d8
READ of size 1 at 0x7ff6cff80d20 thread T0
    #0 0x7ff6cfcc7377 in strlen (C:\Dev\llvm-project\Build_asan\bin\llvm-min-tblgen.exe+0x1400a7377)
    #1 0x7ff6cfde50c2 in operator delete(void *, unsigned __int64) (C:\Dev\llvm-project\Build_asan\bin\llvm-min-tblgen.exe+0x1401c50c2)
    #2 0x7ff6cfdd75ef in operator delete(void *, unsigned __int64) (C:\Dev\llvm-project\Build_asan\bin\llvm-min-tblgen.exe+0x1401b75ef)
    #3 0x7ff6cfde59f9 in operator delete(void *, unsigned __int64) (C:\Dev\llvm-project\Build_asan\bin\llvm-min-tblgen.exe+0x1401c59f9)
    #4 0x7ff6cff03f6c in operator delete(void *, unsigned __int64) (C:\Dev\llvm-project\Build_asan\bin\llvm-min-tblgen.exe+0x1402e3f6c)
    #5 0x7ff6cfefbcbc in operator delete(void *, unsigned __int64) (C:\Dev\llvm-project\Build_asan\bin\llvm-min-tblgen.exe+0x1402dbcbc)
    #6 0x7ffb7f247343  (C:\WINDOWS\System32\KERNEL32.DLL+0x180017343)
    #7 0x7ffb800826b0  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x1800526b0)

0x7ff6cff80d20 is located 31 bytes after global variable '"#error \"ArgKind is not defined\"\n"...' defined in 'C:\Dev\llvm-project\llvm\utils\TableGen\IntrinsicEmitter.cpp' (0x7ff6cff80ce0) of size 33
  '"#error \"ArgKind is not defined\"\n"...' is ascii string '#error "ArgKind is not defined"
'
0x7ff6cff80d20 is located 0 bytes inside of global variable '""' defined in 'C:\Dev\llvm-project\llvm\utils\TableGen\IntrinsicEmitter.cpp' (0x7ff6cff80d20) of size 1
  '""' is ascii string ''
SUMMARY: AddressSanitizer: global-buffer-overflow (C:\Dev\llvm-project\Build_asan\bin\llvm-min-tblgen.exe+0x1400a7377) in strlen
Shadow bytes around the buggy address:
  0x7ff6cff80a80: 01 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 01 f9 f9 f9
  0x7ff6cff80b00: f9 f9 f9 f9 00 00 00 00 00 00 00 00 01 f9 f9 f9
  0x7ff6cff80b80: f9 f9 f9 f9 00 00 00 00 01 f9 f9 f9 f9 f9 f9 f9
  0x7ff6cff80c00: 00 00 00 00 01 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x7ff6cff80c80: 00 00 00 00 01 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
=>0x7ff6cff80d00: 01 f9 f9 f9[f9]f9 f9 f9 00 00 00 00 00 00 00 00
  0x7ff6cff80d80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ff6cff80e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ff6cff80e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ff6cff80f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ff6cff80f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==31944==ABORTING
```
This is reproducible with the 17.0.3 release:
```console
$ clang-cl --version
clang version 17.0.3
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
$ cmake -S llvm -B Build -G Ninja -DLLVM_USE_SANITIZER=Address -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_BUILD_TYPE=Release
$ cd Build
$ ninja all
```
2023-12-07 11:44:24 +00:00
Paul Kirth
d22944d1cc
[cmake] Fix relative paths in prefix map (#74132)
When building debug version of LLVM with
`LLVM_USE_RELATIVE_PATHS_IN_FILES=On` would cause source paths to be
incorrect, and be prefixed by the build directory. This lead to source
locations like the following: `../build/llvm/...`. Such paths do not
exist, and existing debuggers can't adjust their search location because
of the incorrect prefix. Ultimately, this happened because the relative
path creation goes in the wrong direction, from source-dir to build-dir
instead of from build-dir to source-dir.

This patch swaps the directionality of the relative paths so that they
get a proper prefix from the build directory. Given a build dir at
`/build` and a project directory at `/llvm-project`, we get source
locations like: `../llvm-project/llvm/lib/Transforms/...`, which a
debugger can resolve once pointed to the correct project directory.
2023-12-01 14:51:21 -08:00
Hans
54984f58f5
Add llvm-mca to the list of toolchain tools (#72840)
It's a user-facing tool, so including it makes sense.

Fixes https://github.com/llvm/llvm-project/issues/72754
2023-11-20 13:29:19 +01:00
Matheus Izvekov
a67b85ef63
Add llvm-dlltool to the toolchain list (#72563)
This adds dlltool to the list of tools which don't get excluded from
installation when LLVM_INSTALL_TOOLCHAIN_ONLY is set.

The most important effect here is that this tool will now be included in
the official Windows release.

While llvm-lib reuses the dlltool machinary internally and has many of
the same capabilities, it does not expose the functionality controller
by the '-k' flag, which is currently the only way to create import
libraries for i386 with stdcall symbols from a module definition alone.

We avoid changing llvm-lib tool, since it is designed to emulate LIB.EXE
from MSVC toolchain, and as this functionality is not supported there,
we would have had to introduce an LLVM extension flag in order to
support it.

See https://reviews.llvm.org/D36548 for reference on rationale for
dlltool '-k' flag.
2023-11-17 11:39:20 +01:00
David Spickett
c4afeccdd2
[llvm][CMake][TableGen] Add all TableGen files to tablegen_compile_commands.yml (#71686)
This file is a list of files and their required include dirs, used by
the TableGen LSP server
(https://mlir.llvm.org/docs/Tools/MLIRLSP/#tablegen-lsp-language-server--tblgen-lsp-server).

Initialy this only included MLIR TableGen files, so I've expanded that
by moving it into llvm so all projects that use the llvm `tablegen`
function will be added to the file.

You could already do some things in llvm TableGen files without this,
but were limited with files that don't include their dependencies using
`include`, only with command line arguments.

Once those are in the yml file, the language server sees all that and go
to definition etc. all works.
2023-11-16 09:26:26 +00:00
Konstantin Varlamov
4a9c71b8c2
[libc++][hardening] Fix references to old names for hardening modes (#71743)
This should fix some builds broken by
https://github.com/llvm/llvm-project/pull/70575
2023-11-08 13:16:01 -10:00
Jeremy Kun
ebc3302725
Improve error message for cmake failure (#71404)
I ran into this error as a newbie, was educated
[here](https://discord.com/channels/636084430946959380/642426447167881246/1171016269387018310).
Updating the error message to be more descriptive about the problem and
my options.
2023-11-07 09:54:04 +01:00
Will Hawkins
4aae5387a8
[llvm][CMake] Respect LIBCXX_HARDENING_MODE on command-line (#68541)
When the user specifies `LIBCXX_HARDENING_MODE` on the command line in a
bootstrapping build, it should override the setting implied by
`LLVM_ENABLE_ASSERTIONS`.
2023-10-20 23:13:33 -07:00
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