Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

[WIN] LLVM error : IMAGE_REL_AMD64_ADDR32NB relocation requires an ordered section layout #488

Open
gshimansky opened this issue May 17, 2023 · 1 comment

Comments

@gshimansky
Copy link
Contributor

When running HDK tests it is possible to encounter LLVM error from subject. It happens randomly and most often happens in Release but possible in Debug as well. The error comes from this code https://github.com/llvm/llvm-project/blob/release/14.x/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h#L117-L118

My understanding is that when LLVM loads an object file it needs to create at least three sections: code, RW data and RO data. When first section is loaded and allocated, it becomes image base address. Consequent sections have to be in the address space within 2GB of this base address and cannot reside below base address. If any consequent section happens to be below base address or above it more than 2GB then assertion fails.

The problem is that default memory allocator on windows simply calls VirtualAlloc with image base address trying to convince VirtualAlloc to allocate memory somewhere there. In practice VirtualAlloc always returns zero and then allocator retries with NULL NearBlock parameter which allows VirtualAlloc to allocate memory anywhere in process address space sometimes breaking the condition of ordered sections layout described above.

With this said there is no clear solution to fix the problem. It looks like it is necessary to implement a more intelligent memory allocator instead of the DefaultMMapper but the problem is how to ensure that memory allocated for object file sections always satisifies ordered section layout? Sections are allocated in granularity of 64Kb (that is what getAllocationGranularity returns) and our allocator could call VirtualAlloc for 64Kb*3 to allocate all three sections in one chunk of memory, but what if some of object file's section is bigger than 64Kb? We cannot be sure than 64Kb ought to be enough for everyone even if MS founder said something like that. Another call to VirtualAlloc would be necessary and then it may return any address in memory including address that violate ordered section layout conditions.

Test suites affected by this bug are ArrowBasedExecuteTest, ArrowStorageSqlTest, NoCatalogRelAlgTest, maybe some other.

@gshimansky
Copy link
Contributor Author

Also CorrelatedSubqueryTest and ExecutionSequenceTest are affected by this problem.

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

No branches or pull requests

1 participant