From a6d74a20a65fea48d12b67ace38db6478c60e2bb Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Thu, 14 Sep 2023 03:40:11 -0700 Subject: [PATCH] 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 --- .circleci/config.yml | 9 +++++---- CMakeLists.txt | 6 +++--- oi/OICodeGen.cpp | 4 ---- oi/OICompiler.cpp | 16 +++++++++++----- oi/OICompiler.h | 2 ++ oi/OIGenerator.cpp | 1 + oi/OIGenerator.h | 6 +++++- oi/type_graph/AddChildren.cpp | 4 ---- test/ci.oid.toml | 2 +- test/integration/alignment.toml | 22 ---------------------- test/integration_mttest.cpp | 7 ------- test/integration_sleepy.cpp | 7 ------- tools/OILGen.cpp | 7 +++++++ 13 files changed, 35 insertions(+), 58 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 08846b6..a6991e1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -134,13 +134,14 @@ jobs: bison \ build-essential \ clang-12 \ + clang-15 \ cmake \ flex \ gawk \ libboost-all-dev \ libbz2-dev \ libcap2-bin \ - libclang-12-dev \ + libclang-15-dev \ libcurl4-gnutls-dev \ libdouble-conversion-dev \ libdw-dev \ @@ -152,7 +153,7 @@ jobs: libjemalloc-dev \ libmsgpack-dev \ libzstd-dev \ - llvm-12-dev \ + llvm-15-dev \ ninja-build \ pkg-config \ python3-setuptools @@ -196,10 +197,10 @@ jobs: command: | sudo apt-get update sudo apt-get install -y \ - clang-12 \ + clang-15 \ libboost-all-dev \ libgflags-dev \ - llvm-12-dev \ + llvm-15-dev \ libfmt-dev \ libjemalloc-dev environment: diff --git a/CMakeLists.txt b/CMakeLists.txt index 39156ba..d275f68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ FetchContent_Declare( FetchContent_Populate(rocksdb) add_custom_target(librocksdb ALL 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 BYPRODUCTS ${rocksdb_BINARY_DIR}/librocksdb.a COMMENT "Building RocksDB" @@ -162,8 +162,8 @@ find_package(Boost REQUIRED COMPONENTS ) message(STATUS "Linking Boost libraries: ${Boost_LIBRARIES}") -### LLVM and Clang - Preferring Clang 12 -find_package(LLVM 12 REQUIRED CONFIG) +### LLVM and Clang - Preferring Clang 15 +find_package(LLVM 15 REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") diff --git a/oi/OICodeGen.cpp b/oi/OICodeGen.cpp index cfed5ae..c924734 100644 --- a/oi/OICodeGen.cpp +++ b/oi/OICodeGen.cpp @@ -991,10 +991,7 @@ bool OICodeGen::enumerateChildClasses() { return false; } - int i = 0; - int j = 0; while (true) { - i++; drgn_qualified_type* t; err = drgn_type_iterator_next(typesIterator, &t); if (err) { @@ -1007,7 +1004,6 @@ bool OICodeGen::enumerateChildClasses() { if (!t) { break; } - j++; auto kind = drgn_type_kind(t->type); if (kind != DRGN_TYPE_CLASS && kind != DRGN_TYPE_STRUCT) { diff --git a/oi/OICompiler.cpp b/oi/OICompiler.cpp index a6971fe..1aafd1f 100644 --- a/oi/OICompiler.cpp +++ b/oi/OICompiler.cpp @@ -28,12 +28,13 @@ #include #include #include +#include #include #include #include +#include #include #include -#include #include #include @@ -158,7 +159,7 @@ class OIMemoryManager : public RTDyldMemoryManager { * failure upwards so we can shutdown cleanly. */ if (errorCode) { - report_fatal_error("Can't allocate enough memory: " + + report_fatal_error(llvm::Twine("Can't allocate enough memory: ") + errorCode.message()); } @@ -490,9 +491,9 @@ bool OICompiler::compile(const std::string& code, compInv->getLangOpts()->Char8 = true; compInv->getLangOpts()->CXXOperatorNames = true; compInv->getLangOpts()->DoubleSquareBracketAttributes = true; - compInv->getLangOpts()->ImplicitInt = false; compInv->getLangOpts()->Exceptions = true; compInv->getLangOpts()->CXXExceptions = true; + compInv->getLangOpts()->Coroutines = true; compInv->getPreprocessorOpts(); compInv->getPreprocessorOpts().addRemappedFile( @@ -540,7 +541,8 @@ bool OICompiler::compile(const std::string& code, std::string{"/synthetic/headers/"} + v.second, MemoryBuffer::getMemBuffer(v.first).release()); } - for (const auto& [k, _] : syntheticHeaders) { + for (const auto& kv : syntheticHeaders) { + const auto& k = kv.first; if (config.features[k]) { headerSearchOptions.AddPath( "/synthetic/headers", @@ -552,7 +554,11 @@ bool OICompiler::compile(const std::string& code, compInv->getFrontendOpts().OutputFile = objectPath; compInv->getTargetOpts().Triple = llvm::Triple::normalize(llvm::sys::getProcessTriple()); - compInv->getCodeGenOpts().RelocationModel = llvm::Reloc::Static; + if (config.usePIC) { + compInv->getCodeGenOpts().RelocationModel = llvm::Reloc::PIC_; + } else { + compInv->getCodeGenOpts().RelocationModel = llvm::Reloc::Static; + } compInv->getCodeGenOpts().CodeModel = "large"; compInv->getCodeGenOpts().OptimizationLevel = 3; compInv->getCodeGenOpts().NoUseJumpTables = 1; diff --git a/oi/OICompiler.h b/oi/OICompiler.h index e75518e..d730191 100644 --- a/oi/OICompiler.h +++ b/oi/OICompiler.h @@ -48,6 +48,8 @@ class OICompiler { std::vector userHeaderPaths{}; std::vector sysHeaderPaths{}; + + bool usePIC = false; }; /** diff --git a/oi/OIGenerator.cpp b/oi/OIGenerator.cpp index 28b6f44..0dc1115 100644 --- a/oi/OIGenerator.cpp +++ b/oi/OIGenerator.cpp @@ -187,6 +187,7 @@ int OIGenerator::generate(fs::path& primaryObject, SymbolService& symbols) { OICodeGen::Config generatorConfig{}; OICompiler::Config compilerConfig{}; + compilerConfig.usePIC = pic; auto features = utils::processConfigFile(configFilePath, featuresMap, compilerConfig, generatorConfig); diff --git a/oi/OIGenerator.h b/oi/OIGenerator.h index 24b193e..cc9a32a 100644 --- a/oi/OIGenerator.h +++ b/oi/OIGenerator.h @@ -40,12 +40,16 @@ class OIGenerator { void setFailIfNothingGenerated(bool fail) { failIfNothingGenerated = fail; } + void setUsePIC(bool pic_) { + pic = pic_; + } private: std::filesystem::path outputPath; std::filesystem::path configFilePath; std::filesystem::path sourceFileDumpPath; - bool failIfNothingGenerated; + bool failIfNothingGenerated = false; + bool pic = false; std::unordered_map oilStrongToWeakSymbolsMap( drgnplusplus::program& prog); diff --git a/oi/type_graph/AddChildren.cpp b/oi/type_graph/AddChildren.cpp index 0ff8fc9..4f24029 100644 --- a/oi/type_graph/AddChildren.cpp +++ b/oi/type_graph/AddChildren.cpp @@ -171,10 +171,7 @@ void AddChildren::enumerateChildClasses(SymbolService& symbols) { abort(); } - int i = 0; - int j = 0; while (true) { - i++; drgn_qualified_type* t; err = drgn_type_iterator_next(typesIterator, &t); if (err) { @@ -189,7 +186,6 @@ void AddChildren::enumerateChildClasses(SymbolService& symbols) { if (!t) { break; } - j++; auto kind = drgn_type_kind(t->type); if (kind != DRGN_TYPE_CLASS && kind != DRGN_TYPE_STRUCT) { diff --git a/test/ci.oid.toml b/test/ci.oid.toml index f5b4287..571270e 100644 --- a/test/ci.oid.toml +++ b/test/ci.oid.toml @@ -63,7 +63,7 @@ system_paths = [ "/usr/include/x86_64-linux-gnu/c++/11", "/usr/include/c++/11/backward", "/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", ] diff --git a/test/integration/alignment.toml b/test/integration/alignment.toml index f118548..2d7e845 100644 --- a/test/integration/alignment.toml +++ b/test/integration/alignment.toml @@ -39,12 +39,6 @@ definitions = ''' char c; alignas(32) char c32; }; - - enum class alignas(16) AlignedEnum16 : int8_t { - Val1, - Val2, - Val3, - }; ''' [cases] [cases.wrapper_struct] @@ -212,19 +206,3 @@ definitions = ''' {"typeName": "char", "staticSize": 1, "exclusiveSize": 1}, {"typeName": "char", "staticSize": 1, "exclusiveSize": 1} ]}]}]''' - [cases.wrapper_enum] - param_types = ["const Wrapper&"] - 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&"] - setup = "return {};" - expect_json = '''[ - {"staticSize": 32, "exclusiveSize": 31, "members": [ - {"typeName": "AlignedEnum16", "staticSize": 1, "exclusiveSize": 1} - ]}]''' diff --git a/test/integration_mttest.cpp b/test/integration_mttest.cpp index 83e495c..9263624 100644 --- a/test/integration_mttest.cpp +++ b/test/integration_mttest.cpp @@ -310,13 +310,6 @@ int main(int argc, char* argv[]) { } 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 << "nameList vector addr = " << &nameList << std::endl; diff --git a/test/integration_sleepy.cpp b/test/integration_sleepy.cpp index ade0ad2..7ff7a1a 100644 --- a/test/integration_sleepy.cpp +++ b/test/integration_sleepy.cpp @@ -232,13 +232,6 @@ int main(int argc, char* argv[]) { } 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 << "nameList vector addr = " << &nameList << std::endl; diff --git a/tools/OILGen.cpp b/tools/OILGen.cpp index fb5b67d..52c7811 100644 --- a/tools/OILGen.cpp +++ b/tools/OILGen.cpp @@ -37,6 +37,8 @@ constexpr static OIOpts opts{ "Write generated code to a file (for debugging)."}, OIOpt{'e', "exit-code", no_argument, nullptr, "Return a bad exit code if nothing is generated."}, + OIOpt{'p', "pic", no_argument, nullptr, + "Generate position independent code."}, }; void usage() { @@ -59,6 +61,7 @@ int main(int argc, char* argv[]) { fs::path configFilePath = "/usr/local/share/oi/base.oid.toml"; fs::path sourceFileDumpPath = ""; bool exitCode = false; + bool pic = false; int c; while ((c = getopt_long(argc, argv, opts.shortOpts(), opts.longOpts(), @@ -79,6 +82,9 @@ int main(int argc, char* argv[]) { case 'e': exitCode = true; break; + case 'p': + pic = true; + break; } } @@ -100,6 +106,7 @@ int main(int argc, char* argv[]) { oigen.setConfigFilePath(std::move(configFilePath)); oigen.setSourceFileDumpPath(sourceFileDumpPath); oigen.setFailIfNothingGenerated(exitCode); + oigen.setUsePIC(pic); SymbolService symbols(primaryObject);