Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wrighton <davidwr@microsoft.com>2022-01-20 02:05:08 +0300
committerGitHub <noreply@github.com>2022-01-20 02:05:08 +0300
commita56b5bda0ca83789e87bf9d34fc0a9e8d2148115 (patch)
tree19a86c4489f694025be31b28ecdf88063fa67aee /Mono.Cecil.Metadata
parent75372c781ee228c11406c86751d75a9d27fea291 (diff)
FieldRVA alignment (#817)
* FieldRVA alignment In support of dotnet/runtime#60948 the linker (an assembly rewriter) will need to be able to preserve the alignment of RVA based fields which are to be used to create the data for `CreateSpan<T>` records This is implemented by adding a concept that RVA fields detect their required alignment by examining the PackingSize of the type of the field (if the field type is defined locally in the module) * Update Mono.Cecil.Metadata/Buffers.cs Co-authored-by: Aaron Robinson <arobins@microsoft.com> * Enhace logic used to ensure type providing PackingSize is local to the module. Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Diffstat (limited to 'Mono.Cecil.Metadata')
-rw-r--r--Mono.Cecil.Metadata/Buffers.cs18
1 files changed, 17 insertions, 1 deletions
diff --git a/Mono.Cecil.Metadata/Buffers.cs b/Mono.Cecil.Metadata/Buffers.cs
index 0dbf568..b32dd43 100644
--- a/Mono.Cecil.Metadata/Buffers.cs
+++ b/Mono.Cecil.Metadata/Buffers.cs
@@ -256,17 +256,33 @@ namespace Mono.Cecil.Metadata {
sealed class DataBuffer : ByteBuffer {
+ int buffer_align = 4;
+
public DataBuffer ()
: base (0)
{
}
- public RVA AddData (byte [] data)
+ void Align (int align)
+ {
+ align--;
+ // Compute the number of bytes to align the current position.
+ // Values of 0 will be written.
+ WriteBytes (((position + align) & ~align) - position);
+ }
+
+ public RVA AddData (byte [] data, int align)
{
+ if (buffer_align < align)
+ buffer_align = align;
+
+ Align (align);
var rva = (RVA) position;
WriteBytes (data);
return rva;
}
+
+ public int BufferAlign => buffer_align;
}
abstract class HeapBuffer : ByteBuffer {