Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • opensrc/zipr
  • whh8b/zipr
2 results
Show changes
Commits on Source (5146)
Showing
with 952 additions and 136 deletions
* text=auto !eol irdb-libs/third_party/capstone norecurse
/build-all.sh -text irdb-libs/third_party/keystone norecurse
/cfar_postgres_setup.sh -text irdb-libs/third_party/elfio-code norecurse
/cfar_postgres_setup_for_other.sh -text irdb-libs/third_party/pebliss norecurse
/clean-all.sh -text
/get-peasoup-packages.sh -text
/irdb_vars -text
non_overlapping_heap/Makefile -text
non_overlapping_heap/noh.c -text
non_overlapping_heap/tests/Makefile -text
non_overlapping_heap/tests/inputfile -text
non_overlapping_heap/tests/test1.c -text
non_overlapping_heap/tests/test2.c -text
non_overlapping_libraries/ld-linux-x86-64.so.2 -text
non_overlapping_libraries/patchelf -text
/postgres_setup.sh -text
/set_command_envs -text
/set_env_vars -text
/set_ida_server -text
/start_dev.sh -text
/svn.externals.uva_dev -text
installed
manifest.txt.config
ubuntu16_files/manifest.txt.config
zest_runtime
.sconsign.dblite
build
irdb-libs/build/
irdb-libs/.sconsign.dblite
irdb-libs/bin/
irdb-libs/lib/
irdb-libs/manifest.txt.config
irdb-libs/tools/meds2pdb/meds2pdb
irdb-libs/plugins_install/*.exe
irdb-libs/plugins_install/*.so
irdb-libs/*.swp
irdb-libs/*.os
irdb-libs/*.o
scons_buiirdb-libs/ld
peasoup_examples/cgc_spri/spawner
peasoup_examples/chopzero_src/chopzero
peasoup_examples/manifest.txt.config
peasoup_examples/tests/tmp*
peasoup_examples/*.swp
irdb-libs/scons_build/
*.o
*.os
*.so
*.exe
.*.swp
irdb-libs/libEXEIO/test/exeio_test
irdb-libs/meds2pdb/meds2pdb
before_script:
- "source ~gitlab-runner/cicd_support/cicd_support.shinc"
after_script:
- "echo Test Complete."
stages:
- gather
- build
- cross-protect
- test
- deploy
#
# gather artifacts and ship them to x86 boxes
#
.gather-bins: &do_gather
stage: gather
script:
- ./cicd_testing/do-gather-bins.sh
artifacts:
expire_in: 1 day
paths:
- artifacts/
gather-bins-arm32:
<<: *do_gather
tags:
- arm32
gather-bins-arm64:
<<: *do_gather
tags:
- arm64
#
# protect gathered arm binaries on an x86 box.
#
.protect-arm-bins: &prot_bins
needs: [gather-bins-arm32, gather-bins-arm64]
stage: cross-protect
script:
- ./cicd_testing/do-clean.sh
- ./cicd_testing/do-build.sh
- ./cicd_testing/do-prot-bins.sh
artifacts:
expire_in: 1 day
paths:
- artifacts/
protect-arm-ubuntu22:
<<: *prot_bins
tags:
- ubuntu22
#
# Test the cross-protected binaries.
#
.test_arm_bins: &test_arm_bins
needs: [protect-arm-ubuntu22]
stage: test
script:
- ./cicd_testing/do-test-bins.sh
artifacts:
expire_in: 1 day
paths:
- artifacts/
test-bins-arm32:
<<: *test_arm_bins
tags:
- arm32
test-bins-arm64:
<<: *test_arm_bins
tags:
- arm64
#
# Cleaning, build, test for x86 on various OSes
#
.test: &test
needs: []
stage: test
script:
- ./cicd_testing/do-clean.sh
- ./cicd_testing/do-build.sh
- ./cicd_testing/libc_test.sh
- ./cicd_testing/eh-tests.sh
- ./cicd_testing/builtin-xforms.sh
- ./cicd_testing/elfdep.sh
- ./cicd_testing/go_tests.sh
- ./cicd_testing/rust_tests.sh
# ubuntu 22 only for now
test-ubuntu22:
<<: *test
tags:
- ubuntu22
test-ubuntu24:
<<: *test
tags:
- ubuntu24
# ARM testing is more limited.
test-arm32:
needs: []
stage: test
script:
- ./cicd_testing/do-clean.sh
- ./cicd_testing/do-build.sh
tags:
- arm32
test-arm64:
needs: []
stage: test
script:
- ./cicd_testing/do-clean.sh
- ./cicd_testing/do-build.sh
- ./cicd_testing/builtin-xforms.sh
tags:
- arm64
#
# deploy a docker image
#
deploy-u22:
needs: [test-ubuntu22, test-ubuntu24, test-arm32, test-arm64, test-bins-arm32, test-bins-arm64]
stage: deploy
script:
- ./cicd_testing/do-clean.sh
- ./cicd_testing/do-build.sh
- ./cicd_testing/deploy.sh
tags:
- ubuntu22
[submodule "SMPStaticAnalyzer"]
path = SMPStaticAnalyzer
url = ../SMPStaticAnalyzer.git
[submodule "zipr-sdk"]
path = zipr-sdk
url = ../../opensrc/zipr-sdk.git
[submodule "pedi"]
path = pedi
url = ../pedi.git
[submodule "IdaProServer"]
path = IdaProServer
url = ../IdaProServer.git
[submodule "irdb-sdk"]
path = irdb-sdk
url = ../../opensrc/irdb-sdk.git
[submodule "irdb-libs/libehp"]
path = irdb-libs/libehp
url = ../../opensrc/libehp.git
[submodule "irdb-libs/third_party/elfio-code"]
path = irdb-libs/third_party/elfio-code
url = ../../third-party-mirrors/ELFIO.git
[submodule "irdb-libs/third_party/pebliss"]
path = irdb-libs/third_party/pebliss
url = ../../third-party-mirrors/pebliss.git
[submodule "irdb-libs/third_party/capstone"]
path = irdb-libs/third_party/capstone
url = ../../third-party-mirrors/capstone.git
[submodule "irdb-libs/third_party/keystone"]
path = irdb-libs/third_party/keystone
url = ../../third-party-mirrors/keystone.git
{
"cmake.configureOnOpen": false,
"files.associations": {
"iosfwd": "cpp",
"iostream": "cpp"
}
}
\ No newline at end of file
# Notes for setting up, building and installing peasoup_umbrella (non-CFAR)
0. IMPORTANT: You will need your own valid IDA Pro license key and IDA Pro installation. Update the IDA* lines in the file set_env_vars to point to your installation.
1. Get the required packages by running the get-peasoup-packages.sh script.
. ./set_env_vars; bash ./get-peasoup-packages.sh all
2. Set up the postgres databases (enter password of your choice)
bash ./postgres_setup.sh
3. Build and save the build results to build.out
bash ./build.sh | tee -ai build.out
If the build succeeds, a directory named $PEASOUP_UMBRELLA_DIR/installed will be created (see file set_env_vars for environment variable settings). This directory will contain the built versions of the modules that comprise the toolchain.
To test your installation, try a simple analysis using zipr static rewriter.
. ./set_env_vars; $PSZ `which ls` ls.zipr
If the toolchain build has completed successfully, then ls.zipr will be a working, statically rewritten version of ls.
Subproject commit 59abf408fdfc83000c2bf77670b06f5f80bed549
BSD 3-Clause License
Copyright (c) 2014-2021, Zephyr Software LLC
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Zipr via Docker
Run our docker image by [installing Docker](https://docs.docker.com/get-docker/), then running:
```
docker run -it git.zephyr-software.com:4567/opensrc/zipr/zipr-bin
```
The image will prompt you how to proceed. To learn how to invoke and use Zipr transforms, see the [IRDB Cookbook Examples repository](https://git.zephyr-software.com/opensrc/irdb-cookbook-examples) section on using [transforms in Docker](https://git.zephyr-software.com/opensrc/irdb-cookbook-examples#docker-recommended).
# Building Zipr/Peasoup
The instructions that follow assume that:
* you have access to both the Zipr repo
* you have sudo privileges
* you are installing in your home directory
* you are using a recent version of Linux, e.g., Ubuntu 18.04
First install the Zipr static binary rewriting infrastructure
```
git clone --recurse-submodules https://git.zephyr-software.com/opensrc/zipr.git # or git@git.zephyr-software.com:opensrc/zipr.git
cd zipr
. set_env_vars
./get-peasoup-packages.sh all
scons -j3
```
Carefully watch the `get-peasoup-packages` command for errors.
It leverages' Ubuntu's `apt` or CentOS' `yum` commands to install packages.
All packages should be in standard repositiories, but your local configuration may
need to be adjusted if it doesn't work by default.
# Preparing Zipr for Use (Setting up local postgres tables)
Next we need to setup the proper tables in a local copy of the postgres database. In the `zipr` directory, run:
```
./postgres_setup.sh
```
If all goes well with the postgres setup, you should be able to login into the database by typing: psql
The output of psql should look something like this:
```
psql (9.3.22)
SSL connection (cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256)
Type "help" for help.
peasoup_XXX=>
```
# Testing Zipr
Test the binary rewriting infrastructure by rewriting /bin/ls
```
cd /tmp
$PSZ /bin/ls ls.zipr -c rida
```
Your terminal's output should look like this:
```
Using Zipr backend.
Detected ELF shared object.
Performing step rida [dependencies=mandatory] ...Done. Successful.
Performing step pdb_register [dependencies=mandatory] ...Done. Successful.
Performing step fill_in_cfg [dependencies=unknown] ...Done. Successful.
Performing step fill_in_indtargs [dependencies=unknown] ...Done. Successful.
Performing step fix_calls [dependencies=unknown] ...Done. Successful.
Performing step zipr [dependencies=none] ...Done. Successful.
```
Invoke the rewritten version of /bin/ls and make sure it runs normally:
```
./ls.zipr
```
# Zipr with IDAPro
In some configurations, Zipr can leverage IDA Pro's information to get better rewriting. IDA is most useful when Rida cannot analyze the program (Rida currently only handles ELF x86 binaries, not PE binaries for Windows or other architectures). To setup Zipr to use IDA, install (or clone) IDA and the corresponding IDA SDK, then set these environment variables:
```
export IDAROOT=/path/to/idapro
export IDASDK=/path/to/idapro-sdk
```
Next, rebuild Zipr:
```
$ cd /path/to/zipr
$ scons
```
The `$PSZ` script uses IDA Pro by default if it is setup properly. You'll see the `meds-static` step replace the `rida` step.
If this step fails, make sure that IDA Pro is installed properly, and that you have started IDA Pro's GUI to accept the license agreement.
The cookbook and other tools may use `pszr` to invoke Zipr. This command means "invoke Zipr with Rida" as the front end, or `$PSZ -c rida`. If you've using `pszr` and wish to change
to IDA, just switch to `$PSZ`.
# Zipr and non-X86 Architectures.
Zipr's origins are in the X86 world, and thus most of the scripts, examples, etc. implicitly assume X86 code.
However, Zipr has at least some support for ARM32/64, MIPS32/64 and X86 32/64.
Zipr _can_ run on ARM box, but has never been tested/built on a MIPS box.
To make Zipr run on an X86 machine with non-x86 binaries, you'll need to have completed these steps:
* Build Zipr with IDA Pro support (ensure IDAROOT and IDASDK are set when running Zipr).
* Install core-utils and gcc for cross compilation. For arm32 and arm64, you can use `sudo apt install binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu`.
* Set the environment variables to specify that Zipr should use the cross-compilation tools. In particular, set `PS_OBJDUMP`, `PS_READELF`, `PS_GCC`, `PS_OBJCOPY`, `PS_NM`, `PS_STRIP`.
For example, to use Zipr for the ARM architecture (32 or 64-bit), run `export PS_GCC=aarch64-linux-gnu-gcc` (and the other environment variables).
This can be simplified with the `set-cross.sh` script by invoking it like so: `source set-cross.sh arm32` (or substitute, for e.g., arm64.)
## Windows
Zipr (running on x86-64/linux) can possibly transform PE/PE+ files for Windows. Support is _very_ preliminary. Your mileage may vary.
Zipr has never been built to run on a Windows machine.
import shutil
import os
import tarfile
Import('env')
def createFolder(directory):
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print ('Error: Creating directory. ' + directory)
createFolder(os.environ['ZEST_RUNTIME']+'/lib32')
createFolder(os.environ['ZEST_RUNTIME']+'/lib64')
createFolder(os.environ['ZEST_RUNTIME']+'/sbin')
createFolder(os.environ['ZEST_RUNTIME']+'/bin')
if not os.path.isfile("manifest.txt.config"):
os.system("$PEDI_HOME/pedi --setup -m manifest.txt -l ida -l ida_key -l ps -l zipr -l stars -i $PS_INSTALL")
# build stars and libirdb
libirdb= SConscript("irdb-libs/SConscript")
libsmpsa= SConscript("SMPStaticAnalyzer/SConscript")
# now finish building irdb-libs once stars is setup
libirdbdeep=SConscript("irdb-libs/SConscript.deep")
Depends(libirdbdeep,libsmpsa)
Export('env')
# list of zipr plugins and irdb xforms to build
transformDirs='''
builtin_xforms/add_lib
builtin_xforms/move_globals
builtin_xforms/resolve_callbacks
zipr_push64_reloc_plugin
zipr
zipr_unpin_plugin
'''
# build the xforms and plugins
xforms=list()
for i in Split(transformDirs):
Export('env')
xform = SConscript(i+"/SConscript")
Depends(xform, libirdbdeep)
xforms = xforms + xform
#finally, run pedi to do the final install
pedi = Command( target = "./zipr-umb-testoutput-install",
source = xforms,
action = os.environ['PEDI_HOME']+"/pedi -m manifest.txt " )
ret=[]+xforms
if Dir('.').abspath == Dir('#.').abspath:
ret=ret+pedi
if env.GetOption('clean') and os.path.isfile("manifest.txt.config"):
with open("manifest.txt.config") as myfile:
first_line=myfile.readlines()[0].rstrip()
# if [[ $(head -1 manifest.txt.config) == $PS_INSTALL ]] ; then
if str(first_line) == str(os.environ['PS_INSTALL']):
print("Doing pedi clean as I'm the pedi root")
os.system( "pwd; $PEDI_HOME/pedi -c -m manifest.txt " )
shutil.rmtree(os.environ['PS_INSTALL'])
Default(ret)
Return('ret')
import os
import sys
env=Environment()
# default build options
env.Replace(CFLAGS=" -fPIC -fmax-errors=2 -Wall -Werror -fmax-errors=2 ")
env.Replace(CXXFLAGS=" -fPIC -fmax-errors=2 -Wall -Werror -fmax-errors=2 ")
env.Replace(LINKFLAGS="-fPIC -fmax-errors=2 -Wall -Werror -fmax-errors=2 -Wl,-unresolved-symbols=ignore-in-shared-libs ")
env.Replace(SHLINKFLAGS="-fPIC -fmax-errors=2 -Wall -Werror -fmax-errors=2 -shared ") # default is ignore all link errors
# parse arguments into env and set default values.
env.Replace(SECURITY_TRANSFORMS_HOME=os.environ['SECURITY_TRANSFORMS_HOME'])
env.Replace(IRDB_SDK=os.environ['IRDB_SDK'])
env.Replace(SMPSA_HOME=os.environ['SMPSA_HOME'])
env.Replace(PEASOUP_HOME=os.environ['PEASOUP_HOME'])
env.Replace(debug=ARGUMENTS.get("debug",0))
env.Replace(PEDI_HOME=os.environ['PEDI_HOME'])
env.Replace(ZIPR_PLUGIN_PATH=os.environ['ZIPR_PLUGIN_PATH'])
if int(env['debug']) == 1:
print("Setting debug mode")
env.Append(CFLAGS=" -g ")
env.Append(CXXFLAGS=" -g ")
env.Append(LINKFLAGS=" -g ")
env.Append(SHLINKFLAGS=" -g ")
else:
print("Setting release mode")
env.Append(CFLAGS=" -O ")
env.Append(CXXFLAGS=" -O ")
env.Append(LINKFLAGS=" -O ")
env.Append(SHLINKFLAGS=" -O ")
Export('env')
ret=SConscript("SConscript")
Default(ret)
Return('ret')
Subproject commit 543a9a140eef96a99dfe2cb9a2e4b11118e89e03
#!/bin/bash #!/bin/bash
# check if DIR is the directory containing the build script.
BUILD_LOC=`dirname $0`
FULL_BUILD_LOC=`cd $BUILD_LOC; pwd`
echo $PEASOUP_UMBRELLA_DIR
if [ "$PEASOUP_UMBRELLA_DIR" != "$FULL_BUILD_LOC" ]; then
echo "PEASOUP_UMBRELLA_DIR differs from build-all.sh location ($FULL_BUILD_LOC).";
echo "Did you source set_env_vars from the root of the umbrella working copy?";
exit 1;
fi
if [ `basename $FULL_BUILD_LOC` == "cfar_umbrella" ]; then
cfar_mode="--enable-cfar"
fi
# stratafier
cd $PEASOUP_UMBRELLA_DIR/stratafier
make || exit
# strata
if [ ! "$STRATA_HOME" ]; then
echo "STRATA_HOME not set.";
exit 1;
fi
if [ `uname -m` = 'x86_64' ]; then
# build 32-bit strata
if [ ! -d $STRATA_HOME32 ] ; then
cd $STRATA
if [ -f Makefile ] ; then
make clean distclean
fi
cd $PEASOUP_UMBRELLA_DIR
echo Creating strata 32-bit build directory
cp -R $STRATA $STRATA32
fi
cd $STRATA_HOME32
STRATA_HOME=$STRATA_HOME32 STRATA=$STRATA_HOME32 ./build -host=i386-linux || exit
# build x86-64 strata
cd $STRATA_HOME
if [ -f Makefile -a Makefile -nt configure -a Makefile -nt Makefile.in ]; then
echo Skipping Strata reconfigure step
else
./configure $cfar_mode || exit
fi
make || exit
else if [[ "$*" =~ "--debug" ]]; then
cd $STRATA_HOME SCONSDEBUG=" debug=1 "
./build $cfar_mode || exit
fi fi
# smp-static-analyzer
if [ ! "$SMPSA_HOME" ]; then
echo "SMPSA_HOME not set.";
exit 1;
fi
# security-transforms if [[ $(uname -m) == 'armv7l' ]] || [[ $(uname -m) == 'aarch64' ]]; then
if [ ! "$SECURITY_TRANSFORMS_HOME" ]; then scons $SCONSDEBUG debug=1
echo "SECURITY_TRANSFORMS_HOME not set."; else
exit 1; scons $SCONSDEBUG -j 3
fi fi
cd $SECURITY_TRANSFORMS_HOME exit
scons || exit
cd $SMPSA_HOME
scons || exit
cd $PEASOUP_HOME
make || exit
if [ -d $ZIPR_CALLBACKS ]; then
cd $ZIPR_CALLBACKS
./configure --enable-p1 --prefix=$ZIPR_INSTALL
make || exit
make install || exit
fi
if [ -d $ZIPR_HOME ]; then
cd $ZIPR_HOME
scons || exit
fi
if [ -d $ZIPR_SCFI_PLUGIN ]; then
cd $ZIPR_SCFI_PLUGIN
scons || exit
fi
cd $PEASOUP_UMBRELLA_DIR/zipr_large_only_plugin/
scons || exit
cd $PEASOUP_UMBRELLA_DIR/zipr_push64_reloc_plugin
scons || exit
cd $PEASOUP_UMBRELLA_DIR/zipr_unpin_plugin
scons || exit
cd $IRDB_TRANSFORMS
scons || exit
cd $PEASOUP_UMBRELLA_DIR
if [ -d DieHard ]; then
cd DieHard
./build_diehard.sh
fi
cd $PEASOUP_UMBRELLA_DIR
if [ -d non_overlapping_heap ]; then
make -C non_overlapping_heap
fi
cd $PEASOUP_UMBRELLA_DIR
echo
echo
echo "peasoup/cfar_umbrella Overall build complete."
echo
echo
import os
Import('env')
# import and create a copy of the environment so we don't screw up anyone elses env.
myenv=env.Clone()
files=Glob( Dir('.').srcnode().abspath+"/*.cpp")
cpppath='''
$IRDB_SDK/include
'''
myenv.Append(CPPPATH=Split(cpppath))
pgm="add_lib.exe"
LIBPATH="$SECURITY_TRANSFORMS_HOME/lib"
LIBS=Split("stars "+ myenv.subst('$BASE_IRDB_LIBS')+ " irdb-elfdep irdb-transform pqxx pq")
pgm=myenv.Program(pgm, files, LIBPATH=LIBPATH, LIBS=LIBS)
install=myenv.Install("$SECURITY_TRANSFORMS_HOME/plugins_install/", pgm)
Default(install)
Return('install')
#include "al.hpp"
#include <irdb-elfdep>
using namespace IRDB_SDK;
using namespace std;
using namespace AddLib;
AddLib_t::AddLib_t(FileIR_t* firp, const StringSet_t &p_prepended, const StringSet_t &p_appended)
: Transform_t(firp), prepended(p_prepended), appended(p_appended)
{
}
int AddLib_t::execute()
{
auto ed=ElfDependencies_t::factory(getFileIR());
for(const auto &p : prepended)
ed->prependLibraryDepedencies(p);
for(const auto &a : appended)
ed->appendLibraryDepedencies(a);
return 0;
}
#include <string>
#include <set>
#include <irdb-core>
#include <irdb-transform>
namespace AddLib
{
using namespace IRDB_SDK;
using namespace std;
typedef set<string> StringSet_t;
class AddLib_t : Transform_t
{
public:
AddLib_t(FileIR_t* firp, const StringSet_t &prepended, const StringSet_t &appended);
int execute();
private:
StringSet_t prepended;
StringSet_t appended;
};
}
#include <stdlib.h>
#include <fstream>
#include <string>
#include "al.hpp"
#include <irdb-core>
#include <getopt.h>
using namespace std;
using namespace IRDB_SDK;
using namespace AddLib;
void usage(string programName)
{
cerr << "Usage: " << programName << " <variant id> <annotation file>" <<endl;
cout<<"--append lib Append named library" <<endl;
cout<<"-a lib" <<endl;
cout<<""<<endl;
cout<<"--prepend lib Prepend named library" <<endl;
cout<<"-p lib" <<endl;
cout<<""<<endl;
cout<<"--help,--usage,-?,-h Display this message"<<endl;
}
int main(int argc, char **argv)
{
string programName(argv[0]);
char *strtolError = NULL;
int transformExitCode = 0;
int variantID = -1;
auto pqxx_interface=pqxxDB_t::factory();
int exit_code=0;
/*
* Check that we've been called correctly:
* <program> <variant id> <annotation file>
*/
if(argc < 2)
{
usage(programName);
exit(1);
}
variantID = strtol(argv[1], &strtolError, 10);
if (*strtolError != '\0')
{
cerr << "Invalid variantID: " << argv[1] << endl;
exit(1);
}
// Parse some options for the transform
const static struct option long_options[] = {
{"prepend", required_argument, 0, 'p'},
{"append", required_argument, 0, 'a'},
{"help", no_argument, 0, 'h'},
{"usage", no_argument, 0, '?'},
{0,0,0,0}
};
auto short_opts="p:ah?";
auto prepended_libs=set<string>();
auto appended_libs=set<string>();
while(1) {
int index = 0;
int c = getopt_long(argc, argv,short_opts, long_options, &index);
if(c == -1)
break;
switch(c) {
case 0:
break;
case 'p':
prepended_libs.insert(string(optarg));
break;
case 'a':
appended_libs.insert(string(optarg));
break;
break;
case '?':
case 'h':
usage(argv[0]);
exit(1);
break;
default:
break;
}
}
/* setup the interface to the sql server */
BaseObj_t::setInterface(pqxx_interface.get());
auto pidp=VariantID_t::factory(variantID);
assert(pidp && pidp->isRegistered()==true);
for(set<File_t*>::iterator it=pidp->getFiles().begin();
it!=pidp->getFiles().end();
++it)
{
try
{
/* read the IR from the DB */
File_t* this_file = *it;
auto firp = FileIR_t::factory(pidp.get(), this_file);
cout<<"Transforming "<<this_file->getURL()<<endl;
assert(firp && pidp);
/*
* Create a transformation and then
* invoke its execution.
*/
AddLib_t al(firp.get(),prepended_libs,appended_libs);
transformExitCode = al.execute();
/*
* If everything about the transformation
* went okay, then we will write the updated
* set of instructions to the database.
*/
if (transformExitCode == 0)
{
if(getenv("MG_NOUPDATE")==NULL)
{
firp->writeToDB();
}
}
else
{
cerr << programName << ": transform failed. Check logs." << endl;
exit_code=2;
}
}
catch (const DatabaseError_t &pnide)
{
cerr << programName << ": Unexpected database error: " << pnide << endl;
exit(1);
}
catch (const std::exception &exc)
{
// catch anything thrown within try block that derives from std::exception
std::cerr << "Unexpected exception: " << exc.what();
exit(1);
}
catch (...)
{
cerr << programName << ": Unexpected error" << endl;
exit(1);
}
}
pqxx_interface->commit();
return exit_code;
}
#!/bin/bash
#benchmarks="473.astar"
# 447.dealII // broken build
benchmarks=" 400.perlbench 401.bzip2 403.gcc 410.bwaves 416.gamess 429.mcf 433.milc 434.zeusmp 435.gromacs 436.cactusADM 437.leslie3d 444.namd 445.gobmk 450.soplex 453.povray 454.calculix 456.hmmer 458.sjeng 459.GemsFDTD 462.libquantum 464.h264ref 465.tonto 470.lbm 471.omnetpp 473.astar 481.wrf 482.sphinx3 483.xalancbmk "
#benchmarks="bzip2"
#benchmarks="400.perlbench 403.gcc 445.gobmk 453.povray 458.sjeng 464.h264ref 464.tonto 471.omnetpp 481.wrf 482.sphinx3 483.xalancbmk"
number=1
setup()
{
if [ ! -d spec2006 ]; then
#svn co ^/spec2006/trunk spec2006
git clone --depth 1 http://git.zephyr-software.com/allzp/spec2006.git spec2006
fi
cd spec2006/
if [ ! -L bin ]; then
ln -s bin.power/ bin
fi
source shrc
bin/relocate
}
run_test()
{
local config_name=$1
local config=$2
all_configs_that_were_run="$all_configs_that_were_run $config_name"
cd $SPEC
if [ ! -d result.$config_name ]; then
echo "Re-doing runspec for test $config_name"
dropdb $PGDATABASE
createdb $PGDATABASE
$PEASOUP_HOME/tools/db/pdb_setup.sh
rm -Rf result/*
runspec --action scrub --config $config $benchmarks
runspec --action validate --config $config -n $number $benchmarks
cp benchspec/CPU2006/*/exe/* result
mv result result.$config_name
dropdb $PGDATABASE
createdb $PGDATABASE
$PEASOUP_HOME/tools/db/pdb_setup.sh
fi
}
get_size_result()
{
bench=$1
if [ -f $1 ]; then
size=$(stat --printf="%s" $bench)
echo -n $size
else
echo -n 0
fi
}
get_result()
{
bench=$1
config=$2
results=$(cat $SPEC/result.$config/CPU2006.002.log 2>/dev/null|grep Success|grep $bench|grep ratio=|sed 's/.*ratio=//'|sed 's/,.*//')
sum=0
count=0
for res in $results
do
sum=$(echo $sum + $res | bc)
count=$(echo $count + 1 | bc)
done
#echo sum=$sum
#echo count=$count
res=$(echo "scale=2; $sum / $count" | bc 2> /dev/null )
count=$(echo $res|wc -w)
if [ $count = 1 ]; then
echo -n $res
else
echo -n "N/A"
fi
}
# global
all_configs_that_were_run=""
get_raw_results()
{
echo "--------------------------------------------------------------"
echo "Performance results are:"
echo "--------------------------------------------------------------"
local configs="$all_configs_that_were_run"
echo benchmark $configs
for bench in $benchmarks
do
echo -n "$bench "
for config in $configs
do
get_result $bench $config
echo -n " "
done
echo
done
echo "--------------------------------------------------------------"
echo "Size results are:"
echo "--------------------------------------------------------------"
echo benchmark $configs
for bench in $SPEC/result.$config/*_base.amd64-m64-gcc42-nn
do
echo -n "$(basename $bench _base.amd64-m64-gcc42-nn) "
for config in $configs
do
file="$SPEC/result.$config/$(basename $bench)"
get_size_result $file
echo -n " "
done
echo
done
}
main()
{
start_dir=$(pwd)
setup
local zipr_flags="--backend zipr -o zipr:--add-sections -o zipr:true "
local hral_flags="-c move_globals=on -o move_globals:--elftables-only -c add_lib=on -o add_lib:--prepend -o add_lib:libheaprand.so"
if [[ -z $DIEHARD_HOME ]] ; then
echo "Cannot find DieHard for heap randomization test. Abborting now..."
exit 1
else
cp $DIEHARD_HOME/src/libdiehard-4k.so $PWD/libheaprand.so
export LD_LIBRARY_PATH="$PWD:$LD_LIBRARY_PATH"
fi
# zipr, etc.
PSOPTS="$zipr_flags $hral_flags " run_test hral $SPEC/config/ubuntu14.04lts-64bit-withps.cfg
PSOPTS="$zipr_flags" run_test zipr $SPEC/config/ubuntu14.04lts-64bit-withps.cfg
# no $PS -- aka, baseline.
run_test original $SPEC/config/ubuntu14.04lts-64bit.cfg
get_raw_results
}
main "$@"
*.os
*.so
build
.sconsign.dblite
import os
Import('env')
# import and create a copy of the environment so we don't screw up anyone elses env.
myenv=env.Clone()
cpppath='''
$PEASOUP_HOME/irdb-libs/third_party/elfio-code
$PEASOUP_HOME/irdb-libs/libEXEIO/include
$IRDB_SDK/include
'''
files=Glob( Dir('.').srcnode().abspath+"/*.cpp")
pgm="move_globals.so"
LIBPATH="$PEASOUP_HOME/irdb-libs/lib"
LIBS=Split("irdb-core irdb-cfg irdb-util irdb-transform irdb-deep StructDiv EXEIO pqxx pq")
myenv.Append(CPPPATH=Split(cpppath))
pgm=myenv.SharedLibrary(pgm, files, LIBPATH=LIBPATH, LIBS=LIBS)
install=myenv.Install("$PEASOUP_HOME/irdb-libs/plugins_install/", pgm)
Default(install)
Return('install')