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