Exemple #1
0
        public void WriteToOutput(binary_library.IBinaryFile of,
                                  metadata.MetadataStream ms, target.Target t,
                                  binary_library.ISection rd = null)
        {
            if (str_tab.Count == 0)
            {
                return;
            }

            if (rd == null)
            {
                rd = of.GetRDataSection();
            }
            rd.Align(t.GetCTSize(ir.Opcode.ct_object));

            var stab_lab = of.CreateSymbol();

            stab_lab.Name       = Label;
            stab_lab.ObjectType = binary_library.SymbolObjectType.Object;
            stab_lab.Offset     = (ulong)rd.Data.Count;
            stab_lab.Type       = binary_library.SymbolType.Weak;
            rd.AddSymbol(stab_lab);

            int stab_base = rd.Data.Count;

            foreach (byte b in str_tab)
            {
                rd.Data.Add(b);
            }

            foreach (var kvp in sig_metadata_addrs)
            {
                var reloc = of.CreateRelocation();
                reloc.DefinedIn = rd;
                reloc.Type      = t.GetDataToDataReloc();
                reloc.Addend    = 0;

                if (sig_metadata_addends.ContainsKey(kvp.Key))
                {
                    reloc.Addend = sig_metadata_addends[kvp.Key];
                }

                var md_lab = of.CreateSymbol();
                md_lab.Name       = kvp.Value;
                md_lab.ObjectType = binary_library.SymbolObjectType.Object;

                reloc.References = md_lab;
                reloc.Offset     = (ulong)(kvp.Key + stab_base);
                of.AddRelocation(reloc);
            }

            stab_lab.Size = rd.Data.Count - (int)stab_lab.Offset;
        }
Exemple #2
0
        public void WriteToOutput(binary_library.IBinaryFile of,
                                  metadata.MetadataStream ms, target.Target t)
        {
            var rd = of.GetRDataSection();

            rd.Align(t.GetCTSize(ir.Opcode.ct_object));

            var stab_lab = GetStringTableSymbol(of);

            stab_lab.Name       = Label;
            stab_lab.ObjectType = binary_library.SymbolObjectType.Object;
            stab_lab.Offset     = (ulong)rd.Data.Count;
            stab_lab.Type       = binary_library.SymbolType.Global;
            rd.AddSymbol(stab_lab);

            int stab_base = rd.Data.Count;

            foreach (byte b in str_tab)
            {
                rd.Data.Add(b);
            }

            var str_lab = of.CreateSymbol();

            str_lab.Name       = StringObject.m.MangleType(StringObject);
            str_lab.ObjectType = binary_library.SymbolObjectType.Object;

            foreach (var str_addr in str_addrs.Values)
            {
                var reloc = of.CreateRelocation();
                reloc.DefinedIn  = rd;
                reloc.Type       = t.GetDataToDataReloc();
                reloc.Addend     = 0;
                reloc.References = str_lab;
                reloc.Offset     = (ulong)(str_addr + stab_base);
                of.AddRelocation(reloc);
            }

            stab_lab.Size = rd.Data.Count - (int)stab_lab.Offset;
        }