Exemplo n.º 1
0
        protected void EmitRelocation(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 relocationEntry = new RelocationEntry()
                    {
                        RelocationType = ConvertType(patch.LinkType, linker.MachineType),
                        Symbol         = symbolTableOffset[symbol],
                        Offset         = (ulong)patch.PatchOffset,
                    };

                    relocationEntry.Write(linkerFormatType, writer);
                    count++;
                }

                section.Size = (uint)(count * RelocationEntry.GetEntrySize(linkerFormatType));
            }
        }
Exemplo n.º 2
0
        private void EmitRelocation(Section section, BinaryWriter writer)
        {
            int count = 0;

            foreach (var symbol in linker.Symbols)
            {
                if (symbol.IsExternalSymbol)
                {
                    continue;
                }

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

                    if (patch.ReferenceSymbol.SectionKind != section.SectionKind)
                    {
                        continue;
                    }

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

                    if (!patch.ReferenceSymbol.IsExternalSymbol)                     // FUTURE: include relocations for static symbols, if option selected
                    {
                        continue;
                    }

                    Debug.Assert(symbolTableOffset.ContainsKey(patch.ReferenceSymbol));

                    var relocationEntry = new RelocationEntry()
                    {
                        RelocationType = ConvertType(linker.MachineType, patch.LinkType, patch.PatchType),
                        Symbol         = symbolTableOffset[patch.ReferenceSymbol],
                        Offset         = (ulong)(symbol.SectionOffset + patch.PatchOffset),
                    };

                    relocationEntry.Write(linkerFormatType, writer);
                    count++;
                }

                section.Size = (uint)(count * RelocationEntry.GetEntrySize(linkerFormatType));
            }
        }
Exemplo n.º 3
0
        private void CreateRelocationSection(SectionKind kind, bool addend)
        {
            var relocationSection = new Section()
            {
                Name             = (addend ? ".rela" : ".rel") + LinkerSectionNames[(int)kind],
                Type             = addend ? SectionType.RelocationA : SectionType.Relocation,
                Link             = symbolSection,
                Info             = GetSection(kind),
                AddressAlignment = linker.SectionAlignment,
                EntrySize        = addend ? RelocationAddendEntry.GetEntrySize(linkerFormatType) : RelocationEntry.GetEntrySize(linkerFormatType),
                EmitMethod       = WriteRelocationSection
            };

            AddSection(relocationSection);

            relocationSection.AddDependency(symbolSection);
            relocationSection.AddDependency(GetSection(kind));
        }
Exemplo n.º 4
0
        private void RegisterRelocationSection(SectionKind kind, bool addend)
        {
            var relocationSection = new Section()
            {
                Name      = (addend ? ".rela" : ".rel") + SectionNames[(int)kind],
                Type      = addend ? SectionType.RelocationA : SectionType.Relocation,
                Link      = symbolSection,
                Info      = GetSection(kind),
                EntrySize = addend ? RelocationAddendEntry.GetEntrySize(LinkerFormatType) : RelocationEntry.GetEntrySize(LinkerFormatType),
                Emitter   = () => { return(addend ? EmitRelocationAddendSection(kind) : EmitRelocationSection(kind)); }
            };

            RegisterSection(relocationSection);

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