Skip to content

Commit

Permalink
Allow 64bit compilation (#86)
Browse files Browse the repository at this point in the history
* feat: Add 64 bit compilation

* fix: Support multiple host systems

* feat: Revert default build to 32bits

* doc: Update README to reflect changes to default build type.
  • Loading branch information
DarkaMaul authored Mar 31, 2021
1 parent ad66950 commit 9328f80
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 27 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Using this min version for now
cmake_minimum_required(VERSION 3.1)

project(challenge_sets)
project(challenge_sets C CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Needed for newer challenges
Expand Down Expand Up @@ -58,13 +58,8 @@ else(WIN32)
-fcommon
-w
-g3
-m32
)

# Link everything 32-bit (until we have a 64-bit option)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")

# Linker options
# Dynamic by default
option(BUILD_SHARED_LIBS "" ON)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ $ NO_PYTHON_I_KNOW_WHAT_I_AM_DOING_I_SWEAR=1 ./build.sh

This is **not** a publicly supported build mode.

#### Build 64-bits version of the challenges
By default, the build system will build 32 bits version of the challenges.
However, by defining `BUILD64`, the build system will build 64-bits version of the challenges.

```bash
$ BUILD64=1 ./build.sh
```

Note: This has only been tested on *Linux*

### Windows

The following packages are required for building the challenges on Windows:
Expand Down
20 changes: 10 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ if [[ -z "${NO_PYTHON_I_KNOW_WHAT_I_AM_DOING_I_SWEAR}" ]]; then
fi
fi

echo "Creating build directory"
mkdir -p "${DIR}/build"
cd "${DIR}/build"

echo "Creating Makefiles"
CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"

# Honor CC and CXX environment variables, default to clang otherwise
CC=${CC:-clang}
CXX=${CXX:-clang++}
if [ -n "$BUILD64" ]; then
CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_TOOLCHAIN_FILE=../cmake/64.cmake"
BUILD_DIR="build64"
else
CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_TOOLCHAIN_FILE=../cmake/32.cmake"
BUILD_DIR="build"
fi;

CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_C_COMPILER=$CC"
CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_ASM_COMPILER=$CC"
CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_CXX_COMPILER=$CXX"
echo "Creating build directory"
mkdir -p "${DIR}/${BUILD_DIR}"
cd "${DIR}/${BUILD_DIR}"

LINK=${LINK:-SHARED}
case $LINK in
Expand Down
4 changes: 2 additions & 2 deletions challenges/Azurad/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS )
add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS)
set( SERVICE_ID "00119" )
set( AUTHOR_ID "KPRCA" )
add_compile_options( -Oz -g )
add_compile_options( -Os -g )
set( VULN_COUNT "1" )
buildCB()
2 changes: 1 addition & 1 deletion challenges/Blubber/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS )
set( SERVICE_ID "00111" )
set( AUTHOR_ID "KPRCA" )
add_compile_options( -O1 -g )
add_compile_options( -O1 -g -fpermissive -fms-extensions )
set( VULN_COUNT "1" )
buildCB()
2 changes: 1 addition & 1 deletion challenges/CML/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS )
add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS -fpermissive -fms-extensions)
set( SERVICE_ID "00097" )
set( AUTHOR_ID "KPRCA" )
add_compile_options( -O3 -g )
Expand Down
2 changes: 1 addition & 1 deletion challenges/Charter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set( POLLS_TESTING_SEED "-710644949" )
set( POLLS_RELEASE_MAX_DEPTH "20" )
set( POLLS_RELEASE_SEED "40" )
add_compile_options( -O0 -g -mno-sse -fblocks )
add_compile_options( -O0 -g -msse2 -fblocks )
set( SERVICE_ID "00006" )
set( AUTHOR_ID "CROMU" )
set( NO_STRIP "1" )
Expand Down
9 changes: 7 additions & 2 deletions challenges/FUN/lib/cgc_stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;

typedef int intptr_t;
typedef unsigned int uintptr_t;
#ifdef X32_COMPILE
typedef int32_t intptr_t;
typedef uint32_t uintptr_t;
#else
typedef int64_t intptr_t;
typedef uint64_t uintptr_t;
#endif

# define __INT64_C(c) c ## LL
# define __UINT64_C(c) c ## ULL
Expand Down
2 changes: 1 addition & 1 deletion challenges/FailAV/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set( VULN_COUNT "1" )
add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS )
set( override LDFLAGS "-nostdlib -static -Ttext=0x90000000" )
add_compile_options( -Oz -g )
add_compile_options( -Os -g -fpermissive -fms-extensions)
set( SERVICE_ID "00091" )
set( AUTHOR_ID "KPRCA" )
buildCB()
2 changes: 1 addition & 1 deletion challenges/Messaging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS )
set( SERVICE_ID "00075" )
set( AUTHOR_ID "KPRCA" )
add_compile_options( -O3 -g -DDISABLE_HEAP_GUARD )
add_compile_options( -O3 -g -DDISABLE_HEAP_GUARD -fpermissive -fms-extensions )
set( VULN_COUNT "1" )
buildCB()
2 changes: 1 addition & 1 deletion challenges/PTaaS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set( SERVICE_ID "00054" )
set( AUTHOR_ID "NRFIN" )
add_compile_options( -O0 -g -mno-sse )
add_compile_options( -O0 -g -msse2 )
set( VULN_COUNT "1" )
buildCB()
buildSO()
2 changes: 1 addition & 1 deletion challenges/ValveChecks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set( POLLS_TESTING_SEED "1677617456" )
set( POLLS_RELEASE_SEED "1681795162" )
add_compile_options( -mno-sse -O0 -g -fcommon )
add_compile_options( -msse2 -O0 -g -fcommon )
set( SERVICE_ID "00016" )
set( AUTHOR_ID "NRFIN" )
set( POLLS_RELEASE_COUNT "1000" )
Expand Down
20 changes: 20 additions & 0 deletions cmake/32.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(CMAKE_SYSTEM_PROCESSOR i686)

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

if(WIN32)
set(CMAKE_ASM_MASM_COMPILER clang)
else(WIN32)
set(CMAKE_ASM_COMPILER clang)
endif(WIN32)

set(CMAKE_C_FLAGS_INIT -m32)
set(CMAKE_CXX_FLAGS_INIT -m32)
set(CMAKE_ASM_FLAGS_INIT -m32)

set(CMAKE_EXE_LINKER_FLAGS_INIT -m32)
set(CMAKE_SHARED_LINKER_FLAGS_INIT -m32)
set(CMAKE_MODULE_LINKER_FLAGS_INIT -m32)

add_compile_definitions(X32_COMPILE)
10 changes: 10 additions & 0 deletions cmake/64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(CMAKE_SYSTEM_PROCESSOR amd64)

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

if(WIN32)
set(CMAKE_ASM_MASM_COMPILER clang)
else(WIN32)
set(CMAKE_ASM_COMPILER clang)
endif(WIN32)

2 comments on commit 9328f80

@halsalem
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi I have this error while trying to rub build.sh on linux. How can fix it?
Creating Makefiles
Creating build directory
CMake Error at cmake/32.cmake:20 (add_compile_definitions):
Unknown CMake command "add_compile_definitions".
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/CMakeDetermineSystem.cmake:91 (include)
CMakeLists.txt:4 (project)

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!

@ReversingWithMe
Copy link

@ReversingWithMe ReversingWithMe commented on 9328f80 Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi I have this error while trying to rub build.sh on linux. How can fix it?
Creating Makefiles
Creating build directory
CMake Error at cmake/32.cmake:20 (add_compile_definitions):
Unknown CMake command "add_compile_definitions".
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/CMakeDetermineSystem.cmake:91 (include)
CMakeLists.txt:4 (project)

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!

I think Cmake version minimum needs to updated to 3.12 for that function

https://github.com/trailofbits/cb-multios/blob/master/CMakeLists.txt#L2
cmake_minimum_required(VERSION 3.1) ->
cmake_minimum_required(VERSION 3.12)

Please sign in to comment.