Update to clang/llvm 15 (#342)

Summary:

Update to clang-15 compiler and libraries as clang-12 is ancient.

The changes to oilgen are necessary because the new internal toolchain is being more picky about linking PIC to PIC. In certain modes we build with PIC, but try to link a non-PIC oilgen artifact. Add the ability to build the oilgen artifacts with PIC which sorts this.

Reviewed By: ttreyer

Differential Revision: D46220858
This commit is contained in:
Jake Hillion 2023-09-14 03:40:11 -07:00 committed by Facebook Community Bot
parent 1d387ca880
commit a6d74a20a6
13 changed files with 35 additions and 58 deletions

View File

@ -134,13 +134,14 @@ jobs:
bison \ bison \
build-essential \ build-essential \
clang-12 \ clang-12 \
clang-15 \
cmake \ cmake \
flex \ flex \
gawk \ gawk \
libboost-all-dev \ libboost-all-dev \
libbz2-dev \ libbz2-dev \
libcap2-bin \ libcap2-bin \
libclang-12-dev \ libclang-15-dev \
libcurl4-gnutls-dev \ libcurl4-gnutls-dev \
libdouble-conversion-dev \ libdouble-conversion-dev \
libdw-dev \ libdw-dev \
@ -152,7 +153,7 @@ jobs:
libjemalloc-dev \ libjemalloc-dev \
libmsgpack-dev \ libmsgpack-dev \
libzstd-dev \ libzstd-dev \
llvm-12-dev \ llvm-15-dev \
ninja-build \ ninja-build \
pkg-config \ pkg-config \
python3-setuptools python3-setuptools
@ -196,10 +197,10 @@ jobs:
command: | command: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y \ sudo apt-get install -y \
clang-12 \ clang-15 \
libboost-all-dev \ libboost-all-dev \
libgflags-dev \ libgflags-dev \
llvm-12-dev \ llvm-15-dev \
libfmt-dev \ libfmt-dev \
libjemalloc-dev libjemalloc-dev
environment: environment:

View File

@ -73,7 +73,7 @@ FetchContent_Declare(
FetchContent_Populate(rocksdb) FetchContent_Populate(rocksdb)
add_custom_target(librocksdb ALL add_custom_target(librocksdb ALL
WORKING_DIRECTORY ${rocksdb_SOURCE_DIR} WORKING_DIRECTORY ${rocksdb_SOURCE_DIR}
COMMAND cmake -G Ninja -B ${rocksdb_BINARY_DIR} -DCMAKE_BUILD_TYPE=Release -DWITH_GFLAGS=Off -DWITH_LIBURING=Off -DWITH_ZSTD=On COMMAND cmake -G Ninja -B ${rocksdb_BINARY_DIR} -DCMAKE_BUILD_TYPE=Release -DWITH_GFLAGS=Off -DWITH_LIBURING=Off -DWITH_ZSTD=On -DFAIL_ON_WARNINGS=Off
COMMAND cmake --build ${rocksdb_BINARY_DIR} --target rocksdb COMMAND cmake --build ${rocksdb_BINARY_DIR} --target rocksdb
BYPRODUCTS ${rocksdb_BINARY_DIR}/librocksdb.a BYPRODUCTS ${rocksdb_BINARY_DIR}/librocksdb.a
COMMENT "Building RocksDB" COMMENT "Building RocksDB"
@ -162,8 +162,8 @@ find_package(Boost REQUIRED COMPONENTS
) )
message(STATUS "Linking Boost libraries: ${Boost_LIBRARIES}") message(STATUS "Linking Boost libraries: ${Boost_LIBRARIES}")
### LLVM and Clang - Preferring Clang 12 ### LLVM and Clang - Preferring Clang 15
find_package(LLVM 12 REQUIRED CONFIG) find_package(LLVM 15 REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

View File

@ -991,10 +991,7 @@ bool OICodeGen::enumerateChildClasses() {
return false; return false;
} }
int i = 0;
int j = 0;
while (true) { while (true) {
i++;
drgn_qualified_type* t; drgn_qualified_type* t;
err = drgn_type_iterator_next(typesIterator, &t); err = drgn_type_iterator_next(typesIterator, &t);
if (err) { if (err) {
@ -1007,7 +1004,6 @@ bool OICodeGen::enumerateChildClasses() {
if (!t) { if (!t) {
break; break;
} }
j++;
auto kind = drgn_type_kind(t->type); auto kind = drgn_type_kind(t->type);
if (kind != DRGN_TYPE_CLASS && kind != DRGN_TYPE_STRUCT) { if (kind != DRGN_TYPE_CLASS && kind != DRGN_TYPE_STRUCT) {

View File

@ -28,12 +28,13 @@
#include <glog/logging.h> #include <glog/logging.h>
#include <llvm/ADT/SmallVector.h> #include <llvm/ADT/SmallVector.h>
#include <llvm/ADT/Triple.h> #include <llvm/ADT/Triple.h>
#include <llvm/ADT/Twine.h>
#include <llvm/Demangle/Demangle.h> #include <llvm/Demangle/Demangle.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h> #include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/RTDyldMemoryManager.h> #include <llvm/ExecutionEngine/RTDyldMemoryManager.h>
#include <llvm/MC/TargetRegistry.h>
#include <llvm/Support/Host.h> #include <llvm/Support/Host.h>
#include <llvm/Support/Memory.h> #include <llvm/Support/Memory.h>
#include <llvm/Support/TargetRegistry.h>
#include <llvm/Support/TargetSelect.h> #include <llvm/Support/TargetSelect.h>
#include <llvm/Support/raw_os_ostream.h> #include <llvm/Support/raw_os_ostream.h>
@ -158,7 +159,7 @@ class OIMemoryManager : public RTDyldMemoryManager {
* failure upwards so we can shutdown cleanly. * failure upwards so we can shutdown cleanly.
*/ */
if (errorCode) { if (errorCode) {
report_fatal_error("Can't allocate enough memory: " + report_fatal_error(llvm::Twine("Can't allocate enough memory: ") +
errorCode.message()); errorCode.message());
} }
@ -490,9 +491,9 @@ bool OICompiler::compile(const std::string& code,
compInv->getLangOpts()->Char8 = true; compInv->getLangOpts()->Char8 = true;
compInv->getLangOpts()->CXXOperatorNames = true; compInv->getLangOpts()->CXXOperatorNames = true;
compInv->getLangOpts()->DoubleSquareBracketAttributes = true; compInv->getLangOpts()->DoubleSquareBracketAttributes = true;
compInv->getLangOpts()->ImplicitInt = false;
compInv->getLangOpts()->Exceptions = true; compInv->getLangOpts()->Exceptions = true;
compInv->getLangOpts()->CXXExceptions = true; compInv->getLangOpts()->CXXExceptions = true;
compInv->getLangOpts()->Coroutines = true;
compInv->getPreprocessorOpts(); compInv->getPreprocessorOpts();
compInv->getPreprocessorOpts().addRemappedFile( compInv->getPreprocessorOpts().addRemappedFile(
@ -540,7 +541,8 @@ bool OICompiler::compile(const std::string& code,
std::string{"/synthetic/headers/"} + v.second, std::string{"/synthetic/headers/"} + v.second,
MemoryBuffer::getMemBuffer(v.first).release()); MemoryBuffer::getMemBuffer(v.first).release());
} }
for (const auto& [k, _] : syntheticHeaders) { for (const auto& kv : syntheticHeaders) {
const auto& k = kv.first;
if (config.features[k]) { if (config.features[k]) {
headerSearchOptions.AddPath( headerSearchOptions.AddPath(
"/synthetic/headers", "/synthetic/headers",
@ -552,7 +554,11 @@ bool OICompiler::compile(const std::string& code,
compInv->getFrontendOpts().OutputFile = objectPath; compInv->getFrontendOpts().OutputFile = objectPath;
compInv->getTargetOpts().Triple = compInv->getTargetOpts().Triple =
llvm::Triple::normalize(llvm::sys::getProcessTriple()); llvm::Triple::normalize(llvm::sys::getProcessTriple());
if (config.usePIC) {
compInv->getCodeGenOpts().RelocationModel = llvm::Reloc::PIC_;
} else {
compInv->getCodeGenOpts().RelocationModel = llvm::Reloc::Static; compInv->getCodeGenOpts().RelocationModel = llvm::Reloc::Static;
}
compInv->getCodeGenOpts().CodeModel = "large"; compInv->getCodeGenOpts().CodeModel = "large";
compInv->getCodeGenOpts().OptimizationLevel = 3; compInv->getCodeGenOpts().OptimizationLevel = 3;
compInv->getCodeGenOpts().NoUseJumpTables = 1; compInv->getCodeGenOpts().NoUseJumpTables = 1;

View File

@ -48,6 +48,8 @@ class OICompiler {
std::vector<fs::path> userHeaderPaths{}; std::vector<fs::path> userHeaderPaths{};
std::vector<fs::path> sysHeaderPaths{}; std::vector<fs::path> sysHeaderPaths{};
bool usePIC = false;
}; };
/** /**

View File

@ -187,6 +187,7 @@ int OIGenerator::generate(fs::path& primaryObject, SymbolService& symbols) {
OICodeGen::Config generatorConfig{}; OICodeGen::Config generatorConfig{};
OICompiler::Config compilerConfig{}; OICompiler::Config compilerConfig{};
compilerConfig.usePIC = pic;
auto features = utils::processConfigFile(configFilePath, featuresMap, auto features = utils::processConfigFile(configFilePath, featuresMap,
compilerConfig, generatorConfig); compilerConfig, generatorConfig);

View File

@ -40,12 +40,16 @@ class OIGenerator {
void setFailIfNothingGenerated(bool fail) { void setFailIfNothingGenerated(bool fail) {
failIfNothingGenerated = fail; failIfNothingGenerated = fail;
} }
void setUsePIC(bool pic_) {
pic = pic_;
}
private: private:
std::filesystem::path outputPath; std::filesystem::path outputPath;
std::filesystem::path configFilePath; std::filesystem::path configFilePath;
std::filesystem::path sourceFileDumpPath; std::filesystem::path sourceFileDumpPath;
bool failIfNothingGenerated; bool failIfNothingGenerated = false;
bool pic = false;
std::unordered_map<std::string, std::string> oilStrongToWeakSymbolsMap( std::unordered_map<std::string, std::string> oilStrongToWeakSymbolsMap(
drgnplusplus::program& prog); drgnplusplus::program& prog);

View File

@ -171,10 +171,7 @@ void AddChildren::enumerateChildClasses(SymbolService& symbols) {
abort(); abort();
} }
int i = 0;
int j = 0;
while (true) { while (true) {
i++;
drgn_qualified_type* t; drgn_qualified_type* t;
err = drgn_type_iterator_next(typesIterator, &t); err = drgn_type_iterator_next(typesIterator, &t);
if (err) { if (err) {
@ -189,7 +186,6 @@ void AddChildren::enumerateChildClasses(SymbolService& symbols) {
if (!t) { if (!t) {
break; break;
} }
j++;
auto kind = drgn_type_kind(t->type); auto kind = drgn_type_kind(t->type);
if (kind != DRGN_TYPE_CLASS && kind != DRGN_TYPE_STRUCT) { if (kind != DRGN_TYPE_CLASS && kind != DRGN_TYPE_STRUCT) {

View File

@ -63,7 +63,7 @@ system_paths = [
"/usr/include/x86_64-linux-gnu/c++/11", "/usr/include/x86_64-linux-gnu/c++/11",
"/usr/include/c++/11/backward", "/usr/include/c++/11/backward",
"/usr/local/include", "/usr/local/include",
"/usr/lib/llvm-12/lib/clang/12.0.1/include", "/usr/lib/llvm-15/lib/clang/15.0.7/include",
"/usr/include/x86_64-linux-gnu", "/usr/include/x86_64-linux-gnu",
"/usr/include", "/usr/include",
] ]

View File

@ -39,12 +39,6 @@ definitions = '''
char c; char c;
alignas(32) char c32; alignas(32) char c32;
}; };
enum class alignas(16) AlignedEnum16 : int8_t {
Val1,
Val2,
Val3,
};
''' '''
[cases] [cases]
[cases.wrapper_struct] [cases.wrapper_struct]
@ -212,19 +206,3 @@ definitions = '''
{"typeName": "char", "staticSize": 1, "exclusiveSize": 1}, {"typeName": "char", "staticSize": 1, "exclusiveSize": 1},
{"typeName": "char", "staticSize": 1, "exclusiveSize": 1} {"typeName": "char", "staticSize": 1, "exclusiveSize": 1}
]}]}]''' ]}]}]'''
[cases.wrapper_enum]
param_types = ["const Wrapper<AlignedEnum16>&"]
setup = "return {};"
expect_json = '''[
{"staticSize": 32, "exclusiveSize": 30, "members": [
{"typeName": "int8_t", "staticSize": 1, "exclusiveSize": 1},
{"typeName": "AlignedEnum16", "staticSize": 1, "exclusiveSize": 1}
]}]'''
[cases.container_enum]
skip = "container alignment is broken (#143)"
param_types = ["const std::optional<AlignedEnum16>&"]
setup = "return {};"
expect_json = '''[
{"staticSize": 32, "exclusiveSize": 31, "members": [
{"typeName": "AlignedEnum16", "staticSize": 1, "exclusiveSize": 1}
]}]'''

View File

@ -310,13 +310,6 @@ int main(int argc, char* argv[]) {
} }
std::cout << "mapOfWords #elements: " << mapOfWords.size() << std::endl; std::cout << "mapOfWords #elements: " << mapOfWords.size() << std::endl;
int size = 0;
for (auto it = mapOfWords.begin(); it != mapOfWords.end(); ++it) {
size += (int)it->first.size();
}
std::cout << "mapOfWords map addr = " << &mapOfWords << std::endl; std::cout << "mapOfWords map addr = " << &mapOfWords << std::endl;
std::cout << "nameList vector addr = " << &nameList << std::endl; std::cout << "nameList vector addr = " << &nameList << std::endl;

View File

@ -232,13 +232,6 @@ int main(int argc, char* argv[]) {
} }
std::cout << "mapOfWords #elements: " << mapOfWords.size() << std::endl; std::cout << "mapOfWords #elements: " << mapOfWords.size() << std::endl;
int size = 0;
for (auto it = mapOfWords.begin(); it != mapOfWords.end(); ++it) {
size += (int)it->first.size();
}
std::cout << "mapOfWords map addr = " << &mapOfWords << std::endl; std::cout << "mapOfWords map addr = " << &mapOfWords << std::endl;
std::cout << "nameList vector addr = " << &nameList << std::endl; std::cout << "nameList vector addr = " << &nameList << std::endl;

View File

@ -37,6 +37,8 @@ constexpr static OIOpts opts{
"Write generated code to a file (for debugging)."}, "Write generated code to a file (for debugging)."},
OIOpt{'e', "exit-code", no_argument, nullptr, OIOpt{'e', "exit-code", no_argument, nullptr,
"Return a bad exit code if nothing is generated."}, "Return a bad exit code if nothing is generated."},
OIOpt{'p', "pic", no_argument, nullptr,
"Generate position independent code."},
}; };
void usage() { void usage() {
@ -59,6 +61,7 @@ int main(int argc, char* argv[]) {
fs::path configFilePath = "/usr/local/share/oi/base.oid.toml"; fs::path configFilePath = "/usr/local/share/oi/base.oid.toml";
fs::path sourceFileDumpPath = ""; fs::path sourceFileDumpPath = "";
bool exitCode = false; bool exitCode = false;
bool pic = false;
int c; int c;
while ((c = getopt_long(argc, argv, opts.shortOpts(), opts.longOpts(), while ((c = getopt_long(argc, argv, opts.shortOpts(), opts.longOpts(),
@ -79,6 +82,9 @@ int main(int argc, char* argv[]) {
case 'e': case 'e':
exitCode = true; exitCode = true;
break; break;
case 'p':
pic = true;
break;
} }
} }
@ -100,6 +106,7 @@ int main(int argc, char* argv[]) {
oigen.setConfigFilePath(std::move(configFilePath)); oigen.setConfigFilePath(std::move(configFilePath));
oigen.setSourceFileDumpPath(sourceFileDumpPath); oigen.setSourceFileDumpPath(sourceFileDumpPath);
oigen.setFailIfNothingGenerated(exitCode); oigen.setFailIfNothingGenerated(exitCode);
oigen.setUsePIC(pic);
SymbolService symbols(primaryObject); SymbolService symbols(primaryObject);