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#3544 RV64: Implement mangle_rel_addr() #6388

Merged
merged 4 commits into from
Oct 29, 2023
Merged
Changes from all commits
Commits
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
34 changes: 32 additions & 2 deletions core/arch/riscv64/mangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@

#include "../globals.h"
#include "arch.h"
#include "instrument.h" /* instrlist_meta_preinsert */
/* Make code more readable by shortening long lines.
* We mark everything we add as non-app instr.
*/
#define PRE instrlist_meta_preinsert
ksco marked this conversation as resolved.
Show resolved Hide resolved

void
mangle_arch_init(void)
Expand Down Expand Up @@ -190,8 +195,33 @@ instr_t *
mangle_rel_addr(dcontext_t *dcontext, instrlist_t *ilist, instr_t *instr,
instr_t *next_instr)
{
/* FIXME i#3544: Not implemented */
ASSERT_NOT_IMPLEMENTED(false);
opnd_t dst = instr_get_dst(instr, 0);
app_pc tgt;
ASSERT(instr_get_opcode(instr) == OP_auipc);
ASSERT(instr_has_rel_addr_reference(instr));
instr_get_rel_data_or_instr_target(instr, &tgt);
ASSERT(opnd_is_reg(dst));
ASSERT(opnd_is_rel_addr(instr_get_src(instr, 0)));

ASSERT_NOT_IMPLEMENTED(!instr_uses_reg(instr, DR_REG_TP));

if (instr_uses_reg(instr, dr_reg_stolen)) {
dst = opnd_create_reg(DR_REG_A0);
PRE(ilist, next_instr,
instr_create_save_to_tls(dcontext, DR_REG_A0, TLS_REG0_SLOT));
}

insert_mov_immed_ptrsz(dcontext, (ptr_int_t)tgt, dst, ilist, next_instr, NULL, NULL);

if (instr_uses_reg(instr, dr_reg_stolen)) {
PRE(ilist, next_instr,
instr_create_save_to_tls(dcontext, DR_REG_A0, TLS_REG_STOLEN_SLOT));
PRE(ilist, next_instr,
instr_create_restore_from_tls(dcontext, DR_REG_A0, TLS_REG0_SLOT));
}

instrlist_remove(ilist, instr);
instr_destroy(dcontext, instr);
return NULL;
}

Expand Down
Loading