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/zafl
1 result
Show changes
Commits on Source (19)
Showing
with 751 additions and 265 deletions
......@@ -38,6 +38,8 @@ usage()
echo " -C, --no-break-critical-edges Same as '-c none' (default)"
echo " -j, --enable-loop-count-instr Insert instrumentation to afl-style count loop headers."
echo " -J, --disable-loop-count-instr Do not do -j (default)"
echo " -k, --keep-loop-headers-only Prune all nodes from a CFG except the loop header nodes (note: other opts, e.g. -g may prune loop headers)"
echo " -J, --disable-loop-count-instr Do not do -j (default)"
echo " --loop-count-buckets <bucket_spec> The buckets for -j. bucket_spec = int[,int]*, Default = 0,1,2,4,8,16,32,128. (Spaces disallowed.)"
echo " -f, --fork-server-only Fork server only"
echo " -F, --disable-fork-server No fork server"
......@@ -223,12 +225,12 @@ parse_args()
zax_opt=" $zax_opt -o zax:-c -o fallthroughs "
shift
;;
all|"")
all)
zax_opt=" $zax_opt -o zax:-c -o all"
shift
;;
*)
echo "Cannot map $1 to critical edge type "
echo "Cannot map '$1' to critical edge type "
exit 2
;;
esac
......@@ -241,6 +243,10 @@ parse_args()
zax_opt=" $zax_opt -o zax:-J "
shift
;;
-k | --keep-loop-headers-only)
zax_opt=" $zax_opt -o zax:-k "
shift
;;
--loop-count-buckets)
shift
zax_opt=" $zax_opt -o zax:--loop-count-buckets -o $1 "
......
Subproject commit 420989e02ac542914311392a6535245d18babe88
Subproject commit 14d03f2edaac5d6d22d103eaebc38990dec57e9f
# @HEADER_LANG python
# @HEADER_COMPONENT zafl
# @HEADER_BEGIN
#
# Copyright (c) 2018-2019 Zephyr Software LLC
#
# This file may be used and modified for non-commercial purposes as long as
# all copyright, permission, and nonwarranty notices are preserved.
# Redistribution is prohibited without prior written consent from Zephyr
# Software.
#
# Please contact the authors for restrictions applying to commercial use.
#
# THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# Author: Zephyr Software
# e-mail: jwd@zephyr-software.com
# URL : http://www.zephyr-software.com/
#
# This software was developed with SBIR funding and is subject to SBIR Data Rights,
# as detailed below.
#
# SBIR DATA RIGHTS
#
# Contract No. __FA8750-17-C-0295___________________________.
# Contractor Name __Zephyr Software LLC_____________________.
# Address __4826 Stony Point Rd, Barboursville, VA 22923____.
#
# @HEADER_END
import os
......
# @HEADER_LANG python
# @HEADER_COMPONENT zafl
# @HEADER_BEGIN
#
# Copyright (c) 2018-2019 Zephyr Software LLC
#
# This file may be used and modified for non-commercial purposes as long as
# all copyright, permission, and nonwarranty notices are preserved.
# Redistribution is prohibited without prior written consent from Zephyr
# Software.
#
# Please contact the authors for restrictions applying to commercial use.
#
# THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# Author: Zephyr Software
# e-mail: jwd@zephyr-software.com
# URL : http://www.zephyr-software.com/
#
# This software was developed with SBIR funding and is subject to SBIR Data Rights,
# as detailed below.
#
# SBIR DATA RIGHTS
#
# Contract No. __FA8750-17-C-0295___________________________.
# Contractor Name __Zephyr Software LLC_____________________.
# Address __4826 Stony Point Rd, Barboursville, VA 22923____.
#
# @HEADER_END
......
/***************************************************************************
* Copyright (c) 2018-2019 Zephyr Software LLC. All rights reserved.
*
* This software is furnished under a license and/or other restrictive
* terms and may be used and copied only in accordance with such terms
* and the inclusion of the above copyright notice. This software or
* any other copies thereof may not be provided or otherwise made
* available to any other person without the express written consent
* of an authorized representative of Zephyr Software LCC. Title to,
* ownership of, and all rights in the software is retained by
* Zephyr Software LCC.
*
* Zephyr Software LLC. Proprietary Information
*
* Unless otherwise specified, the information contained in this
* directory, following this legend, and/or referenced herein is
* Zephyr Software LLC. (Zephyr) Proprietary Information.
*
* CONTACT INFO
*
* E-mail: jwd@zephyr-software.com
**************************************************************************/
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#include <iostream>
#include <algorithm>
......
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#ifndef _ZAFL_LAF_H
#define _ZAFL_LAF_H
......
/***************************************************************************
* Copyright (c) 2018-2019 Zephyr Software LLC. All rights reserved.
*
* This software is furnished under a license and/or other restrictive
* terms and may be used and copied only in accordance with such terms
* and the inclusion of the above copyright notice. This software or
* any other copies thereof may not be provided or otherwise made
* available to any other person without the express written consent
* of an authorized representative of Zephyr Software LCC. Title to,
* ownership of, and all rights in the software is retained by
* Zephyr Software LCC.
*
* Zephyr Software LLC. Proprietary Information
*
* Unless otherwise specified, the information contained in this
* directory, following this legend, and/or referenced herein is
* Zephyr Software LLC. (Zephyr) Proprietary Information.
*
* CONTACT INFO
*
* E-mail: jwd@zephyr-software.com
**************************************************************************/
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#include <getopt.h>
......
# @HEADER_LANG python
# @HEADER_COMPONENT zafl
# @HEADER_BEGIN
#
# Copyright (c) 2018-2019 Zephyr Software LLC
#
# This file may be used and modified for non-commercial purposes as long as
# all copyright, permission, and nonwarranty notices are preserved.
# Redistribution is prohibited without prior written consent from Zephyr
# Software.
#
# Please contact the authors for restrictions applying to commercial use.
#
# THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# Author: Zephyr Software
# e-mail: jwd@zephyr-software.com
# URL : http://www.zephyr-software.com/
#
# This software was developed with SBIR funding and is subject to SBIR Data Rights,
# as detailed below.
#
# SBIR DATA RIGHTS
#
# Contract No. __FA8750-17-C-0295___________________________.
# Contractor Name __Zephyr Software LLC_____________________.
# Address __4826 Stony Point Rd, Barboursville, VA 22923____.
#
# @HEADER_END
import os
Import('env')
......
# @HEADER_LANG python
# @HEADER_COMPONENT zafl
# @HEADER_BEGIN
#
# Copyright (c) 2018-2019 Zephyr Software LLC
#
# This file may be used and modified for non-commercial purposes as long as
# all copyright, permission, and nonwarranty notices are preserved.
# Redistribution is prohibited without prior written consent from Zephyr
# Software.
#
# Please contact the authors for restrictions applying to commercial use.
#
# THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# Author: Zephyr Software
# e-mail: jwd@zephyr-software.com
# URL : http://www.zephyr-software.com/
#
# This software was developed with SBIR funding and is subject to SBIR Data Rights,
# as detailed below.
#
# SBIR DATA RIGHTS
#
# Contract No. __FA8750-17-C-0295___________________________.
# Contractor Name __Zephyr Software LLC_____________________.
# Address __4826 Stony Point Rd, Barboursville, VA 22923____.
#
# @HEADER_END
env=Environment()
Export('env')
......
/***************************************************************************
* Copyright (c) 2018-2019 Zephyr Software LLC. All rights reserved.
*
* This software is furnished under a license and/or other restrictive
* terms and may be used and copied only in accordance with such terms
* and the inclusion of the above copyright notice. This software or
* any other copies thereof may not be provided or otherwise made
* available to any other person without the express written consent
* of an authorized representative of Zephyr Software LCC. Title to,
* ownership of, and all rights in the software is retained by
* Zephyr Software LCC.
*
* Zephyr Software LLC. Proprietary Information
*
* Unless otherwise specified, the information contained in this
* directory, following this legend, and/or referenced herein is
* Zephyr Software LLC. (Zephyr) Proprietary Information.
*
* CONTACT INFO
*
* E-mail: jwd@zephyr-software.com
**************************************************************************/
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#include <fstream>
#include <iomanip>
#include <irdb-cfg>
#include <irdb-transform>
#include <fstream>
#include "critical_edge_breaker.hpp"
using namespace std;
......@@ -41,7 +53,7 @@ CriticalEdgeBreaker_t::CriticalEdgeBreaker_t(IRDB_SDK::FileIR_t *p_IR, set<strin
map_file.open("ceb.map");
if(!map_file)
throw invalid_argument("Cannot open ceb.map");
map_file << "instID\tbroken\ttype" << endl;
map_file << "instID\tbroken\ttype\tNewInsnID" << endl;
breakCriticalEdges();
}
......@@ -68,6 +80,24 @@ void CriticalEdgeBreaker_t::breakCriticalEdges()
if (f->getEntryPoint())
m_extra_nodes += breakCriticalEdges(f);
}
// emit broken edges into the map after updating the base IDs
m_IR->setBaseIDS();
const auto emit_line=[&](Instruction_t* from, Instruction_t* to, const string& type) -> void
{
// start a line in th emap
map_file << hex << from ->getBaseID() << "\t";
map_file << "true\t" << type << "\t" << hex << setw(8) << to->getBaseID();
map_file << endl;
};
for(const auto insn : broken_fallthroughs)
emit_line(insn,insn->getFallthrough(), "fall");
for(const auto insn : broken_targets)
emit_line(insn,insn->getTarget(), "targ");
}
//
......@@ -105,14 +135,12 @@ unsigned CriticalEdgeBreaker_t::breakCriticalEdges(Function_t* p_func)
auto source_block = get<0>(edge);
auto target_block = get<1>(edge);
auto last_instruction_in_source_block = source_block->getInstructions()[source_block->getInstructions().size()-1];
auto last_instruction_in_source_block = source_block->getInstructions()[source_block->getInstructions().size()-1];
auto first_instruction_in_target_block = target_block->getInstructions()[0];
if (source_block->endsInConditionalBranch())
{
// start a line in th emap
map_file << hex << last_instruction_in_source_block ->getBaseID() << "\t";
const auto func = last_instruction_in_source_block->getFunction();
const auto is_target = last_instruction_in_source_block->getTarget() == first_instruction_in_target_block;
......@@ -123,29 +151,30 @@ unsigned CriticalEdgeBreaker_t::breakCriticalEdges(Function_t* p_func)
auto jmp=m_IR->addNewInstruction(nullptr,func);
setInstructionAssembly(m_IR, jmp, "jmp 0", nullptr, first_instruction_in_target_block);
jmp->setComment("break_critical_edge_jmp");
last_instruction_in_source_block->setTarget(jmp);
num_critical_edges_instrumented++;
map_file << "true\ttarget";
broken_targets.insert(last_instruction_in_source_block);
}
else if (is_fallthru && breakFallthru)
{
auto jmp=m_IR->addNewInstruction(nullptr,func);
setInstructionAssembly(m_IR, jmp, "jmp 0", nullptr, first_instruction_in_target_block);
jmp->setComment("break_critical_edge_fallthrough");
last_instruction_in_source_block->setFallthrough(jmp);
num_critical_edges_instrumented++;
map_file << "true\tfallthrough";
broken_fallthroughs.insert(last_instruction_in_source_block);
}
else
{
map_file << hex << last_instruction_in_source_block->getBaseID() << "\t";
if(is_target)
map_file << "false\ttarget";
map_file << "false\ttarg\tffffffff";
else
map_file << "false\tfallthrough";
map_file << "false\tfall\tffffffff";
map_file << endl;
}
map_file << endl;
}
}
......
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#ifndef _LIBTRANSFORM_CRITICAL_EDGE_BREAKER_H
#define _LIBTRANSFORM_CRITICAL_EDGE_BREAKER_H
#include <irdb-core>
#include "zax.hpp"
#include <fstream>
namespace Zafl
{
......@@ -29,7 +63,10 @@ namespace Zafl
const bool m_verbose;
unsigned m_extra_nodes;
const bceStyle_t m_break_style;
ofstream map_file;
InstructionSet_t broken_targets;
InstructionSet_t broken_fallthroughs;
};
}
......
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
Copyright 2017-2019 University of Virginia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#include <assert.h>
#include "loop_count.hpp"
......
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
Copyright 2017-2019 University of Virginia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#ifndef _LIB_ZEDGE_H
#define _LIB_ZEDGE_H
......
/***************************************************************************
* Copyright (c) 2018-2019 Zephyr Software LLC. All rights reserved.
*
* This software is furnished under a license and/or other restrictive
* terms and may be used and copied only in accordance with such terms
* and the inclusion of the above copyright notice. This software or
* any other copies thereof may not be provided or otherwise made
* available to any other person without the express written consent
* of an authorized representative of Zephyr Software LCC. Title to,
* ownership of, and all rights in the software is retained by
* Zephyr Software LCC.
*
* Zephyr Software LLC. Proprietary Information
*
* Unless otherwise specified, the information contained in this
* directory, following this legend, and/or referenced herein is
* Zephyr Software LLC. (Zephyr) Proprietary Information.
*
* CONTACT INFO
*
* E-mail: jwd@zephyr-software.com
**************************************************************************/
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#include "zax.hpp"
#define ALLOF(a) begin(a),end(a)
using namespace std;
using namespace IRDB_SDK;
using namespace Zafl;
......@@ -67,19 +80,21 @@ ZaflBlockId_t Zax_t::getBlockId(const unsigned p_max)
void Zax_t::instrumentBasicBlock(BasicBlock_t *p_bb, bool p_honorRedZone, const bool p_collafl_optimization)
{
char buf[8192];
auto live_flags = true;
char *reg_temp = NULL;
char *reg_temp32 = NULL;
char *reg_temp16 = NULL;
auto live_flags = true;
char *reg_temp = NULL;
char *reg_temp32 = NULL;
char *reg_temp16 = NULL;
char *reg_trace_map = NULL;
char *reg_prev_id = NULL;
char *reg_context = NULL;
char *reg_prev_id = NULL;
char *reg_context = NULL;
char *reg_context16 = NULL;
auto save_temp = true;
auto save_temp = true;
auto save_trace_map = true;
auto save_prev_id = true;
auto save_context = (getContextSensitivity() != ContextSensitivity_None) ? true : false;
auto block_record=BBRecord_t();
auto save_prev_id = true;
auto save_context = (getContextSensitivity() != ContextSensitivity_None) ? true : false;
auto block_record = BBRecord_t();
const auto &bb_insns = p_bb->getInstructions();
// if fixed address, only need 1 register
// if not, need up to 4 registers
......@@ -102,7 +117,7 @@ void Zax_t::instrumentBasicBlock(BasicBlock_t *p_bb, bool p_honorRedZone, const
auto instr = getInstructionToInstrument(p_bb, num_free_regs_desired);
if (!instr) throw;
block_record.push_back(instr);
block_record.insert(end(block_record), ALLOF(bb_insns));
// If we are using stars, try to assign rax, rcx, and rdx to their
// most desireable position in the instrumentation.
......
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#ifndef _LIBTRANSFORM_ZAX_H
#define _LIBTRANSFORM_ZAX_H
......
/***************************************************************************
* Copyright (c) 2018-2019 Zephyr Software LLC. All rights reserved.
*
* This software is furnished under a license and/or other restrictive
* terms and may be used and copied only in accordance with such terms
* and the inclusion of the above copyright notice. This software or
* any other copies thereof may not be provided or otherwise made
* available to any other person without the express written consent
* of an authorized representative of Zephyr Software LCC. Title to,
* ownership of, and all rights in the software is retained by
* Zephyr Software LCC.
*
* Zephyr Software LLC. Proprietary Information
*
* Unless otherwise specified, the information contained in this
* directory, following this legend, and/or referenced herein is
* Zephyr Software LLC. (Zephyr) Proprietary Information.
*
* CONTACT INFO
*
* E-mail: jwd@zephyr-software.com
**************************************************************************/
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#include <cstdlib>
#include <string.h>
......@@ -33,8 +44,6 @@
#include <irdb-deep>
#include "zax.hpp"
#include "critical_edge_breaker.hpp"
#include "loop_count.hpp"
using namespace std;
using namespace IRDB_SDK;
......@@ -50,8 +59,8 @@ void create_got_reloc(FileIR_t* fir, pair<DataScoop_t*,int> wrt, Instruction_t*
RegisterSet_t ZaxBase_t::getDeadRegs(Instruction_t* insn) const
{
auto it = dead_registers -> find(insn);
if(it != dead_registers->end())
auto it = m_dead_registers -> find(insn);
if(it != m_dead_registers->end())
return it->second;
return RegisterSet_t();
}
......@@ -110,8 +119,7 @@ ZaxBase_t::ZaxBase_t(IRDB_SDK::pqxxDB_t &p_dbinterface, IRDB_SDK::FileIR_t *p_va
m_graph_optimize(false),
m_domgraph_optimize(false),
m_forkserver_enabled(true),
m_breakupCriticalEdges(bceNone),
m_doLoopCountInstrumentation(false),
m_doKeepLoopHeadersOnly(false),
m_fork_server_entry(p_forkServerEntryPoint),
m_exitpoints(p_exitPoints),
m_do_fixed_addr_optimization(false),
......@@ -119,10 +127,11 @@ ZaxBase_t::ZaxBase_t(IRDB_SDK::pqxxDB_t &p_dbinterface, IRDB_SDK::FileIR_t *p_va
m_previd_fixed_addr(0),
m_context_fixed_addr(0)
{
if (m_use_stars) {
if (m_use_stars)
{
cout << "Use STARS analysis engine" << endl;
auto deep_analysis=DeepAnalysis_t::factory(getFileIR());
dead_registers = deep_analysis -> getDeadRegisters();
m_deep_analysis = DeepAnalysis_t::factory(getFileIR());
m_dead_registers = m_deep_analysis -> getDeadRegisters();
}
auto ed=ElfDependencies_t::factory(getFileIR());
......@@ -191,6 +200,7 @@ ZaxBase_t::ZaxBase_t(IRDB_SDK::pqxxDB_t &p_dbinterface, IRDB_SDK::FileIR_t *p_va
m_num_bb_skipped = 0;
m_num_bb_skipped_pushjmp = 0;
m_num_bb_skipped_nop_padding = 0;
m_num_bb_loop_header_trimmed = 0;
m_num_bb_skipped_cbranch = 0;
m_num_style_collafl = 0;
m_num_bb_float_instrumentation = 0;
......@@ -264,15 +274,13 @@ void ZaxBase_t::setFixedMapAddress(VirtualOffset_t p_fixed_addr)
void ZaxBase_t::setBasicBlockOptimization(bool p_bb_graph_optimize)
{
m_graph_optimize = p_bb_graph_optimize;
const auto enabled = m_graph_optimize ? "enable" : "disable";
cout << enabled << " basic block optimization" << endl ;
cout << "basic block optimization enabled: " << boolalpha << m_graph_optimize << endl ;
}
void ZaxBase_t::setDomgraphOptimization(bool p_domgraph_optimize)
{
m_domgraph_optimize = p_domgraph_optimize;
const auto enabled = m_domgraph_optimize ? "enable" : "disable";
cout << enabled << " dominator graph optimization" << endl ;
cout << "dominator graph optimization enabled: " << boolalpha << m_domgraph_optimize << endl;
}
......@@ -281,40 +289,16 @@ void ZaxBase_t::setEnableForkServer(bool p_forkserver_enabled)
m_forkserver_enabled = p_forkserver_enabled;
}
void ZaxBase_t::setBreakCriticalEdgeStyle(bceStyle_t p_sty)
{
m_breakupCriticalEdges = p_sty;
const auto style_str =
p_sty == bceAll ? "all" :
p_sty == bceNone ? "none" :
p_sty == bceTargets ? "targets" :
p_sty == bceFallthroughs ? "fallthroughs" :
throw invalid_argument("Cannot map p_sty to string")
;
cout << "breaking of critical edge style: " << style_str << endl ;
}
void ZaxBase_t::setDoLoopCountInstrumentation(bool p_lc)
void ZaxBase_t::setKeepLoopHeadersOnly(bool p_klho)
{
m_doLoopCountInstrumentation = p_lc;
m_doLoopCountInstrumentation ?
cout << "enable loop count instr." << endl :
cout << "disable loop count instr." << endl ;
}
void ZaxBase_t::setLoopCountBuckets(string p_buckets)
{
m_loopCountBuckets = p_buckets;
cout << "loop count buckets = " << m_loopCountBuckets << endl;
m_doKeepLoopHeadersOnly = p_klho;
cout << "Keep loop headers only enabled: " << boolalpha << m_doKeepLoopHeadersOnly << endl;
}
void ZaxBase_t::setBasicBlockFloatingInstrumentation(bool p_float)
{
m_bb_float_instrumentation = p_float;
m_bb_float_instrumentation ?
cout << "enable floating instrumentation" << endl :
cout << "disable floating instrumentation" << endl;
cout << "floating instrumentation enabled: " << boolalpha << m_bb_float_instrumentation << endl ;
}
bool ZaxBase_t::getBasicBlockFloatingInstrumentation() const
......@@ -353,7 +337,7 @@ void ZaxBase_t::setWhitelist(const string& p_whitelist)
std::ifstream whitelistFile(p_whitelist);
if (!whitelistFile.is_open())
throw std::runtime_error("Could not open file " + p_whitelist);
std::string line;
auto line = string();
while(whitelistFile >> line)
{
cout <<"Adding " << line << " to white list" << endl;
......@@ -720,24 +704,49 @@ BasicBlockSet_t ZaxBase_t::getBlocksToInstrument(const ControlFlowGraph_t &cfg)
keepers.insert(bb);
}
if(m_verbose)
cout << "#ATTRIBUTE orig_blocks_to_instrument=" << dec << keepers.size() << endl;
return keepers;
}
void ZaxBase_t::filterPaddingNOP(BasicBlockSet_t& p_in_out)
{
const auto orig_size = p_in_out.size();
auto copy=p_in_out;
for(auto block : copy)
{
if (BB_isPaddingNop(block))
{
p_in_out.erase(block);
m_num_bb_skipped_nop_padding++;
}
}
if(m_verbose)
cout << "#ATTRIBUTE nop_padding_filter=" << dec << orig_size << " -> " << p_in_out.size() << endl;
}
void ZaxBase_t::filterKeepLoopHeadersOnly(BasicBlockSet_t& p_in_out, ControlFlowGraph_t& cfg)
{
if(!m_doKeepLoopHeadersOnly)
return;
const auto orig_size = p_in_out.size();
auto input_set=move(p_in_out);
assert(p_in_out.size()==0);
auto loop_header_blocks=BasicBlockSet_t();
const auto loop_nest = m_deep_analysis->getLoops(&cfg);
for(auto loop : loop_nest->getAllLoops())
{
loop_header_blocks.insert(loop -> getHeader());
}
set_intersection(ALLOF(input_set),ALLOF(loop_header_blocks), inserter(p_in_out,p_in_out.begin()));
if(m_verbose)
cout << "#ATTRIBUTE loop_headers_filter=" << dec << orig_size << " -> " << p_in_out.size() << endl;
m_num_bb_loop_header_trimmed += (orig_size-p_in_out.size());
}
void ZaxBase_t::filterEntryBlock(BasicBlockSet_t& p_in_out, BasicBlock_t* p_entry)
{
const auto orig_size = p_in_out.size();
if (p_entry->getSuccessors().size() != 1)
return;
......@@ -754,10 +763,13 @@ void ZaxBase_t::filterEntryBlock(BasicBlockSet_t& p_in_out, BasicBlock_t* p_entr
if (m_verbose) {
cout << "Eliding entry block" << endl;
}
if(m_verbose)
cout << "#ATTRIBUTE entry_block_filter=" << dec << orig_size << " -> " << p_in_out.size() << endl;
}
void ZaxBase_t::filterExitBlocks(BasicBlockSet_t& p_in_out)
{
const auto orig_size = p_in_out.size();
auto copy=p_in_out;
for(auto block : copy)
{
......@@ -787,10 +799,13 @@ void ZaxBase_t::filterExitBlocks(BasicBlockSet_t& p_in_out)
cout << "Eliding exit block" << endl;
}
}
if(m_verbose)
cout << "#ATTRIBUTE exit_block_filter=" << dec << orig_size << " -> " << p_in_out.size() << endl;
}
void ZaxBase_t::filterConditionalBranches(BasicBlockSet_t& p_in_out)
{
const auto orig_size = p_in_out.size();
if (!m_graph_optimize)
return;
auto copy=p_in_out;
......@@ -830,10 +845,13 @@ void ZaxBase_t::filterConditionalBranches(BasicBlockSet_t& p_in_out)
continue;
}
}
if(m_verbose)
cout << "#ATTRIBUTE cond_branch_filter=" << dec << orig_size << " -> " << p_in_out.size() << endl;
}
void ZaxBase_t::filterBlocksByDomgraph(BasicBlockSet_t& p_in_out, const DominatorGraph_t* dg)
{
const auto orig_size = p_in_out.size();
if(!m_domgraph_optimize)
return;
......@@ -887,6 +905,8 @@ void ZaxBase_t::filterBlocksByDomgraph(BasicBlockSet_t& p_in_out, const Dominat
}
}
}
if(m_verbose)
cout << "#ATTRIBUTE dom_graph_filter=" << dec << orig_size << " -> " << p_in_out.size() << endl;
}
// by default, return the first instruction in block
......@@ -971,6 +991,7 @@ void ZaxBase_t::dumpAttributes()
cout << "#ATTRIBUTE num_bb_skipped=" << m_num_bb_skipped << endl;
cout << "#ATTRIBUTE num_bb_skipped_pushjmp=" << m_num_bb_skipped_pushjmp << endl;
cout << "#ATTRIBUTE num_bb_skipped_nop_padding=" << m_num_bb_skipped_nop_padding << endl;
cout << "#ATTRIBUTE num_bb_loop_header_trimmed=" << m_num_bb_loop_header_trimmed << endl;
cout << "#ATTRIBUTE num_bb_float_instrumentation=" << m_num_bb_float_instrumentation << endl;
cout << "#ATTRIBUTE num_bb_float_register_saved=" << m_num_bb_float_regs_saved << endl;
cout << "#ATTRIBUTE graph_optimize=" << boolalpha << m_graph_optimize << endl;
......@@ -993,14 +1014,14 @@ void ZaxBase_t::dumpMap()
ofstream mapfile("zax.map");
mapfile << "# BLOCK_ID ID_EP:size ID_OLDEP:size (ID_INSTRUMENTATION:size)*" << endl;
mapfile << "blockID\t(insnID:size)*" << endl;
for (auto &mb : m_modifiedBlocks)
{
const auto blockid = mb.first;
mapfile << dec << blockid << " ";
mapfile << hex << blockid << "\t";
for (auto &entry : mb.second)
{
mapfile << hex << entry->getBaseID() << ":" << dec << entry->getDataBits().size() << " ";
mapfile << hex << entry->getBaseID() << ":" << dec << entry->getDataBits().size() << "\t";
}
mapfile << endl;
}
......@@ -1218,22 +1239,6 @@ void ZaxBase_t::addLibZaflIntegration()
*/
int ZaxBase_t::execute()
{
getFileIR()->setBaseIDS();
getFileIR()->assembleRegistry();
if (m_breakupCriticalEdges != bceNone)
{
CriticalEdgeBreaker_t ceb(getFileIR(), m_blacklist, m_breakupCriticalEdges, m_verbose);
cout << "#ATTRIBUTE num_bb_extra_blocks=" << ceb.getNumberExtraNodes() << endl;
getFileIR()->setBaseIDS();
getFileIR()->assembleRegistry();
}
if (m_doLoopCountInstrumentation)
{
ZedgeNS::Zedge_t(getFileIR(), m_loopCountBuckets).execute();
getFileIR()->setBaseIDS();
getFileIR()->assembleRegistry();
}
setup();
// for all functions
......@@ -1262,8 +1267,8 @@ int ZaxBase_t::execute()
auto honorRedZone = shouldHonorRedZone(f);
const auto cfgp = ControlFlowGraph_t::factory(f);
const auto &cfg = *cfgp;
auto cfgp = ControlFlowGraph_t::factory(f);
auto &cfg = *cfgp;
const auto num_blocks_in_func = cfg.getBlocks().size();
m_num_bb += num_blocks_in_func;
......@@ -1310,6 +1315,7 @@ int ZaxBase_t::execute()
}
filterPaddingNOP(keepers);
filterKeepLoopHeadersOnly(keepers,cfg);
struct BBSorter
{
......@@ -1370,7 +1376,6 @@ int ZaxBase_t::execute()
addLibZaflIntegration();
teardown();
return 1;
......
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#ifndef _LIBTRANSFORM_ZAXBASE_H
#define _LIBTRANSFORM_ZAXBASE_H
......@@ -20,7 +54,7 @@ namespace Zafl
using ZaflLabelId_t = uint32_t;
using ZaflContextId_t = uint32_t;
using BBRecord_t = vector<Instruction_t*>;
using RegisterSet_t = IRDB_SDK::RegisterIDSet_t;
using RegisterSet_t = RegisterIDSet_t;
enum ContextSensitivity_t {ContextSensitivity_None, ContextSensitivity_Callsite, ContextSensitivity_Function};
/*
......@@ -43,11 +77,13 @@ namespace Zafl
void setDomgraphOptimization(bool);
void setBasicBlockFloatingInstrumentation(bool);
void setEnableForkServer(bool);
void setBreakCriticalEdgeStyle(const bceStyle_t sty);
void setDoLoopCountInstrumentation(bool);
void setLoopCountBuckets(string);
// void setBreakCriticalEdgeStyle(const bceStyle_t sty);
// void setDoLoopCountInstrumentation(bool);
// void setLoopCountBuckets(string);
void setKeepLoopHeadersOnly(bool);
void setContextSensitivity(ContextSensitivity_t);
void filterPaddingNOP(BasicBlockSet_t& p_in_out);
void filterKeepLoopHeadersOnly(BasicBlockSet_t& p_in_out, ControlFlowGraph_t& f);
void filterBlocksByDomgraph(BasicBlockSet_t& in_out, const DominatorGraph_t * dg );
void filterConditionalBranches(BasicBlockSet_t& p_in_out);
void filterEntryBlock(BasicBlockSet_t& in_out, BasicBlock_t* p_entry);
......@@ -96,16 +132,15 @@ namespace Zafl
protected:
pqxxDB_t& m_dbinterface;
unique_ptr<DeadRegisterMap_t> dead_registers;
unique_ptr<DeepAnalysis_t> m_deep_analysis;
unique_ptr<DeadRegisterMap_t> m_dead_registers;
bool m_use_stars; // use STARS to have access to dead register info
bool m_autozafl; // link in library w/ auto fork server
bool m_graph_optimize; // skip basic blocks based on graph
bool m_domgraph_optimize; // skip basic blocks based on dominator graph
bool m_forkserver_enabled; // fork server enabled?
bceStyle_t m_breakupCriticalEdges;
bool m_doLoopCountInstrumentation;
string m_loopCountBuckets;
bool m_doKeepLoopHeadersOnly;
bool m_bb_float_instrumentation; // skip basic blocks based on graph
bool m_verbose;
pair<DataScoop_t*,int> m_trace_map; // afl shared memory trace map
......@@ -126,6 +161,7 @@ namespace Zafl
size_t m_num_bb_skipped;
size_t m_num_bb_skipped_pushjmp;
size_t m_num_bb_skipped_nop_padding;
size_t m_num_bb_loop_header_trimmed;
size_t m_num_bb_skipped_cbranch;
size_t m_num_bb_float_instrumentation;
size_t m_num_bb_float_regs_saved;
......
/***************************************************************************
* Copyright (c) 2018-2019 Zephyr Software LLC. All rights reserved.
*
* This software is furnished under a license and/or other restrictive
* terms and may be used and copied only in accordance with such terms
* and the inclusion of the above copyright notice. This software or
* any other copies thereof may not be provided or otherwise made
* available to any other person without the express written consent
* of an authorized representative of Zephyr Software LCC. Title to,
* ownership of, and all rights in the software is retained by
* Zephyr Software LCC.
*
* Zephyr Software LLC. Proprietary Information
*
* Unless otherwise specified, the information contained in this
* directory, following this legend, and/or referenced herein is
* Zephyr Software LLC. (Zephyr) Proprietary Information.
*
* CONTACT INFO
*
* E-mail: jwd@zephyr-software.com
**************************************************************************/
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
#include "zax.hpp"
#include "critical_edge_breaker.hpp"
#include "loop_count.hpp"
#include "zuntracer.hpp"
using namespace std;
......@@ -80,6 +93,7 @@ int main(int argc, char **argv)
auto untracer_mode=false;
auto break_critical_edge_style=bceNone;
auto do_loop_count_instr=false;
auto do_keep_loop_headers_only=false;
auto loop_count_buckets=string("0,1,2,4,8,16,32,64,128");
auto floating_instrumentation=false;
auto context_sensitivity=ContextSensitivity_None;
......@@ -112,6 +126,7 @@ int main(int argc, char **argv)
{"break-critical-edge", required_argument, 0, 'c'},
{"enable-loop-count-instr", no_argument, 0, 'j'},
{"disable-loop-count-instr", no_argument, 0, 'J'},
{"keep-loop-headers-only", no_argument, 0, 'k'},
{"loop-count-buckets", required_argument, 0, ':'},
{"enable-floating-instrumentation", no_argument, 0, 'i'},
{"disable-floating-instrumentation", no_argument, 0, 'I'},
......@@ -119,7 +134,7 @@ int main(int argc, char **argv)
{"random-seed", required_argument, 0, 'r'},
{0,0,0,0}
};
const char* short_opts="r:z:e:E:w:sv?hagGdDfFuc:jJiIm:M";
const char* short_opts="r:z:e:E:w:sv?hagGdDfFuc:jJkiIm:M";
while(true)
{
......@@ -213,6 +228,9 @@ int main(int argc, char **argv)
case 'J':
do_loop_count_instr=false;
break;
case 'k':
do_keep_loop_headers_only=true;
break;
case ':':
loop_count_buckets = string(optarg);
break;
......@@ -276,9 +294,24 @@ int main(int argc, char **argv)
try
{
const auto zax = (untracer_mode) ?
unique_ptr<ZaxBase_t>(new ZUntracer_t(*pqxx_interface, firp.get(), entry_fork_server, exitpoints, use_stars, autozafl)) :
unique_ptr<ZaxBase_t>(new Zax_t (*pqxx_interface, firp.get(), entry_fork_server, exitpoints, use_stars, autozafl));
if (do_loop_count_instr)
{
ZedgeNS::Zedge_t(firp.get(), loop_count_buckets).execute();
firp->setBaseIDS();
firp->assembleRegistry();
}
if (break_critical_edge_style != bceNone)
{
CriticalEdgeBreaker_t ceb(firp.get(), {}, break_critical_edge_style, verbose);
cout << "#ATTRIBUTE num_bb_extra_blocks=" << ceb.getNumberExtraNodes() << endl;
firp->setBaseIDS();
firp->assembleRegistry();
}
const auto zax = unique_ptr<ZaxBase_t>(
untracer_mode ? static_cast<ZaxBase_t*>(new ZUntracer_t(*pqxx_interface, firp.get(), entry_fork_server, exitpoints, use_stars, autozafl)) :
static_cast<ZaxBase_t*>(new Zax_t (*pqxx_interface, firp.get(), entry_fork_server, exitpoints, use_stars, autozafl)));
if (whitelistFile.size()>0)
zax->setWhitelist(whitelistFile);
......@@ -290,9 +323,10 @@ int main(int argc, char **argv)
zax->setDomgraphOptimization(domgraph_optimize);
zax->setBasicBlockFloatingInstrumentation(floating_instrumentation);
zax->setEnableForkServer(forkserver_enabled);
zax->setBreakCriticalEdgeStyle(break_critical_edge_style);
zax->setDoLoopCountInstrumentation(do_loop_count_instr);
zax->setLoopCountBuckets(loop_count_buckets);
// zax->setBreakCriticalEdgeStyle(break_critical_edge_style);
zax->setKeepLoopHeadersOnly(do_keep_loop_headers_only);
// zax->setDoLoopCountInstrumentation(do_loop_count_instr);
// zax->setLoopCountBuckets(loop_count_buckets);
zax->setContextSensitivity(context_sensitivity);
zax->setFixedMapAddress(fixed_map_address);
......
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#include "zuntracer.hpp"
#define ALLOF(a) begin(a),end(a)
using namespace std;
using namespace IRDB_SDK;
using namespace Zafl;
......@@ -24,6 +59,7 @@ void ZUntracer_t::instrumentBasicBlock(BasicBlock_t *p_bb, const bool p_redZoneH
// Highly efficient instrumentation using known address for tracemap
void ZUntracer_t::_instrumentBasicBlock_fixed(BasicBlock_t *p_bb, char* p_tracemap_addr)
{
const auto &bb_instructions = p_bb->getInstructions();
// 1st instruction in block record is the new entry point of the block (instr)
// 2nd instruction in block record is where the instruction at the old entry point is now at (orig)
auto instr = getInstructionToInstrument(p_bb);
......@@ -31,7 +67,7 @@ void ZUntracer_t::_instrumentBasicBlock_fixed(BasicBlock_t *p_bb, char* p_tracem
const auto blockid = getBlockId();
BBRecord_t block_record;
block_record.push_back(instr);
block_record.insert(end(block_record), ALLOF(bb_instructions));
// e.g.: mov BYTE [ 0x10000 + blockid ], 0x1
const auto s = string("mov BYTE [") + p_tracemap_addr + "+" + to_string(blockid) + "], 0x1";
......
// @HEADER_LANG C++
// @HEADER_COMPONENT zafl
// @HEADER_BEGIN
/*
* Copyright (c) 2018-2019 Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
* This software was developed with SBIR funding and is subject to SBIR Data Rights,
* as detailed below.
*
* SBIR DATA RIGHTS
*
* Contract No. __FA8750-17-C-0295___________________________.
* Contractor Name __Zephyr Software LLC_____________________.
* Address __4826 Stony Point Rd, Barboursville, VA 22923____.
*
*/
// @HEADER_END
#ifndef _LIBTRANSFORM_ZUNTRACER_H
#define _LIBTRANSFORM_ZUNTRACER_H
......