diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b8f091f8..44b351629 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,10 @@ else(WIN32) -m32 ) + if(ONLY_80386) + add_compile_options(-march=i386) + endif(ONLY_80386) + # 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") diff --git a/build.sh b/build.sh index 7c94cf4a2..46a33960e 100755 --- a/build.sh +++ b/build.sh @@ -25,6 +25,16 @@ CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" CC=${CC:-clang} CXX=${CXX:-clang++} +if [[ -n "${ONLY_80386}" ]]; then + # NOTE(ww): clang's -march=i386 generates instructions for i486 and i586. + # See: https://reviews.llvm.org/D18802 (which was never merged) + if [[ "${CC}" == "clang" ]]; then + echo "80386-only instructions requested, but clang has a buggy -march=i386. Good luck!" + fi + + CMAKE_OPTS="$CMAKE_OPTS -DONLY_80386=1" +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" diff --git a/challenges/Azurad/CMakeLists.txt b/challenges/Azurad/CMakeLists.txt index 3a35022bd..8501ae3b2 100644 --- a/challenges/Azurad/CMakeLists.txt +++ b/challenges/Azurad/CMakeLists.txt @@ -1,6 +1,6 @@ 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() diff --git a/challenges/Blubber/cb_1/src/server.cc b/challenges/Blubber/cb_1/src/server.cc index f9a4a3c46..189e7c989 100644 --- a/challenges/Blubber/cb_1/src/server.cc +++ b/challenges/Blubber/cb_1/src/server.cc @@ -48,7 +48,7 @@ typedef struct bool registered; bool waiting; uint32_t last_read; - blubber* blubber; + blubber* blubber_; } client_state; client_state* new_client(int n) @@ -73,7 +73,7 @@ client_state* new_client(int n) c->last_read = 0; c->registered = false; - c->blubber = new blubber(); + c->blubber_ = new blubber(); return c; } @@ -128,11 +128,11 @@ void handle_read(server_state* s, client_state* c) for (cgc_size_t i = 0; i < s->num_clients; ++i) { client_state* other = s->clients[i]; - if (c->blubber->subs.contains(other->blubber)) + if (c->blubber_->subs.contains(other->blubber_)) { - for (cgc_size_t j = 0; j < other->blubber->blubs.length(); j++) + for (cgc_size_t j = 0; j < other->blubber_->blubs.length(); j++) { - blub* b = (blub*)other->blubber->blubs.get(j); + blub* b = (blub*)other->blubber_->blubs.get(j); if (b->ts > c->last_read) { unread.add(b); @@ -169,11 +169,11 @@ void handle_blub(client_state* c) tmp[BLUB_MAX] = '\0'; dbg("Recorded blub (%s) %d", tmp, cgc_strlen(tmp)) - c->blubber->record_blub(tmp); + c->blubber_->record_blub(tmp); } else { - blub* b = c->blubber->gen_blub(); + blub* b = c->blubber_->gen_blub(); if (b) { dbg("Recorded blub (%s) %d", b->content, cgc_strlen(b->content)); @@ -202,23 +202,23 @@ void handle_reblub(server_state* s, client_state* c) idx = cgc_strtol(num, NULL, 10); - dbg("(%s) attempting to reblub (%s)'s %d blub", c->blubber->username, username, idx); + dbg("(%s) attempting to reblub (%s)'s %d blub", c->blubber_->username, username, idx); for (cgc_size_t i = 0; i < s->num_clients; ++i) { client_state* other = s->clients[i]; // Make sure author exists and client is subbed to them. - if (cgc_strcmp(other->blubber->username, username) == 0 && c->blubber->subs.contains(other->blubber)) + if (cgc_strcmp(other->blubber_->username, username) == 0 && c->blubber_->subs.contains(other->blubber_)) { - dbg("Found (%s) in (%s)'s subs", other->blubber->username, c->blubber->username); - if (other->blubber->blubs.length() > idx) + dbg("Found (%s) in (%s)'s subs", other->blubber_->username, c->blubber_->username); + if (other->blubber_->blubs.length() > idx) { - dbg("Fetching (%s) %d blub", other->blubber->username, idx); - blub* b = (blub*)other->blubber->blubs.get(idx); + dbg("Fetching (%s) %d blub", other->blubber_->username, idx); + blub* b = (blub*)other->blubber_->blubs.get(idx); if (b) { - dbg("(%s) reblubbed (%s)'s %d blub", c->blubber->username, other->blubber->username, idx); - blub* n = new blub(c->blubber->username, b->content); - c->blubber->blubs.add(n); + dbg("(%s) reblubbed (%s)'s %d blub", c->blubber_->username, other->blubber_->username, idx); + blub* n = new blub(c->blubber_->username, b->content); + c->blubber_->blubs.add(n); } } } @@ -235,26 +235,26 @@ void handle_sub(server_state* s, client_state* c) } username[USERNAME_MAX] = '\0'; - dbg("Attempting to sub (%s) to (%s)", c->blubber->username, username); + dbg("Attempting to sub (%s) to (%s)", c->blubber_->username, username); for (cgc_size_t i = 0; i < s->num_clients; ++i) { client_state* other = s->clients[i]; - if (cgc_strcmp(other->blubber->username, username) == 0) + if (cgc_strcmp(other->blubber_->username, username) == 0) { - if (c->blubber->subs.contains(other->blubber)) + if (c->blubber_->subs.contains(other->blubber_)) { - dbg("(%s) is already subbed to (%s)", c->blubber->username, username); + dbg("(%s) is already subbed to (%s)", c->blubber_->username, username); return; } else { - dbg("Subbed (%s) to (%s)", c->blubber->username, username); - c->blubber->subs.add(other->blubber); + dbg("Subbed (%s) to (%s)", c->blubber_->username, username); + c->blubber_->subs.add(other->blubber_); return; } } } - dbg("Failed to sub (%s) to (%s)", c->blubber->username, username); + dbg("Failed to sub (%s) to (%s)", c->blubber_->username, username); } int run_server(server_state* state) @@ -275,7 +275,7 @@ int run_server(server_state* state) dbg("Registered %d as (%s)", c->n, username); cgc_fprintf(c->tx, (char *)"Welcome to blubber, %s" EOT_S, username); c->registered = true; - c->blubber->set_username(username); + c->blubber_->set_username(username); state->num_alive++; } diff --git a/challenges/FailAV/CMakeLists.txt b/challenges/FailAV/CMakeLists.txt index ed717c236..aafd87829 100644 --- a/challenges/FailAV/CMakeLists.txt +++ b/challenges/FailAV/CMakeLists.txt @@ -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 ) set( SERVICE_ID "00091" ) set( AUTHOR_ID "KPRCA" ) buildCB()