Skip to content

[RuntimeDyld][ELF][AArch64] Fix resolveAArch64ShortBranch. #8761

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

Merged

Conversation

al45tair
Copy link

We don't know the load addresses when this function is called, so it shouldn't be trying to use them to determine whether or not the branch is short. Notably, this will fail in the case where the code is being loaded into a target in such a way that the section offsets differ between the process generating the code and the target process.

We don't know the load addresses when this function is called, so it
shouldn't be trying to use them to determine whether or not the branch
is short.  Notably, this will fail in the case where the code is being
loaded into a target in such a way that the section offsets differ
between the process generating the code and the target process.
@al45tair
Copy link
Author

@swift-ci Please test

@al45tair
Copy link
Author

al45tair commented May 15, 2024

Explanation: Code was added in https://reviews.llvm.org/D28108 to try to generate direct branches on aarch64 ELF systems when dynamically loading an object file, provided the address was in range. Unfortunately, the address computation used is erroneous, because we don't know the load addresses when the resolveAArch64ShortBranch() function gets called; this doesn't matter if both addresses are in the same section, because the offset from one to the other won't change, and it also doesn't matter if the two sections in question get loaded with the same offset in the target process that they've been loaded at in the host process — but in the LLDB REPL tests, that wasn't happening, so the relocation resolution was wrong and it broke the REPL. Prior to my changes to use @llvm.used instead of @llvm.compiler.used, we were getting away with this because all the functions tended to land in the same section, but a side-effect of @llvm.used on ELF is to cause LLVM to put retained functions in their own section, triggering this bug.
Original PR: llvm#92245
Risk: Low. Fixes a fairly serious bug in the AArch64 RuntimeDyld implementation.
Reviewed by: @adrian-prantl
Resolves: rdar://127673408
Tests: The LLDB REPL tests fail on AArch64 without this; with it, they pass. Have also added a separate test to the RuntimeDyld tests to check that cross-section branches don't end up directly resolved.

We mustn't use direct branches for cross-section branches, because doing
so will result in problems if the sections aren't loaded at the same
offsets in the target process as in the host process.

rdar://127673408
@al45tair
Copy link
Author

@swift-ci Please test

@adrian-prantl adrian-prantl merged commit d6375b0 into swiftlang:swift/release/6.0 May 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants