Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RhpCallCatchFunclet .text relocation on amd64. #111227

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lateralusX
Copy link
Member

@lateralusX lateralusX commented Jan 9, 2025

c8e4f2c changed asm implementation in RhpThrowHwEx on amd64 from a relative jump, using jmp RhpThrowHwEx to a mov rax, RhpThrowHwEx that is later jumped to using jmp rax.

This introduce an ADDR64 relocation record in the generated object file:

000004EC ADDR64 00000000 00000000 2A RhpThrowHwEx

That will then be left as a relocation that needs to be fixed up by the loader:

73000 RVA,        C SizeOfBlock
     F7C  DIR64      0000000140073A90  RhpThrowHwEx
       0  ABS

Where the RVA 73000 is part of the .text section that is read, execute section.

Having relocations done to the .text section is however not supported on all Windows platform configurations leading to loader errors blocking use of nativeaot on these configurations.

This commit change the mov to a lea instruction using relative offset to calculate address of RhpThrowHwEx. That will end up with a REL32 relocation record in the generated object file:

000004ED REL32 00000000 2A RhpThrowHwEx

Since this uses relative addressing it won't leave any relocation in the final image making sure the generated nativeaot image can be successfully loaded on Windows platforms configurations that prevents relocations to .text section.

dotnet@c8e4f2c
changed asm implementation in RhpThrowHwEx on amd64 from a relative
jump, using jmp RhpThrowHwEx to a mov rax, RhpThrowHwEx that is later
jumped to using jmp rax.

This introduce a ADDR64 relocation record in the generated object file:

000004EC  ADDR64            00000000 00000000        2A  RhpThrowHwEx

That will then be left as a relocation that needs to be fixed up
by the loader:

73000 RVA,        C SizeOfBlock
     F7C  DIR64      0000000140073A90  RhpThrowHwEx
       0  ABS

Where the RVA 73000 is part of the .text section that is read, execute
section.

Having relocations done to the .text section is however not supported on
all Windows platform configurations leading to loader errors
blocking use of nativeaot on these configurations.

This commit change the mov to a lea instruction using relative offset
to calculate address of RhpThrowHwEx. That will end up with a REL32
relocation record in the generated object file:

000004ED  REL32                      00000000        2A  RhpThrowHwEx

Since this uses relative addressing it won't leave any
relocation in the final image making sure the generated nativeaot image
can be successfully loaded on Windows platforms with configurations
preventing relocation in .text section.
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky
Copy link
Member

/azp run runtime-nativeaot-outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

LGTM assuming CET pipeline in outerloop is green (cc @VSadov in case there are some CET considerations in general). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants