1- // Copyright 2015-2021 Carnegie Mellon University. See LICENSE file for terms.
1+ // Copyright 2015-2022 Carnegie Mellon University. See LICENSE file for terms.
22
33#include < boost/optional.hpp>
44
@@ -226,7 +226,7 @@ bool RegisterUsage::check_saved_register(SgAsmX86Instruction *insn, RegisterDesc
226226 // that qualified as a save/restore pair and no evidence to the contrary (e..g having return
227227 // false already), then it's time to make the instructions as a save/restore pair.
228228 if (restore_insn) {
229- GTRACE << " Saved register: reg=" << unparseX86Register (reg, NULL )
229+ GTRACE << " Saved register: reg=" << unparseX86Register (reg, {} )
230230 << " save=" << debug_instruction (insn)
231231 << " restore=" << debug_instruction (restore_insn) << LEND;
232232 saved_registers.insert (SavedRegister (reg, insn, restore_insn));
@@ -284,8 +284,8 @@ void RegisterUsage::analyze_parameters() {
284284 const Addr2DUChainMap& dd = p->get_usedef ().get_dependencies ();
285285
286286 // Get a handle to the stack pointer register, because it's special.
287- const RegisterDictionary regdict = fd->ds .get_regdict ();
288- RegisterDescriptor esp = regdict. find (" esp" );
287+ RegisterDictionaryPtrArg regdict = fd->ds .get_regdict ();
288+ RegisterDescriptor esp = regdict-> find (" esp" );
289289
290290 // This is for keeping track of which stack parameter deltas we've actually used, and which
291291 // which haven't. This might be duplicated work, and we've not saved this anywhere. Here is
@@ -404,11 +404,11 @@ void RegisterUsage::analyze_parameters() {
404404 // Strictly speaking, I think this means that skipping memory reads earlier could be
405405 // incorrect as well... :-(
406406
407- RegisterDescriptor initial_reg = regdict. find (cmt.substr (0 , clen - 2 ));
407+ RegisterDescriptor initial_reg = regdict-> find (cmt.substr (0 , clen - 2 ));
408408
409409 parameter_registers[initial_reg] = insn;
410410 GTRACE << " Function " << fd->address_string () << " uses register "
411- << unparseX86Register (initial_reg, NULL )
411+ << unparseX86Register (initial_reg, {} )
412412 << " as parameter in " << debug_instruction (insn) << LEND;
413413 break ;
414414 }
@@ -420,7 +420,7 @@ void RegisterUsage::analyze_parameters() {
420420 GTRACE << " Function " << fd->address_string () << " has parameters: " ;
421421 for (const RegisterEvidenceMap::value_type& rpair : parameter_registers) {
422422 RegisterDescriptor reg = rpair.first ;
423- GTRACE << " " << unparseX86Register (reg, NULL );
423+ GTRACE << " " << unparseX86Register (reg, {} );
424424 }
425425 GTRACE << LEND;
426426}
@@ -448,12 +448,12 @@ void RegisterUsage::analyze_changed() {
448448
449449 RegisterSet all_changed_registers = routput->diff (rinput);
450450
451- const RegisterDictionary regdict = fd->ds .get_regdict ();
452- RegisterDescriptor esp = regdict. find (" esp" );
453- RegisterDescriptor ebp = regdict. find (" ebp" );
454- RegisterDescriptor esi = regdict. find (" esi" );
455- RegisterDescriptor edi = regdict. find (" edi" );
456- RegisterDescriptor ebx = regdict. find (" ebx" );
451+ RegisterDictionaryPtrArg regdict = fd->ds .get_regdict ();
452+ RegisterDescriptor esp = regdict-> find (" esp" );
453+ RegisterDescriptor ebp = regdict-> find (" ebp" );
454+ RegisterDescriptor esi = regdict-> find (" esi" );
455+ RegisterDescriptor edi = regdict-> find (" edi" );
456+ RegisterDescriptor ebx = regdict-> find (" ebx" );
457457
458458 // It turns out that we can't enable this code properly because our system is just too
459459 // fragile. If we're incorrect in any low-level function, this propogates that failure
@@ -481,7 +481,7 @@ void RegisterUsage::analyze_changed() {
481481 // Warn about cases where we reject register changes based on calling convention assumptions.
482482 if (rd == ebp or rd == esi or rd == edi or rd == ebx) {
483483 GDEBUG << " Function " << fd->address_string () << " overwrites "
484- << unparseX86Register (rd, NULL )
484+ << unparseX86Register (rd, {} )
485485 << " violating all known calling conventions." << LEND;
486486 }
487487 else {
@@ -491,7 +491,7 @@ void RegisterUsage::analyze_changed() {
491491
492492 GDEBUG << " Function " << fd->address_string () << " changed registers: " ;
493493 for (RegisterDescriptor rd : changed_registers) {
494- GDEBUG << " " << unparseX86Register (rd, NULL );
494+ GDEBUG << " " << unparseX86Register (rd, {} );
495495 }
496496 GDEBUG << LEND;
497497}
@@ -537,8 +537,8 @@ CallingConvention::CallingConvention(size_t word_size_, const std::string &name_
537537 assert (!name.empty ());
538538}
539539
540- void CallingConvention::add_nonvolatile (const RegisterDictionary & dict, std::string rname) {
541- RegisterDescriptor rd = dict. find (rname);
540+ void CallingConvention::add_nonvolatile (RegisterDictionaryPtrArg dict, std::string rname) {
541+ RegisterDescriptor rd = dict-> find (rname);
542542 if (!rd.is_valid ()) {
543543 GFATAL << " Unable to find non-volatile register '" << rname << " '." << LEND;
544544 assert (rd.is_valid ());
@@ -578,13 +578,13 @@ void CallingConvention::report() const {
578578
579579 GTRACE << " Parameter regs: " ;
580580 for (RegisterDescriptor rd : reg_params) {
581- GTRACE << " " << unparseX86Register (rd, NULL );
581+ GTRACE << " " << unparseX86Register (rd, {} );
582582 }
583583 GTRACE << LEND;
584584
585585 GTRACE << " Nonvolatile regs: " ;
586586 for (RegisterDescriptor rd : nonvolatile) {
587- GTRACE << " " << unparseX86Register (rd, NULL );
587+ GTRACE << " " << unparseX86Register (rd, {} );
588588 }
589589 GTRACE << LEND;
590590}
@@ -727,7 +727,7 @@ std::string ParameterDefinition::to_string() const {
727727 std::stringstream out;
728728 out << " num=" << d.num ;
729729 if (is_reg ()) {
730- out << " reg=" << unparseX86Register (d.reg , NULL );
730+ out << " reg=" << unparseX86Register (d.reg , {} );
731731 }
732732 else {
733733 out << " sd=" << d.stack_delta ;
@@ -786,7 +786,7 @@ void ParameterDefinition::debug() const {
786786
787787 OINFO << " num=" << d.num ;
788788 if (is_reg ()) {
789- OINFO << " reg=" << unparseX86Register (d.reg , NULL );
789+ OINFO << " reg=" << unparseX86Register (d.reg , {} );
790790 }
791791 else {
792792 OINFO << " sd=" << d.stack_delta ;
@@ -1110,7 +1110,7 @@ CallingConventionMatcher::match(const FunctionDescriptor* fd,
11101110 if (ru.changed_registers .find (rd) != ru.changed_registers .end ()) {
11111111 GDEBUG << " Function " << fd->address_string () << " can't match "
11121112 << cc.get_name () << " because non-volatile register "
1113- << unparseX86Register (rd, NULL ) << " was changed." << LEND;
1113+ << unparseX86Register (rd, {} ) << " was changed." << LEND;
11141114 follows_nonvolatile_rule = false ;
11151115 break ;
11161116 }
@@ -1142,7 +1142,7 @@ CallingConventionMatcher::match(const FunctionDescriptor* fd,
11421142 static char const * allowed_registers[] =
11431143 {" esp" , " df" , " cs" , " ds" , " ss" , " es" , " gs" , " fs" , nullptr };
11441144 for (char const ** regname = allowed_registers; *regname; ++regname) {
1145- RegisterDescriptor rd = regdict. find (*regname);
1145+ RegisterDescriptor rd = regdict-> find (*regname);
11461146 if (temp_params.find (rd) != temp_params.end ()) temp_params.erase (rd);
11471147 }
11481148
@@ -1166,7 +1166,7 @@ CallingConventionMatcher::match(const FunctionDescriptor* fd,
11661166 }
11671167 else {
11681168 GTRACE << " Function " << fd->address_string () << " does not use parameter register "
1169- << unparseX86Register (rd, NULL ) << LEND;
1169+ << unparseX86Register (rd, {} ) << LEND;
11701170 // If there are function parameters that are passed in registers, but not actually
11711171 // used, then breaking here causes a premature end to the consideration of the
11721172 // remaining parameters in the calling convention, leaving any additional parameters
@@ -1183,7 +1183,7 @@ CallingConventionMatcher::match(const FunctionDescriptor* fd,
11831183 GTRACE << " Unmatched parameter registers: " ;
11841184 for (const RegisterEvidenceMap::value_type& rpair : temp_params) {
11851185 RegisterDescriptor rd = rpair.first ;
1186- GTRACE << " " << unparseX86Register (rd, NULL );
1186+ GTRACE << " " << unparseX86Register (rd, {} );
11871187 }
11881188 GTRACE << LEND;
11891189 continue ;
@@ -1213,16 +1213,20 @@ CallingConventionMatcher::match(const FunctionDescriptor* fd,
12131213CallingConventionMatcher::CallingConventionMatcher ()
12141214 // It is presumes that the amd64 register dictionary is a superset of the 32-bit and 16-bit
12151215 // dictionaries
1216- : regdict(*Rose::BinaryAnalysis::RegisterDictionary::dictionary_amd64 ())
1216+ #if PHAROS_ROSE_REGISTERDICTIONARY_PTR_HACK
1217+ : regdict(Rose::BinaryAnalysis::RegisterDictionary::instanceAmd64())
1218+ #else
1219+ : regdict(Rose::BinaryAnalysis::RegisterDictionary::dictionary_amd64())
1220+ #endif
12171221{
12181222 // ================================================================================
12191223 // 16-bit calling conventions...
12201224 // ================================================================================
12211225 // Agner says 16-bit DOS and windows has SI, DI, BP and DS as nonvolatile.
12221226
1223- RegisterDescriptor eax = regdict. find (" eax" );
1224- RegisterDescriptor ecx = regdict. find (" ecx" );
1225- RegisterDescriptor edx = regdict. find (" edx" );
1227+ RegisterDescriptor eax = regdict-> find (" eax" );
1228+ RegisterDescriptor ecx = regdict-> find (" ecx" );
1229+ RegisterDescriptor edx = regdict-> find (" edx" );
12261230 // RegisterDescriptor st0 = regdict->find("st0");
12271231
12281232 // Agner says this list is correct for Windows & Unix
@@ -1341,18 +1345,18 @@ CallingConventionMatcher::CallingConventionMatcher()
13411345 // See earlier comment on clearing df being allowed.
13421346 nonvol.add_nonvolatile (regdict, " df" );
13431347
1344- RegisterDescriptor rax = regdict. find (" rax" );
1345- RegisterDescriptor rdi = regdict. find (" rdi" );
1346- RegisterDescriptor rsi = regdict. find (" rsi" );
1347- RegisterDescriptor rcx = regdict. find (" rcx" );
1348- RegisterDescriptor rdx = regdict. find (" rdx" );
1349- RegisterDescriptor r8 = regdict. find (" r8" );
1350- RegisterDescriptor r9 = regdict. find (" r9" );
1351-
1352- RegisterDescriptor xmm0 = regdict. find (" xmm0" );
1353- RegisterDescriptor xmm1 = regdict. find (" xmm1" );
1354- RegisterDescriptor xmm2 = regdict. find (" xmm2" );
1355- RegisterDescriptor xmm3 = regdict. find (" xmm3" );
1348+ RegisterDescriptor rax = regdict-> find (" rax" );
1349+ RegisterDescriptor rdi = regdict-> find (" rdi" );
1350+ RegisterDescriptor rsi = regdict-> find (" rsi" );
1351+ RegisterDescriptor rcx = regdict-> find (" rcx" );
1352+ RegisterDescriptor rdx = regdict-> find (" rdx" );
1353+ RegisterDescriptor r8 = regdict-> find (" r8" );
1354+ RegisterDescriptor r9 = regdict-> find (" r9" );
1355+
1356+ RegisterDescriptor xmm0 = regdict-> find (" xmm0" );
1357+ RegisterDescriptor xmm1 = regdict-> find (" xmm1" );
1358+ RegisterDescriptor xmm2 = regdict-> find (" xmm2" );
1359+ RegisterDescriptor xmm3 = regdict-> find (" xmm3" );
13561360
13571361 cc = CallingConvention (64 , " __x64call" , " GNU C Compiler" );
13581362 cc.set_stack_alignment (64 );
0 commit comments