Commit e63aaf6e authored by Jason Hiser's avatar Jason Hiser 🚜

code cleanup in stack stamp

parent d3cc5fc9
Pipeline #2582 passed with stages
in 6 minutes and 38 seconds
This diff is collapsed.
......@@ -25,22 +25,30 @@
#include <irdb-transform>
#include <memory>
// use a namespace for clarity
namespace Stamper
// std and IRDB namespaces needed
using namespace std;
using namespace IRDB_SDK;
// a type for the stame values
using StampValue_t = unsigned int;
// a class to transform an IR by stamping (xoring) return addresses
class StackStamp_t : public Transform
StackStamp_t(FileIR_t *p_variantIR, StampValue_t sv, bool p_verbose);
int execute();
private: // methods
// methods
// determine if we can stamp the given function
bool can_stamp(Function_t* f);
// stamp a function
......@@ -55,26 +63,55 @@ namespace Stamper
// stamp an instruction in a function
Instruction_t* stamp(Function_t* f, Instruction_t* i);
// jdh: ???
// get the stamp value for a function -- this is for future expansion
// if we want different stamp values per function. Right now it
// just returns the global stamp value
StampValue_t get_stamp(Function_t* f);
private: // data
// types
// Stack stamping changes the return address representation. For
// programs that use stack unwinding or exception handling, we need
// to update the unwind info.
// The IRDB FileIR representation shares unwind information between
// instructions for memory efficiency purposes.
// Since we will be editing the IR's unwind info, we have to be cautious
// about not using excess memory or this transform may build an IR that
// requires excessive memory for large programs. (This has ben observed
// for SPEC's WRF program).
// The class below is a cache for EH programs (related to stack unwinding)
// so we can re-use newly created unwind structures for other instructions.
struct EhProgramPlaceHolder_t
uint8_t caf;
int8_t daf;
int8_t rr;
uint8_t ptrsize; // needed for interpreting programs
EhProgramListing_t cie_program;
EhProgramListing_t fde_program;
RelocationSet_t relocs;
// these are the fields in an EH program
// we willb e changing only the FDE program, but need the others
// to decide on equality of EH programs.
uint8_t caf; // code alignment factor
int8_t daf; // data alignment factor
int8_t rr; // return register
uint8_t ptrsize; // pointer size
EhProgramListing_t cie_program; // the DWARF program in the CIE
EhProgramListing_t fde_program; // the DWARF program in the FDE
RelocationSet_t relocs; // any relocations for the EH program
// getters
EhProgramListing_t& getCIEProgram() { return cie_program; }
EhProgramListing_t& getFDEProgram() { return fde_program; }
uint8_t getCodeAlignmentFactor() const { return caf; }
int8_t getDataAlignmentFactor() const { return daf; }
int8_t getReturnRegNumber() const { return rr; }
uint8_t getPointerSize() const { return ptrsize; }
// construct a "placeholder" from the real thing.
EhProgramPlaceHolder_t(const IRDB_SDK::EhProgram_t* orig)
......@@ -89,22 +126,24 @@ namespace Stamper
// data
StampValue_t stamp_value = (StampValue_t)0; // how to stamp, for now this value is shared across all functions in the IR
bool verbose = false; // how verbose to be
StampValue_t stamp_value = (StampValue_t)0;
bool verbose = false;
int instructions_added = 0;
int functionsTransformed = 0;
int functionsNotTransformed = 0;
// a "cache" for EH programs (related to stack unwinding) so we can re-use newly created EH programs
map<EhProgramPlaceHolder_t, EhProgram_t*> all_eh_pgms;
// stats
int instructions_added = 0; // how many instructions were added
int functionsTransformed = 0; // how many functions were transformed
int functionsNotTransformed = 0; // how many functions were skipped
friend bool operator<(const EhProgramPlaceHolder_t &a, const EhProgramPlaceHolder_t& b) ;
// this is how we compare "Placeholders" for eh programs. Useful for std::containers
bool operator<(const StackStamp_t::EhProgramPlaceHolder_t &a, const StackStamp_t::EhProgramPlaceHolder_t& b);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment