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

[x86/Linux] add three functions for _X86_TARGET_#10378

Merged
janvorli merged 4 commits into
dotnet:masterfrom
ragmani:master
Apr 5, 2017
Merged

[x86/Linux] add three functions for _X86_TARGET_#10378
janvorli merged 4 commits into
dotnet:masterfrom
ragmani:master

Conversation

@ragmani
Copy link
Copy Markdown

@ragmani ragmani commented Mar 22, 2017

There is no functions for X86_TARGET.

  • ZapUnwindData::GetAlignment()
  • DWORD ZapUnwindData::GetSize()
  • void ZapUnwindData::Save(ZapWriter * pZapWriter)

@dnfclas
Copy link
Copy Markdown

dnfclas commented Mar 22, 2017

@ragmani,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla2.dotnetfoundation.org.

It will cover your contributions to all .NET Foundation-managed open source projects.
Thanks,
.NET Foundation Pull Request Bot

@ragmani
Copy link
Copy Markdown
Author

ragmani commented Mar 22, 2017

@parjong This PR is from #10139

Comment thread src/zap/zapcode.cpp Outdated
dwSize = AlignUp(dwSize, sizeof(ULONG));

dwSize += sizeof(ULONG);
#endif //REDHAWK
Copy link
Copy Markdown

@parjong parjong Mar 22, 2017

Choose a reason for hiding this comment

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

While working on #8889, I overhear that x86 has no personality routine space (please refer to reservePersonalityRoutineSpace in vm/jitinterface.cpp), but I'm not sure whether the line should be aligned with that, or not.

@jkotas @janvorli Could you correct me if there is something wrong?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this should do the same thing as reservePersonalityRoutineSpace in VM

@parjong
Copy link
Copy Markdown

parjong commented Mar 22, 2017

@dotnet-bot test Windows_NT x86 Checked Build and Test please

@ragmani ragmani closed this Mar 24, 2017
@ragmani ragmani reopened this Mar 24, 2017
@dnfclas
Copy link
Copy Markdown

dnfclas commented Mar 24, 2017

@ragmani,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla2.dotnetfoundation.org.

It will cover your contributions to all .NET Foundation-managed open source projects.
Thanks,
.NET Foundation Pull Request Bot

ragmani and others added 2 commits March 27, 2017 14:06
There is no functions for _X86_TARGET_.
  - ZapUnwindData::GetAlignment()
  - DWORD ZapUnwindData::GetSize()
  - void ZapUnwindData::Save(ZapWriter * pZapWriter)
	remove creating personaly routine when assemblies is generated to ni.
	add a function for getting size of UnwindDataBlob on x86/linux.

Signed-off-by: ragmani <ragmani0216@gmail.com>
@ragmani
Copy link
Copy Markdown
Author

ragmani commented Mar 28, 2017

I modified it as removing personality routine and succeeded in generating to ni with readytorun option.

@ragmani
Copy link
Copy Markdown
Author

ragmani commented Mar 28, 2017

I confirmed that simple ni assembly runs normally.

root@03c7d4352d95:/home/jang/DotNet/enable_x86/work# /home/jang/DotNet/enable_x86/work/ragmani/overlay.debug/corerun HelloDotNetCoreCS.dll 
Hello World
root@03c7d4352d95:/home/jang/DotNet/enable_x86/work# /home/jang/DotNet/enable_x86/work/ragmani/overlay.debug/corerun HelloDotNetCoreCS.ni.exe 
Hello World

Comment thread src/zap/zapcode.cpp Outdated
PVOID pData = GetData();
DWORD dwSize = GetBlobSize();

UNWIND_INFO * pUnwindInfo = (UNWIND_INFO *)pData;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is unnecessary - pUnwindInfo is not used.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I remoted it.

Comment thread src/vm/codeman.cpp Outdated
#elif defined(_TARGET_X86_) && defined(FEATURE_PAL)
PTR_UNWIND_INFO pUnwindInfo(dac_cast<PTR_UNWIND_INFO>(moduleBase + RUNTIME_FUNCTION__GetUnwindInfoAddress(pRuntimeFunction)));

*pSize = ALIGN_UP(sizeof(ULONG), sizeof(DWORD));
Copy link
Copy Markdown
Member

@jkotas jkotas Mar 28, 2017

Choose a reason for hiding this comment

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

This is not correct - it will be always 4. It needs to be the actual size like in other cases

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I modified to "*pSize = ALIGN_UP(sizeof(UNWIND_INFO), sizeof(BYTE));"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aligning to sizeof(BYTE) doesn't make sense, it would always return the first parameter of the macro unchanged (align ensures that the value returned by the macro is a multiple of the second parameter and sizeof(BYTE) is 1 and all numbers are multiple of 1)

Comment thread src/zap/zapcode.cpp Outdated

UINT ZapUnwindData::GetAlignment()
{
return sizeof(ULONG);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this be just sizeof(BYTE) ? The JIT case does not seem to have any extra alignment. It can be same here.

Copy link
Copy Markdown
Author

@ragmani ragmani Mar 30, 2017

Choose a reason for hiding this comment

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

I modified to BYTE in here and GetUnwindDataBlob function.

@dnfclas
Copy link
Copy Markdown

dnfclas commented Mar 29, 2017

@ragmani, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, .NET Foundation Pull Request Bot

change Unwindinfo's size from sizeof(ULONG) to sizeof(UNWIND_INFO).
change Unwindinfo's alignment from sizeof(DWORD) to sizeof(BYTE).
remove unnecessary code.
Comment thread src/vm/codeman.cpp Outdated
#elif defined(_TARGET_X86_) && defined(FEATURE_PAL)
PTR_UNWIND_INFO pUnwindInfo(dac_cast<PTR_UNWIND_INFO>(moduleBase + RUNTIME_FUNCTION__GetUnwindInfoAddress(pRuntimeFunction)));

*pSize = ALIGN_UP(sizeof(UNWIND_INFO), sizeof(BYTE));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The first argument to ALIGN_UP is correct now, but the second should be sizeof(DWORD)

@janvorli
Copy link
Copy Markdown
Member

janvorli commented Apr 3, 2017

@dotnet-bot test Ubuntu x64 Checked Build and Test please

@janvorli
Copy link
Copy Markdown
Member

janvorli commented Apr 3, 2017

@dotnet-bot test OSX10.12 x64 Checked Build and Test please

@parjong
Copy link
Copy Markdown

parjong commented Apr 5, 2017

@jkotas @janvorli Could you please take a look? I overhear that this PR resolves 2 readytorun test failures.

Comment thread src/zap/zapcode.cpp

UINT ZapUnwindData::GetAlignment()
{
return sizeof(BYTE);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be sizeof(ULONG) like on the other platforms.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change was introduced according to the following comment by @jkotas:

Can this be just sizeof(BYTE) ? The JIT case does not seem to have any extra alignment. It can be same here.

Could you let us know the semantics of GetAlignment? x86/Linux currently emits no unwind data, and thus sizeof(BYTE) also looks fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, I was comparing it just to the other platforms. I've missed that comment from @jkotas and he knows better than me the semantics here. So let's ignore all of my comments.

Comment thread src/zap/zapcode.cpp

DWORD ZapUnwindData::GetSize()
{
DWORD dwSize = ZapBlob::GetSize();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add dwSize = AlignUp(dwSize, sizeof(ULONG)); here, like we use on other platforms.

Comment thread src/zap/zapcode.cpp
PVOID pData = GetData();
DWORD dwSize = GetBlobSize();

pZapWriter->Write(pData, dwSize);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And finally here, I believe we should add the following after the write (again, like we do on other platforms)

    DWORD dwPad = AlignmentPad(dwSize, sizeof(DWORD));
    if (dwPad != 0)
        pZapWriter->WritePad(dwPad);

@janvorli janvorli merged commit c7241a9 into dotnet:master Apr 5, 2017
Comment thread src/vm/codeman.cpp
#elif defined(_TARGET_X86_) && defined(FEATURE_PAL)
PTR_UNWIND_INFO pUnwindInfo(dac_cast<PTR_UNWIND_INFO>(moduleBase + RUNTIME_FUNCTION__GetUnwindInfoAddress(pRuntimeFunction)));

*pSize = ALIGN_UP(sizeof(UNWIND_INFO), sizeof(DWORD));
Copy link
Copy Markdown
Member

@jkotas jkotas Apr 5, 2017

Choose a reason for hiding this comment

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

This does not look right. There is no alignment when the unwind blob is getting produced, and so there should be no alignment here where it is getting consumed either.

You should see crashes during GC or exception handling with R2R images because of this bug.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe this should be identical to the !WIN64EXCEPTIONS path:

PTR_VOID GetUnwindDataBlob(TADDR moduleBase, PTR_RUNTIME_FUNCTION pRuntimeFunction, /* out */ SIZE_T * pSize)
{
    *pSize = 0;
    return dac_cast<PTR_VOID>(pRuntimeFunction->UnwindData + moduleBase);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, I am confused here. The added alignment was my request, since we do align in a similar way on AMD64 too (see few lines above).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The structure of the unwind info is different on x86. There is no actual isolated unwind info blob like on x64. The unwind info is part of GCInfo on x86. So mirroring x64 is not the right strategy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, I see, the size is used to get location of the GCInfo from the address of the unwind data blob, so returning zero size like the Windows x86 is the right thing to do here. I can see now that that's what all the callers of GetUnwindDataBlob expect for x86.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ragmani, @parjong I am sorry for causing the confusion here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Btw, it looks like we will need to modify the following functions to take into account the fact that there is no personality routine for x86 Linux:
NativeImageJitManager::IsFilterFunclet
ReadyToRunJitManager::IsFilterFunclet

Copy link
Copy Markdown

@parjong parjong Apr 5, 2017

Choose a reason for hiding this comment

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

@jkotas Should *pSize be set as 0? x86/Linux produces a unwind info that consists of FunctionLength unlike x86/Windows. (from inc/win64unwind.h).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see - this may be just sizeof(UNWIND_INFO) for clarity then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

#10750 is submitted for cleanup.

hadibrais pushed a commit to hadibrais/coreclr that referenced this pull request Apr 7, 2017
* [x86/Linux] add three functions for _X86_TARGET_

There is no functions for _X86_TARGET_.
  - ZapUnwindData::GetAlignment()
  - DWORD ZapUnwindData::GetSize()
  - void ZapUnwindData::Save(ZapWriter * pZapWriter)

* [x86/Linux] remove personality routine on x86/linux.

	remove creating personaly routine when assemblies is generated to ni.
	add a function for getting size of UnwindDataBlob on x86/linux.

Signed-off-by: ragmani <ragmani0216@gmail.com>

* [x86/Linux] correct the unclearly fixed parts.

change Unwindinfo's size from sizeof(ULONG) to sizeof(UNWIND_INFO).
change Unwindinfo's alignment from sizeof(DWORD) to sizeof(BYTE).
remove unnecessary code.

* [x86/Linux] change alignment from sizeof(BYTE) to sizeof(DWORD).
@karelz karelz modified the milestone: 2.0.0 Aug 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants