[llvm-commits] [llvm] r166920 - in /llvm/trunk: test/ExecutionEngine/MCJIT/test-data-align.ll tools/lli/lli.cpp
Tim Northover
Tim.Northover at arm.com
Mon Oct 29 03:47:07 PDT 2012
Author: tnorthover
Date: Mon Oct 29 05:47:07 2012
New Revision: 166920
URL: http://llvm.org/viewvc/llvm-project?rev=166920&view=rev
Log:
Align the data section correctly when loading an ELF file.
Patch by Amara Emerson.
Added:
llvm/trunk/test/ExecutionEngine/MCJIT/test-data-align.ll (with props)
Modified:
llvm/trunk/tools/lli/lli.cpp
Added: llvm/trunk/test/ExecutionEngine/MCJIT/test-data-align.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/test-data-align.ll?rev=166920&view=auto
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/test-data-align.ll (added)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/test-data-align.ll Mon Oct 29 05:47:07 2012
@@ -0,0 +1,15 @@
+; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 %s
+
+; Check that a variable is always aligned as specified.
+
+ at var = global i32 0, align 32
+define i32 @main() {
+ %addr = ptrtoint i32* @var to i64
+ %mask = and i64 %addr, 31
+ %tst = icmp eq i64 %mask, 0
+ br i1 %tst, label %good, label %bad
+good:
+ ret i32 0
+bad:
+ ret i32 1
+}
Propchange: llvm/trunk/test/ExecutionEngine/MCJIT/test-data-align.ll
------------------------------------------------------------------------------
svn:eol-style = native
Modified: llvm/trunk/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=166920&r1=166919&r2=166920&view=diff
==============================================================================
--- llvm/trunk/tools/lli/lli.cpp (original)
+++ llvm/trunk/tools/lli/lli.cpp Mon Oct 29 05:47:07 2012
@@ -42,6 +42,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/Memory.h"
+#include "llvm/Support/MathExtras.h"
#include <cerrno>
#ifdef __linux__
@@ -303,9 +304,16 @@
unsigned SectionID) {
if (!Alignment)
Alignment = 16;
- uint8_t *Addr = (uint8_t*)calloc((Size + Alignment - 1)/Alignment, Alignment);
- AllocatedDataMem.push_back(sys::MemoryBlock(Addr, Size));
- return Addr;
+ // Ensure that enough memory is requested to allow aligning.
+ size_t NumElementsAligned = 1 + (Size + Alignment - 1)/Alignment;
+ uint8_t *Addr = (uint8_t*)calloc(NumElementsAligned, Alignment);
+
+ // Honour the alignment requirement.
+ uint8_t *AlignedAddr = (uint8_t*)RoundUpToAlignment((uint64_t)Addr, Alignment);
+
+ // Store the original address from calloc so we can free it later.
+ AllocatedDataMem.push_back(sys::MemoryBlock(Addr, NumElementsAligned*Alignment));
+ return AlignedAddr;
}
uint8_t *LLIMCJITMemoryManager::allocateCodeSection(uintptr_t Size,
More information about the llvm-commits
mailing list