[PATCH] D57482: [RuntimeDyld] Don't try to allocate sections with alignment 0.
Zachary Turner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 30 15:37:26 PST 2019
zturner created this revision.
zturner added reviewers: lhames, labath.
Herald added a subscriber: hiraditya.
ELF sections allow 0 for the alignment, which is specified to be the same as 1. However many clients do not expect this and will behave poorly in the presence of a 0-aligned section (for
example by trying to modulo something by the section alignment). We can be more polite by making sure that we always pass a more polite value to clients.
This was discovered when running the LLDB test suite on Linux with a debug build of LLDB / LLVM, and we had several hundred failures do an assertion triggering in MathExtras.h where we tried to call `llvm::alignTo(Size, Align=0, ...)`.
I don't really know this code at all, so I'm not sure if the problem is that the JIT was generating a 0-align section in the first place, but this does at least faithfully match the ELF spec, while also fixing all of the bugs in LLDB's test suite.
https://reviews.llvm.org/D57482
Files:
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
Index: llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
===================================================================
--- llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -743,6 +743,11 @@
bool IsReadOnly = isReadOnlyData(Section);
uint64_t DataSize = Section.getSize();
+ // An alignment of 0 (at least with ELF) is identical to an alignment of 1,
+ // while being more "polite". Other formats do not support 0-aligned sections
+ // anyway, so we should guarantee that the alignment is always at least 1.
+ Alignment = std::max(1u, Alignment);
+
StringRef Name;
if (auto EC = Section.getName(Name))
return errorCodeToError(EC);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57482.184390.patch
Type: text/x-patch
Size: 727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190130/f5f2f87e/attachment.bin>
More information about the llvm-commits
mailing list