forked from OSchip/llvm-project
[BOLT] Fix build for Mac
Summary: Change our CMake config for the standalone runtime instrumentation library to check for the elf.h header before using it, so the build doesn't break on systems lacking it. Also fix a SmallPtrSet usage where its elements are not really pointers, but uint64_t, breaking the build in Apple's Clang. (cherry picked from FBD17505759)
This commit is contained in:
parent
5e6d246b9c
commit
ba31344fa9
|
@ -1,14 +1,24 @@
|
|||
cmake_minimum_required(VERSION 3.1.0)
|
||||
|
||||
include(CheckIncludeFiles)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
project(libbolt_rt_project)
|
||||
|
||||
check_include_files(elf.h HAVE_ELF_H)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
|
||||
add_library(bolt_rt STATIC
|
||||
instr.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/config.h
|
||||
)
|
||||
|
||||
# Don't let the compiler think it can create calls to standard libs
|
||||
target_compile_options(bolt_rt PRIVATE -ffreestanding)
|
||||
target_include_directories(bolt_rt PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
install(TARGETS bolt_rt DESTINATION lib)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#cmakedefine HAVE_ELF_H
|
|
@ -15,7 +15,11 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "config.h"
|
||||
#ifdef HAVE_ELF_H
|
||||
#include <elf.h>
|
||||
#endif
|
||||
|
||||
//#define ENABLE_DEBUG
|
||||
|
||||
|
@ -380,6 +384,7 @@ char *serializeLoc(const InstrumentationInfo &Info, char *OutBuf,
|
|||
|
||||
// Read and map to memory the descriptions written by BOLT into the executable's
|
||||
// notes section
|
||||
#ifdef HAVE_ELF_H
|
||||
InstrumentationInfo readDescriptions() {
|
||||
InstrumentationInfo Result;
|
||||
uint64_t FD = __open("/proc/self/exe",
|
||||
|
@ -431,6 +436,15 @@ InstrumentationInfo readDescriptions() {
|
|||
reportError(ErrMsg, sizeof(ErrMsg));
|
||||
return Result;
|
||||
}
|
||||
#else
|
||||
InstrumentationInfo readDescriptions() {
|
||||
InstrumentationInfo Result;
|
||||
const char ErrMsg[] =
|
||||
"BOLT instrumentation runtime error: unsupported binary format.\n";
|
||||
reportError(ErrMsg, sizeof(ErrMsg));
|
||||
return Result;
|
||||
}
|
||||
#endif
|
||||
|
||||
void printStats(const InstrumentationInfo &Info) {
|
||||
char StatMsg[BufSize];
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "DynoStats.h"
|
||||
#include "MCPlusBuilder.h"
|
||||
#include "llvm/ADT/edit_distance.h"
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
|
@ -3653,7 +3654,7 @@ void BinaryFunction::updateLayout(BinaryBasicBlock *Start,
|
|||
}
|
||||
|
||||
bool BinaryFunction::checkForAmbiguousJumpTables() {
|
||||
SmallPtrSet<uint64_t, 4> JumpTables;
|
||||
SmallSet<uint64_t, 4> JumpTables;
|
||||
for (auto &BB : BasicBlocks) {
|
||||
for (auto &Inst : *BB) {
|
||||
if (!BC.MIB->isIndirectBranch(Inst))
|
||||
|
@ -3664,8 +3665,7 @@ bool BinaryFunction::checkForAmbiguousJumpTables() {
|
|||
// This address can be inside another jump table, but we only consider
|
||||
// it ambiguous when the same start address is used, not the same JT
|
||||
// object.
|
||||
auto Iter = JumpTables.find(JTAddress);
|
||||
if (Iter == JumpTables.end()) {
|
||||
if (!JumpTables.count(JTAddress)) {
|
||||
JumpTables.insert(JTAddress);
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue