mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-28 04:33:05 +00:00
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
This commit is contained in:
parent
f00677d74f
commit
b210e6fea5
15
test/ExecutionEngine/MCJIT/test-data-align.ll
Normal file
15
test/ExecutionEngine/MCJIT/test-data-align.ll
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 %s
|
||||||
|
|
||||||
|
; Check that a variable is always aligned as specified.
|
||||||
|
|
||||||
|
@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
|
||||||
|
}
|
@ -42,6 +42,7 @@
|
|||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/DynamicLibrary.h"
|
#include "llvm/Support/DynamicLibrary.h"
|
||||||
#include "llvm/Support/Memory.h"
|
#include "llvm/Support/Memory.h"
|
||||||
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
@ -303,9 +304,16 @@ uint8_t *LLIMCJITMemoryManager::allocateDataSection(uintptr_t Size,
|
|||||||
unsigned SectionID) {
|
unsigned SectionID) {
|
||||||
if (!Alignment)
|
if (!Alignment)
|
||||||
Alignment = 16;
|
Alignment = 16;
|
||||||
uint8_t *Addr = (uint8_t*)calloc((Size + Alignment - 1)/Alignment, Alignment);
|
// Ensure that enough memory is requested to allow aligning.
|
||||||
AllocatedDataMem.push_back(sys::MemoryBlock(Addr, Size));
|
size_t NumElementsAligned = 1 + (Size + Alignment - 1)/Alignment;
|
||||||
return Addr;
|
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,
|
uint8_t *LLIMCJITMemoryManager::allocateCodeSection(uintptr_t Size,
|
||||||
|
Loading…
Reference in New Issue
Block a user