Beispiel #1
0
        protected void EmitRelocationAddend(LinkerSection linkerSection, Section section)
        {
            int count = 0;

            foreach (var symbol in linkerSection.Symbols)
            {
                foreach (var patch in symbol.LinkRequests)
                {
                    if (patch.ReferenceOffset == 0)
                    {
                        continue;
                    }

                    if (patch.LinkType == LinkType.Size)
                    {
                        continue;
                    }

                    var relocationAddendEntry = new RelocationAddendEntry()
                    {
                        RelocationType = ConvertType(patch.LinkType, linker.MachineType),
                        Symbol         = symbolTableOffset[symbol],
                        Offset         = (ulong)patch.PatchOffset,
                        Addend         = (ulong)patch.ReferenceOffset,
                    };

                    relocationAddendEntry.Write(linkerFormatType, writer);

                    count++;
                }
            }

            section.Size = (uint)(count * RelocationAddendEntry.GetEntrySize(linkerFormatType));
        }
        protected void CreateRelocationSection(SectionKind kind, bool addend)
        {
            var relocationSection = new Section();

            relocationSection.Name             = (addend ? ".rela" : ".rel") + LinkerSectionNames[(int)kind];
            relocationSection.Type             = addend ? SectionType.RelocationA : SectionType.Relocation;
            relocationSection.Link             = symbolSection;
            relocationSection.Info             = GetSection(kind);
            relocationSection.AddressAlignment = linker.SectionAlignment;
            relocationSection.EntrySize        = (uint)(addend ? RelocationAddendEntry.GetEntrySize(linkerFormatType) : RelocationEntry.GetEntrySize(linkerFormatType));
            relocationSection.EmitMethod       = WriteRelocationSection;

            AddSection(relocationSection);

            relocationSection.AddDependency(symbolSection);
            relocationSection.AddDependency(GetSection(kind));
        }