From 2daa034e87ca1d7d8dcca3540a2373e7ea9b7971 Mon Sep 17 00:00:00 2001 From: xsvm <2479667226@qq.com> Date: Thu, 8 Oct 2026 10:13:03 +0800 Subject: [PATCH] perf(relinker): write in-place --to-intel substitutions directly Each in-place substitution went through X64InstructionRewriter::Rewrite, which copies the whole code segment and decodes every instruction in it to adjust references. The converter only accepts equal-length replacements, so the adjustment is always zero and the copy and scan are wasted: conversion time grew by one segment scan per substitution. Copy the replacement bytes into the segment instead. --- core/relinker/codegen/src/Amd64OnlyConverter.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/relinker/codegen/src/Amd64OnlyConverter.cpp b/core/relinker/codegen/src/Amd64OnlyConverter.cpp index aa0bc0d09..1b97d1853 100644 --- a/core/relinker/codegen/src/Amd64OnlyConverter.cpp +++ b/core/relinker/codegen/src/Amd64OnlyConverter.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -39,7 +38,6 @@ private: Amd64OnlyMatch Substitution; }; - X64InstructionRewriter _rewriter; std::unique_ptr _matcher = MakeAmd64OnlyInstructionMatcher(); std::unique_ptr _scanner = MakeInstructionScanner(); @@ -120,7 +118,7 @@ void Amd64OnlyConverter::_convertSegment( case Amd64OnlyLowering::InPlace: { if (substitution.ReplacementBytes.size() != match.Length) throw CodegenException("Intel substitution changes the instruction length", fileOffset); - seg = _atFileOffset(ph.Offset, [&] { return _rewriter.Rewrite(seg, {match.Offset, substitution.ReplacementBytes}).Bytes; }); + std::copy(substitution.ReplacementBytes.begin(), substitution.ReplacementBytes.end(), seg.begin() + static_cast(match.Offset)); replacementLength = substitution.ReplacementBytes.size(); ++result.ReplacedCount; break;