Exemple #1
0
        /// <summary>
        /// A request to patch already emitted code by storing the calculated virtual address value.
        /// </summary>
        /// <param name="linkType">Type of the link.</param>
        /// <param name="patches">The patches.</param>
        /// <param name="symbolVirtualAddress">The virtual virtualAddress of the method whose code is being patched.</param>
        /// <param name="symbolOffset">The value to store at the position in code.</param>
        /// <param name="symbolRelativeBase">The method relative base.</param>
        /// <param name="targetAddress">The position in code, where it should be patched.</param>
        /// <exception cref="System.InvalidOperationException"></exception>
        private void ApplyPatch(LinkType linkType, Patch[] patches, ExtendedLinkerSection section, long symbolVirtualAddress, long symbolOffset, long symbolRelativeBase, long targetAddress)
        {
            if (!SymbolsResolved)
                throw new InvalidOperationException(@"Can't apply patches - symbols not resolved.");

            // Calculate the patch offset
            long offset = (symbolVirtualAddress - section.VirtualAddress) + symbolOffset;

            if ((linkType & LinkType.KindMask) == LinkType.AbsoluteAddress)
            {
                // FIXME: Need a .reloc section with a relocation entry if the module is moved in virtual memory
                // the runtime loader must patch this link request, we'll fail it until we can do relocations.
                //throw new NotSupportedException(@".reloc section not supported.");
            }
            else
            {
                // Change the absolute into a relative offset
                targetAddress = targetAddress - (symbolVirtualAddress + symbolRelativeBase);
            }

            ulong value = Patch.GetResult(patches, (ulong)targetAddress);
            ulong mask = Patch.GetFinalMask(patches);

            // Save the stream position
            section.ApplyPatch(offset, linkType, value, mask, Endianness);
        }
Exemple #2
0
 /// <summary>
 /// Adds the section.
 /// </summary>
 /// <param name="section">The section.</param>
 public void AddSection(ExtendedLinkerSection section)
 {
     sections[(int)section.SectionKind] = section;
 }