llvm.org GIT mirror llvm / b210e6f
Align the data section correctly when loading an ELF file. Patch by Amara Emerson. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166920 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Northover 8 years ago
2 changed file(s) with 26 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 %s
1
2 ; Check that a variable is always aligned as specified.
3
4 @var = global i32 0, align 32
5 define i32 @main() {
6 %addr = ptrtoint i32* @var to i64
7 %mask = and i64 %addr, 31
8 %tst = icmp eq i64 %mask, 0
9 br i1 %tst, label %good, label %bad
10 good:
11 ret i32 0
12 bad:
13 ret i32 1
14 }
4141 #include "llvm/Support/Debug.h"
4242 #include "llvm/Support/DynamicLibrary.h"
4343 #include "llvm/Support/Memory.h"
44 #include "llvm/Support/MathExtras.h"
4445 #include
4546
4647 #ifdef __linux__
302303 unsigned SectionID) {
303304 if (!Alignment)
304305 Alignment = 16;
305 uint8_t *Addr = (uint8_t*)calloc((Size + Alignment - 1)/Alignment, Alignment);
306 AllocatedDataMem.push_back(sys::MemoryBlock(Addr, Size));
307 return Addr;
306 // Ensure that enough memory is requested to allow aligning.
307 size_t NumElementsAligned = 1 + (Size + Alignment - 1)/Alignment;
308 uint8_t *Addr = (uint8_t*)calloc(NumElementsAligned, Alignment);
309
310 // Honour the alignment requirement.
311 uint8_t *AlignedAddr = (uint8_t*)RoundUpToAlignment((uint64_t)Addr, Alignment);
312
313 // Store the original address from calloc so we can free it later.
314 AllocatedDataMem.push_back(sys::MemoryBlock(Addr, NumElementsAligned*Alignment));
315 return AlignedAddr;
308316 }
309317
310318 uint8_t *LLIMCJITMemoryManager::allocateCodeSection(uintptr_t Size,