92 Commits

Author SHA1 Message Date
Eric Wang
fcb65ad2a2
[BOLT] Fix kernel version check for THP in hugify (#129380)
BOLT --hugify does not work in kernel 6.x.

Co-authored-by: rfwang07 <wangrufeng5@huawei.com>
2025-03-04 20:38:41 -08:00
Nikita Popov
3c42a77456
[BOLT] Fix handling of LLVM_LIBDIR_SUFFIX (#122874)
This fixes a number of issues introduced in #97130 when
LLVM_LIBDIR_SUFFIX is a non-empty string. Make sure that the libdir is
always referenced as `lib${LLVM_LIBDIR_SUFFIX}`, not as just `lib` or
`${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}`.

This is the standard libdir convention for all LLVM subprojects. Using
`${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}` would result in a
duplicate suffix.
2025-01-17 09:38:00 +01:00
Tristan Ross
5909979869
[BOLT] Fix archive output directory for standalone on Mac (#100643)
CC @gulfemsavrun

Fixes a line which wasn't changed in #97130
2024-07-25 13:29:38 -07:00
Tristan Ross
abc2eae682
[BOLT] Enable standalone build (#97130)
Continue from #87196 as author did not have much time, I have taken over
working on this PR. We would like to have this so it'll be easier to
package for Nix.

Can be tested by copying cmake, bolt, third-party, and llvm directories
out into their own directory with this PR applied and then build bolt.

---------

Co-authored-by: pca006132 <john.lck40@gmail.com>
2024-07-25 08:18:14 -07:00
Heewon Cho
219ea26733
[BOLT][NFC] Remove dead initialization code (#92952)
Addressing #81441
2024-05-21 16:28:17 -07:00
spaette
1a2f83366b
[BOLT] Fix typos (#68121)
Closes https://github.com/llvm/llvm-project/issues/63097

Before merging please make sure the change to
bolt/include/bolt/Passes/StokeInfo.h is correct.

bolt/include/bolt/Passes/StokeInfo.h

```diff
  //  This Pass solves the two major problems to use the Stoke program without
- //  proting its code:
+ //  probing its code:
```

I'm still not happy about the awkward wording in this comment.

bolt/include/bolt/Passes/FixRelaxationPass.h

```
$ ed -s bolt/include/bolt/Passes/FixRelaxationPass.h <<<'9,12p'
// This file declares the FixRelaxations class, which locates instructions with
// wrong targets and fixes them. Such problems usually occures when linker
// relaxes (changes) instructions, but doesn't fix relocations types properly
// for them.
$
```


bolt/docs/doxygen.cfg.in
bolt/include/bolt/Core/BinaryContext.h
bolt/include/bolt/Core/BinaryFunction.h
bolt/include/bolt/Core/BinarySection.h
bolt/include/bolt/Core/DebugData.h
bolt/include/bolt/Core/DynoStats.h
bolt/include/bolt/Core/Exceptions.h
bolt/include/bolt/Core/MCPlusBuilder.h
bolt/include/bolt/Core/Relocation.h
bolt/include/bolt/Passes/FixRelaxationPass.h
bolt/include/bolt/Passes/InstrumentationSummary.h
bolt/include/bolt/Passes/ReorderAlgorithm.h
bolt/include/bolt/Passes/StackReachingUses.h
bolt/include/bolt/Passes/StokeInfo.h
bolt/include/bolt/Passes/TailDuplication.h
bolt/include/bolt/Profile/DataAggregator.h
bolt/include/bolt/Profile/DataReader.h
bolt/lib/Core/BinaryContext.cpp
bolt/lib/Core/BinarySection.cpp
bolt/lib/Core/DebugData.cpp
bolt/lib/Core/DynoStats.cpp
bolt/lib/Core/Relocation.cpp
bolt/lib/Passes/Instrumentation.cpp
bolt/lib/Passes/JTFootprintReduction.cpp
bolt/lib/Passes/ReorderData.cpp
bolt/lib/Passes/RetpolineInsertion.cpp
bolt/lib/Passes/ShrinkWrapping.cpp
bolt/lib/Passes/TailDuplication.cpp
bolt/lib/Rewrite/BoltDiff.cpp
bolt/lib/Rewrite/DWARFRewriter.cpp
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/lib/Utils/CommandLineOpts.cpp
bolt/runtime/instr.cpp
bolt/test/AArch64/got-ld64-relaxation.test
bolt/test/AArch64/unmarked-data.test
bolt/test/X86/Inputs/dwarf5-cu-no-debug-addr-helper.s
bolt/test/X86/Inputs/linenumber.cpp
bolt/test/X86/double-jump.test
bolt/test/X86/dwarf5-call-pc-function-null-check.test
bolt/test/X86/dwarf5-split-dwarf4-monolithic.test
bolt/test/X86/dynrelocs.s
bolt/test/X86/fallthrough-to-noop.test
bolt/test/X86/tail-duplication-cache.s
bolt/test/runtime/X86/instrumentation-ind-calls.s
2023-11-09 11:29:46 -08:00
Vladislav Khmelevsky
80c01dd626 [BOLT][runtime] Test for outline-atomics support
I'm using clang-10 to build bolt which doesn't have moutline-atomics
option and though it doesn't do it. So test compiler for supporting it
before appending to the list of cxxflags.

Differential Revision: https://reviews.llvm.org/D159521
2023-09-19 23:29:05 +04:00
Elvina Yakubova
6678f602c2 [BOLT][test] Fix cross-compilation tests after D151920
Fix tests that are failing in cross-compilation after D151920
(https://lab.llvm.org/buildbot/#/builders/221/builds/17715):

- instrumentation-ind-call, basic-instrumentation: add -mno-outline-atomics flag to runtime lib
- bolt-address-translation-internal-call, internal-call-instrument: add %cflags
- meta-merge-fdata: restrict to x86_64

Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D159094
2023-09-08 00:05:39 +03:00
Elvina Yakubova
87e9c42495 [BOLT][Instrumentation] AArch64 instrumentation support in runtime
This commit adds support for AArch64 in instrumentation runtime library,
including AArch64 system calls.
Also this commit divides syscalls into target-specific files.

Reviewed By: rafauler, yota9

Differential Revision: https://reviews.llvm.org/D151942
2023-08-24 19:34:57 +03:00
Denis Revunov
a86dd9ae60 [BOLT][Instrumentation] Fix indirect call profile in PIE
Because indirect call tables use static addresses for call sites, but pc
values recorded by runtime may be subject to ASLR in PIE, we couldn't
find indirect call descriptions by their runtime address in PIE. It
resulted in [unknown] entries in profile for all indirect calls. We need
to substract base address of .text from runtime addresses to get the
corresponding static addresses. Here we create a getter for base address
of .text and substract it's return value from recorded PC values. It
converts them to static addresses, which then may be used to find the
corresponding indirect call descriptions.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D154121
2023-08-23 23:50:31 +03:00
Denis Revunov
a799298152 [BOLT][Instrumentation] Keep profile open in WatchProcess
When a binary is instrumented with --instrumentation-sleep-time and
instrumentation-wait-forks options and lauched, the profile is
periodically written until all the forks die. The problem is that we
cannot wait for the whole process tree, and we have no way to tell when
it's safe to read the profile. Hovewer, if we keep profile open
throughout the life of the process tree, we can use fuser to determine
when writing is finished.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D154436
2023-08-23 23:50:31 +03:00
Denis Revunov
60bbddf3c1 [BOLT][Instrumentation][NFC] Define and use more syscall constants
Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D154419
2023-07-10 21:36:04 +03:00
Denis Revunov
0cc19b564d Reland "[BOLT][Instrumentation] Put Allocator itslef in shared memory by default"
The issue was caused by the absence of placement new definition. It
worked for clang and thus passed Phabricator checks, but broke when
compiled with GCC on buildbot.
Full problem description: https://reviews.llvm.org/D153771#4468239

Original patch description:
In absence of instrumentation-file-append-pid option,
global allocator uses shared pages for allocation. However, since it is a
global variable, it gets COW'd after fork if instrumentation-sleep-time
is used, or if a process forks by itself. This means it handles the same
pages to every process which causes hash table corruption. Thus, if we
want shared pages, we need to put the allocator itself in a shared page,
which we do in this commit in __bolt_instr_setup.
I also added a couple of assertions to sanity-check the hash table.

Reviewed By: rafauler, Amir
Differential Revision: https://reviews.llvm.org/D153771
2023-07-07 16:33:45 +03:00
Amir Ayupov
58a16d843e Reland "[BOLT][Instrumentation] Don't share counters when using append-pid"
This reverts commit c15e9b6814e53bccb0194268a826c1213a84b395.

The issue appears unrelated as the crash happened in the BOLTed binary, not
instrumented binary.
2023-06-30 09:14:58 -07:00
Denis Revunov
8ed172cfd5 Reland [BOLT][Instrumentation] Add mmap return value assertions
In a very rare case that mmap call fails, we'll at least get a message
instead of segfault.

Reviewed By: rafauler, Amir
Differential Revision: https://reviews.llvm.org/D154056
2023-06-30 11:10:33 +03:00
Denis Revunov
8b23a853b9 Reland [BOLT][Instrumentation][NFC] define and use mmap flags
Reviewed By: rafauler, Amir
Differential Revision: https://reviews.llvm.org/D154056
2023-06-30 11:10:08 +03:00
Amir Aupov
3e13b299f9 Revert "[BOLT][Instrumentation][NFC] define and use mmap flags"
This reverts commit f0b45fba4b64ab0b5d6c50d978e02f0d12d4d070.

The stack broke https://lab.llvm.org/buildbot/#/builders/252.
2023-06-29 22:11:17 -07:00
Amir Aupov
d1849045fc Revert "[BOLT][Instrumentation] Add mmap return value assertions"
This reverts commit 8f7c53ef81c17ae9d773818181d04ef1c3890912.

The stack broke https://lab.llvm.org/buildbot/#/builders/252.
2023-06-29 22:10:31 -07:00
Amir Ayupov
c15e9b6814 Revert "[BOLT][Instrumentation] Don't share counters when using append-pid"
This reverts commit 02c3724d43840339fdc91d21747e96b5f7405bb0.

This change breaks instrumented Clang:
https://lab.llvm.org/buildbot/#/builders/252/builds/2700
2023-06-29 19:54:29 -07:00
Amir Ayupov
4314f4ceb5 Revert "[BOLT][Instrumentation] Put Allocator itslef in shared memory by default"
This reverts commit ad4e0770ca7ebbc4dd6635b17421819b2393aa33.
Breaks BOLT upstream testing:
https://lab.llvm.org/buildbot/#/builders/244/builds/13736
2023-06-29 19:29:36 -07:00
Denis Revunov
47934c119e [BOLT][Instrumentation] Add dumping function to instrumentation hash tables
Since there are no other means to debug the instrumentation library
other than using stdout, having a function to print hash table entries
is very useful.

Reviewed By: rafauler, Amir
Differential Revision: https://reviews.llvm.org/D153771
2023-06-30 01:03:53 +03:00
Denis Revunov
ad4e0770ca [BOLT][Instrumentation] Put Allocator itslef in shared memory by default
In absence of instrumentation-file-append-pid option,
global allocator uses shared pages for allocation. However, since it is a
global variable, it gets COW'd after fork if instrumentation-sleep-time
is used, or if a process forks by itself. This means it handles the same
pages to every process which causes hash table corruption. Thus, if we
want shared pages, we need to put the allocator itself in a shared page,
which we do in this commit in __bolt_instr_setup.
I also added a couple of assertions to sanity-check the hash table.

Reviewed By: rafauler, Amir
Differential Revision: https://reviews.llvm.org/D153771
2023-06-30 01:03:52 +03:00
Denis Revunov
02c3724d43 [BOLT][Instrumentation] Don't share counters when using append-pid
The point of append-pid option is to record separate profiles for
separate forks, which is impossible when counters are the same for
every process. It leads to a sum of all profiles in every file, plus
GlobalWriteProfileMutex located in a shared memory prevents some
processes from dumping their data at all.

Reviewed By: rafauler, Amir
Differential Revision: https://reviews.llvm.org/D153771
2023-06-30 01:03:52 +03:00
Denis Revunov
8f7c53ef81 [BOLT][Instrumentation] Add mmap return value assertions
In a very rare case that mmap call fails, we'll at least get a message
instead of segfault.

Reviewed By: rafauler, Amir
Differential Revision: https://reviews.llvm.org/D154056
2023-06-30 01:03:52 +03:00
Denis Revunov
f0b45fba4b [BOLT][Instrumentation][NFC] define and use mmap flags
Reviewed By: rafauler, Amir
Differential Revision: https://reviews.llvm.org/D154056
2023-06-30 01:03:52 +03:00
Jakub Beránek
eaf1b5664b Increase memory of BOLT runtime instrumentation bump allocator used for writing resulting profile
The BOLT instrumentation runtime uses a bump allocator that has a fixed amount of maximum memory. In some cases, this memory limit is not large enough (https://github.com/llvm/llvm-project/issues/59174). We are hitting this limit when instrumenting the Rust compiler with BOLT.

This change increases the memory of the bump allocator used for writing the resulting BOLT profile.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D151891
2023-06-08 10:53:10 -07:00
Mark de Wever
cbaa3597aa Reland "[CMake] Bumps minimum version to 3.20.0.
This reverts commit d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6.

Adds the patch by @hans from
https://github.com/llvm/llvm-project/issues/62719
This patch fixes the Windows build.

d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6 reverted the reviews

D144509 [CMake] Bumps minimum version to 3.20.0.

This partly undoes D137724.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193

Note this does not remove work-arounds for older CMake versions, that
will be done in followup patches.

D150532 [OpenMP] Compile assembly files as ASM, not C

Since CMake 3.20, CMake explicitly passes "-x c" (or equivalent)
when compiling a file which has been set as having the language
C. This behaviour change only takes place if "cmake_minimum_required"
is set to 3.20 or newer, or if the policy CMP0119 is set to new.

Attempting to compile assembly files with "-x c" fails, however
this is workarounded in many cases, as OpenMP overrides this with
"-x assembler-with-cpp", however this is only added for non-Windows
targets.

Thus, after increasing cmake_minimum_required to 3.20, this breaks
compiling the GNU assembly for Windows targets; the GNU assembly is
used for ARM and AArch64 Windows targets when building with Clang.
This patch unbreaks that.

D150688 [cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump

The build uses other mechanism to select the runtime.

Fixes #62719

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D151344
2023-05-27 12:51:21 +02:00
Petr Hosek
9e6e3375f1 [BOLT][CMake] Use correct output paths and passthrough necessary options
This addresses https://github.com/llvm/llvm-project/issues/62748.

Differential Revision: https://reviews.llvm.org/D150752
2023-05-19 17:43:27 +00:00
Nico Weber
d763c6e5e2 Revert "Reland "[CMake] Bumps minimum version to 3.20.0.""
This reverts commit 65429b9af6a2c99d340ab2dcddd41dab201f399c.

Broke several projects, see https://reviews.llvm.org/D144509#4347562 onwards.

Also reverts follow-up commit "[OpenMP] Compile assembly files as ASM, not C"

This reverts commit 4072c8aee4c89c4457f4f30d01dc9bb4dfa52559.

Also reverts fix attempt  "[cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump"

This reverts commit 7d47dac5f828efd1d378ba44a97559114f00fb64.
2023-05-17 10:53:33 -04:00
Mark de Wever
65429b9af6 Reland "[CMake] Bumps minimum version to 3.20.0."
The owner of the last two failing buildbots updated CMake.

This reverts commit e8e8707b4aa6e4cc04c0cffb2de01d2de71165fc.
2023-05-13 11:42:25 +02:00
Mark de Wever
e8e8707b4a Revert "Reland "[CMake] Bumps minimum version to 3.20.0.""
Unfortunatly not all buildbots are updated.

This reverts commit ffb807ab5375b3f78df198dc5d4302b3b552242f.
2023-05-06 17:03:56 +02:00
Mark de Wever
ffb807ab53 Reland "[CMake] Bumps minimum version to 3.20.0."
All build bots should be updated now.

This reverts commit 44d38022ab29a3156349602733b3459df5beef93.
2023-05-06 11:43:02 +02:00
Nathan Sidwell
1c3653df08 [BOLT] Robustify compile-time config check
The BOLT runtime is specifically hard coded for x86_64 linux or x86_64
darwin. (Using x86_64 syscalls, hardcoding syscall numbers.)

Make it very clear this is for those specific pair of systems.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D148825
2023-04-21 12:37:54 -04:00
Mark de Wever
44d38022ab Revert "Revert "Revert "[CMake] Bumps minimum version to 3.20.0."""
This reverts commit 1ef4c3c859728008cf707cad8d67f45ae5070ae1.

Two buildbots still haven't been updated.
2023-04-15 20:12:24 +02:00
Mark de Wever
1ef4c3c859 Revert "Revert "[CMake] Bumps minimum version to 3.20.0.""
This reverts commit 92523a35a827539db8557bbc3ecab7f9ea3f6ade.

Reland to see whether CIs are updated.
2023-04-15 13:12:04 +02:00
Mark de Wever
d0398d3593 Revert "Reland "[CMake] Bumps minimum version to 3.20.0.""
This reverts commit a72165e5df59032cdd54dcb18155f2630d73abd1.

Some buildbots have not been updated yet.
2023-03-18 20:32:43 +01:00
Mark de Wever
a72165e5df Reland "[CMake] Bumps minimum version to 3.20.0."
This reverts commit 92523a35a827539db8557bbc3ecab7f9ea3f6ade.

Test whether all CI runners are updated.
2023-03-18 13:33:42 +01:00
Mark de Wever
92523a35a8 Revert "[CMake] Bumps minimum version to 3.20.0."
Some build bots have not been updated to the new minimal CMake version.
Reverting for now and ping the buildbot owners.

This reverts commit 44c6b905f8527635e49bb3ea97dea315f92d38ec.
2023-03-04 18:28:13 +01:00
Mark de Wever
44c6b905f8 [CMake] Bumps minimum version to 3.20.0.
This partly undoes D137724.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193

Note this does not remove work-arounds for older CMake versions, that
will be done in followup patches.

Reviewed By: mehdi_amini, MaskRay, ChuanqiXu, to268, thieta, tschuett, phosek, #libunwind, #libc_vendors, #libc, #libc_abi, sivachandra, philnik, zibi

Differential Revision: https://reviews.llvm.org/D144509
2023-03-04 12:40:57 +01:00
Vladislav Khmelevsky
750d17bb72 [BOLT][runtime] Change fPIE flag to fPIC
Since instrumentation could be used on libraries we need to use fPIC,
not fPIE flag.

Differential Revision: https://reviews.llvm.org/D138099
2022-11-17 11:50:43 +04:00
Rafael Auler
687ce3dec1 [BOLT][Hugify] Fix apple builds
Fix placement of ifdefs in hugify.cpp after D129107 landed.
2022-11-04 13:10:29 -07:00
Alexey Moksyakov
1fb186198a adds huge pages support of PIE/no-PIE binaries
This patch adds the huge pages support (-hugify) for PIE/no-PIE
binaries. Also returned functionality to support the kernels < 5.10
where there is a problem in a dynamic loader with the alignment of
pages addresses.

Differential Revision: https://reviews.llvm.org/D129107
2022-11-04 15:14:21 +03:00
serge-sans-paille
f71d32a0ee
Honor LLVM_LIBDIR_SUFFIX
Some distribution install libraries under lib64. LLVM supports this
through LLVM_LIBDIR_SUFFIX, have bolt do the same.

Differential Revision: https://reviews.llvm.org/D137039
2022-11-01 23:54:06 +01:00
John Ericson
90dcdc4b6e [bolt][llvm][cmake] Use CMAKE_INSTALL_LIBDIR too
Working back towards D130586.

Bolt didn't use `LLVM_LIBDIR_SUFFIX` before, and has no in-tree reverse
dependencies, it seems easier to add.

The change in LLVM itself is to prevent some unexpected `lib64` from
cropping up due to the `CMAKE_INSTALL_LIBDIR` defaulting logic.

Differential Revision: https://reviews.llvm.org/D132297
2022-08-20 13:08:06 -04:00
John Ericson
e941b031d3 Revert "[cmake] Use CMAKE_INSTALL_LIBDIR too"
This reverts commit f7a33090a91015836497c75f173775392ab0304d.

Unfortunately this causes a number of failures that didn't show up in my
local build.
2022-08-18 22:46:32 -04:00
John Ericson
f7a33090a9 [cmake] Use CMAKE_INSTALL_LIBDIR too
We held off on this before as `LLVM_LIBDIR_SUFFIX` conflicted with it.
Now we return this.

`LLVM_LIBDIR_SUFFIX` is kept as a deprecated way to set
`CMAKE_INSTALL_LIBDIR`. The other `*_LIBDIR_SUFFIX` are just removed
entirely.

I imagine this is too potentially-breaking to make LLVM 15. That's fine.
I have a more minimal version of this in the disto (NixOS) patches for
LLVM 15 (like previous versions). This more expansive version I will
test harder after the release is cut.

Reviewed By: sebastian-ne, ldionne, #libc, #libc_abi

Differential Revision: https://reviews.llvm.org/D130586
2022-08-18 15:33:35 -04:00
Tobias Hieta
b1356504e6
[LLVM] Update C++ standard to 17
Also make the soft toolchain requirements hard. This allows
us to use C++17 features in LLVM now.

If we find patterns with C++17 that improve readability
it should be recommended in the coding standards.

Reviewed By: jhenderson, cor3ntin, MaskRay

Differential Revision: https://reviews.llvm.org/D130689
2022-08-06 09:42:10 +02:00
Vladislav Khmelevsky
e10e120cea [BOLT][Runtime] Fix memset definition
Differential Revision: https://reviews.llvm.org/D129321
2022-07-09 01:17:08 +03:00
Michał Chojnowski
bd301a418b [BOLT] Fix concurrent hash table modification in the instrumentation runtime
`__bolt_instr_data_dump()` does not lock the hash tables when iterating
over them, so the iteration can happen concurrently with a modification
done in another thread, when the table is in an inconsistent state. This
also has been observed in practice, when it caused a segmentation fault.

We fix this by locking hash tables during iteration. This is done by taking
the lock in `forEachElement()`.
The only other site of iteration, `resetCounters()`, has been correctly
locking the table even before this patch. This patch removes its `Lock`
because the lock is now taken in the inner `forEachElement()`.

Reviewed By: maksfb, yota9

Differential Revision: https://reviews.llvm.org/D129089
2022-07-07 14:27:29 +03:00
Maksim Panchenko
ea2182fedd [BOLT] Add runtime functions required by freestanding environment
Compiler can generate calls to some functions implicitly, even under
constraints of freestanding environment. Make sure these functions are
available in our runtime objects.

Fixes test failures on some systems after https://reviews.llvm.org/D128960.

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D129168
2022-07-06 11:22:22 -07:00