From a3905888895a919bf6a8922b65289a8428823b17 Mon Sep 17 00:00:00 2001 From: Daniel Trugman Date: Thu, 16 May 2024 10:48:43 +0100 Subject: [PATCH] Allow compilation of 32-bit on 64-bit machines --- CMakeLists.txt | 6 ++++++ README.md | 2 ++ docker/Dockerfile-debian12 | 2 +- src/mem.cpp | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 294ea22..dbb29e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ endif () # Flags that are NOT expected to be shared when added as sub-directory # ------------------------------------------------------------------------ +option (pfs_BUILD_32BIT "Build a 32-bit executable" OFF) option (pfs_BUILD_COVERAGE "Enable coverage instrumentation" OFF) option (pfs_BUILD_ASAN "Enable address sanitizer" OFF) option (pfs_BUILD_SAMPLES "Build samples" ON) @@ -49,6 +50,11 @@ target_include_directories( $ ) +if (pfs_BUILD_32BIT) + set (pfs_BUILD_32BIT_FLAGS -m32) + target_compile_options (pfs PUBLIC ${pfs_BUILD_32BIT_FLAGS}) +endif () + if (pfs_BUILD_COVERAGE) set (pfs_BUILD_COVERAGE_FLAGS -O0 --coverage) target_compile_options (pfs PUBLIC ${pfs_BUILD_COVERAGE_FLAGS}) diff --git a/README.md b/README.md index a20fbfd..be268ea 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Run `cmake . && make` ### Currently supported CMake configuration flags: - `CMAKE_BUILD_TYPE=`: Standard CMake flags to control build type (DEFAULT: Debug) +- `pfs_BUILD_32BIT=`: ON to compile a 32-bit binary. OFF to compile using the default configuration of your compiler (DEFAULT: `OFF`)) + - You will need the `g++-multilib` package. - `pfs_BUILD_SHARED_LIBS=`: ON to compile a shared library. OFF to compile a static library (DEFAULT: Inherit `BUILD_SHARE_LIBS`, which is `OFF` by default)) - `pfs_BUILD_ASAN=`: ON to enable address sanitizer (DEFAULT: `OFF`) - `pfs_BUILD_SAMPLES=`: ON to build the sample programs (DEFAULT: `ON`) diff --git a/docker/Dockerfile-debian12 b/docker/Dockerfile-debian12 index 86b5eb6..a6a3743 100644 --- a/docker/Dockerfile-debian12 +++ b/docker/Dockerfile-debian12 @@ -1,4 +1,4 @@ -FROM debian:bookworm +FROM i386/debian:bookworm WORKDIR /pfs diff --git a/src/mem.cpp b/src/mem.cpp index 48a833f..da649f5 100644 --- a/src/mem.cpp +++ b/src/mem.cpp @@ -51,7 +51,7 @@ std::vector mem::read(loff_t offset, size_t bytes) struct iovec iov = {&buffer[0], buffer.size()}; - ssize_t bytes_read = preadv64(_fd, &iov, 1, offset); + ssize_t bytes_read = preadv(_fd, &iov, 1, offset); if (bytes_read == -1) { throw std::system_error(errno, std::system_category(),