Пример #1
0
        protected void WriteSymbolSection(Section section)
        {
            Debug.Assert(section == symbolSection);

            // first entry is completely filled with zeros
            writer.WriteZeroBytes(SymbolEntry.GetEntrySize(linkerFormatType));

            uint count = 1;

            foreach (var symbol in linker.Symbols)
            {
                var symbolEntry = new SymbolEntry()
                {
                    Name                    = AddToStringTable(symbol.Name),
                    Value                   = symbol.VirtualAddress,
                    Size                    = symbol.Size,
                    SymbolBinding           = SymbolBinding.Global,
                    SymbolVisibility        = SymbolVisibility.Default,
                    SymbolType              = symbol.SectionKind == SectionKind.Text ? SymbolType.Function : SymbolType.Object,
                    SectionHeaderTableIndex = GetSection(symbol.SectionKind).Index
                };

                symbolEntry.Write(linkerFormatType, writer);
                symbolTableOffset.Add(symbol, count);

                count++;
            }

            section.Size = (uint)(count * SymbolEntry.GetEntrySize(linkerFormatType));
        }
Пример #2
0
        private Stream EmitSymbolSection()
        {
            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);

            var emitSymbols = Linker.LinkerSettings.Symbols;

            // first entry is completely filled with zeros
            writer.WriteZeroBytes(SymbolEntry.GetEntrySize(LinkerFormatType));

            uint count = 1;

            foreach (var symbol in Linker.Symbols)
            {
                if (symbol.SectionKind == SectionKind.Unknown && symbol.LinkRequests.Count == 0)
                {
                    continue;
                }

                Debug.Assert(symbol.SectionKind != SectionKind.Unknown, "symbol.SectionKind != SectionKind.Unknown");

                if (!(symbol.IsExternalSymbol || emitSymbols))
                {
                    continue;
                }

                if (symbol.VirtualAddress == 0)
                {
                    continue;
                }

                if (symbol.Size == 0)
                {
                    continue;
                }

                var name = GetFinalSymboName(symbol);

                var symbolEntry = new SymbolEntry()
                {
                    Name                    = AddToStringTable(name),
                    Value                   = symbol.VirtualAddress,
                    Size                    = symbol.Size,
                    SymbolBinding           = SymbolBinding.Global,
                    SymbolVisibility        = SymbolVisibility.Default,
                    SymbolType              = symbol.SectionKind == SectionKind.Text ? SymbolType.Function : SymbolType.Object,
                    SectionHeaderTableIndex = GetSection(symbol.SectionKind).Index
                };

                symbolEntry.Write(LinkerFormatType, writer);
                symbolTableOffset.Add(symbol, count);

                count++;
            }

            return(stream);
        }
Пример #3
0
        private void WriteSymbolSection(Section section, BinaryWriter writer)
        {
            Debug.Assert(section == symbolSection);

            // first entry is completely filled with zeros
            writer.WriteZeroBytes(SymbolEntry.GetEntrySize(linkerFormatType));

            uint count = 1;

            foreach (var symbol in linker.Symbols)
            {
                if (symbol.SectionKind == SectionKind.Unknown && symbol.LinkRequests.Count == 0)
                {
                    continue;
                }

                Debug.Assert(symbol.SectionKind != SectionKind.Unknown, "symbol.SectionKind != SectionKind.Unknown");

                if (!(symbol.IsExternalSymbol || linker.EmitAllSymbols))
                {
                    continue;
                }

                var symbolEntry = new SymbolEntry()
                {
                    Name                    = AddToStringTable(symbol.ExternalSymbolName ?? symbol.Name),
                    Value                   = symbol.VirtualAddress,
                    Size                    = symbol.Size,
                    SymbolBinding           = SymbolBinding.Global,
                    SymbolVisibility        = SymbolVisibility.Default,
                    SymbolType              = symbol.SectionKind == SectionKind.Text ? SymbolType.Function : SymbolType.Object,
                    SectionHeaderTableIndex = GetSection(symbol.SectionKind).Index
                };

                symbolEntry.Write(linkerFormatType, writer);
                symbolTableOffset.Add(symbol, count);

                count++;
            }

            section.Size = count * SymbolEntry.GetEntrySize(linkerFormatType);
        }