Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#4940: Fix the wrong aflags estimation in drreg #4941

Merged
merged 33 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0fdb97f
fix issue#4940
JerryYouxin Jun 8, 2021
17928a6
summarize the comment
JerryYouxin Jun 9, 2021
c3fdf00
add test for aflag reservation of analysis phase
JerryYouxin Jun 9, 2021
e6fbd30
make the aflag test general
JerryYouxin Jun 10, 2021
71c9950
delete redundant test
JerryYouxin Jun 10, 2021
e6db5db
fix format with clang-format
JerryYouxin Jun 10, 2021
1c423ae
update assertion message for aflag liveness test
JerryYouxin Jun 10, 2021
816ee64
delete the unused variables
JerryYouxin Jun 10, 2021
dc01bcc
Attempt debugging failing test using tmate
JerryYouxin Jun 15, 2021
2906920
Update ci-windows.yml
JerryYouxin Jun 16, 2021
62fcca1
Merge branch 'master' into master
JerryYouxin Jun 16, 2021
7577dc1
Update ci-windows.yml
JerryYouxin Jun 17, 2021
b483d76
Merge branch 'master' into master
JerryYouxin Jun 18, 2021
0b3f360
Merge branch 'master' into master
JerryYouxin Jun 21, 2021
60fe1a7
Update drreg-test.c
JerryYouxin Jun 21, 2021
39eff78
Merge branch 'master' into master
JerryYouxin Jun 22, 2021
8f59ad7
Merge branch 'master' into master
JerryYouxin Jun 24, 2021
ffe3aea
Merge branch 'master' into master
JerryYouxin Jun 25, 2021
49e297c
fix aflags over-estimation of drx
JerryYouxin Jul 8, 2021
753450c
Merge branch 'master' into master
JerryYouxin Jul 8, 2021
a22d098
fix format error
JerryYouxin Jul 8, 2021
114fd30
Revert "Update ci-windows.yml"
JerryYouxin Jul 9, 2021
85080f4
Revert "Update ci-windows.yml"
JerryYouxin Jul 9, 2021
90a117b
Revert "Attempt debugging failing test using tmate"
JerryYouxin Jul 9, 2021
8ef077e
Merge branch 'master' into master
JerryYouxin Jul 9, 2021
7cc24ac
simplify drx_aflags_are_dead
JerryYouxin Jul 13, 2021
9a23c38
Merge branch 'master' into master
JerryYouxin Jul 13, 2021
63be997
use DR_ASSERT_MSG to avoid unused var error
JerryYouxin Jul 13, 2021
94518c2
Merge branch 'master' of https://github.com/JerryYouxin/dynamorio
JerryYouxin Jul 13, 2021
a0ac116
use IF_DEBUG instead
JerryYouxin Jul 13, 2021
8936219
skip drx init and exit
JerryYouxin Jul 14, 2021
2c1e21e
Merge branch 'master' into master
JerryYouxin Jul 14, 2021
df7a6f4
add comment on drx init/exit
JerryYouxin Jul 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/drreg/drreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ drreg_forward_analysis(void *drcontext, instr_t *start)
aflags_new = instr_get_arith_flags(inst, DR_QUERY_INCLUDE_COND_SRCS);
/* reading and writing counts only as reading */
aflags_new &= (~(EFLAGS_READ_TO_WRITE(aflags_new)));
/* writing doesn't count if already read */
aflags_new &= (~(EFLAGS_READ_TO_WRITE(aflags_cur)));
/* reading doesn't count if already written */
aflags_new &= (~(EFLAGS_WRITE_TO_READ(aflags_cur)));
aflags_cur |= aflags_new;
Expand Down
30 changes: 4 additions & 26 deletions ext/drx/drx.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,32 +219,10 @@ DR_EXPORT
bool
drx_aflags_are_dead(instr_t *where)
{
instr_t *instr;
uint flags;
for (instr = where; instr != NULL; instr = instr_get_next(instr)) {
/* we treat syscall/interrupt as aflags read */
if (instr_is_syscall(instr) || instr_is_interrupt(instr))
return false;
flags = instr_get_arith_flags(instr, DR_QUERY_DEFAULT);
if (TESTANY(EFLAGS_READ_ARITH, flags))
return false;
if (TESTALL(EFLAGS_WRITE_ARITH, flags))
return true;
if (instr_is_cti(instr)) {
if (instr_is_app(instr) &&
(instr_is_ubr(instr) || instr_is_call_direct(instr))) {
instr_t *next = instr_get_next(instr);
opnd_t tgt = instr_get_target(instr);
/* continue on elision */
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
if (next != NULL && instr_is_app(next) && opnd_is_pc(tgt) &&
opnd_get_pc(tgt) == instr_get_app_pc(next))
continue;
}
/* unknown target, assume aflags is live */
return false;
}
}
return false;
bool dead = false;
drreg_status_t res = drreg_are_aflags_dead(dr_get_current_drcontext(), where, &dead);
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
ASSERT(res == DRREG_SUCCESS, "drreg_are_aflags_dead failed!");
return dead;
}

/***************************************************************************
Expand Down
1 change: 1 addition & 0 deletions suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,7 @@ endif (UNIX)
tobuild_ci(client.drreg-test client-interface/drreg-test.c "" "" "")
use_DynamoRIO_extension(client.drreg-test.dll drmgr)
use_DynamoRIO_extension(client.drreg-test.dll drreg)
use_DynamoRIO_extension(client.drreg-test.dll drx)
target_include_directories(client.drreg-test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/client-interface)

Expand Down
16 changes: 14 additions & 2 deletions suite/tests/client-interface/drreg-test.dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "dr_api.h"
#include "drmgr.h"
#include "drreg.h"
#include "drx.h"
#include "client_tools.h"
#include "drreg-test-shared.h"
#include <string.h> /* memset */
Expand Down Expand Up @@ -388,6 +389,14 @@ static dr_emit_flags_t
event_app_analysis(void *drcontext, void *tag, instrlist_t *bb, bool for_trace,
bool translating, OUT void *user_data)
{
for (instr_t *instr = instrlist_first(bb); instr != NULL;
instr = instr_get_next(instr)) {
bool dead;
CHECK(drreg_are_aflags_dead(drcontext, instr, &dead) == DRREG_SUCCESS,
"drreg_are_aflags_dead should always work");
CHECK(drx_aflags_are_dead(instr) == dead,
"aflags liveness estimation of drx and drreg should always be consistent");
}
return DR_EMIT_DEFAULT;
}

Expand Down Expand Up @@ -1139,10 +1148,13 @@ event_instru2instru(void *drcontext, void *tag, instrlist_t *bb, bool for_trace,
static void
event_exit(void)
{
if (!drmgr_unregister_bb_insertion_event(event_app_instruction) ||
if (!drmgr_unregister_bb_instrumentation_ex_event(event_app2app, event_app_analysis,
event_app_instruction,
event_instru2instru) ||
drreg_exit() != DRREG_SUCCESS)
CHECK(false, "exit failed");

drx_exit();
drmgr_exit();
}

Expand All @@ -1153,7 +1165,7 @@ dr_init(client_id_t id)
* a DR slot.
*/
drreg_options_t ops = { sizeof(ops), 2 /*max slots needed*/, false };
if (!drmgr_init() || drreg_init(&ops) != DRREG_SUCCESS)
if (!drx_init() || !drmgr_init() || drreg_init(&ops) != DRREG_SUCCESS)
CHECK(false, "init failed");

note_base = drmgr_reserve_note_range(DRREG_TEST_NOTE_COUNT);
Expand Down