Skip to content

Conversation

@jakobbotsch
Copy link
Member

Introduce a CorInfoReloc enum and use it exclusively to communicate relocation types between the EE and JIT. Translate it in crossgen2/ILC to the file-format relocation type when necessary.

Fix #121878

Introduce a `CorInfoReloc` enum and use it exclusively to communicate
relocation types between the EE and JIT. Translate it in crossgen2/ILC
to the file-format relocation type when necessary.
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 24, 2025
@dotnet-policy-service
Copy link
Contributor

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

@kg
Copy link
Member

kg commented Nov 24, 2025

LGTM

@am11
Copy link
Member

am11 commented Nov 24, 2025

@jakobbotsch, I added a smoke test in #121895 to see whether or not it works on community platforms. I tried merging this PR branch and commenting out [RuntimeAsyncMethodGeneration(false)] lines added in that PR, src/tests/build.sh is failing on osx-arm64:

$ ./build.sh clr+libs
$ src/tests/build.sh -nativeaot -tree:nativeaot -p:TasksConfiguration=Debug -p:LibrariesConfiguration=Debug -keepnativesymbols

    Illegal text-relocations:
      text-relocation in '_S_P_CoreLib_System_Threading_Tasks_Task__<AsyncCallable>S_P_CoreLib_System_Threading_Tasks_Task__get_CompletedTask'+0x180 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_S_P_CoreLib_System_Threading_Tasks_Task__<AsyncCallable>S_P_CoreLib_System_Threading_Tasks_Task__get_CompletedTask'
      text-relocation in '_S_P_CoreLib_System_Threading_Tasks_Task__<AsyncCallable>S_P_CoreLib_System_Threading_Tasks_Task__get_CompletedTask'+0x178 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_Internal_CompilerGenerated__Module___<Resume>S_P_CoreLib_System_Threading_Tasks_Task__<AsyncCallable>S_P_CoreLib_System_Threading_Tasks_Task__get_CompletedTask'
      text-relocation in '_fram1_UnitTests_TaskReturningAsyncTest__<AsyncCallable>UnitTests_TaskReturningAsyncTest__SimpleAsyncMethod'+0x34 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_UnitTests_TaskReturningAsyncTest__<AsyncCallable>UnitTests_TaskReturningAsyncTest__SimpleAsyncMethod'
      text-relocation in '_fram1_UnitTests_TaskReturningAsyncTest__<AsyncCallable>UnitTests_TaskReturningAsyncTest__SimpleAsyncMethod'+0x2C (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_Internal_CompilerGenerated__Module___<Resume>UnitTests_TaskReturningAsyncTest__<AsyncCallable>UnitTests_TaskReturningAsyncTest__SimpleAsyncMethod'
      text-relocation in '_fram1_UnitTests_ValueTaskReturningAsyncTest__<AsyncCallable>UnitTests_ValueTaskReturningAsyncTest__SimpleValueTaskAsync'+0x34 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_UnitTests_ValueTaskReturningAsyncTest__<AsyncCallable>UnitTests_ValueTaskReturningAsyncTest__SimpleValueTaskAsync'
      text-relocation in '_fram1_UnitTests_ValueTaskReturningAsyncTest__<AsyncCallable>UnitTests_ValueTaskReturningAsyncTest__SimpleValueTaskAsync'+0x2C (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_Internal_CompilerGenerated__Module___<Resume>UnitTests_ValueTaskReturningAsyncTest__<AsyncCallable>UnitTests_ValueTaskReturningAsyncTest__SimpleValueTaskAsync'
      text-relocation in '_fram1_UnitTests_TaskWithResultTest__<AsyncCallable>UnitTests_TaskWithResultTest__ComputeAsync'+0x34 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_UnitTests_TaskWithResultTest__<AsyncCallable>UnitTests_TaskWithResultTest__ComputeAsync'
      text-relocation in '_fram1_UnitTests_TaskWithResultTest__<AsyncCallable>UnitTests_TaskWithResultTest__ComputeAsync'+0x2C (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_Internal_CompilerGenerated__Module___<Resume>UnitTests_TaskWithResultTest__<AsyncCallable>UnitTests_TaskWithResultTest__ComputeAsync'
      text-relocation in '_fram1_UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__GetMessageAsync'+0x34 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__GetMessageAsync'
      text-relocation in '_fram1_UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__GetMessageAsync'+0x2C (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_Internal_CompilerGenerated__Module___<Resume>UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__GetMessageAsync'
      text-relocation in '_fram1_UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__CombineAsync'+0x48 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__CombineAsync'
      text-relocation in '_fram1_UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__CombineAsync'+0x40 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_Internal_CompilerGenerated__Module___<Resume>UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__CombineAsync'
      text-relocation in '_fram1_UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__CombineAsync'+0x38 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__CombineAsync'
      text-relocation in '_fram1_UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__CombineAsync'+0x30 (/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o) to '_Internal_CompilerGenerated__Module___<Resume>UnitTests_AwaitCompletedTaskTest__<AsyncCallable>UnitTests_AwaitCompletedTaskTest__CombineAsync'
    ld: Found illegal text-relocations
clang : error : linker command failed with exit code 1 (use -v to see invocation) [/Users/adeel/projects/runtime5/src/tests/build.proj]
/Users/adeel/projects/runtime5/artifacts/bin/coreclr/osx.arm64.Debug/build/Microsoft.NETCore.Native.targets(389,5): error MSB3073: The command ""/usr/bin/clang" "/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.o" -o "/Users/adeel/projects/runtime5/artifacts/tests/coreclr/osx.arm64.Debug/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests" -exported_symbols_list "/Users/adeel/projects/runtime5/artifacts/tests/coreclr/obj/osx.arm64.Debug/Managed/nativeaot/SmokeTests/UnitTests/UnitTests/native/UnitTests.exports" -Wl,-dead_strip -Wl,-rpath,'@executable_path/..' -gz=zlib /Users/adeel/projects/runtime5/artifacts/bin/microsoft.netcore.app.runtime.osx-arm64/Debug/runtimes/osx-arm64/native/libSystem.Native.a /Users/adeel/projects/runtime5/artifacts/bin/microsoft.netcore.app.runtime.osx-arm64/Debug/runtimes/osx-arm64/native/libSystem.Globalization.Native.a /Users/adeel/projects/runtime5/artifacts/bin/microsoft.netcore.app.runtime.osx-arm64/Debug/runtimes/osx-arm64/native/libSystem.IO.Compression.Native.a /Users/adeel/projects/runtime5/artifacts/bin/microsoft.netcore.app.runtime.osx-arm64/Debug/runtimes/osx-arm64/native/libSystem.Net.Security.Native.a /Users/adeel/projects/runtime5/artifacts/bin/microsoft.netcore.app.runtime.osx-arm64/Debug/runtimes/osx-arm64/native/libSystem.Security.Cryptography.Native.Apple.a /Users/adeel/projects/runtime5/artifacts/bin/coreclr/osx.arm64.Debug/aotsdk/libbootstrapper.o /Users/adeel/projects/runtime5/artifacts/bin/coreclr/osx.arm64.Debug/aotsdk/libRuntime.WorkstationGC.a /Users/adeel/projects/runtime5/artifacts/bin/coreclr/osx.arm64.Debug/aotsdk/libeventpipe-disabled.a /Users/adeel/projects/runtime5/artifacts/bin/coreclr/osx.arm64.Debug/aotsdk/libRuntime.VxsortDisabled.a /Users/adeel/projects/runtime5/artifacts/bin/coreclr/osx.arm64.Debug/aotsdk/libstandalonegc-disabled.a /Users/adeel/projects/runtime5/artifacts/bin/coreclr/osx.arm64.Debug/aotsdk/libaotminipal.a /Users/adeel/projects/runtime5/artifacts/bin/coreclr/osx.arm64.Debug/aotsdk/libstdc++compat.a /Users/adeel/projects/runtime5/artifacts/bin/microsoft.netcore.app.runtime.osx-arm64/Debug/runtimes/osx-arm64/native/libz.a /Users/adeel/projects/runtime5/artifacts/bin/microsoft.netcore.app.runtime.osx-arm64/Debug/runtimes/osx-arm64/native/libbrotlienc.a /Users/adeel/projects/runtime5/artifacts/bin/microsoft.netcore.app.runtime.osx-arm64/Debug/runtimes/osx-arm64/native/libbrotlidec.a /Users/adeel/projects/runtime5/artifacts/bin/microsoft.netcore.app.runtime.osx-arm64/Debug/runtimes/osx-arm64/native/libbrotlicommon.a --target=arm64-apple-macos12.0 -g -ldl -lobjc -lswiftCore -lswiftFoundation -licucore -lm -L/usr/lib/swift -framework CoreFoundation -framework CryptoKit -framework Foundation -framework Network -framework Security -framework GSS" exited with code 1. [/Users/adeel/projects/runtime5/src/tests/nativeaot/SmokeTests/UnitTests/UnitTests.csproj] [/Users/adeel/projects/runtime5/src/tests/build.proj]

without your PR, the error/callstack is same as: #121878 (comment).

@jakobbotsch
Copy link
Member Author

That looks like #121871. It needs a separate change.

@jakobbotsch jakobbotsch marked this pull request as ready for review November 24, 2025 19:51
Copilot AI review requested due to automatic review settings November 24, 2025 19:51
Copilot finished reviewing on behalf of jakobbotsch November 24, 2025 19:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 35 out of 35 changed files in this pull request and generated no comments.

@jakobbotsch
Copy link
Member Author

PTAL @dotnet/jit-contrib @jkotas

@jakobbotsch jakobbotsch requested review from a team and jkotas November 24, 2025 20:24
return (RelocType)fRelocType;
}
}
// Translates relocation type constants used by JIT to RelocType enumeration
Copy link
Member

@jkotas jkotas Nov 24, 2025

Choose a reason for hiding this comment

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

Would it make sense to use the CorInfoReloc enumeration inside the ObjectWriter too?

I see the ObjectWriter (the reloc handling in particular) as tightly coupled with the JIT. I am not sure whether we need two nearly identical enums and mapping between them.

Copy link
Member Author

@jakobbotsch jakobbotsch Nov 24, 2025

Choose a reason for hiding this comment

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

Maybe? I do count a significant number of relocation types that the object writer has that the JIT never uses for its code and that we would not want to care about outside ObjectWriter (in the VM or superpmi particularly).
I suppose we could define those in the managed copy of CorInfoReloc specifically, next to the existing fake relocations that RelocType defines.

Copy link
Member

Choose a reason for hiding this comment

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

IMAGE_REL_BASED_... constants make it look like that these constants came from Windows SDK, but that's not actually true except ~3 of them. It is a left-over from fragile NGen that a lot of unrelated stuff got added to over time.

Copy link
Member

Choose a reason for hiding this comment

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

I do count a significant number of relocation types that the object writer has that the JIT never uses

I see SYMBOL_SIZE, FILE_ABSOLUTE, FILE_CHECKSUM_CALLBACK. Anything else?

Copy link
Member Author

@jakobbotsch jakobbotsch Nov 24, 2025

Choose a reason for hiding this comment

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

Although seems like some of them can be deleted. These are the ones that the JIT does not use:

IMAGE_REL_BASED_ABSOLUTE
IMAGE_REL_BASED_ADDR32NB
IMAGE_REL_BASED_RELPTR32
IMAGE_REL_SECTION
IMAGE_REL_BASED_ARM64_PAGEOFFSET_12L
IMAGE_REL_TPOFF (looks unused)
IMAGE_REL_AARCH64_TLSLE_ADD_TPREL_HI12 (looks unused)
IMAGE_REL_AARCH64_TLSLE_ADD_TPREL_LO12_NC (looks unused)
IMAGE_REL_ARM_PREL31
IMAGE_REL_ARM_JUMP24
IMAGE_REL_SYMBOL_SIZE
IMAGE_REL_FILE_ABSOLUTE
IMAGE_REL_FILE_CHECKSUM_CALLBACK

For example, we could define these starting at 0x1000 in the managed view of the enum.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGTM. The additional cleanup can be done in separate PR

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.

Relocation problem on ARM64 Linux

4 participants