From patchwork Wed Jun 15 08:38:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 13101 Received: (qmail 56336 invoked by alias); 15 Jun 2016 08:38:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 56320 invoked by uid 89); 15 Jun 2016 08:38:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:yao X-HELO: mail-pf0-f195.google.com Received: from mail-pf0-f195.google.com (HELO mail-pf0-f195.google.com) (209.85.192.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 15 Jun 2016 08:38:21 +0000 Received: by mail-pf0-f195.google.com with SMTP id 66so1311566pfy.1 for ; Wed, 15 Jun 2016 01:38:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=xOSJDvQWyT9EgLvSsYM2JHoG7zpGOI6uvIDTFkJVaL8=; b=emwJNDKjvYJCHlAsIQMlnZWcMu9BqqiQ4vNXDhIC/tWMPmk0EKO4CjVPFl1B6nwbLG qeQ1N1t9tXPzxibwQnTkZJVBR5QIbDMjnTte1JKozT48m3n7Fa1MHWIDUxcq0Wb7xTQr 4kH/xJ00uHFfLSQetZXkKfR7vneOcAehbDyA4ocbi2CL/BG70zWNrOm7h84rxXeywunX mBcGTNI9tuOU5ul/yB4g8RC0JiQBIk4ZzlRPs36bQKQlPR7RoSOP/r3jr9Rc5AAJ9c5z Fp7zdkk1uE8p39fXOy1m3YmSHL7J2a76XeGLoxD42YqDwT303qzxjp6JsweMlw4vVkaE JTgw== X-Gm-Message-State: ALyK8tLaqA6zsZfj2FqqoR5ZOwiYJ9taFQpsQx59tXb36cMNo1dNl8eBsZ86RzMIBMKsNw== X-Received: by 10.98.39.129 with SMTP id n123mr2609501pfn.31.1465979899221; Wed, 15 Jun 2016 01:38:19 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc113.osuosl.org. [140.211.9.71]) by smtp.gmail.com with ESMTPSA id ez6sm51016864pab.12.2016.06.15.01.38.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Jun 2016 01:38:18 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH] [AArch64] Use int64_t for address offset Date: Wed, 15 Jun 2016 09:38:10 +0100 Message-Id: <1465979890-14353-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes In AArch64 displaced stepping and fast tracepoint, GDB/GDBserver needs to check whether the offset can fit in the range. We are using int32_t for offset, it is sufficient to get an offset from an instruction, but it is not enough to get an offset from two addresses. For example, we have a BL in shared lib which is at 0x0000002000040774, and the scratch pad for displaced stepping is at 0x400698. The offset can't fit in 28 bit imm. However, since we are using int32_t for offset, GDB thinks the offset can fit it, and generate the B instruction with wrong offset. It fixes the following fail, -FAIL: gdb.base/dso2dso.exp: next over call to sub2 gdb: 2016-06-13 Yao Qi * aarch64-tdep.c (aarch64_displaced_step_b): Use int64_t for variable new_offset. gdb/gdbserver: 2016-06-13 Yao Qi * linux-aarch64-low.c (aarch64_ftrace_insn_reloc_b): Use int64_t for variable new_offset. (aarch64_ftrace_insn_reloc_b_cond): Likewise. (aarch64_ftrace_insn_reloc_cb): Likewise. (aarch64_ftrace_insn_reloc_tb): Likewise. (aarch64_install_fast_tracepoint_jump_pad): Likewise. Use PRIx64 instead of PRIx32. --- gdb/aarch64-tdep.c | 2 +- gdb/gdbserver/linux-aarch64-low.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 88fcf4b..e5ce13e 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -2322,7 +2322,7 @@ aarch64_displaced_step_b (const int is_bl, const int32_t offset, { struct aarch64_displaced_step_data *dsd = (struct aarch64_displaced_step_data *) data; - int32_t new_offset = data->insn_addr - dsd->new_addr + offset; + int64_t new_offset = data->insn_addr - dsd->new_addr + offset; if (can_encode_int32 (new_offset, 28)) { diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c index d237bde..24ac1ee 100644 --- a/gdb/gdbserver/linux-aarch64-low.c +++ b/gdb/gdbserver/linux-aarch64-low.c @@ -1557,7 +1557,7 @@ aarch64_ftrace_insn_reloc_b (const int is_bl, const int32_t offset, { struct aarch64_insn_relocation_data *insn_reloc = (struct aarch64_insn_relocation_data *) data; - int32_t new_offset + int64_t new_offset = insn_reloc->base.insn_addr - insn_reloc->new_addr + offset; if (can_encode_int32 (new_offset, 28)) @@ -1572,7 +1572,7 @@ aarch64_ftrace_insn_reloc_b_cond (const unsigned cond, const int32_t offset, { struct aarch64_insn_relocation_data *insn_reloc = (struct aarch64_insn_relocation_data *) data; - int32_t new_offset + int64_t new_offset = insn_reloc->base.insn_addr - insn_reloc->new_addr + offset; if (can_encode_int32 (new_offset, 21)) @@ -1609,7 +1609,7 @@ aarch64_ftrace_insn_reloc_cb (const int32_t offset, const int is_cbnz, { struct aarch64_insn_relocation_data *insn_reloc = (struct aarch64_insn_relocation_data *) data; - int32_t new_offset + int64_t new_offset = insn_reloc->base.insn_addr - insn_reloc->new_addr + offset; if (can_encode_int32 (new_offset, 21)) @@ -1646,7 +1646,7 @@ aarch64_ftrace_insn_reloc_tb (const int32_t offset, int is_tbnz, { struct aarch64_insn_relocation_data *insn_reloc = (struct aarch64_insn_relocation_data *) data; - int32_t new_offset + int64_t new_offset = insn_reloc->base.insn_addr - insn_reloc->new_addr + offset; if (can_encode_int32 (new_offset, 16)) @@ -1782,7 +1782,7 @@ aarch64_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, { uint32_t buf[256]; uint32_t *p = buf; - int32_t offset; + int64_t offset; int i; uint32_t insn; CORE_ADDR buildaddr = *jump_entry; @@ -2119,7 +2119,7 @@ aarch64_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, { sprintf (err, "E.Jump back from jump pad too far from tracepoint " - "(offset 0x%" PRIx32 " cannot be encoded in 28 bits).", + "(offset 0x%" PRIx64 " cannot be encoded in 28 bits).", offset); return 1; } @@ -2133,7 +2133,7 @@ aarch64_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, { sprintf (err, "E.Jump pad too far from tracepoint " - "(offset 0x%" PRIx32 " cannot be encoded in 28 bits).", + "(offset 0x%" PRIx64 " cannot be encoded in 28 bits).", offset); return 1; }