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

Assertion failure in RuntimeDyldELF::resolveAArch64Relocation #71963

Open
MikaelSmith opened this issue Nov 10, 2023 · 0 comments · May be fixed by #71968
Open

Assertion failure in RuntimeDyldELF::resolveAArch64Relocation #71963

MikaelSmith opened this issue Nov 10, 2023 · 0 comments · May be fixed by #71968
Labels

Comments

@MikaelSmith
Copy link

Using MCJIT, several projects have run into failures like

lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:400: void llvm::RuntimeDyldELF::resolveAArch64Relocation(const llvm::SectionEntry&, uint64_t, uint64_t, uint32_t, int64_t): Assertion `isInt<33>(Result) && "overflow check failed for relocation"' failed.

at https://github.com/llvm/llvm-project/blob/llvmorg-17.0.4/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp#L518.

I believe this issue is unaddressed in newer releases. As summarized here, MCJIT with the SectionMemoryManager or TrivialMemoryManager allocates sections in separate memory allocation calls. On systems with lots of memory, this can wind up allocating them in different locations in a way that violates AArch64 ABI restrictions (that text and GOT segments must be within 4GB of each other). 574713c is insufficient to fix the issue (tested it in Impala).

RTDyldMemoryManager provides needsToReserveAllocationSpace/reserveAllocationSpace. One proposal is to reserve all necessary memory in a single allocation, ensuring it's one contiguous block. This puts slightly stricter requirements on contiguous memory, which may not be suitable for memory-constrained environments, but for most use-cases it switches from 2-3 allocations to 1 larger allocation. This approach seems to address the issue in Impala.

MikaelSmith added a commit to MikaelSmith/llvm-project that referenced this issue Nov 20, 2023
Implements `reserveAllocationSpace` and provides an option to enable
`needsToReserveAllocationSpace` for large-memory environments with
AArch64.

The [AArch64 ABI](https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst)
has limits on the distance between sections as the instructions to
reference them are limited to 2 or 4GB. Allocating sections in multiple
blocks can result in distances greater than that on systems with lots of
memory. In those environments several projects using
SectionMemoryManager with MCJIT have run across assertion failures for
the R_AARCH64_ADR_PREL_PG_HI21 instruction as it attempts to address
across distances greater than 2GB (an int32).

Fixes llvm#71963 by allocating all sections in a single contiguous memory
allocation, limiting the distance required for instruction offsets
similar to how pre-compiled binaries would be loaded into memory. Does
not change the default behavior of SectionMemoryManager.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants