Fix a bug where the DWARF emitter in the JIT was not initializing alignment

bytes.  libgcc doesn't seem to mind, but if you pass this DWARF to GDB, it
doesn't like it.  

Also make the JIT memory manager to initialize it's memory to garbage in debug
mode, so that it's easier to find bugs like these in the future.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79674 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Kleckner 2009-08-21 21:03:57 +00:00
parent c692cb77aa
commit 01248e6711
4 changed files with 40 additions and 35 deletions

View File

@ -19,6 +19,7 @@
#include <string> #include <string>
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/CodeGen/MachineCodeEmitter.h" #include "llvm/CodeGen/MachineCodeEmitter.h"
using namespace std; using namespace std;
@ -161,18 +162,27 @@ public:
/// alignment (saturated to BufferEnd of course). /// alignment (saturated to BufferEnd of course).
void emitAlignment(unsigned Alignment) { void emitAlignment(unsigned Alignment) {
if (Alignment == 0) Alignment = 1; if (Alignment == 0) Alignment = 1;
uint8_t *NewPtr = (uint8_t*)RoundUpToAlignment((uintptr_t)CurBufferPtr,
Alignment);
CurBufferPtr = std::min(NewPtr, BufferEnd);
}
if(Alignment <= (uintptr_t)(BufferEnd-CurBufferPtr)) { /// emitAlignmentWithFill - Similar to emitAlignment, except that the
// Move the current buffer ptr up to the specified alignment. /// extra bytes are filled with the provided byte.
CurBufferPtr = void emitAlignmentWithFill(unsigned Alignment, uint8_t Fill) {
(uint8_t*)(((uintptr_t)CurBufferPtr+Alignment-1) & if (Alignment == 0) Alignment = 1;
~(uintptr_t)(Alignment-1)); uint8_t *NewPtr = (uint8_t*)RoundUpToAlignment((uintptr_t)CurBufferPtr,
} else { Alignment);
// Fail if we don't have room.
if (NewPtr > BufferEnd) {
CurBufferPtr = BufferEnd; CurBufferPtr = BufferEnd;
return;
}
while (CurBufferPtr < NewPtr) {
*CurBufferPtr++ = Fill;
} }
} }
/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be
/// written to the output stream. /// written to the output stream.
void emitULEB128Bytes(uint64_t Value) { void emitULEB128Bytes(uint64_t Value) {

View File

@ -449,6 +449,7 @@ enum dwarf_constants {
// Call frame instruction encodings // Call frame instruction encodings
DW_CFA_extended = 0x00, DW_CFA_extended = 0x00,
DW_CFA_nop = 0x00,
DW_CFA_advance_loc = 0x40, DW_CFA_advance_loc = 0x40,
DW_CFA_offset = 0x80, DW_CFA_offset = 0x80,
DW_CFA_restore = 0xc0, DW_CFA_restore = 0xc0,

View File

@ -396,19 +396,9 @@ unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF,
TargetAsmInfo::getULEB128Size(SizeSites) + TargetAsmInfo::getULEB128Size(SizeSites) +
SizeSites + SizeActions + SizeTypes; SizeSites + SizeActions + SizeTypes;
unsigned TotalSize = sizeof(int8_t) + // LPStart format
sizeof(int8_t) + // TType format
TargetAsmInfo::getULEB128Size(TypeOffset) + // TType base offset
TypeOffset;
unsigned SizeAlign = (4 - TotalSize) & 3;
// Begin the exception table. // Begin the exception table.
JCE->emitAlignment(4); JCE->emitAlignmentWithFill(4, 0);
for (unsigned i = 0; i != SizeAlign; ++i) {
JCE->emitByte(0);
// Asm->EOL("Padding"); // Asm->EOL("Padding");
}
unsigned char* DwarfExceptionTable = (unsigned char*)JCE->getCurrentPCValue(); unsigned char* DwarfExceptionTable = (unsigned char*)JCE->getCurrentPCValue();
@ -497,7 +487,7 @@ unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF,
//Asm->EOL("Filter TypeInfo index"); //Asm->EOL("Filter TypeInfo index");
} }
JCE->emitAlignment(4); JCE->emitAlignmentWithFill(4, 0);
return DwarfExceptionTable; return DwarfExceptionTable;
} }
@ -546,7 +536,8 @@ JITDwarfEmitter::EmitCommonEHFrame(const Function* Personality) const {
std::vector<MachineMove> Moves; std::vector<MachineMove> Moves;
RI->getInitialFrameState(Moves); RI->getInitialFrameState(Moves);
EmitFrameMoves(0, Moves); EmitFrameMoves(0, Moves);
JCE->emitAlignment(PointerSize);
JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop);
JCE->emitInt32At((uintptr_t*)StartCommonPtr, JCE->emitInt32At((uintptr_t*)StartCommonPtr,
(uintptr_t)((unsigned char*)JCE->getCurrentPCValue() - (uintptr_t)((unsigned char*)JCE->getCurrentPCValue() -
@ -591,7 +582,7 @@ JITDwarfEmitter::EmitEHFrame(const Function* Personality,
// frame. // frame.
EmitFrameMoves((intptr_t)StartFunction, MMI->getFrameMoves()); EmitFrameMoves((intptr_t)StartFunction, MMI->getFrameMoves());
JCE->emitAlignment(PointerSize); JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop);
// Indicate the size of the table // Indicate the size of the table
JCE->emitInt32At((uintptr_t*)StartEHPtr, JCE->emitInt32At((uintptr_t*)StartEHPtr,
@ -607,7 +598,6 @@ JITDwarfEmitter::EmitEHFrame(const Function* Personality,
JCE->emitInt32(0); JCE->emitInt32(0);
} }
return StartEHPtr; return StartEHPtr;
} }

View File

@ -650,6 +650,10 @@ sys::MemoryBlock DefaultJITMemoryManager::allocateNewSlab(size_t size) {
} }
LastSlab = B; LastSlab = B;
++NumSlabs; ++NumSlabs;
// Initialize the slab to garbage when debugging.
if (PoisonMemory) {
memset(B.base(), 0xCD, B.size());
}
return B; return B;
} }