public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Cary Coutant <ccoutant@gmail.com>
To: Vladislav Khmelevsky <och95@yandex.ru>
Cc: Binutils <binutils@sourceware.org>
Subject: Re: [PATCH] gold/aarch64: Fix adrp distance check
Date: Fri, 29 Jul 2022 13:14:08 -0700	[thread overview]
Message-ID: <CAJimCsFaZnnHW9v6i4DgQxf_P7j5SUOJmp5i42AWwMXau5uVKw@mail.gmail.com> (raw)
In-Reply-To: <20220625175259.3171982-1-och95@yandex.ru>

> The offset between destination and location is a signed number,
> currently the offset is treated as unsigned number, thus mathematical
> shifting of negative value is performed incorrectly.

Do you have a test case to illustrate the problem?

+    int64_t offset
+        = static_cast<int64_t> (Reloc::Page (dest) - Reloc::Page (location));
+    int64_t adrp_imm = offset < 0 ? ~(~offset >> 12) : offset >> 12;

C++ conventions: No space before paren in a function call.

The cast is unnecessary here for assignment to an int64_t. Once the
result is in a signed int, I don't think you need to go to all that
extra trouble to shift it.

I'd suggest this instead:

    int64_t adrp_imm = Reloc::Page(dest) - Reloc::Page(location);
    adrp_imm >>= 12;

-cary

  reply	other threads:[~2022-07-29 20:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-25 17:52 Vladislav Khmelevsky
2022-07-29 20:14 ` Cary Coutant [this message]
2022-07-29 20:44   ` Andreas Schwab
2022-07-29 22:14     ` Cary Coutant
2022-08-08 19:18       ` Vladislav Khmelevsky
2022-11-07 11:28 Vladislav Khmelevsky
2022-11-11  0:49 ` Cary Coutant

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJimCsFaZnnHW9v6i4DgQxf_P7j5SUOJmp5i42AWwMXau5uVKw@mail.gmail.com \
    --to=ccoutant@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=och95@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).