Commit 25c88c68 authored by Xuan Chen's avatar Xuan Chen Committed by andre.bargull@gmail.com
Browse files

Bug 1967367 - [macOS] Fix build of various simulators. r=anba

On macOS, int64_t is long long while intptr_t is long. Many of the
simulators have only been tested on Linux, so the mixed use of both
types haven't been caught. This problem also affects format strings
as the underlying types of int64_t changes, so macros like PRIx64
have to be used here instead.

Differential Revision: https://phabricator.services.mozilla.com/D250120
parent 7e9ced65
Loading
Loading
Loading
Loading
+16 −7
Changes for js/src/jit/loong64/Simulator-loong64.cpp: 16 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -804,9 +804,10 @@ bool loong64Debugger::getValue(const char* desc, int64_t* value) {
  }

  if (strncmp(desc, "0x", 2) == 0) {
    return sscanf(desc + 2, "%lx", reinterpret_cast<uint64_t*>(value)) == 1;
    return sscanf(desc + 2, "%" PRIx64, reinterpret_cast<uint64_t*>(value)) ==
           1;
  }
  return sscanf(desc, "%lu", reinterpret_cast<uint64_t*>(value)) == 1;
  return sscanf(desc, "%" PRIu64, reinterpret_cast<uint64_t*>(value)) == 1;
}

bool loong64Debugger::setBreakpoint(SimInstruction* breakpc) {
@@ -1093,7 +1094,12 @@ void loong64Debugger::debug() {
        }
      } else if (strcmp(cmd, "gdb") == 0) {
        printf("relinquishing control to gdb\n");
#if defined(__x86_64__)
        asm("int $3");
#elif defined(__aarch64__)
        // see masm.breakpoint for arm64
        asm("brk #0xf000");
#endif
        printf("regaining control from gdb\n");
      } else if (strcmp(cmd, "break") == 0) {
        if (argc == 2) {
@@ -1715,7 +1721,10 @@ void Simulator::setCallResultFloat(float result) {
}

void Simulator::setCallResult(int64_t res) { setRegister(a0, res); }

#ifdef XP_DARWIN
// add a dedicated setCallResult for intptr_t on Darwin
void Simulator::setCallResult(intptr_t res) { setRegister(v0, I64(res)); }
#endif
void Simulator::setCallResult(__int128_t res) {
  setRegister(a0, I64(res));
  setRegister(a1, I64(res >> 64));
@@ -2041,8 +2050,8 @@ int Simulator::storeConditionalW(uint64_t addr, int value,
  // return 0, but there is no point at allowing that. It is certainly an
  // indicator of a bug.
  if (addr != LLAddr_) {
    printf("SC to bad address: 0x%016" PRIx64 ", pc=0x%016" PRIx64
           ", expected: 0x%016" PRIx64 "\n",
    printf("SC to bad address: 0x%016" PRIx64 ", pc=0x%016" PRIxPTR
           ", expected: 0x%016" PRIxPTR "\n",
           addr, reinterpret_cast<intptr_t>(instr), LLAddr_);
    MOZ_CRASH();
  }
@@ -2095,8 +2104,8 @@ int Simulator::storeConditionalD(uint64_t addr, int64_t value,
  // return 0, but there is no point at allowing that. It is certainly an
  // indicator of a bug.
  if (addr != LLAddr_) {
    printf("SC to bad address: 0x%016" PRIx64 ", pc=0x%016" PRIx64
           ", expected: 0x%016" PRIx64 "\n",
    printf("SC to bad address: 0x%016" PRIx64 ", pc=0x%016" PRIxPTR
           ", expected: 0x%016" PRIxPTR "\n",
           addr, reinterpret_cast<intptr_t>(instr), LLAddr_);
    MOZ_CRASH();
  }
+4 −0
Changes for js/src/jit/loong64/Simulator-loong64.h: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -521,6 +521,10 @@ class Simulator {
  void setCallResultDouble(double result);
  void setCallResultFloat(float result);
  void setCallResult(int64_t res);
#  ifdef XP_DARWIN
  // add a dedicated setCallResult for intptr_t on Darwin
  void setCallResult(intptr_t res);
#  endif
  void setCallResult(__int128 res);

  void callInternal(uint8_t* entry);
+13 −5
Changes for js/src/jit/mips64/Simulator-mips64.cpp: 13 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -944,7 +944,12 @@ void MipsDebugger::debug() {
        }
      } else if (strcmp(cmd, "gdb") == 0) {
        printf("relinquishing control to gdb\n");
#if defined(__x86_64__)
        asm("int $3");
#elif defined(__aarch64__)
        // see masm.breakpoint for arm64
        asm("brk #0xf000");
#endif
        printf("regaining control from gdb\n");
      } else if (strcmp(cmd, "break") == 0) {
        if (argc == 2) {
@@ -1437,7 +1442,10 @@ void Simulator::setCallResultFloat(float result) {
}

void Simulator::setCallResult(int64_t res) { setRegister(v0, res); }

#ifdef XP_DARWIN
// add a dedicated setCallResult for intptr_t on Darwin
void Simulator::setCallResult(intptr_t res) { setRegister(v0, I64(res)); }
#endif
void Simulator::setCallResult(__int128_t res) {
  setRegister(v0, I64(res));
  setRegister(v1, I64(res >> 64));
@@ -1801,8 +1809,8 @@ int Simulator::storeConditionalW(uint64_t addr, int value,
  // return 0, but there is no point at allowing that. It is certainly an
  // indicator of a bug.
  if (addr != LLAddr_) {
    printf("SC to bad address: 0x%016" PRIx64 ", pc=0x%016" PRIx64
           ", expected: 0x%016" PRIx64 "\n",
    printf("SC to bad address: 0x%016" PRIx64 ", pc=0x%016" PRIxPTR
           ", expected: 0x%016" PRIxPTR "\n",
           addr, reinterpret_cast<intptr_t>(instr), LLAddr_);
    MOZ_CRASH();
  }
@@ -1855,8 +1863,8 @@ int Simulator::storeConditionalD(uint64_t addr, int64_t value,
  // return 0, but there is no point at allowing that. It is certainly an
  // indicator of a bug.
  if (addr != LLAddr_) {
    printf("SC to bad address: 0x%016" PRIx64 ", pc=0x%016" PRIx64
           ", expected: 0x%016" PRIx64 "\n",
    printf("SC to bad address: 0x%016" PRIx64 ", pc=0x%016" PRIxPTR
           ", expected: 0x%016" PRIxPTR "\n",
           addr, reinterpret_cast<intptr_t>(instr), LLAddr_);
    MOZ_CRASH();
  }
+4 −0
Changes for js/src/jit/mips64/Simulator-mips64.h: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -409,6 +409,10 @@ class Simulator {
  void setCallResultDouble(double result);
  void setCallResultFloat(float result);
  void setCallResult(int64_t res);
#  ifdef XP_DARWIN
  // add a dedicated setCallResult for intptr_t on Darwin
  void setCallResult(intptr_t res);
#  endif
  void setCallResult(__int128 res);

  void callInternal(uint8_t* entry);
+11 −8
Changes for js/src/jit/riscv64/Assembler-riscv64.cpp: 11 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -469,7 +469,8 @@ void Assembler::li_ptr(Register rd, int64_t imm) {
  // Initialize rd with an address
  // Pointers are 48 bits
  // 6 fixed instructions are generated
  DEBUG_PRINTF("li_ptr(%d, %lx <%ld>)\n", ToNumber(rd), imm, imm);
  DEBUG_PRINTF("li_ptr(%d, %" PRIx64 " <%" PRId64 ">)\n", ToNumber(rd), imm,
               imm);
  MOZ_ASSERT((imm & 0xfff0000000000000ll) == 0);
  int64_t a6 = imm & 0x3f;                      // bits 0:5. 6 bits
  int64_t b11 = (imm >> 6) & 0x7ff;             // bits 6:11. 11 bits
@@ -488,7 +489,8 @@ void Assembler::li_ptr(Register rd, int64_t imm) {
void Assembler::li_constant(Register rd, int64_t imm) {
  m_buffer.enterNoNops();
  m_buffer.assertNoPoolAndNoNops();
  DEBUG_PRINTF("li_constant(%d, %lx <%ld>)\n", ToNumber(rd), imm, imm);
  DEBUG_PRINTF("li_constant(%d, %" PRIx64 " <%" PRId64 ">)\n", ToNumber(rd),
               imm, imm);
  lui(rd, (imm + (1LL << 47) + (1LL << 35) + (1LL << 23) + (1LL << 11)) >>
              48);  // Bits 63:48
  addiw(rd, rd,
@@ -564,7 +566,7 @@ int Assembler::disassembleInstr(Instr instr, bool enable_spew) {
  return size;
}

uintptr_t Assembler::target_address_at(Instruction* pc) {
uint64_t Assembler::target_address_at(Instruction* pc) {
  Instruction* instr0 = pc;
  DEBUG_PRINTF("target_address_at: pc: 0x%p\t", instr0);
  Instruction* instr1 = pc + 1 * kInstrSize;
@@ -591,8 +593,8 @@ uintptr_t Assembler::target_address_at(Instruction* pc) {
    addr <<= 6;
    addr |= (int64_t)instr5->Imm12Value();

    DEBUG_PRINTF("addr: %lx\n", addr);
    return static_cast<uintptr_t>(addr);
    DEBUG_PRINTF("addr: %" PRIx64 "\n", addr);
    return static_cast<uint64_t>(addr);
  }
  // We should never get here, force a bad address if we do.
  MOZ_CRASH("RISC-V  UNREACHABLE");
@@ -651,7 +653,7 @@ uint64_t Assembler::ExtractLoad64Value(Instruction* inst0) {
      MOZ_ASSERT(instr6->Imm12Value() == 12);
      imm <<= 12;
      imm += (int64_t)instr7->Imm12Value();
      DEBUG_PRINTF("imm:%lx\n", imm);
      DEBUG_PRINTF("imm:%" PRIx64 "\n", imm);
      return imm;
    } else {
      FLAG_riscv_debug = true;
@@ -690,7 +692,7 @@ uint64_t Assembler::ExtractLoad64Value(Instruction* inst0) {
}

void Assembler::UpdateLoad64Value(Instruction* pc, uint64_t value) {
  DEBUG_PRINTF("\tUpdateLoad64Value: pc: %p\tvalue: %lx\n", pc, value);
  DEBUG_PRINTF("\tUpdateLoad64Value: pc: %p\tvalue: %" PRIx64 "\n", pc, value);
  Instruction* instr1 = pc + 1 * kInstrSize;
  if (IsJal(*reinterpret_cast<Instr*>(pc))) {
    pc = pc + pc->Imm20JValue();
@@ -767,7 +769,8 @@ void Assembler::UpdateLoad64Value(Instruction* pc, uint64_t value) {
}

void Assembler::set_target_value_at(Instruction* pc, uint64_t target) {
  DEBUG_PRINTF("\tset_target_value_at: pc: %p\ttarget: %lx\n", pc, target);
  DEBUG_PRINTF("\tset_target_value_at: pc: %p\ttarget: %" PRIx64 "\n", pc,
               target);
  uint32_t* p = reinterpret_cast<uint32_t*>(pc);
  MOZ_ASSERT((target & 0xffff000000000000ll) == 0);
#ifdef DEBUG
Loading