Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

[Arm64/Unix] WIP-DoNotMerge-Draft 64K static support #10891

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/gc/gcsvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@



#define OS_PAGE_SIZE 0x1000
#include "common.h"
Copy link
Author

Choose a reason for hiding this comment

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

This creates two definitions for OS_PAGE_SIZE in the same project. Needs to be actual current OS_PAGE_SIZE.


#if defined(FEATURE_SVR_GC)
Expand Down
1 change: 1 addition & 0 deletions src/gc/gcwks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@



#define OS_PAGE_SIZE 0x1000
Copy link
Author

Choose a reason for hiding this comment

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

Same as above

#include "common.h"

#include "gcenv.h"
Expand Down
2 changes: 1 addition & 1 deletion src/inc/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#define USE_UPPER_ADDRESS 0

#elif defined(_TARGET_AMD64_) || defined(_TARGET_ARM64_)
#define PAGE_SIZE 0x1000
#define PAGE_SIZE 0x10000
Copy link
Author

Choose a reason for hiding this comment

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

Page size will become dynamic

#define UPPER_ADDRESS_MAPPING_FACTOR 2
#define CLR_UPPER_ADDRESS_MIN 0x64400000000
#define CODEHEAP_START_ADDRESS 0x64480000000
Expand Down
2 changes: 1 addition & 1 deletion src/pal/src/include/pal/virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ enum VIRTUAL_CONSTANTS
VIRTUAL_EXECUTE,
VIRTUAL_EXECUTE_READ,

VIRTUAL_PAGE_SIZE = 0x1000,
VIRTUAL_PAGE_SIZE = 0x10000,
Copy link
Author

Choose a reason for hiding this comment

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

Virtual page size will become dynamic an so will VIRTUAL_PAGE_SIZE_MASK

VIRTUAL_PAGE_MASK = VIRTUAL_PAGE_SIZE - 1,
BOUNDARY_64K = 0xffff
};
Expand Down
2 changes: 2 additions & 0 deletions src/utilcode/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ LPVOID ClrVirtualAllocAligned(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocatio

#else // !FEATURE_PAL

if(alignment < PAGE_SIZE) alignment = PAGE_SIZE;

// UNIXTODO: Add a specialized function to PAL so that we don't have to waste memory
Copy link
Author

Choose a reason for hiding this comment

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

64K page size will increase the amount of wasted memory

dwSize += alignment;
SIZE_T addr = (SIZE_T)ClrVirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect);
Expand Down
2 changes: 1 addition & 1 deletion src/zap/zapimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ void ZapImage::OutputTables()

#if defined(FEATURE_PAL)
// PAL library requires native image sections to align to page bounaries.
SetFileAlignment(0x1000);
SetFileAlignment(0x10000);
Copy link
Author

Choose a reason for hiding this comment

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

Section alignment to match maximum supported page size.

Copy link
Member

Choose a reason for hiding this comment

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

I believe that this will make native images a lot bigger. I am not sure whether this would be acceptable.

How are the native binary formats like ELF dealing with the 64k pages? Do they have the sections aligned at 64k boundaries as well?

Copy link
Author

Choose a reason for hiding this comment

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

@jkotas Based on what I read in golang/go#10180 (cited by @vielmetti). I think ELF will be aligning the sections to 64K page boundaries. However the ELF file size will not be padded to fill 64K, it will truncated as needed.

It is possible we could support file with 4K alignment, but PAL loader would need to be updated. This seems feasible since we have RELOC_PAGE_SIZE set to 4K.

Copy link
Member

Choose a reason for hiding this comment

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

@sdmaclea what do you mean by RELOC_PAGE_SIZE? I don't see such a symbol defined anywhere.

Copy link
Author

Choose a reason for hiding this comment

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

@janvorli src/zap/zaprelocs.h:#define RELOCATION_PAGE_SIZE 0x1000

Copy link
Author

Choose a reason for hiding this comment

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

@jkotas For the smallest files the size is growing about the same amount

 12288  4KAligned/System.Xml.XPath.ni.dll
196608 64KAligned/System.Xml.XPath.ni.dll

Copy link
Author

Choose a reason for hiding this comment

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

@jkotas I'll see if I can fix the native image loader to not require 64K alignment

Copy link
Member

Choose a reason for hiding this comment

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

We may to tweak the file format so that we can get the page alignment, without the padding.

Copy link
Author

@sdmaclea sdmaclea Apr 13, 2017

Choose a reason for hiding this comment

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

How are the native binary formats like ELF dealing with the 64k pages? Do they have the sections aligned at 64k boundaries as well?

@jkotas We objdumped an elf. The sections are only aligned to something like 8 byte boundaries. The VA of the section is incremented by a multiple of the maximum page size. I think for Arm64 is should be 16byte boundaries.

I took a look at "Visual Studio, Microsoft Portable Executable and Common Object File Format Specification Revision 9.3 – December 29, 2015" the following statement appears in the text.

If the SectionAlignment is less than the architecture’s page size, then 
FileAlignment must match SectionAlignment.

I think this would allow the PE to behave similarly to ELF.

Copy link
Author

Choose a reason for hiding this comment

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

OK I created PR #10959 with the ZapWriter Loader rework to prevent this bloat.

#elif defined(_TARGET_ARM_) && defined(FEATURE_CORESYSTEM)
if (!IsReadyToRunCompilation())
{
Expand Down
2 changes: 1 addition & 1 deletion src/zap/zapwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void ZapWriter::Initialize()
m_FileAlignment = 0x200;
}

#define SECTION_ALIGNMENT 0x1000
#define SECTION_ALIGNMENT 0x10000

Copy link
Author

Choose a reason for hiding this comment

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

Section alignment to match maximum supported page size.

void ZapWriter::Save(IStream * pStream)
{
Expand Down