Skip to content

Commit 4eb1e1f

Browse files
committed
Bump to green commit 'e864ac694540342d5e59f59c525c5082f2594fb8'
2 parents 628f4c3 + e864ac6 commit 4eb1e1f

File tree

4,601 files changed

+174608
-76835
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,601 files changed

+174608
-76835
lines changed

bolt/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ if (BOLT_ENABLE_RUNTIME)
5555
-DCMAKE_BUILD_TYPE=Release
5656
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
5757
-DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR}
58+
-DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
5859
BUILD_ALWAYS True
5960
)
6061
install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/cmake_install.cmake \)"
@@ -87,3 +88,6 @@ option(BOLT_INCLUDE_DOCS "Generate build targets for the BOLT docs."
8788
if (BOLT_INCLUDE_DOCS)
8889
add_subdirectory(docs)
8990
endif()
91+
92+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc.in
93+
${CMAKE_CURRENT_BINARY_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc @ONLY)

bolt/include/bolt/Passes/Hugify.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- bolt/Passes/Hugify.h -------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef BOLT_PASSES_HUGIFY_H
10+
#define BOLT_PASSES_HUGIFY_H
11+
12+
#include "bolt/Passes/BinaryPasses.h"
13+
14+
namespace llvm {
15+
namespace bolt {
16+
17+
class HugePage : public BinaryFunctionPass {
18+
public:
19+
HugePage(const cl::opt<bool> &PrintPass) : BinaryFunctionPass(PrintPass) {}
20+
21+
void runOnFunctions(BinaryContext &BC) override;
22+
23+
const char *getName() const override { return "HugePage"; }
24+
};
25+
26+
} // namespace bolt
27+
} // namespace llvm
28+
29+
#endif

bolt/include/bolt/RuntimeLibs/HugifyRuntimeLibrary.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ class HugifyRuntimeLibrary : public RuntimeLibrary {
2222
public:
2323
/// Add custom section names generated by the runtime libraries to \p
2424
/// SecNames.
25-
void addRuntimeLibSections(std::vector<std::string> &SecNames) const final {
26-
SecNames.push_back(".bolt.hugify.entries");
27-
}
25+
void addRuntimeLibSections(std::vector<std::string> &SecNames) const final {}
2826

2927
void adjustCommandLineOptions(const BinaryContext &BC) const final;
3028

31-
void emitBinary(BinaryContext &BC, MCStreamer &Streamer) final;
29+
void emitBinary(BinaryContext &BC, MCStreamer &Streamer) final {}
3230

3331
void link(BinaryContext &BC, StringRef ToolPath, RuntimeDyld &RTDyld,
3432
std::function<void(RuntimeDyld &)> OnLoad) final;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- RuntimeLibraryVariables.inc.in - bolt build variables -*- C++ -*---===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file is configured by the build system to define the runtime library
10+
// location.
11+
//
12+
// The variant of this file not ending with .in has been autogenerated by the
13+
// LLVM build. Do not edit!
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@"

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern llvm::cl::opt<unsigned long long> HeatmapMinAddress;
4444
extern llvm::cl::opt<bool> HotData;
4545
extern llvm::cl::opt<bool> HotFunctionsAtEnd;
4646
extern llvm::cl::opt<bool> HotText;
47+
extern llvm::cl::opt<bool> Hugify;
4748
extern llvm::cl::opt<bool> Instrument;
4849
extern llvm::cl::opt<std::string> OutputFilename;
4950
extern llvm::cl::opt<std::string> PerfData;

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,12 @@ void BinaryEmitter::emitJumpTables(const BinaryFunction &BF) {
740740

741741
for (auto &JTI : BF.jumpTables()) {
742742
JumpTable &JT = *JTI.second;
743+
// Only emit shared jump tables once, when processing the first parent
744+
if (JT.Parents.size() > 1 && JT.Parents[0] != &BF)
745+
continue;
743746
if (opts::PrintJumpTables)
744747
JT.print(outs());
745-
if ((opts::JumpTables == JTS_BASIC || !BF.isSimple()) &&
746-
BC.HasRelocations) {
748+
if (opts::JumpTables == JTS_BASIC && BC.HasRelocations) {
747749
JT.updateOriginal();
748750
} else {
749751
MCSection *HotSection, *ColdSection;

bolt/lib/Passes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_llvm_library(LLVMBOLTPasses
1515
FrameOptimizer.cpp
1616
HFSort.cpp
1717
HFSortPlus.cpp
18+
Hugify.cpp
1819
IdenticalCodeFolding.cpp
1920
IndirectCallPromotion.cpp
2021
Inliner.cpp

bolt/lib/Passes/Hugify.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//===--- bolt/Passes/Hugify.cpp -------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "bolt/Passes/Hugify.h"
10+
#include "llvm/Support/CommandLine.h"
11+
12+
#define DEBUG_TYPE "bolt-hugify"
13+
14+
using namespace llvm;
15+
16+
namespace llvm {
17+
namespace bolt {
18+
19+
void HugePage::runOnFunctions(BinaryContext &BC) {
20+
auto *RtLibrary = BC.getRuntimeLibrary();
21+
if (!RtLibrary || !BC.isELF() || !BC.StartFunctionAddress) {
22+
return;
23+
}
24+
25+
auto createSimpleFunction =
26+
[&](std::string Title, std::vector<MCInst> Instrs) -> BinaryFunction * {
27+
BinaryFunction *Func = BC.createInjectedBinaryFunction(Title);
28+
29+
std::vector<std::unique_ptr<BinaryBasicBlock>> BBs;
30+
BBs.emplace_back(Func->createBasicBlock(nullptr));
31+
BBs.back()->addInstructions(Instrs.begin(), Instrs.end());
32+
BBs.back()->setCFIState(0);
33+
BBs.back()->setOffset(BinaryBasicBlock::INVALID_OFFSET);
34+
35+
Func->insertBasicBlocks(nullptr, std::move(BBs),
36+
/*UpdateLayout=*/true,
37+
/*UpdateCFIState=*/false);
38+
Func->updateState(BinaryFunction::State::CFG_Finalized);
39+
return Func;
40+
};
41+
42+
const BinaryFunction *const Start =
43+
BC.getBinaryFunctionAtAddress(*BC.StartFunctionAddress);
44+
assert(Start && "Entry point function not found");
45+
const MCSymbol *StartSym = Start->getSymbol();
46+
createSimpleFunction("__bolt_hugify_start_program",
47+
BC.MIB->createSymbolTrampoline(StartSym, BC.Ctx.get()));
48+
}
49+
} // namespace bolt
50+
} // namespace llvm

bolt/lib/Rewrite/BinaryPassManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "bolt/Passes/AsmDump.h"
1414
#include "bolt/Passes/CMOVConversion.h"
1515
#include "bolt/Passes/FrameOptimizer.h"
16+
#include "bolt/Passes/Hugify.h"
1617
#include "bolt/Passes/IdenticalCodeFolding.h"
1718
#include "bolt/Passes/IndirectCallPromotion.h"
1819
#include "bolt/Passes/Inliner.h"
@@ -333,6 +334,8 @@ void BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
333334

334335
if (opts::Instrument)
335336
Manager.registerPass(std::make_unique<Instrumentation>(NeverPrint));
337+
else if (opts::Hugify)
338+
Manager.registerPass(std::make_unique<HugePage>(NeverPrint));
336339

337340
Manager.registerPass(std::make_unique<ShortenInstructions>(NeverPrint));
338341

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,11 @@ Error RewriteInstance::discoverStorage() {
479479
NextAvailableAddress = alignTo(NextAvailableAddress, BC->PageAlign);
480480
NextAvailableOffset = alignTo(NextAvailableOffset, BC->PageAlign);
481481

482+
// Hugify: Additional huge page from left side due to
483+
// weird ASLR mapping addresses (4KB aligned)
484+
if (opts::Hugify && !BC->HasFixedLoadAddress)
485+
NextAvailableAddress += BC->PageAlign;
486+
482487
if (!opts::UseGnuStack) {
483488
// This is where the black magic happens. Creating PHDR table in a segment
484489
// other than that containing ELF header is tricky. Some loaders and/or
@@ -3719,6 +3724,12 @@ void RewriteInstance::mapCodeSections(RuntimeDyld &RTDyld) {
37193724
Address = alignTo(Address, Section->getAlignment());
37203725
Section->setOutputAddress(Address);
37213726
Address += Section->getOutputSize();
3727+
3728+
// Hugify: Additional huge page from right side due to
3729+
// weird ASLR mapping addresses (4KB aligned)
3730+
if (opts::Hugify && !BC->HasFixedLoadAddress &&
3731+
Section->getName() == BC->getMainCodeSectionName())
3732+
Address = alignTo(Address, Section->getAlignment());
37223733
}
37233734

37243735
// Make sure we allocate enough space for huge pages.

bolt/lib/RuntimeLibs/HugifyRuntimeLibrary.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,6 @@ void HugifyRuntimeLibrary::adjustCommandLineOptions(
6060
}
6161
}
6262

63-
void HugifyRuntimeLibrary::emitBinary(BinaryContext &BC, MCStreamer &Streamer) {
64-
const BinaryFunction *StartFunction =
65-
BC.getBinaryFunctionAtAddress(*(BC.StartFunctionAddress));
66-
assert(!StartFunction->isFragment() && "expected main function fragment");
67-
if (!StartFunction) {
68-
errs() << "BOLT-ERROR: failed to locate function at binary start address\n";
69-
exit(1);
70-
}
71-
72-
const auto Flags = BinarySection::getFlags(/*IsReadOnly=*/false,
73-
/*IsText=*/false,
74-
/*IsAllocatable=*/true);
75-
MCSectionELF *Section =
76-
BC.Ctx->getELFSection(".bolt.hugify.entries", ELF::SHT_PROGBITS, Flags);
77-
78-
// __bolt_hugify_init_ptr stores the poiter the hugify library needs to
79-
// jump to after finishing the init code.
80-
MCSymbol *InitPtr = BC.Ctx->getOrCreateSymbol("__bolt_hugify_init_ptr");
81-
82-
Section->setAlignment(llvm::Align(BC.RegularPageSize));
83-
Streamer.switchSection(Section);
84-
85-
Streamer.emitLabel(InitPtr);
86-
Streamer.emitSymbolAttribute(InitPtr, MCSymbolAttr::MCSA_Global);
87-
Streamer.emitValue(
88-
MCSymbolRefExpr::create(StartFunction->getSymbol(), *(BC.Ctx)),
89-
/*Size=*/8);
90-
}
91-
9263
void HugifyRuntimeLibrary::link(BinaryContext &BC, StringRef ToolPath,
9364
RuntimeDyld &RTDyld,
9465
std::function<void(RuntimeDyld &)> OnLoad) {

bolt/lib/RuntimeLibs/RuntimeLibrary.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "bolt/RuntimeLibs/RuntimeLibrary.h"
14+
#include "bolt/RuntimeLibs/RuntimeLibraryVariables.inc"
1415
#include "bolt/Utils/Utils.h"
1516
#include "llvm/BinaryFormat/Magic.h"
1617
#include "llvm/ExecutionEngine/RuntimeDyld.h"
@@ -28,12 +29,12 @@ std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
2829
StringRef LibFileName) {
2930
StringRef Dir = llvm::sys::path::parent_path(ToolPath);
3031
SmallString<128> LibPath = llvm::sys::path::parent_path(Dir);
31-
llvm::sys::path::append(LibPath, "lib");
32+
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
3233
if (!llvm::sys::fs::exists(LibPath)) {
3334
// In some cases we install bolt binary into one level deeper in bin/,
3435
// we need to go back one more level to find lib directory.
3536
LibPath = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
36-
llvm::sys::path::append(LibPath, "lib");
37+
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
3738
}
3839
llvm::sys::path::append(LibPath, LibFileName);
3940
if (!llvm::sys::fs::exists(LibPath)) {

bolt/runtime/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,39 @@ add_library(bolt_rt_instr STATIC
1515
instr.cpp
1616
${CMAKE_CURRENT_BINARY_DIR}/config.h
1717
)
18+
set_target_properties(bolt_rt_instr PROPERTIES LIBRARY_OUTPUT_DIRECTORY "lib${LLVM_LIBDIR_SUFFIX}")
1819
add_library(bolt_rt_hugify STATIC
1920
hugify.cpp
2021
${CMAKE_CURRENT_BINARY_DIR}/config.h
2122
)
23+
set_target_properties(bolt_rt_hugify PROPERTIES LIBRARY_OUTPUT_DIRECTORY "lib${LLVM_LIBDIR_SUFFIX}")
2224

2325
set(BOLT_RT_FLAGS
2426
-ffreestanding
2527
-fno-exceptions
2628
-fno-rtti
2729
-fno-stack-protector
28-
-mno-sse)
30+
-mno-sse
31+
-fPIE)
2932

3033
# Don't let the compiler think it can create calls to standard libs
31-
target_compile_options(bolt_rt_instr PRIVATE ${BOLT_RT_FLAGS} -fPIE)
34+
target_compile_options(bolt_rt_instr PRIVATE ${BOLT_RT_FLAGS})
3235
target_include_directories(bolt_rt_instr PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
3336
target_compile_options(bolt_rt_hugify PRIVATE ${BOLT_RT_FLAGS})
3437
target_include_directories(bolt_rt_hugify PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
3538

36-
install(TARGETS bolt_rt_instr DESTINATION "${CMAKE_INSTALL_LIBDIR}")
37-
install(TARGETS bolt_rt_hugify DESTINATION "${CMAKE_INSTALL_LIBDIR}")
39+
install(TARGETS bolt_rt_instr DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
40+
install(TARGETS bolt_rt_hugify DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
3841

3942
if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*")
4043
add_library(bolt_rt_instr_osx STATIC
4144
instr.cpp
4245
${CMAKE_CURRENT_BINARY_DIR}/config.h
4346
)
47+
set_target_properties(bolt_rt_instr_osx PROPERTIES LIBRARY_OUTPUT_DIRECTORY "lib${LLVM_LIBDIR_SUFFIX}")
4448
target_include_directories(bolt_rt_instr_osx PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
4549
target_compile_options(bolt_rt_instr_osx PRIVATE
4650
-target x86_64-apple-darwin19.6.0
4751
${BOLT_RT_FLAGS})
48-
install(TARGETS bolt_rt_instr_osx DESTINATION "${CMAKE_INSTALL_LIBDIR}")
52+
install(TARGETS bolt_rt_instr_osx DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
4953
endif()

0 commit comments

Comments
 (0)