Skip to content

Commit

Permalink
Do not build containers with -mach=native/-mtune=native
Browse files Browse the repository at this point in the history
In some cases, the machine building the containers will have
instruction sets that are not supported by the machines running the
containers, causing SIGILL.
  • Loading branch information
lpereira committed May 28, 2022
1 parent 98f102e commit 066b11e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Expand Up @@ -260,8 +260,11 @@ else ()
message(STATUS "Valgrind headers not found -- disabling valgrind support")
endif()

enable_c_flag_if_avail(-mtune=native C_FLAGS_REL LWAN_HAVE_MTUNE_NATIVE)
enable_c_flag_if_avail(-march=native C_FLAGS_REL LWAN_HAVE_MARCH_NATIVE)
option(MTUNE_NATIVE "Build with -mtune=native/-march=native" "ON")
if (MTUNE_NATIVE)
enable_c_flag_if_avail(-mtune=native C_FLAGS_REL LWAN_HAVE_MTUNE_NATIVE)
enable_c_flag_if_avail(-march=native C_FLAGS_REL LWAN_HAVE_MARCH_NATIVE)
endif ()

enable_c_flag_if_avail(-fstack-protector-explicit CMAKE_C_FLAGS
LWAN_HAVE_STACK_PROTECTOR_EXPLICIT)
Expand Down
2 changes: 1 addition & 1 deletion Containerfile
Expand Up @@ -3,7 +3,7 @@ RUN apk add --no-cache gcc make musl-dev cmake pkgconfig linux-headers \
luajit-dev sqlite-dev zlib-dev brotli-dev zstd-dev
COPY . /lwan
WORKDIR /lwan/build
RUN cmake .. -DCMAKE_BUILD_TYPE=Release
RUN cmake .. -DCMAKE_BUILD_TYPE=Release -DMTUNE_NATIVE=OFF
RUN make -j

FROM docker.io/library/alpine:3.14.2
Expand Down
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -159,6 +159,10 @@ names provided in the "Optional dependencies" section.
The `-DUSE_SYSLOG=ON` option can be passed to CMake to also log to the system log
in addition to the standard output.

If you're building Lwan for a distribution, it might be wise to use the
`-DMTUNE_NATIVE=OFF` option, otherwise the generated binary may fail to
run on some computers.

### Tests

~/lwan/build$ make testsuite
Expand Down

0 comments on commit 066b11e

Please sign in to comment.