Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add crossgen option to setup default base address for native image
This is enabled only with -DFEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION.
  • Loading branch information
gbalykov committed Jun 20, 2019
commit b8bd4c0dca9bc22af261491e6eb15d5d7d4e2c9b
3 changes: 3 additions & 0 deletions clrdefinitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ endif ()
if (FEATURE_NGEN_RELOCS_OPTIMIZATIONS)
add_definitions(-DFEATURE_NGEN_RELOCS_OPTIMIZATIONS)
endif(FEATURE_NGEN_RELOCS_OPTIMIZATIONS)
if (FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION)
add_definitions(-DFEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION)
endif(FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION)
add_definitions(-DFEATURE_SVR_GC)
add_definitions(-DFEATURE_SYMDIFF)
add_definitions(-DFEATURE_TIERED_COMPILATION)
Expand Down
5 changes: 5 additions & 0 deletions src/inc/zapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class Zapper

SString m_outputFilename;

SIZE_T m_customBaseAddress;

public:

struct assemblyDependencies
Expand Down Expand Up @@ -362,6 +364,9 @@ class Zapper
void SetOutputFilename(LPCWSTR pwszOutputFilename);
SString GetOutputFileName();

void SetCustomBaseAddress(SIZE_T baseAddress);
SIZE_T GetCustomBaseAddress();

private:

void DestroyDomain();
Expand Down
20 changes: 19 additions & 1 deletion src/tools/crossgen/crossgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum ReturnValues
#define NumItems(s) (sizeof(s) / sizeof(s[0]))

STDAPI CreatePDBWorker(LPCWSTR pwzAssemblyPath, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzAppNiPaths, LPCWSTR pwzPdbPath, BOOL fGeneratePDBLinesInfo, LPCWSTR pwzManagedPdbSearchPath, LPCWSTR pwzPlatformWinmdPaths, LPCWSTR pwzDiasymreaderPath);
STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzOutputFilename=NULL, LPCWSTR pwzPlatformWinmdPaths=NULL, ICorSvcLogger *pLogger = NULL, LPCWSTR pwszCLRJITPath = nullptr);
STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzOutputFilename=NULL, SIZE_T customBaseAddress=0, LPCWSTR pwzPlatformWinmdPaths=NULL, ICorSvcLogger *pLogger = NULL, LPCWSTR pwszCLRJITPath = nullptr);
void SetSvcLogger(ICorSvcLogger *pCorSvcLogger);
void SetMscorlibPath(LPCWSTR wzSystemDirectory);

Expand Down Expand Up @@ -155,6 +155,9 @@ void PrintUsageHelper()
W(" input assemblies\n")

#endif
#ifdef FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION
W(" /BaseAddress <value> - Specifies base address to use for compilation.\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please put this under the ifdef as well?

#endif
#ifdef FEATURE_WINMD_RESILIENT
W(" WinMD Parameters\n")
W(" /WinMDResilient - Generate images resilient to WinMD dependency changes.\n")
Expand Down Expand Up @@ -436,6 +439,7 @@ int _cdecl wmain(int argc, __in_ecount(argc) WCHAR **argv)
LPCWSTR pwzOutputFilename = NULL;
LPCWSTR pwzPublicKeys = nullptr;
bool fLargeVersionBubbleSwitch = false;
SIZE_T baseAddress = 0;

#if !defined(FEATURE_MERGE_JIT_AND_ENGINE)
LPCWSTR pwszCLRJITPath = nullptr;
Expand Down Expand Up @@ -543,6 +547,19 @@ int _cdecl wmain(int argc, __in_ecount(argc) WCHAR **argv)
dwFlags |= NGENWORKER_FLAGS_LARGEVERSIONBUBBLE;
fLargeVersionBubbleSwitch = true;
}
#endif
#ifdef FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION
else if (MatchParameter(*argv, W("BaseAddress")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this place (the rest of the plumbing can stay)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
if (baseAddress != 0)
{
OutputErr(W("Cannot specify multiple base addresses.\n"));
exit(INVALID_ARGUMENTS);
}
baseAddress = (SIZE_T) _wcstoui64(argv[1], NULL, 0);
argv++;
argc--;
}
#endif
else if (MatchParameter(*argv, W("NoMetaData")))
{
Expand Down Expand Up @@ -942,6 +959,7 @@ int _cdecl wmain(int argc, __in_ecount(argc) WCHAR **argv)
pwzPlatformResourceRoots,
pwzAppPaths,
pwzOutputFilename,
baseAddress,
pwzPlatformWinmdPaths
#if !defined(FEATURE_MERGE_JIT_AND_ENGINE)
,
Expand Down
6 changes: 6 additions & 0 deletions src/zap/zapimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,12 @@ void ZapImage::CalculateZapBaseAddress()
}
}

if (m_zapper->GetCustomBaseAddress() != 0)
{
//set baseAddress here from crossgen options
baseAddress = m_zapper->GetCustomBaseAddress();
}

// Round to a multiple of 64K
// 64K is the allocation granularity of VirtualAlloc. (Officially this number is not a constant -
// we should be querying the system for its allocation granularity, but we do this all over the place
Expand Down
17 changes: 16 additions & 1 deletion src/zap/zapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static bool s_fNGenNoMetaData;
// Zapper Object instead of creating one on your own.


STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzOutputFilename=NULL, LPCWSTR pwzPlatformWinmdPaths=NULL, ICorSvcLogger *pLogger = NULL, LPCWSTR pwszCLRJITPath = nullptr)
STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembliesPaths, LPCWSTR pwzTrustedPlatformAssemblies, LPCWSTR pwzPlatformResourceRoots, LPCWSTR pwzAppPaths, LPCWSTR pwzOutputFilename=NULL, SIZE_T customBaseAddress=0, LPCWSTR pwzPlatformWinmdPaths=NULL, ICorSvcLogger *pLogger = NULL, LPCWSTR pwszCLRJITPath = nullptr)
{
HRESULT hr = S_OK;

Expand Down Expand Up @@ -83,6 +83,8 @@ STDAPI NGenWorker(LPCWSTR pwzFilename, DWORD dwFlags, LPCWSTR pwzPlatformAssembl
if (pwzOutputFilename)
zap->SetOutputFilename(pwzOutputFilename);

zap->SetCustomBaseAddress(customBaseAddress);

if (pwzPlatformAssembliesPaths != nullptr)
zap->SetPlatformAssembliesPaths(pwzPlatformAssembliesPaths);

Expand Down Expand Up @@ -408,6 +410,8 @@ void Zapper::Init(ZapperOptions *pOptions, bool fFreeZapperOptions)
m_pAssemblyEmit = NULL;
m_fFreeZapperOptions = fFreeZapperOptions;

m_customBaseAddress = 0;

#ifdef LOGGING
InitializeLogging();
#endif
Expand Down Expand Up @@ -1688,3 +1692,14 @@ SString Zapper::GetOutputFileName()
{
return m_outputFilename;
}


void Zapper::SetCustomBaseAddress(SIZE_T baseAddress)
{
m_customBaseAddress = baseAddress;
}

SIZE_T Zapper::GetCustomBaseAddress()
{
return m_customBaseAddress;
}