Fix the GCC build (#40)
* Make it compile with GCC. * Add GCC to CI. * Add warning to documentation about using GCC.
This commit is contained in:
committed by
GitHub
parent
0b64536be4
commit
8fcedfc290
@@ -52,7 +52,10 @@ if(MSVC)
|
|||||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
|
||||||
else()
|
else()
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
add_compile_options(-mcx16 -march=native -Wall -Wextra -Werror -Wsign-conversion -g -fno-exceptions -fno-rtti)
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
add_compile_options(-Wsign-conversion)
|
||||||
|
endif ()
|
||||||
|
add_compile_options(-mcx16 -march=native -Wall -Wextra -Werror -g -fno-exceptions -fno-rtti)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|||||||
@@ -36,8 +36,10 @@ using the Visual Studio compiler.
|
|||||||
# Building on macOS, Linux or FreeBSD
|
# Building on macOS, Linux or FreeBSD
|
||||||
Snmalloc has very few dependencies, CMake, Ninja, Clang 6.0 or later and a C++17
|
Snmalloc has very few dependencies, CMake, Ninja, Clang 6.0 or later and a C++17
|
||||||
standard library.
|
standard library.
|
||||||
Building with GCC is currently not supported because GCC lacks support for the
|
Building with GCC is currently not recommended because GCC lacks support for the
|
||||||
`selectany` attribute to specify variables in a COMDAT.
|
`selectany` attribute to specify variables in a COMDAT.
|
||||||
|
It will, however, build with GCC-7, but some of global variables will be
|
||||||
|
preemptible.
|
||||||
|
|
||||||
To build a debug configuration:
|
To build a debug configuration:
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -92,6 +92,50 @@ phases:
|
|||||||
failOnStderr: true
|
failOnStderr: true
|
||||||
displayName: 'Test'
|
displayName: 'Test'
|
||||||
|
|
||||||
|
- phase: LinuxGCC
|
||||||
|
queue:
|
||||||
|
name: 'Hosted Ubuntu 1604'
|
||||||
|
parallel: 2
|
||||||
|
matrix:
|
||||||
|
Debug:
|
||||||
|
BuildType: Debug
|
||||||
|
Release:
|
||||||
|
BuildType: Release
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- script: |
|
||||||
|
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y ninja-build libc++-dev libc++abi-dev libc++abi1 libstdc++-7-dev gcc-7
|
||||||
|
# sudo apt-get install clang-6.0 clang++-6.0
|
||||||
|
|
||||||
|
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-7 100
|
||||||
|
sudo update-alternatives --set cc /usr/bin/gcc-7
|
||||||
|
|
||||||
|
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-7 100
|
||||||
|
sudo update-alternatives --set c++ /usr/bin/g++-7
|
||||||
|
|
||||||
|
displayName: 'Install Build Dependencies'
|
||||||
|
|
||||||
|
- task: CMake@1
|
||||||
|
displayName: 'CMake .. -GNinja -DCMAKE_BUILD_TYPE=$(BuildType) -DCMAKE_CXX_FLAGS="-std=c++17"'
|
||||||
|
inputs:
|
||||||
|
cmakeArgs: '.. -GNinja -DCMAKE_BUILD_TYPE=$(BuildType) -DCMAKE_CXX_FLAGS="-std=c++17"'
|
||||||
|
|
||||||
|
- script: |
|
||||||
|
ninja
|
||||||
|
|
||||||
|
workingDirectory: build
|
||||||
|
failOnStderr: true
|
||||||
|
displayName: 'Compile'
|
||||||
|
|
||||||
|
- script: |
|
||||||
|
ctest -j 4 --output-on-failure -C $(BuildType)
|
||||||
|
|
||||||
|
workingDirectory: build
|
||||||
|
failOnStderr: true
|
||||||
|
displayName: 'Test'
|
||||||
|
|
||||||
- phase: Windows64bit
|
- phase: Windows64bit
|
||||||
queue:
|
queue:
|
||||||
name: 'Hosted VS2017'
|
name: 'Hosted VS2017'
|
||||||
|
|||||||
@@ -14,7 +14,13 @@
|
|||||||
# include <emmintrin.h>
|
# include <emmintrin.h>
|
||||||
# define ALWAYSINLINE __attribute__((always_inline))
|
# define ALWAYSINLINE __attribute__((always_inline))
|
||||||
# define NOINLINE __attribute__((noinline))
|
# define NOINLINE __attribute__((noinline))
|
||||||
# define HEADER_GLOBAL __attribute__((selectany))
|
# ifdef __clang__
|
||||||
|
# define HEADER_GLOBAL __attribute__((selectany))
|
||||||
|
# else
|
||||||
|
// GCC does not support selectany, weak is almost the correct
|
||||||
|
// attribute, but leaves the global variable preemptible.
|
||||||
|
# define HEADER_GLOBAL __attribute__((weak))
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || \
|
#if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || \
|
||||||
@@ -299,7 +305,8 @@ namespace snmalloc
|
|||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
size_t prod = x * y;
|
size_t prod = x * y;
|
||||||
return y && (x > ((size_t)-1 / y));
|
overflow = y && (x > ((size_t)-1 / y));
|
||||||
|
return prod;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ namespace snmalloc
|
|||||||
template<class T, Construction c = RequiresInit>
|
template<class T, Construction c = RequiresInit>
|
||||||
class MPMCStack
|
class MPMCStack
|
||||||
{
|
{
|
||||||
using ABA = ABA<T, c>;
|
using ABAT = ABA<T, c>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<decltype(T::next), std::atomic<T*>>::value,
|
std::is_same<decltype(T::next), std::atomic<T*>>::value,
|
||||||
"T->next must be a std::atomic<T*>");
|
"T->next must be a std::atomic<T*>");
|
||||||
|
|
||||||
ABA stack;
|
ABAT stack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void push(T* item)
|
void push(T* item)
|
||||||
@@ -29,7 +29,7 @@ namespace snmalloc
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
T* top = ABA::load(cmp);
|
T* top = ABAT::load(cmp);
|
||||||
last->next.store(top, std::memory_order_release);
|
last->next.store(top, std::memory_order_release);
|
||||||
} while (!stack.compare_exchange(cmp, first));
|
} while (!stack.compare_exchange(cmp, first));
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ namespace snmalloc
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
top = ABA::load(cmp);
|
top = ABAT::load(cmp);
|
||||||
|
|
||||||
if (top == nullptr)
|
if (top == nullptr)
|
||||||
break;
|
break;
|
||||||
@@ -63,7 +63,7 @@ namespace snmalloc
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
top = ABA::load(cmp);
|
top = ABAT::load(cmp);
|
||||||
|
|
||||||
if (top == nullptr)
|
if (top == nullptr)
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include "baseslab.h"
|
#include "baseslab.h"
|
||||||
#include "sizeclass.h"
|
#include "sizeclass.h"
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
template<class PAL>
|
template<class PAL>
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ namespace snmalloc
|
|||||||
|
|
||||||
if constexpr (zero_mem == YesZero)
|
if constexpr (zero_mem == YesZero)
|
||||||
zero<true>(p, size);
|
zero<true>(p, size);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UNUSED(p);
|
||||||
|
UNUSED(size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// OS specific function for zeroing memory
|
/// OS specific function for zeroing memory
|
||||||
|
|||||||
@@ -11,4 +11,4 @@
|
|||||||
auto diff__ = finish__ - start__; \
|
auto diff__ = finish__ - start__; \
|
||||||
std::cout << name << ": " << std::setw(12) << diff__.count() << " ns" \
|
std::cout << name << ": " << std::setw(12) << diff__.count() << " ns" \
|
||||||
<< std::endl; \
|
<< std::endl; \
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user