Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Working builds for macOS, still segfaults on assert
Browse files Browse the repository at this point in the history
  • Loading branch information
larryk85 committed Nov 21, 2018
2 parents d15cdd3 + 27ed56a commit 3290a9a
Show file tree
Hide file tree
Showing 1,040 changed files with 501 additions and 158 deletions.
42 changes: 28 additions & 14 deletions CMakeLists.txt
@@ -1,8 +1,23 @@
cmake_minimum_required(VERSION 3.5)
project(eosio_cdt)

find_program(SCCACHE_FOUND sccache)
if (SCCACHE_FOUND)
message(STATUS "Using sccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE sccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK sccache)
else()
find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
message(STATUS "Using ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif()
endif()


set(VERSION_MAJOR 1)
set(VERSION_MINOR 4)
set(VERSION_MINOR 5)
set(VERSION_PATCH 0)

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
Expand All @@ -14,43 +29,42 @@ endif()

include(GNUInstallDirs)

include(ClangExternalProject.txt)
include(ToolsExternalProject.txt)
include(${CMAKE_SOURCE_DIR}/modules/EosioCDTNative.cmake)

add_subdirectory(external)
include(modules/ClangExternalProject.txt)
include(modules/ToolsExternalProject.txt)
include(modules/EosioCDTNative.cmake)

set(WASM_SDK_BUILD true)

### Configure the EosioWasmToolchain.cmakes
set(CDT_ROOT_DIR ${CMAKE_BINARY_DIR})
configure_file(${CMAKE_SOURCE_DIR}/modules/eosio.cdt-config.cmake ${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/eosio.cdt-config.cmake @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/modules/EosioWasmToolchain.cmake.in ${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/modules/EosioCDTMacros.cmake.in ${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/EosioCDTMacros.cmake @ONLY)

set(CDT_ROOT_DIR ${CMAKE_INSTALL_PREFIX})
configure_file(${CMAKE_SOURCE_DIR}/modules/eosio.cdt-config.cmake ${CMAKE_BINARY_DIR}/modules/eosio.cdt-config.cmake @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/modules/eosio.cdt-config.cmake DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cmake/eosio.cdt)
configure_file(${CMAKE_SOURCE_DIR}/modules/EosioWasmToolchain.cmake.in ${CMAKE_BINARY_DIR}/modules/EosioWasmToolchain.cmake @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/modules/EosioWasmToolchain.cmake DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cmake/eosio.cdt)
configure_file(${CMAKE_SOURCE_DIR}/modules/EosioCDTMacros.cmake.in ${CMAKE_BINARY_DIR}/modules/EosioCDTMacros.cmake @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/modules/EosioCDTMacros.cmake DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cmake/eosio.cdt)

set(CDT_ROOT_DIR "_PREFIX_")
configure_file(${CMAKE_SOURCE_DIR}/modules/EosioWasmToolchain.cmake.in ${CMAKE_BINARY_DIR}/modules/EosioWasmToolchainPackage.cmake @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/modules/EosioCDTMacros.cmake.in ${CMAKE_BINARY_DIR}/modules/EosioCDTMacrosPackage.cmake @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/modules/eosio.cdt-config.cmake ${CMAKE_BINARY_DIR}/modules/eosio.cdt-config.cmake.package @ONLY)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt")
include(EosioWasmToolchain)

add_subdirectory(libraries)
add_subdirectory(tests)
include(modules/LibrariesExternalProject.txt)

include(InstallClang.txt)
include(modules/InstallCDT.cmake)

configure_file(${CMAKE_SOURCE_DIR}/eosio.imports.in ${CMAKE_BINARY_DIR}/eosio.imports COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/imports/eosio.imports.in ${CMAKE_BINARY_DIR}/eosio.imports COPYONLY)
install(FILES ${CMAKE_BINARY_DIR}/eosio.imports DESTINATION ${CMAKE_INSTALL_PREFIX})

configure_file(${CMAKE_SOURCE_DIR}/scripts/ricardeos/ricardeos.py ${CMAKE_BINARY_DIR}/scripts/ricardeos.py COPYONLY)
install(FILES ${CMAKE_BINARY_DIR}/scripts/ricardeos.py DESTINATION ${CMAKE_INSTALL_PREFIX}/scripts)

# section for package construction
set(VENDOR "block.one")
set(PROJECT_NAME "eosio.cdt")
set(DESC "Toolchain and supporting tools for the EOS.IO platform")
Expand All @@ -65,6 +79,6 @@ configure_file(${CMAKE_SOURCE_DIR}/scripts/generate_tarball.sh ${CMAKE_BINARY_DI
# add licenses
configure_file(${CMAKE_SOURCE_DIR}/eosio_llvm/LICENSE.TXT ${CMAKE_BINARY_DIR}/licenses/llvm.license COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/libraries/boost/boost.license ${CMAKE_BINARY_DIR}/licenses/boost.license COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/external/wabt/LICENSE ${CMAKE_BINARY_DIR}/licenses/wabt.license COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/tools/external/wabt/LICENSE ${CMAKE_BINARY_DIR}/licenses/wabt.license COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/tools/jsoncons/LICENSE ${CMAKE_BINARY_DIR}/licenses/jsoncons.license COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/LICENSE ${CMAKE_BINARY_DIR}/licenses/eosio.cdt.license COPYONLY)
25 changes: 18 additions & 7 deletions README.md
@@ -1,5 +1,5 @@
# EOSIO.CDT (Contract Development Toolkit)
## Version : 1.4.0
## Version : 1.4.1

EOSIO.CDT is a toolchain for WebAssembly (WASM) and set of tools to facilitate contract writing for the EOSIO platform. In addition to being a general purpose WebAssembly toolchain, [EOSIO](https://github.com/eosio/eos) specific optimizations are available to support building EOSIO smart contracts. This new toolchain is built around [Clang 7](https://github.com/eosio/llvm), which means that EOSIO.CDT has the most currently available optimizations and analyses from LLVM, but as the WASM target is still considered experimental, some optimizations are not available or incomplete.

Expand All @@ -22,21 +22,32 @@ $ brew remove eosio.cdt
```
#### Debian Package Install
```sh
$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.4.0/eosio.cdt-1.4.0.x86_64.deb
$ sudo apt install ./eosio.cdt-1.4.0.x86_64.deb
$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.4.1/eosio.cdt-1.4.1.x86_64.deb
$ sudo apt install ./eosio.cdt-1.4.1.x86_64.deb
```
#### Debian Package Uninstall
```sh
$ sudo apt remove eosio.cdt
```

#### RPM Package Install
#### Fedora RPM Package Install
```sh
$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.4.0/eosio.cdt-1.4.0.x86_64-0.x86_64.rpm
$ sudo yum install ./eosio.cdt-1.4.0.x86_64-0.x86_64.rpm
$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.4.1/eosio.cdt-fedora-1.4.1.x86_64-0.x86_64.rpm
$ sudo yum install ./eosio.cdt-fedora-1.4.1.x86_64-0.x86_64.rpm
```

#### RPM Package Uninstall
#### Fedora RPM Package Uninstall
```sh
$ sudo yum remove eosio.cdt
```

#### Centos RPM Package Install
```sh
$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.4.1/eosio.cdt-centos-1.4.1.x86_64-0.x86_64.rpm
$ sudo yum install ./eosio.cdt-centos-1.4.1.x86_64-0.x86_64.rpm
```

#### Centos RPM Package Uninstall
```sh
$ sudo yum remove eosio.cdt
```
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -63,7 +63,7 @@ if [[ `uname` == 'Darwin' ]]; then
read -ra FREE_MEM <<< "$FREE_MEM"
FREE_MEM=$((${FREE_MEM[2]%?}*(4096))) # free pages * page size
else
FREE_MEM=`LANG=C free | grep "Mem:" | awk '{print $4}'`
FREE_MEM=`LC_ALL=C free | grep "Mem:" | awk '{print $4}'`
fi

CORES_AVAIL=`getconf _NPROCESSORS_ONLN`
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion libraries/CMakeLists.txt
@@ -1,3 +1,8 @@
project(eosio_libraries)

list(APPEND CMAKE_MODULE_PATH ${EOSIO_CDT_BIN})
include(EosioCDTMacros)

set(CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -O3 -Wall ")
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -O3 -Wall ")

Expand All @@ -6,4 +11,3 @@ add_subdirectory(libc++)
add_subdirectory(eosiolib)
add_subdirectory(boost)
add_subdirectory(crt)
#add_subdirectory(catch2)
3 changes: 1 addition & 2 deletions libraries/boost/CMakeLists.txt
@@ -1,2 +1 @@
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/include/boost DESTINATION ${CMAKE_BINARY_DIR}/include)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/boost DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/include/boost DESTINATION ${BASE_BINARY_DIR}/include)
12 changes: 5 additions & 7 deletions libraries/crt/CMakeLists.txt
@@ -1,14 +1,12 @@
file(GLOB SOURCES _crt.s crt.cpp)
project(crt LANGUAGES CXX ASM)
file(GLOB SOURCES macho_crt.s crt.cpp)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-everything")

add_native_library(crt
${SOURCES})

add_dependencies(crt EosioTools)
target_include_directories(crt PUBLIC ${CMAKE_SOURCE_DIR})
add_dependencies(crt native_eosio)

install(TARGETS crt EXPORT EosioLib
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})

add_custom_command( TARGET crt POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:crt> ${CMAKE_BINARY_DIR}/lib )
add_custom_command( TARGET crt POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:crt> ${BASE_BINARY_DIR}/lib )
10 changes: 5 additions & 5 deletions libraries/crt/crt.cpp
Expand Up @@ -6,7 +6,7 @@
extern "C" {
int main(int, char**);
char* _mmap();

static jmp_buf ___env;
static int ___jmp_ret;
char* ___heap;
Expand Down Expand Up @@ -60,9 +60,6 @@ extern "C" {
}

void printhex(const void* data, uint32_t len) {
char* tmp = (char*)data;
for (int i=0; i < len; i++) {
}
}

void* memset ( void* ptr, int value, size_t num ) {
Expand Down Expand Up @@ -110,9 +107,12 @@ extern "C" {
}
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-noreturn"
void abort() {
eosio_assert(false, "abort");
}
#pragma clang diagnostic pop

void set_blockchain_parameters_packed( char* data, uint32_t datalen ){}
void get_blockchain_parameters_packed( char* data, uint32_t datalen ){}
Expand All @@ -128,7 +128,7 @@ extern "C" {
return (size_t)___heap_ptr;
}

int __wrap_main(int argc, char** argv) {
int _wrap_main(int argc, char** argv) {
int ret_val = 0;
___heap = _mmap();
___heap_ptr = ___heap;
Expand Down
8 changes: 4 additions & 4 deletions libraries/crt/_crt.s → libraries/crt/elf_crt.s
@@ -1,6 +1,6 @@
.global _start
.global ___putc
.global _mmap
.global ____putc
.global __mmap
.global setjmp
.global longjmp
#.type _start,@function
Expand All @@ -18,7 +18,7 @@ _start:
mov $60, %rax
syscall

___putc:
____putc:
dec %rsp
mov %rbx, %r8
mov %rdi, %rax
Expand All @@ -32,7 +32,7 @@ ___putc:
mov %r8, %rbx
ret

_mmap:
__mmap:
mov $9, %eax
mov $0, %rdi
mov $0x6400000, %rsi # 100Mb
Expand Down
70 changes: 70 additions & 0 deletions libraries/crt/macho_crt.s
@@ -0,0 +1,70 @@
.global _start
.global ____putc
.global __mmap
.global setjmp
.global longjmp

_start:
mov %rsp, %rbp
mov 0(%rbp), %rdi
lea 8(%rbp), %rsi
call __wrap_main
mov %rax, %rdi
mov $0x200003C, %rax # exit syscall 0x3C or 60
syscall

____putc:
dec %rsp
mov %rbx, %r8
mov %rdi, %rax
mov %al, 0(%rsp)
mov $1, %edi # using stdout
mov %rsp, %rsi # point to the buffer
mov $1, %edx # buffer is only 1 char
mov $0x2000004, %eax # write syscall 0x4
syscall
inc %rsp
mov %r8, %rbx
ret

__mmap:
mov $0x20000C5, %eax # mmap syscall 0xC5 or 197
mov $0, %rdi # don't map
mov $0x6400000, %rsi # size 100Mb
mov $3, %rdx
mov $0x22, %r10
mov $-1, %r8
mov $0, %r9
syscall
ret

setjmp:
mov %rbx, 0(%rdi)
mov %rbp, 8(%rdi)
mov %r12, 16(%rdi)
mov %r13, 24(%rdi)
mov %r14, 32(%rdi)
mov %r15, 40(%rdi)
lea 8(%rsp), %rdx
mov %rdx, 48(%rdi)
mov (%rsp), %rdx
mov %rdx, 56(%rdi)
xor %rax, %rax
ret

longjmp:
mov %rsi, %rax
test %rax, %rax
jnz 1f
inc %rax
1:
mov 0(%rdi), %rbx
mov 8(%rdi), %rbp
mov 16(%rdi), %r12
mov 24(%rdi), %r13
mov 32(%rdi), %r14
mov 40(%rdi), %r15
mov 48(%rdi), %rdx
mov %rdx, %rsp
mov 56(%rdi), %rdx
jmp *%rdx
Binary file removed libraries/crt/tt
Binary file not shown.
36 changes: 22 additions & 14 deletions libraries/eosiolib/CMakeLists.txt
Expand Up @@ -12,25 +12,33 @@ add_native_library(native_eosio
${HEADERS})

target_include_directories(eosio PUBLIC
"$<BUILD_INTERFACE:${STANDARD_INCLUDES}>"
$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}>)
${CMAKE_SOURCE_DIR}/libc/musl/include
${CMAKE_SOURCE_DIR}/libc/musl/src/internal
${CMAKE_SOURCE_DIR}/libc/musl/src/crypt
${CMAKE_SOURCE_DIR}/libc/musl/arch/eos
{CMAKE_SOURCE_DIR}/libcxx/include
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/boost/include)

target_include_directories(native_eosio PUBLIC
"$<BUILD_INTERFACE:${STANDARD_INCLUDES}>"
$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}>)
${CMAKE_SOURCE_DIR}/libc/musl/include
${CMAKE_SOURCE_DIR}/libc/musl/src/internal
${CMAKE_SOURCE_DIR}/libc/musl/src/crypt
${CMAKE_SOURCE_DIR}/libc/musl/arch/eos
${CMAKE_SOURCE_DIR}/libcxx/include
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/boost/include)

target_link_libraries( eosio c c++ )
target_link_libraries( native_eosio native_c native_c++ )

install(TARGETS eosio EXPORT EosioLib
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../eosiolib DESTINATION ${BASE_BINARY_DIR}/preinclude/eosiolib FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")

install(TARGETS native_eosio EXPORT EosioLib
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
add_custom_command( TARGET eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio> ${BASE_BINARY_DIR}/lib )
add_custom_command( TARGET native_eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:native_eosio> ${BASE_BINARY_DIR}/lib )

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../eosiolib DESTINATION ${CMAKE_BINARY_DIR}/include FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
add_custom_command( TARGET eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio> ${CMAKE_BINARY_DIR}/lib )
add_custom_command( TARGET native_eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:native_eosio> ${CMAKE_BINARY_DIR}/lib )
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../eosiolib DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
add_custom_command( TARGET eosio PRE_BUILD COMMAND rm -rf ${BASE_BINARY_DIR}/include/eosiolib )
add_custom_command( TARGET native_eosio PRE_BUILD COMMAND rm -rf ${BASE_BINARY_DIR}/include/eosiolib )

add_custom_command( TARGET eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${BASE_BINARY_DIR}/preinclude/* ${BASE_BINARY_DIR}/include )
add_custom_command( TARGET native_eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${BASE_BINARY_DIR}/preinclude/* ${BASE_BINARY_DIR}/include )

0 comments on commit 3290a9a

Please sign in to comment.