@@ -815,7 +815,7 @@ Error Assembler::_emit(InstId instId, const Operand_& o0, const Operand_& o1, co
815815 // is valid. All options that require special handling (including invalid
816816 // instruction) are handled by the next branch.
817817 // Check for < 8 bytes remaining because branch relaxation (cbz/cbnz,
818- // tbz/tbnz, b.cond, adr) may emit two 32-bit words (8 bytes).
818+ // tbz/tbnz, b.cond, bl/b, adr) may emit two 32-bit words (8 bytes).
819819 InstOptions options = InstOptions (instId - 1 >= Inst::_kIdCount - 1 ) | InstOptions ((size_t )(_bufferEnd - writer.cursor ()) < 8 ) | instOptions () | forcedInstOptions ();
820820
821821 CondCode instCC = BaseInst::extractARMCondCode (instId);
@@ -854,7 +854,7 @@ Error Assembler::_emit(InstId instId, const Operand_& o0, const Operand_& o1, co
854854 goto InvalidInstruction;
855855
856856 // Grow request, happens rarely. Reserve 8 bytes because branch relaxation
857- // (cbz/cbnz, tbz/tbnz, b.cond, adr) may emit two 32-bit words.
857+ // (cbz/cbnz, tbz/tbnz, b.cond, bl/b, adr) may emit two 32-bit words.
858858 err = writer.ensureSpace (this , 8 );
859859 if (ASMJIT_UNLIKELY (err))
860860 goto Failed;
@@ -5207,9 +5207,9 @@ Error Assembler::_emit(InstId instId, const Operand_& o0, const Operand_& o1, co
52075207
52085208 size_t codeOffset = writer.offsetFrom (_bufferData);
52095209
5210- // For b(imm) and bl(imm), use a branch stub to handle out-of-range
5211- // targets. At emit time we reserve one branch instruction , and during
5212- // relocation we choose either the target or the stub as its destination .
5210+ // For b(imm) and bl(imm), use address table mechanism to handle out-of-range
5211+ // targets. At emit time we reserve 8 bytes , and during relocation we choose
5212+ // the optimal encoding based on the actual displacement .
52135213 if ((instId == Inst::kIdBl || instId == Inst::kIdB ) &&
52145214 offsetFormat.immBitCount () == 26 &&
52155215 (baseAddress == Globals::kNoBaseAddress || _section->id () != 0 ))
@@ -5235,7 +5235,7 @@ Error Assembler::_emit(InstId instId, const Operand_& o0, const Operand_& o1, co
52355235 pc &= ~uint64_t (4096 - 1 );
52365236
52375237 // For b(imm) and bl(imm) when base address is known, try the direct
5238- // encoding first. If it doesn't fit, use the branch stub mechanism.
5238+ // encoding first. If it doesn't fit, use the address table mechanism.
52395239 if ((instId == Inst::kIdBl || instId == Inst::kIdB ) && offsetFormat.immBitCount () == 26 ) {
52405240 int64_t displacement = int64_t (targetOffset - pc);
52415241 int64_t dispImm = displacement >> 2 ;
@@ -5281,7 +5281,7 @@ Error Assembler::_emit(InstId instId, const Operand_& o0, const Operand_& o1, co
52815281 }
52825282
52835283 // --------------------------------------------------------------------------
5284- // [EmitOp - b/bl Relaxation via Branch Stub ]
5284+ // [EmitOp - b/bl Relaxation via Address Table ]
52855285 // --------------------------------------------------------------------------
52865286
52875287EmitOp_BranchReloc:
@@ -5295,21 +5295,21 @@ Error Assembler::_emit(InstId instId, const Operand_& o0, const Operand_& o1, co
52955295 if (err)
52965296 goto Failed;
52975297
5298- size_t codeOffset = writer.offsetFrom (_bufferData);
52995298 uint64_t targetOffset = rmRel->as <Imm>().valueAs <uint64_t >();
5300- err = _code->addAddressToA64BranchStubTable (targetOffset);
5299+ err = _code->addAddressToAddressTable (targetOffset);
53015300 if (err)
53025301 goto Failed;
53035302
5303+ size_t codeOffset = writer.offsetFrom (_bufferData);
53045304 re->_sourceSectionId = _section->id ();
53055305 re->_sourceOffset = codeOffset;
53065306 re->_format = offsetFormat;
53075307 re->_payload = targetOffset;
53085308
5309- // Emit a 32-bit branch placeholder. During relocation this is patched to
5310- // either `b/bl target` or `b/bl stub`, where the stub loads the full target
5311- // address and branches to it.
5312- writer.emit32uLE (opcode. get ());
5309+ // Emit two 32-bit words ( placeholder: nop; nop). These will be patched
5310+ // during relocation to either `b/bl target; nop ` or `ldr x16, [pc+off]; br/blr x16`.
5311+ writer. emit32uLE ( 0xD503201F ); // NOP
5312+ writer.emit32uLE (0xD503201F ); // NOP
53135313 goto EmitDone;
53145314 }
53155315
0 commit comments