[llvm] r245031 - [RuntimeDyld] Make sure code-sections aren't under-aligned.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 23:26:42 PDT 2015


Author: lhames
Date: Fri Aug 14 01:26:42 2015
New Revision: 245031

URL: http://llvm.org/viewvc/llvm-project?rev=245031&view=rev
Log:
[RuntimeDyld] Make sure code-sections aren't under-aligned.

Code-section alignment should be at least as high as the minimum
stub alignment. If the section alignment is lower it can cause
padding to be emitted resulting in alignment errors if the section
is mapped to a higher alignment on the target.

E.g. If a text section with a 4-byte alignment gets 4-bytes of
padding to guarantee 8-byte alignment for stubs but is re-mapped to
an 8-byte alignment on the target, the 4-bytes of padding will push
the stubs to 4-byte alignment causing a crash.

No test case: There is currently no way to control host section
alignment in llvm-rtdyld. This could be made testable by adding
a custom memory manager. I'll look at that in a follow-up patch.



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=245031&r1=245030&r2=245031&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Fri Aug 14 01:26:42 2015
@@ -564,6 +564,12 @@ unsigned RuntimeDyldImpl::emitSection(co
   if (!IsVirtual)
     pData = data.data();
 
+  // Code section alignment needs to be at least as high as stub alignment or
+  // padding calculations may by incorrect when the section is remapped to a
+  // higher alignment.
+  if (IsCode)
+    Alignment = std::max(Alignment, getStubAlignment());
+
   // Some sections, such as debug info, don't need to be loaded for execution.
   // Leave those where they are.
   if (IsRequired) {




More information about the llvm-commits mailing list