if (_nodeFactory.CompilationModuleGroup.IsCompositeBuildMode && _componentModule == null)
{
- headerBuilder = PEHeaderProvider.Create(Subsystem.Unknown, _nodeFactory.Target);
+ headerBuilder = PEHeaderProvider.Create(Subsystem.Unknown, _nodeFactory.Target, _nodeFactory.ImageBase);
peIdProvider = new Func<IEnumerable<Blob>, BlobContentId>(content => BlobContentId.FromHash(CryptographicHashProvider.ComputeSourceHash(content)));
timeDateStamp = null;
r2rHeaderExportSymbol = _nodeFactory.Header;
else
{
PEReader inputPeReader = (_componentModule != null ? _componentModule.PEReader : _nodeFactory.CompilationModuleGroup.CompilationModuleSet.First().PEReader);
- headerBuilder = PEHeaderProvider.Create(inputPeReader.PEHeaders.PEHeader.Subsystem, _nodeFactory.Target);
+ headerBuilder = PEHeaderProvider.Create(inputPeReader.PEHeaders.PEHeader.Subsystem, _nodeFactory.Target, _nodeFactory.ImageBase);
timeDateStamp = inputPeReader.PEHeaders.CoffHeader.TimeDateStamp;
r2rHeaderExportSymbol = null;
}
public CompositeImageSettings CompositeImageSettings { get; set; }
+ public ulong ImageBase;
+
public bool MarkingComplete => _markingComplete;
public void SetMarkingComplete()
CopiedCorHeaderNode corHeaderNode,
DebugDirectoryNode debugDirectoryNode,
ResourceData win32Resources,
- ReadyToRunFlags flags)
+ ReadyToRunFlags flags,
+ ulong imageBase)
{
TypeSystemContext = context;
CompilationModuleGroup = compilationModuleGroup;
DebugDirectoryNode = debugDirectoryNode;
Resolver = compilationModuleGroup.Resolver;
Header = new GlobalHeaderNode(Target, flags);
+ ImageBase = imageBase;
if (!win32Resources.IsEmpty)
Win32ResourcesNode = new Win32ResourcesNode(win32Resources);
copiedCorHeader,
debugDirectory,
win32Resources: new Win32Resources.ResourceData(inputModule),
- flags);
+ flags,
+ _nodeFactory.ImageBase);
IComparer<DependencyNodeCore<NodeFactory>> comparer = new SortableDependencyNode.ObjectNodeComparer(new CompilerComparer());
DependencyAnalyzerBase<NodeFactory> componentGraph = new DependencyAnalyzer<NoLogStrategy<NodeFactory>, NodeFactory>(componentFactory, comparer);
private int _customPESectionAlignment;
private bool _verifyTypeAndFieldLayout;
private CompositeImageSettings _compositeImageSettings;
+ private ulong _imageBase;
private string _jitPath;
private string _outputFile;
return this;
}
+ public ReadyToRunCodegenCompilationBuilder UseImageBase(ulong imageBase)
+ {
+ _imageBase = imageBase;
+ return this;
+ }
+
public override ICompilation ToCompilation()
{
// TODO: only copy COR headers for single-assembly build and for composite build with embedded MSIL
corHeaderNode,
debugDirectoryNode,
win32Resources,
- flags);
+ flags,
+ _imageBase
+ );
factory.CompositeImageSettings = _compositeImageSettings;
/// </summary>
/// <param name="subsystem">Targeting subsystem</param>
/// <param name="target">Target architecture to set in the header</param>
- public static PEHeaderBuilder Create(Subsystem subsystem, TargetDetails target)
+ public static PEHeaderBuilder Create(Subsystem subsystem, TargetDetails target, ulong imageBase)
{
bool is64BitTarget = target.PointerSize == sizeof(long);
Characteristics imageCharacteristics = Characteristics.ExecutableImage | Characteristics.Dll;
imageCharacteristics |= is64BitTarget ? Characteristics.LargeAddressAware : Characteristics.Bit32Machine;
- ulong imageBase = is64BitTarget ? PE64HeaderConstants.DllImageBase : PE32HeaderConstants.ImageBase;
-
int fileAlignment = 0x200;
if (!target.IsWindows && !is64BitTarget)
{
public string FileLayout;
public bool VerifyTypeAndFieldLayout;
public string CallChainProfileFile;
+ public string ImageBase;
public string SingleMethodTypeName;
public string SingleMethodName;
syntax.DefineOption("waitfordebugger", ref WaitForDebugger, SR.WaitForDebuggerOption);
syntax.DefineOptionList("codegenopt|codegen-options", ref CodegenOptions, SR.CodeGenOptions);
syntax.DefineOption("resilient", ref Resilient, SR.ResilientOption);
+ syntax.DefineOption("imagebase", ref ImageBase, SR.ImageBase);
syntax.DefineOption("targetarch", ref TargetArch, SR.TargetArchOption);
syntax.DefineOption("targetos", ref TargetOS, SR.TargetOSOption);
public TargetArchitecture _targetArchitecture;
private bool _armelAbi = false;
public OptimizationMode _optimizationMode;
+ private ulong _imageBase;
// File names as strings in args
private Dictionary<string, string> _inputFilePaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_targetArchitecture);
}
+ private void ConfigureImageBase(TargetDetails targetDetails)
+ {
+ bool is64BitTarget = targetDetails.PointerSize == sizeof(long);
+
+ if (_commandLineOptions.ImageBase != null)
+ _imageBase = is64BitTarget ? Convert.ToUInt64(_commandLineOptions.ImageBase, 16) : Convert.ToUInt32(_commandLineOptions.ImageBase, 16);
+ else
+ _imageBase = is64BitTarget ? PEWriter.PE64HeaderConstants.DllImageBase : PEWriter.PE32HeaderConstants.ImageBase;
+ }
+
private int Run(string[] args)
{
InitializeDefaultOptions();
var targetDetails = new TargetDetails(_targetArchitecture, _targetOS, _armelAbi ? TargetAbi.CoreRTArmel : TargetAbi.CoreRT, instructionSetSupport.GetVectorTSimdVector());
+ ConfigureImageBase(targetDetails);
+
bool versionBubbleIncludesCoreLib = false;
if (_commandLineOptions.InputBubble)
{
.UseCustomPESectionAlignment(_commandLineOptions.CustomPESectionAlignment)
.UseVerifyTypeAndFieldLayout(_commandLineOptions.VerifyTypeAndFieldLayout)
.GenerateOutputFile(outFile)
+ .UseImageBase(_imageBase)
.UseILProvider(ilProvider)
.UseBackendOptions(_commandLineOptions.CodegenOptions)
.UseLogger(logger)
<data name="UnsupportedInputFileExtension" xml:space="preserve">
<value>Input file with '{0}' extension not supported</value>
</data>
+ <data name="ImageBase" xml:space="preserve">
+ <value>Hexademical value to set target PE-file ImageBase field</value>
+ </data>
</root>