Fix PC-relative calculations to work entirely in newspace.
authorTaylor R Campbell <campbell@mumble.net>
Sun, 20 Jan 2019 00:19:13 +0000 (00:19 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Wed, 21 Aug 2019 21:34:04 +0000 (21:34 +0000)
src/microcode/cmpintmd/aarch64.c

index 4ec526ede41a4f5531589358fb2cf2a15197c444..01b7889cc8915201b9fb2b30f266e784c1fd691d 100644 (file)
@@ -241,7 +241,9 @@ write_uuo_insns (insn_t * target, insn_t * iaddr, int pcrel)
      we don't know where the PC will be in the newspace.  */
   if ((((const int64_t *) (newspace_to_tospace (target)))[-1]) == 0)
     {
-      ptrdiff_t offset = (((uintptr_t) target) - ((uintptr_t) (&iaddr[1])));
+      char * from_pc = (tospace_to_newspace ((char *) (&iaddr[1])));
+      char * to_pc = ((char *) target);
+      ptrdiff_t offset = (to_pc - from_pc);
       assert ((offset & 3) == 0);
       if ((-0x10000000 <= offset) && (offset <= 0xfffffff))
        {