You've already forked linux-packaging-mono
Imported Upstream version 5.2.0.175
Former-commit-id: bb0468d0f257ff100aa895eb5fe583fb5dfbf900
This commit is contained in:
parent
4bdbaf4a88
commit
966bba02bb
@@ -39,6 +39,13 @@ namespace Mono.Cecil.PE {
|
||||
BaseStream.Seek (position, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
public void Align (int align)
|
||||
{
|
||||
align--;
|
||||
var position = Position;
|
||||
Advance (((position + align) & ~align) - position);
|
||||
}
|
||||
|
||||
public DataDirectory ReadDataDirectory ()
|
||||
{
|
||||
return new DataDirectory (ReadUInt32 (), ReadUInt32 ());
|
||||
|
||||
@@ -17,6 +17,11 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
class BinaryStreamWriter : BinaryWriter {
|
||||
|
||||
public int Position {
|
||||
get { return (int) BaseStream.Position; }
|
||||
set { BaseStream.Position = value; }
|
||||
}
|
||||
|
||||
public BinaryStreamWriter (Stream stream)
|
||||
: base (stream)
|
||||
{
|
||||
@@ -72,6 +77,16 @@ namespace Mono.Cecil.PE {
|
||||
{
|
||||
BaseStream.Seek (bytes, SeekOrigin.Current);
|
||||
}
|
||||
|
||||
public void Align (int align)
|
||||
{
|
||||
align--;
|
||||
var position = Position;
|
||||
var bytes = ((position + align) & ~align) - position;
|
||||
|
||||
for (int i = 0; i < bytes; i++)
|
||||
WriteByte (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,29 +32,17 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
public int GetHashCode (ByteBuffer buffer)
|
||||
{
|
||||
#if !BYTE_BUFFER_WELL_DISTRIBUTED_HASH
|
||||
var hash = 0;
|
||||
// See http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
const int fnv_offset_bias = unchecked((int)2166136261);
|
||||
const int fnv_prime = 16777619;
|
||||
|
||||
var hash_code = fnv_offset_bias;
|
||||
var bytes = buffer.buffer;
|
||||
|
||||
for (int i = 0; i < buffer.length; i++)
|
||||
hash = (hash * 37) ^ bytes [i];
|
||||
hash_code = unchecked ((hash_code ^ bytes [i]) * fnv_prime);
|
||||
|
||||
return hash;
|
||||
#else
|
||||
const uint p = 16777619;
|
||||
uint hash = 2166136261;
|
||||
|
||||
var bytes = buffer.buffer;
|
||||
for (int i = 0; i < buffer.length; i++)
|
||||
hash = (hash ^ bytes [i]) * p;
|
||||
|
||||
hash += hash << 13;
|
||||
hash ^= hash >> 7;
|
||||
hash += hash << 3;
|
||||
hash ^= hash >> 17;
|
||||
hash += hash << 5;
|
||||
|
||||
return (int) hash;
|
||||
#endif
|
||||
}
|
||||
return hash_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
31
external/linker/cecil/Mono.Cecil.PE/Image.cs
vendored
31
external/linker/cecil/Mono.Cecil.PE/Image.cs
vendored
@@ -13,6 +13,7 @@ using System.IO;
|
||||
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil.Metadata;
|
||||
using Mono.Collections.Generic;
|
||||
|
||||
using RVA = System.UInt32;
|
||||
|
||||
@@ -28,11 +29,14 @@ namespace Mono.Cecil.PE {
|
||||
public TargetArchitecture Architecture;
|
||||
public ModuleCharacteristics Characteristics;
|
||||
|
||||
public ImageDebugHeader DebugHeader;
|
||||
|
||||
public Section [] Sections;
|
||||
|
||||
public Section MetadataSection;
|
||||
|
||||
public uint EntryPointToken;
|
||||
public uint Timestamp;
|
||||
public ModuleAttributes Attributes;
|
||||
|
||||
public DataDirectory Debug;
|
||||
@@ -143,33 +147,6 @@ namespace Mono.Cecil.PE {
|
||||
}
|
||||
}
|
||||
|
||||
public ImageDebugDirectory GetDebugHeader (out byte [] header)
|
||||
{
|
||||
var reader = GetReaderAt (Debug.VirtualAddress);
|
||||
if (reader == null) {
|
||||
header = Empty<byte>.Array;
|
||||
return new ImageDebugDirectory ();
|
||||
}
|
||||
|
||||
var directory = new ImageDebugDirectory {
|
||||
Characteristics = reader.ReadInt32 (),
|
||||
TimeDateStamp = reader.ReadInt32 (),
|
||||
MajorVersion = reader.ReadInt16 (),
|
||||
MinorVersion = reader.ReadInt16 (),
|
||||
Type = reader.ReadInt32 (),
|
||||
SizeOfData = reader.ReadInt32 (),
|
||||
AddressOfRawData = reader.ReadInt32 (),
|
||||
PointerToRawData = reader.ReadInt32 (),
|
||||
};
|
||||
|
||||
reader = GetReaderAt ((uint) directory.AddressOfRawData);
|
||||
header = reader != null
|
||||
? reader.ReadBytes (directory.SizeOfData)
|
||||
: Empty<byte>.Array;
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
public bool HasDebugTables ()
|
||||
{
|
||||
return HasTable (Table.Document)
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil.Metadata;
|
||||
using Mono.Collections.Generic;
|
||||
|
||||
using RVA = System.UInt32;
|
||||
|
||||
@@ -70,10 +72,11 @@ namespace Mono.Cecil.PE {
|
||||
ushort sections = ReadUInt16 ();
|
||||
|
||||
// TimeDateStamp 4
|
||||
image.Timestamp = ReadUInt32 ();
|
||||
// PointerToSymbolTable 4
|
||||
// NumberOfSymbols 4
|
||||
// OptionalHeaderSize 2
|
||||
Advance (14);
|
||||
Advance (10);
|
||||
|
||||
// Characteristics 2
|
||||
ushort characteristics = ReadUInt16 ();
|
||||
@@ -83,6 +86,7 @@ namespace Mono.Cecil.PE {
|
||||
ReadSections (sections);
|
||||
ReadCLIHeader ();
|
||||
ReadMetadata ();
|
||||
ReadDebugHeader ();
|
||||
|
||||
image.Kind = GetModuleKind (characteristics, subsystem);
|
||||
image.Characteristics = (ModuleCharacteristics) dll_characteristics;
|
||||
@@ -90,19 +94,7 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
TargetArchitecture ReadArchitecture ()
|
||||
{
|
||||
var machine = ReadUInt16 ();
|
||||
switch (machine) {
|
||||
case 0x014c:
|
||||
return TargetArchitecture.I386;
|
||||
case 0x8664:
|
||||
return TargetArchitecture.AMD64;
|
||||
case 0x0200:
|
||||
return TargetArchitecture.IA64;
|
||||
case 0x01c4:
|
||||
return TargetArchitecture.ARMv7;
|
||||
}
|
||||
|
||||
throw new NotSupportedException ();
|
||||
return (TargetArchitecture) ReadUInt16 ();
|
||||
}
|
||||
|
||||
static ModuleKind GetModuleKind (ushort characteristics, ushort subsystem)
|
||||
@@ -318,11 +310,52 @@ namespace Mono.Cecil.PE {
|
||||
for (int i = 0; i < streams; i++)
|
||||
ReadMetadataStream (section);
|
||||
|
||||
if (image.TableHeap != null)
|
||||
ReadTableHeap ();
|
||||
|
||||
if (image.PdbHeap != null)
|
||||
ReadPdbHeap ();
|
||||
|
||||
if (image.TableHeap != null)
|
||||
ReadTableHeap ();
|
||||
}
|
||||
|
||||
void ReadDebugHeader ()
|
||||
{
|
||||
if (image.Debug.IsZero) {
|
||||
image.DebugHeader = new ImageDebugHeader (Empty<ImageDebugHeaderEntry>.Array);
|
||||
return;
|
||||
}
|
||||
|
||||
MoveTo (image.Debug);
|
||||
|
||||
var entries = new ImageDebugHeaderEntry [(int) image.Debug.Size / ImageDebugDirectory.Size];
|
||||
|
||||
for (int i = 0; i < entries.Length; i++) {
|
||||
var directory = new ImageDebugDirectory {
|
||||
Characteristics = ReadInt32 (),
|
||||
TimeDateStamp = ReadInt32 (),
|
||||
MajorVersion = ReadInt16 (),
|
||||
MinorVersion = ReadInt16 (),
|
||||
Type = (ImageDebugType) ReadInt32 (),
|
||||
SizeOfData = ReadInt32 (),
|
||||
AddressOfRawData = ReadInt32 (),
|
||||
PointerToRawData = ReadInt32 (),
|
||||
};
|
||||
|
||||
if (directory.AddressOfRawData == 0) {
|
||||
entries [i] = new ImageDebugHeaderEntry (directory, Empty<byte>.Array);
|
||||
continue;
|
||||
}
|
||||
|
||||
var position = Position;
|
||||
try {
|
||||
MoveTo ((uint) directory.PointerToRawData);
|
||||
var data = ReadBytes (directory.SizeOfData);
|
||||
entries [i] = new ImageDebugHeaderEntry (directory, data);
|
||||
} finally {
|
||||
Position = position;
|
||||
}
|
||||
}
|
||||
|
||||
image.DebugHeader = new ImageDebugHeader (entries);
|
||||
}
|
||||
|
||||
void ReadMetadataStream (Section section)
|
||||
@@ -393,6 +426,15 @@ namespace Mono.Cecil.PE {
|
||||
// Sorted 8
|
||||
heap.Sorted = ReadInt64 ();
|
||||
|
||||
if (image.PdbHeap != null) {
|
||||
for (int i = 0; i < Mixin.TableCount; i++) {
|
||||
if (!image.PdbHeap.HasTable ((Table) i))
|
||||
continue;
|
||||
|
||||
heap.Tables [i].Length = image.PdbHeap.TypeSystemTableRows [i];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Mixin.TableCount; i++) {
|
||||
if (!heap.HasTable ((Table) i))
|
||||
continue;
|
||||
@@ -430,7 +472,7 @@ namespace Mono.Cecil.PE {
|
||||
uint offset = (uint) BaseStream.Position - table_heap_offset - image.MetadataSection.PointerToRawData; // header
|
||||
|
||||
int stridx_size = image.StringHeap.IndexSize;
|
||||
int guididx_size = image.GuidHeap.IndexSize;
|
||||
int guididx_size = image.GuidHeap != null ? image.GuidHeap.IndexSize : 2;
|
||||
int blobidx_size = image.BlobHeap != null ? image.BlobHeap.IndexSize : 2;
|
||||
|
||||
var heap = image.TableHeap;
|
||||
|
||||
@@ -29,8 +29,7 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
readonly string runtime_version;
|
||||
|
||||
ImageDebugDirectory debug_directory;
|
||||
byte [] debug_data;
|
||||
ImageDebugHeader debug_header;
|
||||
|
||||
ByteBuffer win32_resources;
|
||||
|
||||
@@ -62,7 +61,7 @@ namespace Mono.Cecil.PE {
|
||||
if (metadataOnly)
|
||||
return;
|
||||
|
||||
this.pe64 = module.Architecture == TargetArchitecture.AMD64 || module.Architecture == TargetArchitecture.IA64;
|
||||
this.pe64 = module.Architecture == TargetArchitecture.AMD64 || module.Architecture == TargetArchitecture.IA64 || module.Architecture == TargetArchitecture.ARM64;
|
||||
this.has_reloc = module.Architecture == TargetArchitecture.I386;
|
||||
this.GetDebugHeader ();
|
||||
this.GetWin32Resources ();
|
||||
@@ -73,11 +72,17 @@ namespace Mono.Cecil.PE {
|
||||
void GetDebugHeader ()
|
||||
{
|
||||
var symbol_writer = metadata.symbol_writer;
|
||||
if (symbol_writer == null)
|
||||
return;
|
||||
if (symbol_writer != null)
|
||||
debug_header = symbol_writer.GetDebugHeader ();
|
||||
|
||||
if (!symbol_writer.GetDebugHeader (out debug_directory, out debug_data))
|
||||
debug_data = Empty<byte>.Array;
|
||||
if (module.HasDebugHeader) {
|
||||
var header = module.GetDebugHeader ();
|
||||
var deterministic = header.GetDeterministicEntry ();
|
||||
if (deterministic == null)
|
||||
return;
|
||||
|
||||
debug_header = debug_header.AddDeterministicEntry ();
|
||||
}
|
||||
}
|
||||
|
||||
void GetWin32Resources ()
|
||||
@@ -108,7 +113,7 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
public static ImageWriter CreateDebugWriter (ModuleDefinition module, MetadataBuilder metadata, Disposable<Stream> stream)
|
||||
{
|
||||
var writer = new ImageWriter (module, "PDB V1.0", metadata, stream, metadataOnly: true);
|
||||
var writer = new ImageWriter (module, "PDB v1.0", metadata, stream, metadataOnly: true);
|
||||
var length = metadata.text_map.GetLength ();
|
||||
writer.text = new Section { SizeOfRawData = length, VirtualSize = length };
|
||||
return writer;
|
||||
@@ -194,7 +199,7 @@ namespace Mono.Cecil.PE {
|
||||
WriteUInt32 (0x00004550); // Magic
|
||||
WriteUInt16 (GetMachine ()); // Machine
|
||||
WriteUInt16 (sections); // NumberOfSections
|
||||
WriteUInt32 (metadata.time_stamp);
|
||||
WriteUInt32 (metadata.timestamp);
|
||||
WriteUInt32 (0); // PointerToSymbolTable
|
||||
WriteUInt32 (0); // NumberOfSymbols
|
||||
WriteUInt16 (SizeOfOptionalHeader ()); // SizeOfOptionalHeader
|
||||
@@ -308,7 +313,7 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
if (text_map.GetLength (TextSegment.DebugDirectory) > 0) {
|
||||
WriteUInt32 (text_map.GetRVA (TextSegment.DebugDirectory));
|
||||
WriteUInt32 (28u);
|
||||
WriteUInt32 ((uint) (debug_header.Entries.Length * ImageDebugDirectory.Size));
|
||||
} else
|
||||
WriteZeroDataDirectory ();
|
||||
|
||||
@@ -526,7 +531,7 @@ namespace Mono.Cecil.PE {
|
||||
1 // #~
|
||||
+ 1 // #Strings
|
||||
+ (metadata.user_string_heap.IsEmpty ? 0 : 1) // #US
|
||||
+ 1 // GUID
|
||||
+ (metadata.guid_heap.IsEmpty ? 0 : 1) // GUID
|
||||
+ (metadata.blob_heap.IsEmpty ? 0 : 1)
|
||||
+ (metadata.pdb_heap == null ? 0 : 1)); // #Blob
|
||||
}
|
||||
@@ -588,16 +593,27 @@ namespace Mono.Cecil.PE {
|
||||
|
||||
void WriteDebugDirectory ()
|
||||
{
|
||||
WriteInt32 (debug_directory.Characteristics);
|
||||
WriteUInt32 (metadata.time_stamp);
|
||||
WriteInt16 (debug_directory.MajorVersion);
|
||||
WriteInt16 (debug_directory.MinorVersion);
|
||||
WriteInt32 (debug_directory.Type);
|
||||
WriteInt32 (debug_directory.SizeOfData);
|
||||
WriteInt32 (debug_directory.AddressOfRawData);
|
||||
WriteInt32 ((int) BaseStream.Position + 4);
|
||||
var data_start = (int) BaseStream.Position + (debug_header.Entries.Length * ImageDebugDirectory.Size);
|
||||
|
||||
WriteBytes (debug_data);
|
||||
for (var i = 0; i < debug_header.Entries.Length; i++) {
|
||||
var entry = debug_header.Entries [i];
|
||||
var directory = entry.Directory;
|
||||
WriteInt32 (directory.Characteristics);
|
||||
WriteInt32 (directory.TimeDateStamp);
|
||||
WriteInt16 (directory.MajorVersion);
|
||||
WriteInt16 (directory.MinorVersion);
|
||||
WriteInt32 ((int) directory.Type);
|
||||
WriteInt32 (directory.SizeOfData);
|
||||
WriteInt32 (directory.AddressOfRawData);
|
||||
WriteInt32 (data_start);
|
||||
|
||||
data_start += entry.Data.Length;
|
||||
}
|
||||
|
||||
for (var i = 0; i < debug_header.Entries.Length; i++) {
|
||||
var entry = debug_header.Entries [i];
|
||||
WriteBytes (entry.Data);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteImportDirectory ()
|
||||
@@ -678,6 +694,7 @@ namespace Mono.Cecil.PE {
|
||||
WriteRsrc ();
|
||||
if (reloc != null)
|
||||
WriteReloc ();
|
||||
Flush ();
|
||||
}
|
||||
|
||||
void BuildTextMap ()
|
||||
@@ -694,11 +711,23 @@ namespace Mono.Cecil.PE {
|
||||
BuildMetadataTextMap ();
|
||||
|
||||
int debug_dir_len = 0;
|
||||
if (!debug_data.IsNullOrEmpty ()) {
|
||||
const int debug_dir_header_len = 28;
|
||||
if (debug_header != null && debug_header.HasEntries) {
|
||||
var directories_len = debug_header.Entries.Length * ImageDebugDirectory.Size;
|
||||
var data_address = (int) map.GetNextRVA (TextSegment.BlobHeap) + directories_len;
|
||||
var data_len = 0;
|
||||
|
||||
debug_directory.AddressOfRawData = (int) map.GetNextRVA (TextSegment.BlobHeap) + debug_dir_header_len;
|
||||
debug_dir_len = debug_data.Length + debug_dir_header_len;
|
||||
for (var i = 0; i < debug_header.Entries.Length; i++) {
|
||||
var entry = debug_header.Entries [i];
|
||||
var directory = entry.Directory;
|
||||
|
||||
directory.AddressOfRawData = entry.Data.Length == 0 ? 0 : data_address;
|
||||
entry.Directory = directory;
|
||||
|
||||
data_len += entry.Data.Length;
|
||||
data_address += data_len;
|
||||
}
|
||||
|
||||
debug_dir_len = directories_len + data_len;
|
||||
}
|
||||
|
||||
map.AddMap (TextSegment.DebugDirectory, debug_dir_len, 4);
|
||||
|
||||
Reference in New Issue
Block a user