Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Elf64Linker"/> class.
        /// </summary>
        public Elf64Linker()
        {
            this.sections = new List <LinkerSection>();

            // Create the default section set
            Elf64Section[] sections = new Elf64Section[(int)SectionKind.Max];
            sections[(int)SectionKind.Text]   = new Elf64CodeSection();
            sections[(int)SectionKind.Data]   = new Elf64DataSection();
            sections[(int)SectionKind.ROData] = new Elf64RoDataSection();
            sections[(int)SectionKind.BSS]    = new Elf64BssSection();
            this.sections.AddRange(sections);

            nullSection        = new Elf64NullSection();
            stringTableSection = new Elf64StringTableSection();
        }
Exemplo n.º 2
0
        /// <summary>
        /// A request to patch already emitted code by storing the calculated virtualAddress value.
        /// </summary>
        /// <param name="linkType">Type of the link.</param>
        /// <param name="methodAddress">The virtual virtualAddress of the method whose code is being patched.</param>
        /// <param name="methodOffset">The value to store at the position in code.</param>
        /// <param name="methodRelativeBase">The method relative base.</param>
        /// <param name="targetAddress">The position in code, where it should be patched.</param>
        protected override void ApplyPatch(LinkType linkType, long methodAddress, long methodOffset, long methodRelativeBase, long targetAddress)
        {
            // Retrieve the text section
            Elf64Section text = (Elf64Section)GetSection(SectionKind.Text);
            // Calculate the patch offset
            long offset = (methodAddress - text.VirtualAddress.ToInt64()) + methodOffset;

            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 - (methodAddress + methodRelativeBase);
            }

            // Save the stream position
            text.ApplyPatch(offset, linkType, targetAddress);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Allocates a symbol of the given name in the specified section.
        /// </summary>
        /// <param name="section">The executable section to allocate From.</param>
        /// <param name="size">The number of bytes to allocate. If zero, indicates an unknown amount of memory is required.</param>
        /// <param name="alignment">The alignment. A value of zero indicates the use of a default alignment for the section.</param>
        /// <returns>
        /// A stream, which can be used to populate the section.
        /// </returns>
        protected override Stream Allocate(SectionKind section, int size, int alignment)
        {
            Elf64Section linkerSection = (Elf64Section)GetSection(section);

            return(linkerSection.Allocate(size, alignment));
        }