diff options
| author | Tim Northover <Tim.Northover@arm.com> | 2012-10-29 10:47:07 +0000 |
|---|---|---|
| committer | Tim Northover <Tim.Northover@arm.com> | 2012-10-29 10:47:07 +0000 |
| commit | 3643a8f8eb300ca9ff4cd0c542dbb15e6d8bef6a (patch) | |
| tree | ccaee66dff7e6f355068eef6ef5081273aa1e302 /llvm/tools/lli/lli.cpp | |
| parent | 94bc73d3d1eb584bf5a8e715aac21a6cb1811500 (diff) | |
| download | bcm5719-llvm-3643a8f8eb300ca9ff4cd0c542dbb15e6d8bef6a.tar.gz bcm5719-llvm-3643a8f8eb300ca9ff4cd0c542dbb15e6d8bef6a.zip | |
Align the data section correctly when loading an ELF file.
Patch by Amara Emerson.
llvm-svn: 166920
Diffstat (limited to 'llvm/tools/lli/lli.cpp')
| -rw-r--r-- | llvm/tools/lli/lli.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index 0ee72387b81..532980a8605 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -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 @@ uint8_t *LLIMCJITMemoryManager::allocateDataSection(uintptr_t Size, 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, |

