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

NativeAOT/Arm64: Do not overwrite gcinfo tracking registers for TLS #112469

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

kunalspathak
Copy link
Member

Fields reg1 and reg2 of instrDesc were repurposed for saving live gc registers. However, this field was getting overwritten when we populate the register for the blr instruction that is needed for TLS access pattern. Since the pattern of the instructions including register requirements for them is very specific and has to be like following:

// For NativeAOT, linux/arm64, linker wants the following pattern, so we will generate
// it as part of the call. Generating individual instructions is tricky to get it
// correct in the format the way linker needs. Also, we might end up spilling or
// reloading a register, which can break the pattern.
//
// mrs x1, tpidr_el0
// adrp x0, :tlsdesc:tlsRoot ; R_AARCH64_TLSDESC_ADR_PAGE21
// ldr x2, [x0] ; R_AARCH64_TLSDESC_LD64_LO12
// add x0, x0, #0 ; R_AARCH64_TLSDESC_ADD_LO12
// blr x2 ; R_AARCH64_TLSDESC_CALL
// add x0, x1, x0
// We guaranteed in LSRA that r0, r1 and r2 are assigned to this node.
// mrs

In LSRA, we already ensure that those requirements are met.

newRefPosition(REG_R0, currentLoc, RefTypeFixedReg, nullptr, genSingleTypeRegMask(REG_R0));
newRefPosition(REG_R1, currentLoc, RefTypeFixedReg, nullptr, genSingleTypeRegMask(REG_R1));
ctrlExprCandidates = genSingleTypeRegMask(REG_R2);

As such, there is no need to track the target handle register separately in a field but can just be used directly in codegen/emitter logic. Also, I noticed that the display was not using the right register, so fixed that as well.

Fixes: #112351

@kunalspathak
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kunalspathak kunalspathak marked this pull request as ready for review February 12, 2025 20:18
@Copilot Copilot bot review requested due to automatic review settings February 12, 2025 20:18

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

Files not reviewed (1)
  • src/coreclr/jit/emitarm64.cpp: Language not supported
@kunalspathak
Copy link
Member Author

@dotnet/jit-contrib

@kunalspathak kunalspathak merged commit 6fe852a into dotnet:main Feb 13, 2025
126 of 134 checks passed
@kunalspathak kunalspathak deleted the tls-naot-gcinfo branch February 13, 2025 00:40
@kunalspathak
Copy link
Member Author

@jkotas - I think this should be backported to net9.0?

@jkotas
Copy link
Member

jkotas commented Feb 14, 2025

Yes, could you please backport this to net9.0?

@kunalspathak
Copy link
Member Author

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/13321667412

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash in System.Collections.Concurrent test
3 participants