Commit c0716c2c by Thomas Barabosch Committed by Enkelmann

Build artificial samples with scons instead of make (#16)

* Building artificial samples with scons-2, removed makefile
parent 6ea36ce1
...@@ -218,3 +218,5 @@ src/cwe_checker.plugin ...@@ -218,3 +218,5 @@ src/cwe_checker.plugin
test/artificial_samples/dockcross* test/artificial_samples/dockcross*
.#* .#*
.sconsign.dblite
\ No newline at end of file
...@@ -7,7 +7,7 @@ services: ...@@ -7,7 +7,7 @@ services:
install: install:
- sudo apt-get update - sudo apt-get update
- sudo apt-get install -y execstack - pip install --user scons
- docker - docker
before_script: before_script:
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
#!/bin/bash #!/bin/bash
cd test/artificial_samples/ cd test/artificial_samples/
./install_cross_compilers.sh ./install_cross_compilers.sh
make scons
cd ../.. cd ../..
docker build -t cwe-checker . docker build -t cwe-checker .
0.2-dev (2019-XX-XX) 0.2-dev (2019-XX-XX)
===== =====
- Refactoring: Unification of cwe_checker function interface - Refactoring: Unification of cwe_checker function interface
- Refactoring: Created utils module for JSON functionality - Refactoring: Created utils module for JSON functionality
- Added check for CWE 248: Uncaught Exception (PR #5) - Added check for CWE 248: Uncaught Exception (PR #5)
- Added automated test suite (run with make test) (PR #7) - Added automated test suite (run with make test) (PR #7)
- Improved cross compiling for acceptance test cases by using dockcross (PR #8) - Improved cross compiling for acceptance test cases by using dockcross (PR #8)
- Added BAP recipe for standard cwe_checker run (PR #9) - Added BAP recipe for standard cwe_checker run (PR #9)
- Improved check for CWE-476 (NULL Pointer Dereference) using data flow analysis (PR #11) - Improved check for CWE-476 (NULL Pointer Dereference) using data flow analysis (PR #11)
- Switched C build system from make to scons (PR #16)
0.1 (2018-10-08) 0.1 (2018-10-08)
===== =====
......
import os
build_path = 'build'
supported_architectures = ['x64', 'x86', 'arm', 'mips', 'ppc']
c_compilers = {'x64': 'gcc',
'x86': './dockcross-linux-x86 gcc',
'arm': 'arm-linux-gnueabi-gcc',
'mips': 'mips-linux-gnu-gcc',
'ppc': 'powerpc-linux-gnu-gcc'}
cpp_compilers = {'x64': 'g++',
'x86': './dockcross-linux-x86 g++',
'arm': 'arm-linux-gnueabi-g++-5',
'mips': 'mips-linux-gnu-g++-5',
'ppc': 'powerpc-linux-gnu-g++-5'}
c_flags = {'x64': '-g -fno-stack-protector -std=c11',
'x86': '-g -m32 -fno-stack-protector -std=c11',
'arm': '-g -fno-stack-protector -std=c11',
'mips': '-g -fno-stack-protector -std=c11',
'ppc': '-g -fno-stack-protector -std=c11'}
cpp_flags = {'x64': '-g -fno-stack-protector',
'x86': '-g -m32 -fno-stack-protector',
'arm': '-g -fno-stack-protector',
'mips': '-g -fno-stack-protector',
'ppc': '-g -fno-stack-protector'}
def which(pgm):
path=os.getenv('PATH')
for p in path.split(os.path.pathsep):
p=os.path.join(p,pgm)
if os.path.exists(p) and os.access(p,os.X_OK):
return p
def optimize(filename):
optimize_me = ['cwe_476.c']
if filename in optimize_me:
return ' -O3'
else:
return ' -O0'
def compile_only_on_x64(filename, arch):
only_x64 = ['cwe_782.c']
return filename in only_x64 and arch != 'x64'
def build_c(arch):
if which(c_compilers[arch]) is not None:
c_programs = Glob('*.c')
for p in c_programs:
if compile_only_on_x64(str(p), arch):
print('Skipping architecture %s for %s' % (arch, str(p)))
continue
env = Environment(CC = c_compilers[arch],
CCFLAGS = c_flags[arch] + optimize(str(p)))
print(str(p))
env.Program('%s/%s_%s.out' % (build_path, str(p).split('.')[0], arch),
env.Object(target='%s/%s_%s.o' % (build_path, str(p), arch),
source='%s/%s' % (build_path, str(p))))
else:
print('Compiler %s for architecture %s is not installed!' % (c_compilers[arch], arch))
def build_cpp(arch):
if which(cpp_compilers[arch]) is not None:
cpp_programs = Glob('*.cpp')
for p in cpp_programs:
env = Environment(CC = cpp_compilers[arch],
CCFLAGS = cpp_flags[arch] + optimize(str(p)))
env.Program('%s/%s_%s.out' % (build_path, str(p).split('.')[0], arch),
'%s/%s' % (build_path, str(p)))
else:
print('Compiler %s for architecture %s is not installed!' % (cpp_compilers[arch], arch))
VariantDir(build_path, '.', duplicate=0)
for arch in supported_architectures:
print('Building for architecture %s' % arch)
build_c(arch)
build_cpp(arch)
CC_x64=gcc
CC_X86=./dockcross-linux-x86 gcc
CC_ARM=arm-linux-gnueabi-gcc
CC_MIPS=mips-linux-gnu-gcc
CC_PPC=powerpc-linux-gnu-gcc
CPP_x64=g++
CPP_X86=./dockcross-linux-x86 g++
CPP_ARM=arm-linux-gnueabi-g++-5
CPP_MIPS=mips-linux-gnu-g++-5
CPP_PPC=powerpc-linux-gnu-g++-5
CFLAGS_X64=-g -fno-stack-protector -std=c11
CFLAGS_X86=-g -m32 -fno-stack-protector -std=c11
CFLAGS_ARM=-g -fno-stack-protector -std=c11
CFLAGS_MIPS=-g -fno-stack-protector -std=c11
CFLAGS_PPC=-g -fno-stack-protector -std=c11
CPPFLAGS_X64=-g -fno-stack-protector
CPPFLAGS_X86=-g -m32 -fno-stack-protector
CPPFLAGS_ARM=-g -fno-stack-protector
CPPFLAGS_MIPS=-g -fno-stack-protector
CPPFLAGS_PPC=-g -fno-stack-protector
OPTIMIZE=-O3
NO_OPTIMIZE=-O0
define compile_x64
@echo "Compiling x64 target:" $(1)
$(CC_x64) $(CFLAGS_X64) $(2) -o build/$(1)_x64.out $(1).c
execstack -s build/$(1)_x64.out
endef
define compile_x64_cpp
@echo "Compiling x64 target:" $(1)
$(CPP_x64) $(CPPFLAGS_X64) $(2) -o build/$(1)_x64.out $(1).cpp
execstack -s build/$(1)_x64.out
endef
define compile_x86
@echo "Compiling x86 target:" $(1)
$(CC_X86) $(CFLAGS_X86) $(2) -o build/$(1)_x86.out $(1).c
execstack -s build/$(1)_x86.out
endef
define compile_x86_cpp
@echo "Compiling x86 target:" $(1)
$(CPP_X86) $(CPPFLAGS_X86) $(2) -o build/$(1)_x86.out $(1).cpp
execstack -s build/$(1)_x86.out
endef
define compile_mips
@echo "Compiling mips target:" $(1)
$(CC_MIPS) $(CFLAGS_MIPS) $(2) -o build/$(1)_mips.out $(1).c
execstack -s build/$(1)_mips.out
endef
define compile_mips_cpp
@echo "Compiling mips target:" $(1)
$(CPP_MIPS) $(CPPFLAGS_MIPS) $(2) -o build/$(1)_mips.out $(1).cpp
execstack -s build/$(1)_mips.out
endef
define compile_arm
@echo "Compiling arm target:" $(1)
$(CC_ARM) $(CFLAGS_ARM) $(2) -o build/$(1)_arm.out $(1).c
execstack -s build/$(1)_arm.out
endef
define compile_arm_cpp
@echo "Compiling arm target:" $(1)
$(CPP_ARM) $(CPPFLAGS_ARM) $(2) -o build/$(1)_arm.out $(1).cpp
execstack -s build/$(1)_arm.out
endef
define compile_ppc
@echo "Compiling ppc target:" $(1)
$(CC_PPC) $(CFLAGS_PPC) $(2) -o build/$(1)_ppc.out $(1).c
execstack -s build/$(1)_ppc.out
endef
define compile_ppc_cpp
@echo "Compiling ppc target:" $(1)
$(CPP_PPC) $(CPPFLAGS_PPC) $(2) -o build/$(1)_ppc.out $(1).cpp
execstack -s build/$(1)_ppc.out
endef
define compile_all
$(shell mkdir -p "build")
$(call compile_x64,$(1),$(2))
$(call compile_x86,$(1),$(2))
$(call compile_arm,$(1),$(2))
$(call compile_mips,$(1),$(2))
$(call compile_ppc,$(1),$(2))
endef
define compile_all_cpp
$(shell mkdir -p "build")
$(call compile_x64_cpp,$(1),$(2))
$(call compile_x86_cpp,$(1),$(2))
$(call compile_arm_cpp,$(1),$(2))
$(call compile_mips_cpp,$(1),$(2))
$(call compile_ppc_cpp,$(1),$(2))
endef
all:
$(call compile_all,c_constructs,$(NO_OPTIMIZE))
$(call compile_all,cwe_190,$(NO_OPTIMIZE))
$(call compile_all,cwe_243,$(NO_OPTIMIZE))
$(call compile_all,cwe_243_clean,$(NO_OPTIMIZE))
$(call compile_all_cpp,cwe_248,$(NO_OPTIMIZE))
$(call compile_all,cwe_332,$(NO_OPTIMIZE))
$(call compile_all,cwe_367,$(NO_OPTIMIZE))
$(call compile_all,cwe_415,$(NO_OPTIMIZE))
$(call compile_all,cwe_426,$(NO_OPTIMIZE))
$(call compile_all,cwe_457,$(NO_OPTIMIZE))
$(call compile_all,cwe_467,$(NO_OPTIMIZE))
$(call compile_all,cwe_476,$(OPTIMIZE))
$(call compile_all,cwe_478,$(NO_OPTIMIZE))
$(call compile_all,cwe_676,$(NO_OPTIMIZE))
$(call compile_x64,cwe_782,$(NO_OPTIMIZE))
$(call compile_all,arrays,$(NO_OPTIMIZE))
$(call compile_all,memory_access,$(NO_OPTIMIZE))
clean:
rm -rf build
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment