Skip to content

Commit

Permalink
Merge pull request #1192 from AntelopeIO/oc_llvm_c++17_only
Browse files Browse the repository at this point in the history
C++20 support - continue to use c++17 on files that use LLVM
  • Loading branch information
spoonincode authored Jul 27, 2023
2 parents 854fbd2 + 66c3045 commit 6ab7c91
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
5 changes: 5 additions & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ if("eos-vm-oc" IN_LIST EOSIO_WASM_RUNTIMES)
webassembly/runtimes/eos-vm-oc.cpp
webassembly/runtimes/eos-vm-oc/default_real_main.cpp)

set_source_files_properties(webassembly/runtimes/eos-vm-oc/LLVMJIT.cpp PROPERTIES COMPILE_FLAGS "--std=gnu++17")
set_source_files_properties(webassembly/runtimes/eos-vm-oc/LLVMEmitIR.cpp PROPERTIES COMPILE_FLAGS "--std=gnu++17")

if(LLVM_VERSION VERSION_LESS 7.1 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
enable_language(ASM-LLVMWAR)
list(APPEND CHAIN_EOSVMOC_SOURCES webassembly/runtimes/eos-vm-oc/llvmWARshim.llvmwar)
set_source_files_properties(webassembly/runtimes/eos-vm-oc/llvmWARshim.llvmwar PROPERTIES COMPILE_FLAGS "--std=gnu++17")
else()
list(APPEND CHAIN_EOSVMOC_SOURCES webassembly/runtimes/eos-vm-oc/llvmWARshim.cpp)
set_source_files_properties(webassembly/runtimes/eos-vm-oc/llvmWARshim.cpp PROPERTIES COMPILE_FLAGS "--std=gnu++17")
endif()

llvm_map_components_to_libnames(LLVM_LIBS support core passes mcjit native orcjit)
Expand Down
18 changes: 18 additions & 0 deletions libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMEmitIR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "Inline/BasicTypes.h"
#include "IR/Module.h"

#include "llvm/IR/Module.h"

#include <vector>
#include <map>

namespace eosio { namespace chain { namespace eosvmoc {

namespace LLVMJIT {
bool getFunctionIndexFromExternalName(const char* externalName,Uptr& outFunctionDefIndex);
const char* getTableSymbolName();
llvm::Module* emitModule(const IR::Module& module);
}
}}}
23 changes: 12 additions & 11 deletions libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*/

#include "LLVMJIT.h"
#include "LLVMEmitIR.h"

#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
Expand All @@ -39,6 +40,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/SymbolSize.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/TargetSelect.h"
Expand All @@ -49,10 +51,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#include "llvm/Transforms/InstCombine/InstCombine.h"
#include "llvm/Transforms/Utils.h"
#include <memory>

#include <fc/io/datastream.hpp>
#include <fc/io/raw.hpp>
#include <fc/reflect/typename.hpp>
#include <unistd.h>

#include "llvm/Support/LEB128.h"

Expand Down Expand Up @@ -151,7 +150,7 @@ namespace LLVMJIT
std::list<std::vector<uint8_t>> stack_sizes;

U8* get_next_code_ptr(uintptr_t numBytes, U32 alignment) {
FC_ASSERT(alignment <= alignof(std::max_align_t), "alignment of section exceeds max_align_t");
WAVM_ASSERT_THROW(alignment <= alignof(std::max_align_t));
uintptr_t p = (uintptr_t)ptr;
p += alignment - 1LL;
p &= ~(alignment - 1LL);
Expand Down Expand Up @@ -306,12 +305,14 @@ namespace LLVMJIT

unsigned num_functions_stack_size_found = 0;
for(const auto& stacksizes : jitModule->unitmemorymanager->stack_sizes) {
fc::datastream<const char*> ds(reinterpret_cast<const char*>(stacksizes.data()), stacksizes.size());
while(ds.remaining()) {
uint64_t funcaddr;
fc::unsigned_int stack_size;
fc::raw::unpack(ds, funcaddr);
fc::raw::unpack(ds, stack_size);
llvm::DataExtractor ds(llvm::ArrayRef(stacksizes.data(), stacksizes.size()), true, 8);
llvm::DataExtractor::Cursor c(0);

while(!ds.eof(c)) {
ds.getAddress(c);
WAVM_ASSERT_THROW(!!c);
const uint64_t stack_size = ds.getULEB128(c);
WAVM_ASSERT_THROW(!!c);

++num_functions_stack_size_found;
if(stack_size > 16u*1024u)
Expand Down
7 changes: 0 additions & 7 deletions libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include "Inline/BasicTypes.h"
#include "IR/Module.h"

#pragma push_macro("N")
#undef N
#include "llvm/IR/Module.h"
#pragma pop_macro("N")
#include <vector>
#include <map>

Expand All @@ -19,9 +15,6 @@ struct instantiated_code {
};

namespace LLVMJIT {
bool getFunctionIndexFromExternalName(const char* externalName,Uptr& outFunctionDefIndex);
const char* getTableSymbolName();
llvm::Module* emitModule(const IR::Module& module);
instantiated_code instantiateModule(const IR::Module& module);
}
}}}

0 comments on commit 6ab7c91

Please sign in to comment.