Commit Graph

359 Commits

Author SHA1 Message Date
Stella Laurenzo 38151a08c2 Reapply "[cmake] Prefix gtest and gtest_main with "llvm_"."
This reverts commit 7cdda6b8ce.

Differential Revision: https://reviews.llvm.org/D121020
2022-03-04 13:45:43 -08:00
Stella Laurenzo 7cdda6b8ce Revert "[cmake] Prefix gtest and gtest_main with "llvm_"."
lldb buildbot failure. will investigate and roll forward.

This reverts commit 9f37775472.
2022-03-02 11:13:46 -08:00
Stella Laurenzo 9f37775472 [cmake] Prefix gtest and gtest_main with "llvm_".
The upstream project ships CMake rules for building vanilla gtest/gmock which conflict with the names chosen by LLVM. Since LLVM's build rules here are quite specific to LLVM, prefixing them to avoid collision is the right thing (i.e. there does not appear to be a path to letting someone *replace* LLVM's googletest with one they bring, so co-existence should be the goal).

This allows LLVM to be included with testing enabled within projects that themselves have a dependency on an official gtest release.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D120789
2022-03-02 10:53:32 -08:00
Petr Hosek 48a38954c9 [CMake] Use generator expression to get in-tree libc++ path
When using the in-tree libc++, we should be using the full path to
ensure that we're using the right library and not accidentally pick up
the system library.

Differential Revision: https://reviews.llvm.org/D118200
2022-01-26 14:12:48 -08:00
Brian Cain 1e68c79987 Reapply [xray] add support for hexagon
Adds x-ray support for hexagon to llvm codegen, clang driver,
compiler-rt libs.

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

Reapplying this after 543a9ad7c4,
which fixes the leak introduced there.
2021-12-10 05:32:28 -08:00
Brian Cain ab28cb1c5c Revert "[xray] add support for hexagon"
This reverts commit 543a9ad7c4.
2021-12-09 07:30:40 -08:00
Brian Cain 543a9ad7c4 [xray] add support for hexagon
Adds x-ray support for hexagon to llvm codegen, clang driver,
compiler-rt libs.

Differential Revision: https://reviews.llvm.org/D113638
2021-12-09 05:47:53 -08:00
Dimitry Andric bbba9d8c1b [XRay] fix more -Wformat warnings
Building xray with recent clang on a 64-bit system results in a number
of -Wformat warnings:

    compiler-rt/lib/xray/xray_allocator.h:70:11: warning: format specifies type 'int' but the argument has type '__sanitizer::uptr' (aka 'unsigned long') [-Wformat]
              RoundedSize, B);
              ^~~~~~~~~~~
    compiler-rt/lib/xray/xray_allocator.h:119:11: warning: format specifies type 'int' but the argument has type '__sanitizer::uptr' (aka 'unsigned long') [-Wformat]
              RoundedSize, B);
              ^~~~~~~~~~~

Since `__sanitizer::uptr` has the same size as `size_t`, these can be
fixed by using the printf specifier `%zu`.

    compiler-rt/lib/xray/xray_basic_logging.cpp:348:46: warning: format specifies type 'int' but the argument has type '__sanitizer::tid_t' (aka 'unsigned long long') [-Wformat]
          Report("Cleaned up log for TID: %d\n", GetTid());
                                          ~~     ^~~~~~~~
                                          %llu
    compiler-rt/lib/xray/xray_basic_logging.cpp:353:62: warning: format specifies type 'int' but the argument has type '__sanitizer::tid_t' (aka 'unsigned long long') [-Wformat]
          Report("Skipping buffer for TID: %d; Offset = %llu\n", GetTid(),
                                           ~~                    ^~~~~~~~
                                           %llu

Since `__sanitizer::tid_t` is effectively declared as `unsigned long
long`, these can be fixed by using the printf specifier `%llu`.

    compiler-rt/lib/xray/xray_basic_logging.cpp:354:14: warning: format specifies type 'unsigned long long' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
                 TLD.BufferOffset);
                 ^~~~~~~~~~~~~~~~

Since `BufferOffset` is declared as `size_t`, this one can be fixed by
using `%zu` as a printf specifier.

    compiler-rt/lib/xray/xray_interface.cpp:172:50: warning: format specifies type 'int' but the argument has type 'uint64_t' (aka 'unsigned long') [-Wformat]
        Report("Unsupported sled kind '%d' @%04x\n", Sled.Address, int(Sled.Kind));
                                       ~~            ^~~~~~~~~~~~
                                       %lu

Since ``xray::SledEntry::Address` is declared as `uint64_t`, this one
can be fixed by using `PRIu64`, and adding `<cinttypes>`.

    compiler-rt/lib/xray/xray_interface.cpp:308:62: warning: format specifies type 'long long' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
        Report("System page size is not a power of two: %lld\n", PageSize);
                                                        ~~~~     ^~~~~~~~
                                                        %zu
    compiler-rt/lib/xray/xray_interface.cpp:359:64: warning: format specifies type 'long long' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
        Report("Provided page size is not a power of two: %lld\n", PageSize);
                                                          ~~~~     ^~~~~~~~
                                                          %zu

Since `PageSize` is declared as `size_t`, these can be fixed by using
`%zu` as a printf specifier.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D114469
2021-12-04 20:01:20 +01:00
Martin Liska 13a442ca49 Enable -Wformat-pedantic and fix fallout.
Differential Revision: https://reviews.llvm.org/D113172
2021-11-05 13:12:35 +01:00
Kazuaki Ishizaki a1e7e401d2 [compiler-rt] NFC: Fix trivial typo
Reviewed By: xgupta

Differential Revision: https://reviews.llvm.org/D77457
2021-09-04 14:12:58 +05:30
Dmitry Vyukov 123c58ea26 sanitizer_common: enable format string checking
Enable -Wformat in sanitizer_common now that it's
cleaned up from existing warnings.
But disable it in all sanitizers for now since
they are not cleaned up yet, but inherit sanitizer_common CFLAGS.

Depends on D107980.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107981
2021-08-13 13:44:52 +02:00
Christopher Di Bella 873e8b96b1 [compiler-rt][iwyu] explicitly includes `<new>` in xray_utils.cpp
Compiling compiler-rt with Clang modules and libc++ revealed that the
global `operator new` is being called without including `<new>`.

Differential Revision: https://reviews.llvm.org/D105401
2021-07-05 21:46:42 +00:00
Elia Geretto b46c89892f [XRay][compiler-rt][x86_64] Fix CFI directives in assembly trampolines
This patch modifies the x86_64 XRay trampolines to fix the CFI information
generated by the assembler. One of the main issues in correcting the CFI
directives is the `ALIGNED_CALL_RAX` macro, which makes the CFA dependent on
the alignment of the stack. However, this macro is not really necessary because
some additional assumptions can be made on the alignment of the stack when the
trampolines are called. The code has been written as if the stack is guaranteed
to be 8-bytes aligned; however, it is instead guaranteed to be misaligned by 8
bytes with respect to a 16-bytes alignment. For this reason, always moving the
stack pointer by 8 bytes is sufficient to restore the appropriate alignment.

Trampolines that are called from within a function as a result of the builtins
`__xray_typedevent` and `__xray_customevent` are necessarely called with the
stack properly aligned so, in this case too, `ALIGNED_CALL_RAX` can be
eliminated.

Fixes https://bugs.llvm.org/show_bug.cgi?id=49060

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D96785
2021-03-06 10:38:27 -08:00
Petr Hosek 46a3f4ae27 Revert "[XRay][x86_64] Fix CFI directives in assembly trampolines"
This reverts commit 9ee61cf3f6 since
it's failing to compile on Darwin.
2021-03-04 01:03:04 -08:00
Elia Geretto 9ee61cf3f6 [XRay][x86_64] Fix CFI directives in assembly trampolines
This patch modifies the x86_64 XRay trampolines to fix the CFI information
generated by the assembler. One of the main issues in correcting the CFI
directives is the `ALIGNED_CALL_RAX` macro, which makes the CFA dependent on
the alignment of the stack. However, this macro is not really necessary because
some additional assumptions can be made on the alignment of the stack when the
trampolines are called. The code has been written as if the stack is guaranteed
to be 8-bytes aligned; however, it is instead guaranteed to be misaligned by 8
bytes with respect to a 16-bytes alignment. For this reason, always moving the
stack pointer by 8 bytes is sufficient to restore the appropriate alignment.

Trampolines that are called from within a function as a result of the builtins
`__xray_typedevent` and `__xray_customevent` are necessarely called with the
stack properly aligned so, in this case too, `ALIGNED_CALL_RAX` can be
eliminated.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=49060

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D96785
2021-03-03 10:01:28 -08:00
Todd Lipcon 5dd29d9922
Fix xray fdr mode to allow multiple flushes
Reviewed By: dberris

Differential Revision: https://reviews.llvm.org/D96382
2021-02-10 12:57:24 +11:00
Raul Tambre 55f07a3400 [XRay] Remove unnecessary <x86intrin.h> include
It hasn't been necessary since commit 4d4ed0e288 (D43278).

Reviewed By: dberris

Differential Revision: https://reviews.llvm.org/D93196
2020-12-14 12:36:35 +02:00
Petr Hosek 11efd002b1 [CMake] Avoid accidental C++ standard library dependency in sanitizers
While sanitizers don't use C++ standard library, we could still end
up accidentally including or linking it just by the virtue of using
the C++ compiler. Pass -nostdinc++ and -nostdlib++ to avoid these
accidental dependencies.

Reviewed By: smeenai, vitalybuka

Differential Revision: https://reviews.llvm.org/D88922
2020-10-31 02:37:38 -07:00
Petr Hosek 59d5031591 [CMake] Add -fno-rtti into tsan unittests
And some other NFC parts of D88922
2020-10-30 20:03:38 -07:00
David Carlier 53065c543f [Sanitizers] Remove OpenBSD support (new attempt)
- Fixing VS compiler and other cases settings this time.

Reviewers: dmajor, hans

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D89759
2020-10-20 11:16:09 +01:00
Evgenii Stepanov 7ecd60bb70 Revert "[Sanitizers] Remove OpenBSD support" + 1
Revert "Fix compiler-rt build on Windows after D89640"

This reverts commit a7acee89d6.
This reverts commit d09b08919c.

Reason: breaks Linux / x86_64 build.
2020-10-19 16:11:21 -07:00
David Carlier d09b08919c [Sanitizers] Remove OpenBSD support
- Removing unused and unusable code.

Reviewers: krytarowski

Reviewed By: krytarowski

Differential Revision: https://reviews.llvm.org/D89640
2020-10-18 14:57:07 +01:00
Petr Hosek 220de1f32a Revert "[CMake] Avoid accidental C++ standard library dependency in sanitizers"
This reverts commit 287c318690 which broke
sanitizer tests that use C++ standard library.
2020-10-14 18:44:09 -07:00
Petr Hosek 287c318690 [CMake] Avoid accidental C++ standard library dependency in sanitizers
While sanitizers don't use C++ standard library, we could still end
up accidentally including or linking it just by the virtue of using
the C++ compiler. Pass -nostdinc++ and -nostdlib++ to avoid these
accidental dependencies.

Differential Revision: https://reviews.llvm.org/D88922
2020-10-14 18:26:56 -07:00
Fangrui Song d06485685d [XRay] Change mips to use version 2 sled (PC-relative address)
Follow-up to D78590. All targets use PC-relative addresses now.

Reviewed By: atanasyan, dberris

Differential Revision: https://reviews.llvm.org/D87977
2020-09-20 17:59:57 -07:00
Petr Hosek 3c7bfbd683 [CMake] Use find_library for ncurses
Currently it is hard to avoid having LLVM link to the system install of
ncurses, since it uses check_library_exists to find e.g. libtinfo and
not find_library or find_package.

With this change the ncurses lib is found with find_library, which also
considers CMAKE_PREFIX_PATH. This solves an issue for the spack package
manager, where we want to use the zlib installed by spack, and spack
provides the CMAKE_PREFIX_PATH for it.

This is a similar change as https://reviews.llvm.org/D79219, which just
landed in master.

Patch By: haampie

Differential Revision: https://reviews.llvm.org/D85820
2020-08-31 20:06:21 -07:00
Harmen Stoppels cdcb9ab10e Revert "Use find_library for ncurses"
The introduction of find_library for ncurses caused more issues than it solved problems. The current open issue is it makes the static build of LLVM fail. It is better to revert for now, and get back to it later.

Revert "[CMake] Fix an issue where get_system_libname creates an empty regex capture on windows"
This reverts commit 1ed1e16ab8.

Revert "Fix msan build"
This reverts commit 34fe9613dd.

Revert "[CMake] Always mark terminfo as unavailable on Windows"
This reverts commit 76bf26236f.

Revert "[CMake] Fix OCaml build failure because of absolute path in system libs"
This reverts commit 8e4acb82f7.

Revert "[CMake] Don't look for terminfo libs when LLVM_ENABLE_TERMINFO=OFF"
This reverts commit 495f91fd33.

Revert "Use find_library for ncurses"
This reverts commit a52173a3e5.

Differential revision: https://reviews.llvm.org/D86521
2020-08-27 17:57:26 -07:00
Harmen Stoppels a52173a3e5 Use find_library for ncurses
Currently it is hard to avoid having LLVM link to the system install of
ncurses, since it uses check_library_exists to find e.g. libtinfo and
not find_library or find_package.

With this change the ncurses lib is found with find_library, which also
considers CMAKE_PREFIX_PATH. This solves an issue for the spack package
manager, where we want to use the zlib installed by spack, and spack
provides the CMAKE_PREFIX_PATH for it.

This is a similar change as https://reviews.llvm.org/D79219, which just
landed in master.

Differential revision: https://reviews.llvm.org/D85820
2020-08-17 19:52:52 -07:00
Ian Levesque 7c7c8e0da4 [xray] Option to omit the function index
Summary:
Add a flag to omit the xray_fn_idx to cut size overhead and relocations
roughly in half at the cost of reduced performance for single function
patching.  Minor additions to compiler-rt support per-function patching
without the index.

Reviewers: dberris, MaskRay, johnislarry

Subscribers: hiraditya, arphaman, cfe-commits, #sanitizers, llvm-commits

Tags: #clang, #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D81995
2020-06-17 13:49:01 -04:00
Ian Levesque 4b9bef7e6c [xray] Preserve x8 in trampoline on AArch64
Summary: Fixes an ABI violation in the trampoline code for AArch64 that causes the indirect result register to get overwritten if the XRay handler function is complex enough to use it.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: kristof.beyls, danielkiss, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78596
2020-04-27 14:57:26 -04:00
Fangrui Song 10bc12588d [XRay] Change Sled.Function to PC-relative for sled version 2 and make llvm-xray support sled version 2 addresses
Follow-up of D78082 and D78590.

Otherwise, because xray_instr_map is now read-only, the absolute
relocation used for Sled.Function will cause a text relocation.
2020-04-24 14:41:56 -07:00
Fangrui Song 25e22613df [XRay] Change ARM/AArch64/powerpc64le to use version 2 sled (PC-relative address)
Follow-up of D78082 (x86-64).

This change avoids dynamic relocations in `xray_instr_map` for ARM/AArch64/powerpc64le.

MIPS64 cannot use 64-bit PC-relative addresses because R_MIPS_PC64 is not defined.
Because MIPS32 shares the same code, for simplicity, we don't use PC-relative addresses for MIPS32 as well.

Tested on AArch64 Linux and ppc64le Linux.

Reviewed By: ianlevesque

Differential Revision: https://reviews.llvm.org/D78590
2020-04-24 08:35:43 -07:00
Ian Levesque 5081468a66 [xray] Avoid text relocations in trampolines for ARM/AArch64
Summary: Switch to pc-relative lookup of the xray handler function to avoid text relocations.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: kristof.beyls, danielkiss, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78595
2020-04-21 23:21:02 -04:00
Ian Levesque eeaabe64e3 [xray] Use hidden symbol visibility for xray trampolines
Summary: We load multiple copies of the trampolines into memory when instrumenting DSOs.  Hidden visibility prevents conflicts in this scenario.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78593
2020-04-21 23:19:52 -04:00
Fangrui Song 5771c98562 [XRay] Change xray_instr_map sled addresses from absolute to PC relative for x86-64
xray_instr_map contains absolute addresses of sleds, which are relocated
by `R_*_RELATIVE` when linked in -pie or -shared mode.

By making these addresses relative to PC, we can avoid the dynamic
relocations and remove the SHF_WRITE flag from xray_instr_map.  We can
thus save VM pages containg xray_instr_map (because they are not
modified).

This patch changes x86-64 and bumps the sled version to 2. Subsequent
changes will change powerpc64le and AArch64.

Reviewed By: dberris, ianlevesque

Differential Revision: https://reviews.llvm.org/D78082
2020-04-21 09:36:09 -07:00
Fangrui Song 4113e388c8 [XRay] Define uint64_t Address = Sled.Address; NFC
This makes it easy to change the address stored in a sled from an
absolute address to a PC-relative address.
2020-04-13 22:44:12 -07:00
Petr Hosek 4e6c778eca [XRay] Record the XRay data size as a property of the VMO
While the VMO size is always page aligned, we can record the content
size as a property and then use this metadata when writing the data to
a file.

Differential Revision: https://reviews.llvm.org/D76462
2020-03-19 19:01:05 -07:00
Jonas Devlieghere 8903433bb2 Re-land "[compiler-rt] Migrate llvm::make_unique to std::make_unique"
With the compiler-rt check for C++14 updated in r368960, this should now
be fine to land.

llvm-svn: 369009
2019-08-15 14:57:44 +00:00
Jonas Devlieghere d65f37dbcc Revert "[compiler-rt] Migrate llvm::make_unique to std::make_unique"
The X-ray unit tests in compiler-rt are overriding the C++ version by
explicitly passing -std=c++11 in the compiler invocation. This poses a
problem as these tests are including LLVM headers that can now use C++14
features. I'm temporarily reverting this as I investigate the correct
solution.

llvm-svn: 368952
2019-08-15 03:02:57 +00:00
Jonas Devlieghere 5edd6843fa [compiler-rt] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

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

llvm-svn: 368946
2019-08-15 00:06:49 +00:00
Puyan Lotfi 1b3718e609 [compiler-rt] Reverting r367962 due to Fuchsia bot build-breakage.
llvm-svn: 367990
2019-08-06 08:08:07 +00:00
Puyan Lotfi c9d90d5002 [compiler-rt] Appending COMPILER_RT_LIBCXX_PATH -isystem include for xray (3)
Third landing attempt: Added "if (HAVE_LIBCXX)" to keep Green Dragon green.

Haven't found a better way to pass the libcxx include path for building
compiler-rt with libcxx; this seems to be missing only for xray.

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

llvm-svn: 367962
2019-08-06 00:34:34 +00:00
Nico Weber bc0d697db9 compiler-rt: Rename .cc file in lib/xray/tests/unit to .cpp
Like r367463, but for xray/texts/unit.

llvm-svn: 367550
2019-08-01 12:35:27 +00:00
Nico Weber b301860321 compiler-rt: Rename .cc file in lib/xray to .cpp
Like r367463, but for xray.

llvm-svn: 367546
2019-08-01 12:30:58 +00:00
Francis Visoiu Mistrih fb3c53af34 Revert "[compiler-rt] Appending COMPILER_RT_LIBCXX_PATH -isystem include for xray (2)"
This reverts commit r367250. It's failing on green dragon:
http://lab.llvm.org:8080/green/job/clang-stage1-RA/482/console.

llvm-svn: 367265
2019-07-29 22:08:12 +00:00
Puyan Lotfi a9c59b2873 [compiler-rt] Appending COMPILER_RT_LIBCXX_PATH -isystem include for xray (2)
Second attempt.

Haven't found a better way to pass the libcxx include path for building
compiler-rt with libcxx; this seems to be missing only for xray.

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

llvm-svn: 367250
2019-07-29 19:21:58 +00:00
Puyan Lotfi 5bf16ec02b [compiler-rt] Reverting r367239 (xray include path) to fix bot build breakage.
llvm-svn: 367246
2019-07-29 17:50:39 +00:00
Puyan Lotfi ba7b7f1de4 Appending COMPILER_RT_LIBCXX_PATH include path to -isystem for compiler-rt xray
Haven't found a better way to pass the libcxx include path for building
compiler-rt with libcxx; this seems to be missing only for xray.

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

llvm-svn: 367239
2019-07-29 16:46:35 +00:00
Vitaly Buka 0b1ea8cb28 Improve error message when '=' is missing in {ASAN,...}_OPTIONS.
Summary:
It's handling isses as described here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89832

Patch by Martin Liška.

Reviewers: kcc, vitalybuka

Reviewed By: vitalybuka

Subscribers: cryptoad, kubamracek

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

llvm-svn: 363480
2019-06-15 01:37:14 +00:00
Petr Hosek 156226bb70 [compiler-rt] Set the ZX_VMO_RESIZABLE option for zx_vmo_create
Currently VMO in Zircon create using the zx_vmo_create is resizable
by default, but we'll be changing this in the future, requiring an
explicit flag to make the VMO resizable.

Prepare for this change by passing ZX_VMO_RESIZABLE option to all
zx_vmo_create calls that need resizable VMO.

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

llvm-svn: 359803
2019-05-02 17:24:53 +00:00