[llvm] r352694 - [RuntimeDyld] Don't try to allocate sections with align 0.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 30 15:52:32 PST 2019


Author: zturner
Date: Wed Jan 30 15:52:32 2019
New Revision: 352694

URL: http://llvm.org/viewvc/llvm-project?rev=352694&view=rev
Log:
[RuntimeDyld] Don't try to allocate sections with align 0.

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
non-zero value to clients.

Differential Revision: https://reviews.llvm.org/D57482

Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=352694&r1=352693&r2=352694&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Wed Jan 30 15:52:32 2019
@@ -743,6 +743,11 @@ RuntimeDyldImpl::emitSection(const Objec
   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);




More information about the llvm-commits mailing list