diff --git a/clients/drcachesim/tracer/raw2trace_shared.cpp b/clients/drcachesim/tracer/raw2trace_shared.cpp index ca2b17e82b2..e31d5287b01 100644 --- a/clients/drcachesim/tracer/raw2trace_shared.cpp +++ b/clients/drcachesim/tracer/raw2trace_shared.cpp @@ -287,8 +287,8 @@ module_mapper_t::read_and_map_modules() modvec_.push_back(module_t(info.path, info.start, NULL, 0, 0, 0)); } else if (info.containing_index != info.index) { // For split segments, we assume our mapped layout matches the original. - byte *seg_map_base = modvec_[info.containing_index].map_seg_base + - (info.start - modvec_[info.containing_index].orig_seg_base); + byte *seg_map_base = modvec_[info.containing_index].map_seg_base - + modvec_[info.containing_index].orig_seg_base + info.start; VPRINT(1, "Secondary segment: module %d seg %p-%p = %s\n", (int)modvec_.size(), seg_map_base, seg_map_base + info.size, info.path); diff --git a/clients/drcachesim/tracer/raw2trace_shared.h b/clients/drcachesim/tracer/raw2trace_shared.h index 47952f9e6f5..b5d51e60eaf 100644 --- a/clients/drcachesim/tracer/raw2trace_shared.h +++ b/clients/drcachesim/tracer/raw2trace_shared.h @@ -286,7 +286,7 @@ class module_mapper_t { reinterpret_cast(entry->start_pc); } else { size_t idx = static_cast(modidx); // Avoid win32 warnings. - app_pc res = map_pc - modvec_[idx].map_seg_base + modvec_[idx].orig_seg_base; + app_pc res = modvec_[idx].orig_seg_base - modvec_[idx].map_seg_base + map_pc; #ifdef ARM // Match Thumb vs Arm mode by setting LSB. if (TESTANY(1, modoffs)) @@ -312,8 +312,8 @@ class module_mapper_t { size_t idx = static_cast(modidx); // Avoid win32 warnings. // Cast to unsigned pointer-sized int first to avoid sign-extending. return reinterpret_cast( - reinterpret_cast(modvec_[idx].orig_seg_base)) + - (modoffs - modvec_[idx].seg_offs); + reinterpret_cast(modvec_[idx].orig_seg_base) + + (modoffs - modvec_[idx].seg_offs)); } } diff --git a/core/drlibc/drlibc_module_elf.c b/core/drlibc/drlibc_module_elf.c index edf5dc0a565..75d0b68c9a3 100644 --- a/core/drlibc/drlibc_module_elf.c +++ b/core/drlibc/drlibc_module_elf.c @@ -198,7 +198,7 @@ module_vaddr_from_prog_header(app_pc prog_header, uint num_segments, min_vaddr = MIN(min_vaddr, (app_pc)ALIGN_BACKWARD(prog_hdr->p_vaddr, PAGE_SIZE)); if (min_vaddr == (app_pc)prog_hdr->p_vaddr) - first_end = (app_pc)prog_hdr->p_vaddr + prog_hdr->p_memsz; + first_end = (app_pc)(prog_hdr->p_vaddr + prog_hdr->p_memsz); max_end = MAX( max_end, (app_pc)ALIGN_FORWARD(prog_hdr->p_vaddr + prog_hdr->p_memsz, PAGE_SIZE)); @@ -456,7 +456,7 @@ elf_loader_map_phdrs(elf_loader_t *elf, bool fixed, map_fn_t map_func, * (notably some kernels) seem to ignore it. These corner cases are left * as unsolved for now. */ - seg_base = (app_pc)ALIGN_BACKWARD(prog_hdr->p_vaddr, PAGE_SIZE) + delta; + seg_base = (app_pc)(ALIGN_BACKWARD(prog_hdr->p_vaddr, PAGE_SIZE) + delta); seg_end = (app_pc)ALIGN_FORWARD(prog_hdr->p_vaddr + prog_hdr->p_filesz, PAGE_SIZE) + delta; @@ -522,7 +522,7 @@ elf_loader_map_phdrs(elf_loader_t *elf, bool fixed, map_fn_t map_func, } ASSERT(map != NULL); /* fill zeros at extend size */ - file_end = (app_pc)prog_hdr->p_vaddr + prog_hdr->p_filesz; + file_end = (app_pc)(prog_hdr->p_vaddr + prog_hdr->p_filesz); if (seg_end > file_end + delta) { /* There is typically one RW PT_LOAD segment for .data and * .bss. If .data ends and .bss starts before filesz bytes, diff --git a/core/ir/aarch64/codec.c b/core/ir/aarch64/codec.c index d1d21a57db2..9d2ab5a617b 100644 --- a/core/ir/aarch64/codec.c +++ b/core/ir/aarch64/codec.c @@ -1081,8 +1081,8 @@ static bool decode_opnd_adr_page(int scale, uint enc, byte *pc, OUT opnd_t *opnd) { uint bits = (enc >> 3 & 0x1ffffc) | (enc >> 29 & 3); - byte *addr = ((byte *)((ptr_uint_t)pc >> scale << scale) + - extract_int(bits, 0, 21) * ((ptr_int_t)1 << scale)); + byte *addr = (byte *)(((ptr_uint_t)pc >> scale << scale) + + extract_int(bits, 0, 21) * ((ptr_int_t)1 << scale)); *opnd = opnd_create_rel_addr(addr, OPSZ_0); return true; } diff --git a/core/ir/instrlist.c b/core/ir/instrlist.c index d8abce3e117..78af876f533 100644 --- a/core/ir/instrlist.c +++ b/core/ir/instrlist.c @@ -572,7 +572,7 @@ instrlist_encode_to_copy(void *drcontext, instrlist_t *ilist, byte *copy_pc, byte *pc = instr_encode_to_copy(dcontext, inst, copy_pc, final_pc); if (pc == NULL) return NULL; - final_pc += pc - copy_pc; + final_pc = (byte *)((ptr_uint_t)final_pc + (pc - copy_pc)); copy_pc = pc; } return copy_pc; diff --git a/core/ir/x86/encode.c b/core/ir/x86/encode.c index d9ea8e9e73d..a354cdae977 100644 --- a/core/ir/x86/encode.c +++ b/core/ir/x86/encode.c @@ -3012,7 +3012,7 @@ encode_cti(instr_t *instr, byte *copy_pc, byte *final_pc, CLIENT_ASSERT(!instr_is_cti_short_rewrite(instr, NULL), "encode_cti error: jecxz/loop already mangled"); /* offset is from start of next instr */ - offset = target - ((ptr_int_t)(pc + 1 - copy_pc + final_pc)); + offset = target - (pc + 1 - copy_pc + (ptr_uint_t)final_pc); if (check_reachable && !(offset >= INT8_MIN && offset <= INT8_MAX)) { CLIENT_ASSERT(!assert_reachable, "encode_cti error: target beyond 8-bit reach"); @@ -3023,7 +3023,7 @@ encode_cti(instr_t *instr, byte *copy_pc, byte *final_pc, } else { /* 32-bit offset */ /* offset is from start of next instr */ - ptr_int_t offset = target - ((ptr_int_t)(pc + 4 - copy_pc + final_pc)); + ptr_int_t offset = target - (pc + 4 - copy_pc + (ptr_uint_t)final_pc); #ifdef X64 if (check_reachable && !REL32_REACHABLE_OFFS(offset)) { CLIENT_ASSERT(!assert_reachable, diff --git a/ext/drcovlib/modules.c b/ext/drcovlib/modules.c index 959e8e3b9e1..ceac2e3dc3a 100644 --- a/ext/drcovlib/modules.c +++ b/ext/drcovlib/modules.c @@ -467,7 +467,8 @@ module_read_entry_print(module_read_entry_t *entry, uint idx, char *buf, size_t len = dr_snprintf(buf, size, "%3u, %3u, " PFX ", " PFX ", " PFX ", " ZHEX64_FORMAT_STRING ", " PFX ", ", - idx, entry->containing_id, entry->base, entry->base + entry->size, + idx, entry->containing_id, entry->base, + (app_pc)((ptr_uint_t)entry->base + (ptr_uint_t)entry->size), entry->entry, entry->offset, entry->preferred_base); if (len == -1) return -1;