Skip to content

Commit 37d232b

Browse files
authored
Fix segmentation fault with -march=native (#40)
1 parent bec9cea commit 37d232b

File tree

4 files changed

+78
-45
lines changed

4 files changed

+78
-45
lines changed

.travis.yml

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,65 @@ dist: trusty
44

55
linux64_addons:
66
addons: &linux64
7-
apt:
8-
sources:
9-
- ubuntu-toolchain-r-test
10-
packages:
11-
- g++-4.8
7+
apt:
8+
sources:
9+
- ubuntu-toolchain-r-test
10+
packages:
11+
- g++-4.8
1212

1313
linux32_addons:
1414
addons: &linux32
15-
apt:
16-
sources:
17-
- ubuntu-toolchain-r-test
18-
packages:
19-
- g++-4.8
20-
- g++-4.8-multilib
21-
- linux-libc-dev:i386
22-
- libc6-dev-i386
15+
apt:
16+
sources:
17+
- ubuntu-toolchain-r-test
18+
packages:
19+
- g++-4.8
20+
- g++-4.8-multilib
21+
- linux-libc-dev:i386
22+
- libc6-dev-i386
23+
24+
linux64_cpp17addons:
25+
addons: &linux64cpp17
26+
apt:
27+
sources:
28+
- ubuntu-toolchain-r-test
2329

2430
# Set empty values for allow_failures to work
25-
env:
31+
env: TEST_COMMAND=$TRAVIS_BUILD_DIR/ci/build_and_run_tests.sh
2632

2733
matrix:
28-
fast_finish: true
29-
include:
30-
- os: linux
31-
env: EMSCRIPTEN=ON
32-
addons: *linux64
33-
- os: linux
34-
compiler: clang
35-
addons: *linux64
36-
- os: linux
37-
compiler: gcc
38-
env: ARCH=x86 CMAKE_EXTRA=-DHAVE_LIBM=/lib32/libm.so.6
39-
addons: *linux32
40-
- os: osx
41-
compiler: clang
34+
fast_finish: true
35+
include:
36+
- os: linux
37+
env: EMSCRIPTEN=ON TEST_COMMAND=$TRAVIS_BUILD_DIR/ci/build_and_run_tests.sh
38+
addons: *linux64
39+
- os: linux
40+
compiler: clang
41+
addons: *linux64
42+
- os: linux
43+
compiler: gcc
44+
env: ARCH=x86 CMAKE_EXTRA=-DHAVE_LIBM=/lib32/libm.so.6 TEST_COMMAND=$TRAVIS_BUILD_DIR/ci/build_and_run_tests.sh
45+
addons: *linux32
46+
- os: osx
47+
compiler: clang
48+
- os: linux
49+
compiler: gcc
50+
env: CMAKE_EXTRA="-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS='-march=native'" TEST_COMMAND=$TRAVIS_BUILD_DIR/ci/build_and_run_tests.sh
51+
addons: *linux64cpp17
52+
dist: bionic
53+
- os: linux
54+
compiler: gcc
55+
addons: *linux64cpp17
56+
dist: bionic
57+
4258

4359
before_install:
44-
# Setting environement
45-
- cd $TRAVIS_BUILD_DIR
46-
- source ci/setup-travis.sh
47-
- $CC --version
48-
- $CXX --version
60+
# Setting environement
61+
- cd $TRAVIS_BUILD_DIR
62+
- source ci/setup-travis.sh
63+
- $CC --version
64+
- $CXX --version
4965

5066
script:
51-
- cd $TRAVIS_BUILD_DIR
52-
- mkdir build && cd build
53-
- $CMAKE_CONFIGURE cmake $CMAKE_ARGS $CMAKE_EXTRA ..
54-
- make -j2
55-
- ctest -j2 --output-on-failure
56-
- bash $TRAVIS_BUILD_DIR/ci/travis-test-example.sh
57-
- cd $TRAVIS_BUILD_DIR
67+
- echo $TEST_COMMAND
68+
- (eval "$TEST_COMMAND")

ci/build_and_run_tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set -e
2+
cd $TRAVIS_BUILD_DIR
3+
mkdir build && cd build
4+
$CMAKE_CONFIGURE cmake $CMAKE_ARGS $CMAKE_EXTRA ..
5+
make -j2
6+
ctest -j2 --output-on-failure
7+
bash $TRAVIS_BUILD_DIR/ci/travis-test-example.sh
8+
cd $TRAVIS_BUILD_DIR

ci/setup-travis.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ if [[ "$EMSCRIPTEN" == "ON" ]]; then
2525
fi
2626

2727
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
28-
if [[ "$CC" == "gcc" ]]; then
29-
export CC=gcc-4.8
30-
export CXX=g++-4.8
28+
if [[ "$TRAVIS_DIST" == "trusty" ]]; then
29+
if [[ "$CC" == "gcc" ]]; then
30+
export CC=gcc-4.8
31+
export CXX=g++-4.8
32+
fi
33+
fi
34+
if [[ "$TRAVIS_DIST" == "bionic" ]]; then
35+
if [[ "$CC" == "gcc" ]]; then
36+
export CC=gcc-7
37+
export CXX=g++-7
38+
fi
3139
fi
3240
fi
3341

include/mmtf/binary_decoder.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,17 @@ namespace {
140140

141141
#ifndef __EMSCRIPTEN__
142142
void assignBigendian4(void* dst, const char* src) {
143-
*((uint32_t*)dst) = ntohl(*((uint32_t*)src));
143+
uint32_t tmp;
144+
std::memcpy(&tmp, src, sizeof(uint32_t));
145+
tmp = ntohl(tmp);
146+
std::memcpy(dst, &tmp, sizeof(uint32_t));
144147
}
145148

146149
void assignBigendian2(void* dst, const char* src) {
147-
*((uint16_t*)dst) = ntohs(*((uint16_t*)src));
150+
uint16_t tmp;
151+
std::memcpy(&tmp, src, sizeof(uint16_t));
152+
tmp = ntohs(tmp);
153+
std::memcpy(dst, &tmp, sizeof(uint16_t));
148154
}
149155
#else
150156
// Need to avoid how emscripten handles memory

0 commit comments

Comments
 (0)