diff --git a/temp_delete_when_merge/build_all.py b/temp_delete_when_merge/build_all.py deleted file mode 100755 index c9027f031d..0000000000 --- a/temp_delete_when_merge/build_all.py +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/python3 - -import os - -os.system("rm -f *.ll") - -SIG_DIR='sigs' - -COMPILE_CMD = """clang-16 \ - -S \ - -fno-discard-value-names \ - -fno-vectorize \ - --language=c \ - -emit-llvm \ - -Werror=unused-command-line-argument \ - -Xclang \ - -disable-O0-optnone \ - %s \ - -o \ - %s \ - -I \ - /home/aragusa/clamav-bytecode-compiler-aragusa/headers \ - -include \ - bytecode.h \ - -D__CLAMBC__""" - -OPTIONS_STR='--disable-loop-unrolling' -OPTIONS_STR+=" --disable-i2p-p2i-opt" -OPTIONS_STR+=" --disable-loop-unrolling" -OPTIONS_STR+=" --disable-promote-alloca-to-lds" -OPTIONS_STR+=" --disable-promote-alloca-to-vector" -OPTIONS_STR+=" --disable-simplify-libcalls" -OPTIONS_STR+=" --disable-tail-calls" -#OPTIONS_STR+=" --polly-vectorizer=none" -#OPTIONS_STR+=" --loop-vectorize" -OPTIONS_STR+=" --vectorize-slp=false" -OPTIONS_STR+=" --vectorize-loops=false" -#OPTIONS_STR+=" --disable-loop-vectorization" - - - -internalizeAPIList = "_Z10entrypointv,entrypoint,__clambc_kind,__clambc_virusname_prefix,__clambc_virusnames,__clambc_filesize,__clambc_match_counts,__clambc_match_offsets,__clambc_pedata,__Copyright" - -OPTIONS_STR+=f' -internalize-public-api-list="{internalizeAPIList}"' - -PASS_STR = "function(mem2reg)" -PASS_STR+=',' -PASS_STR+='clambc-remove-undefs' -PASS_STR+=',verify' -PASS_STR+=',clambc-preserve-abis' -PASS_STR+=',verify' -PASS_STR+=',default' -#PASS_STR+=',default' -PASS_STR+=',globalopt' -PASS_STR+=',clambc-preserve-abis' #remove fake function calls because O3 has already run -PASS_STR+=',verify' -#PASS_STR+=',clambc-remove-umin' -#PASS_STR+=',verify' -#PASS_STR+=',clambc-remove-umax' -#PASS_STR+=',verify' -#PASS_STR+=',clambc-remove-smax' -PASS_STR+=',clambc-remove-unsupported-icmp-intrinsics' -PASS_STR+=',verify' -PASS_STR+=',clambc-remove-usub' -PASS_STR+=',verify' -PASS_STR+=',clambc-remove-fshl' -PASS_STR+=',verify' -PASS_STR+=',clambc-remove-pointer-phis' -#PASS_STR+=',function(clambc-remove-pointer-phis)' -PASS_STR+=',verify' -PASS_STR+=',clambc-lowering-notfinal' # perform lowering pass -PASS_STR+=',verify' -PASS_STR+=',lowerswitch' -PASS_STR+=',verify' -PASS_STR+=',clambc-remove-icmp-sle' -PASS_STR+=',verify' -PASS_STR+=',function(clambc-verifier)' -PASS_STR+=',verify' -PASS_STR+=',clambc-remove-freeze-insts' -PASS_STR+=',verify' -PASS_STR+=',clambc-lowering-notfinal' # perform lowering pass -PASS_STR+=',verify' -PASS_STR+=',clambc-lcompiler-helper' #compile the logical_trigger function to a -PASS_STR+=',verify' -PASS_STR+=',clambc-lcompiler' #compile the logical_trigger function to a -PASS_STR+=',verify' -PASS_STR+=',internalize' -PASS_STR+=',verify' -PASS_STR+=',clambc-rebuild' -PASS_STR+=',verify' -PASS_STR+=',clambc-trace' -PASS_STR+=',verify' -PASS_STR+=',clambc-outline-endianness-calls' -PASS_STR+=',verify' -PASS_STR+=',clambc-change-malloc-arg-size' -PASS_STR+=',verify' -PASS_STR+=',clambc-extend-phis-to-64-bit' -PASS_STR+=',verify' -PASS_STR+=',clambc-convert-intrinsics' -PASS_STR+=',verify' -PASS_STR+=',globalopt' -PASS_STR+=',clambc-prepare-geps-for-writer' -PASS_STR+=',verify' -PASS_STR+=',clambc-writer' -PASS_STR+=',verify' - - - - -INSTALL_DIR=os.path.join(os.getcwd(), "..") -LOAD_STR = "" -LOAD_STR += "--load %s/install/lib/libclambccommon.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremoveundefs.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcpreserveabis.so " % INSTALL_DIR -#LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremoveumin.so " % INSTALL_DIR -#LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremoveumax.so " % INSTALL_DIR -#LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremovesmax.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremoveunsupportedicmpintrinsics.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremoveusub.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremovefshl.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremovepointerphis.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcloweringnf.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremoveicmpsle.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcverifier.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcremovefreezeinsts.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcloweringf.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambclogicalcompilerhelper.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambclogicalcompiler.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcrebuild.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambctrace.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcoutlineendiannesscalls.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcchangemallocargsize.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcextendphisto64bit.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcconvertintrinsics.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcpreparegepsforwriter.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcanalyzer.so " % INSTALL_DIR -#LOAD_STR += " --load-pass-plugin %s/install/lib/libclambctypeanalyzer.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcregalloc.so " % INSTALL_DIR -LOAD_STR += " --load-pass-plugin %s/install/lib/libclambcwriter.so " % INSTALL_DIR - - -#wd = os.getcwd() -#os.chdir(os.path.join(INSTALL_DIR, "install")) - -#os.system("tar xvf lib.tar") - - -#os.chdir(wd) - - - - - - - -#OPT_CMD = 'opt-16 -S %s --passes=\"-mem2reg\" --passes=\"%s\" %s ' % (LOAD_STR, PASS_STR, OPTIONS_STR) -OPT_CMD = 'opt-16 -S %s --passes=\"%s\" %s ' % (LOAD_STR, PASS_STR, OPTIONS_STR) - - -#print ("Re-evaluate here") -#print ("Disabling opaque pointers here") -OPT_CMD += " -opaque-pointers=0 " -COMPILE_CMD += " -Xclang -no-opaque-pointers " - -""" -#This is to find undefs. -print ("Take this part out, used to find undefs") -#PASS_STR = 'default' -OPTIONS_STR = '' -OPTIONS_STR+=" --vectorize-slp=false" -OPTIONS_STR+=" --vectorize-loops=false" -OPT_CMD = 'opt-16 -S %s --passes=\"%s\" %s ' % (LOAD_STR, PASS_STR, OPTIONS_STR) -""" - - - -OPT_CMD += "%s -o %s" - - - - - - -def run(cmd): - return os.system(cmd) - - -def compileFile(d, name): - llFile = name[:-1] + "ll" - - cmd = COMPILE_CMD % (os.path.join(d,name), llFile) - if (run(cmd)): - return - - cmd = OPT_CMD % (llFile, llFile + ".optimized.ll") - print (cmd) - - return run(cmd) - - -if '__main__' == __name__: - for s in os.listdir(SIG_DIR): - if (compileFile(SIG_DIR, s)): - print (f"Failed on {s}") - break -# os.system("rm -f *.ll") - - - - diff --git a/temp_delete_when_merge/run_opt.sh b/temp_delete_when_merge/run_opt.sh deleted file mode 100755 index f6262ecfc4..0000000000 --- a/temp_delete_when_merge/run_opt.sh +++ /dev/null @@ -1,153 +0,0 @@ -#!/bin/bash - - -#might be useful -#https://stackoverflow.com/questions/67206238/how-to-define-and-read-cli-arguments-for-an-llvm-pass-with-the-new-pass-manager - -OPTIONS_STR='--disable-loop-unrolling' -OPTIONS_STR="$OPTIONS_STR --disable-i2p-p2i-opt" -OPTIONS_STR="$OPTIONS_STR --disable-loop-unrolling" -OPTIONS_STR="$OPTIONS_STR --disable-promote-alloca-to-lds" -OPTIONS_STR="$OPTIONS_STR --disable-promote-alloca-to-vector" -OPTIONS_STR="$OPTIONS_STR --disable-simplify-libcalls" -OPTIONS_STR="$OPTIONS_STR --disable-tail-calls" - - - - - - - - - -PASS_STR='clambc-remove-undefs' -PASS_STR=$PASS_STR,'clambc-preserve-abis' -PASS_STR=$PASS_STR,'default' -PASS_STR=$PASS_STR,'clambc-preserve-abis' #remove fake function calls because O3 has already run -PASS_STR=$PASS_STR,'function(clambc-remove-pointer-phis)' -#PASS_STR=$PASS_STR,'dce' -#PASS_STR=$PASS_STR,'globaldce' -#PASS_STR=$PASS_STR,'strip-dead-prototypes' -#PASS_STR=$PASS_STR,'constmerge' -#PASS_STR=$PASS_STR,'mem2reg' -#PASS_STR=$PASS_STR,'always-inline' -#PASS_STR=$PASS_STR,'globalopt' -#PASS_STR=$PASS_STR,'lowerswitch' -#PASS_STR=$PASS_STR,'lowerinvoke' -#PASS_STR=$PASS_STR,'globalopt' -#PASS_STR=$PASS_STR,'simplifycfg' -#PASS_STR=$PASS_STR,'indvars' -#PASS_STR=$PASS_STR,'constprop' #figure this out later -PASS_STR=$PASS_STR,'clambc-lowering-notfinal' # perform lowering pass -PASS_STR=$PASS_STR,'lowerswitch' -PASS_STR=$PASS_STR,'function(clambc-verifier)' -PASS_STR=$PASS_STR,'clambc-lowering-notfinal' # perform lowering pass -#PASS_STR=$PASS_STR,'dce' -#PASS_STR=$PASS_STR,'simplifycfg' -#PASS_STR=$PASS_STR,'mem2reg' -PASS_STR=$PASS_STR,'clambc-lcompiler' #compile the logical_trigger function to a -# #logical signature. -#PASS_STR=$PASS_STR,'internalize -internalize-public-api-list="{internalizeAPIList}"' -#PASS_STR=$PASS_STR,'globaldce' -#PASS_STR=$PASS_STR,'instcombine' -PASS_STR=$PASS_STR,'clambc-rebuild' -#PASS_STR=$PASS_STR,'verify' -#PASS_STR=$PASS_STR,'simplifycfg' -#PASS_STR=$PASS_STR,'dce' -#PASS_STR=$PASS_STR,'lowerswitch' -#PASS_STR=$PASS_STR,'clambc-verifier' -#PASS_STR=$PASS_STR,'verify' -#PASS_STR=$PASS_STR,'strip-debug-declare' -#PASS_STR=$PASS_STR,'clambc-lowering-final' -#PASS_STR=$PASS_STR,'clambc-trace' -#PASS_STR=$PASS_STR,'dce' -#PASS_STR=$PASS_STR,'clambc-module' -#PASS_STR=$PASS_STR,'verify' -#PASS_STR=$PASS_STR,'globalopt' -#PASS_STR=$PASS_STR,'remove-selects' -#PASS_STR=$PASS_STR,'clambc-outline-endianness-calls' #outline the endianness calls -# #because otherwise the call -# #is replaced with a constant -# #that is based on where the -# #signature was compiled, and -# #won't always be accurate. -#PASS_STR=$PASS_STR,'clambc-change-malloc-arg-size' #make sure we always use the -# #64-bit malloc. -#PASS_STR=$PASS_STR,'globalopt' -#PASS_STR=$PASS_STR,'clambc-extend-phis-to-64bit' #make all integer phi nodes 64-bit -# #because the llvm runtime inserts a -# #cast after phi nodes without -# #verifying that there is not -# #another phi node after it. -#PASS_STR=$PASS_STR,'clambc-prepare-geps-for-writer' #format gep indexes to not not -# #have more than 2, because -# #otherwise the writer gets -# #unhappy. -#PASS_STR=$PASS_STR,'globalopt' -#PASS_STR=$PASS_STR,'clambc-convert-intrinsics' #convert all memset intrinsics to -# #the 32-bit instead of the 64-bit -# #intrinsic -#PASS_STR=$PASS_STR,'clambc-writer' #write the bytecode -#PASS_STR=$PASS_STR,'clambc-writer-input-source={inputSourceFile}' -#PASS_STR=$PASS_STR,'clambc-sigfile={sigFile}' -# - - - - - - - -INSTALL_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" - -clang-16 -S -fno-discard-value-names -emit-llvm -O0 -Xclang -disable-O0-optnone $INSTALL_DIR/testing/test.c - -#opt-16 -S \ -# --load $INSTALL_DIR/install/lib/libclambccommon.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcremoveundefs.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcpreserveabis.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcanalyzer.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcremovepointerphis.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcloweringf.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcloweringnf.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcverifier.so \ -# --passes="-mem2reg"\ -# --passes="clambc-remove-undefs,clambc-preserve-abis,default,clambc-preserve-abis,function(clambc-remove-pointer-phis),dce,clambc-lowering-notfinal,clambc-lowering-final,function(clambc-verifier)" \ -# test.ll -o test.t.ll - - - - -#opt-16 -S \ -# --load $INSTALL_DIR/install/lib/libclambccommon.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcremoveundefs.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcpreserveabis.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcanalyzer.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcremovepointerphis.so \ -# --load-pass-plugin $INSTALL_DIR/install/lib/libclambcverifier.so \ -# --passes="-mem2reg"\ -# --passes="clambc-remove-undefs,clambc-preserve-abis,default,clambc-preserve-abis,function(clambc-remove-pointer-phis),dce,function(clambc-verifier)" \ -# test.ll -o test.t.ll -# - - - -opt-16 -S \ - --load $INSTALL_DIR/install/lib/libclambccommon.so \ - --load-pass-plugin $INSTALL_DIR/install/lib/libclambcremoveundefs.so \ - --load-pass-plugin $INSTALL_DIR/install/lib/libclambcpreserveabis.so \ - --load-pass-plugin $INSTALL_DIR/install/lib/libclambcanalyzer.so \ - --load-pass-plugin $INSTALL_DIR/install/lib/libclambcremovepointerphis.so \ - --load-pass-plugin $INSTALL_DIR/install/lib/libclambcloweringf.so \ - --load-pass-plugin $INSTALL_DIR/install/lib/libclambcloweringnf.so \ - --load-pass-plugin $INSTALL_DIR/install/lib/libclambcverifier.so \ - --load-pass-plugin $INSTALL_DIR/install/lib/libclambclogicalcompiler.so \ - --load-pass-plugin $INSTALL_DIR/install/lib/libclambcrebuild.so \ - --passes="$PASS_STR" \ - $OPTIONS_STR \ - test.ll -o test.t.ll - - - - - diff --git a/temp_delete_when_merge/testing/test.c b/temp_delete_when_merge/testing/test.c deleted file mode 100644 index 4ea722edd8..0000000000 --- a/temp_delete_when_merge/testing/test.c +++ /dev/null @@ -1,196 +0,0 @@ -#include -#include -#include -#include - - -int getBufferLen(const char * const buffer){ - int j; - for (j = 0; 0 != buffer[j]; j++) - ; - return j; -} - - -#if 0 -char* encodeUInt_getridofthis(int inval, char buffer[1024], int * size){ - int bufferSize = sizeof(buffer); - - int i; - int idx = bufferSize - 1; - *size = 0; - - for (i = 0; i < bufferSize; i++){ - buffer[i] = 0; - } - - while (inval){ - buffer[idx--] = '0' + (inval - (10 * (inval / 10))); - (*size)++; - - inval /= 10; - } - - idx++; - - return &(buffer[idx]); -} -#endif - - - - -char* encodeUInt(int inval, char * buffer, int bufferSize, int * size){ - - int i; - int idx = bufferSize - 1; - *size = 0; - - for (i = 0; i < bufferSize; i++){ - buffer[i] = 0; - } - - while (inval){ - buffer[idx--] = '0' + (inval - (10 * (inval / 10))); - (*size)++; - - inval /= 10; - } - - idx++; - - return &(buffer[idx]); -} - - -void andyprintf(const char * const formatStr, ...) __attribute__((always_inline)) { - int i; - char buffer[1024]; - - // Declaring pointer to the - // argument list - va_list ptr; - - // Initializing argument to the - // list pointer - va_start(ptr, formatStr); - - for (i = 0; 0 != formatStr[i]; ){ - if ('%' == formatStr[i]){ - i++; - if ('d' == formatStr[i]){ - int tmp = va_arg(ptr, int); - int len; - char * cp = encodeUInt(tmp, buffer, sizeof(buffer), &len); - write(1, cp, len); - } else if ('s' == formatStr[i]){ - const char * const tmp = va_arg(ptr, char*); - int len = getBufferLen(buffer); - write(1, buffer, len); - } - } else { - write(1, &(formatStr[i]), 1); - } - - - - - i++; - } - - // Ending argument list traversal - va_end(ptr); - - - -} - -#define PRINTSTR(__str__) { \ - int i = 0; \ - while (0 != __str__[i]) { \ - write(1, &(__str__[i]), 1) ; \ - } \ -} - -#define PRINTINT(__val__) { \ - int len; \ - char * cp = encodeUInt(__val__, buffer, sizeof(buffer), &len); \ - write(1, cp, len); \ -} - -void func(int val){ -#if 0 - andyprintf("%s::%d\n", __FUNCTION__, __LINE__); -#else - PRINTSTR(__FUNCTION__); - PRINTSTR("\n"); -#endif -} - - -typedef struct s *sp; - -static sp func2(){ - return NULL; -} - -const char * const CONST_CP = "hi there"; - -void func3(const char * const val) { - - if (CONST_CP == val){ - PRINTSTR("val = 'CP'\n"); - } else { - PRINTSTR("val NOT = CP\n"); - } - -} - - -#if 0 - -typedef void (*fc)(); - -void fptestfunc1(){ PRINTSTR(__FUNCTION__); PRINTSTR("\n");} -void fptestfunc2(){ PRINTSTR(__FUNCTION__); PRINTSTR("\n");} -int fptest(int argc, char ** argv){ - - fc func = fptestfunc1; - - if (argc > 1){ - func = fptestfunc2; - } - - func(); - - return 0; -} -#endif - - - - - - - - -int main(int argc, char ** argv){ - - const char * val = CONST_CP; - - if (argc > 2){ - func(1); - } else if (1 == argc){ - val = argv[0]; - } - - func3(val); - -#if 0 - fptest(argc, argv); -#endif - - return 0; - - -}