Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 64bit compilation #86

Merged
merged 4 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)