[llvm-commits] [llvm] r79674 - in /llvm/trunk: include/llvm/CodeGen/JITCodeEmitter.h include/llvm/Support/Dwarf.h lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp lib/ExecutionEngine/JIT/JITMemoryManager.cpp
Reid Kleckner
reid at kleckner.net
Fri Aug 21 14:03:57 PDT 2009
Author: rnk
Date: Fri Aug 21 16:03:57 2009
New Revision: 79674
URL: http://llvm.org/viewvc/llvm-project?rev=79674&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/CodeGen/JITCodeEmitter.h
llvm/trunk/include/llvm/Support/Dwarf.h
llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp
llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
Modified: llvm/trunk/include/llvm/CodeGen/JITCodeEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/JITCodeEmitter.h?rev=79674&r1=79673&r2=79674&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/JITCodeEmitter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/JITCodeEmitter.h Fri Aug 21 16:03:57 2009
@@ -19,6 +19,7 @@
#include <string>
#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/MathExtras.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
using namespace std;
@@ -161,17 +162,26 @@
/// alignment (saturated to BufferEnd of course).
void emitAlignment(unsigned Alignment) {
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)) {
- // Move the current buffer ptr up to the specified alignment.
- CurBufferPtr =
- (uint8_t*)(((uintptr_t)CurBufferPtr+Alignment-1) &
- ~(uintptr_t)(Alignment-1));
- } else {
+ /// emitAlignmentWithFill - Similar to emitAlignment, except that the
+ /// extra bytes are filled with the provided byte.
+ void emitAlignmentWithFill(unsigned Alignment, uint8_t Fill) {
+ if (Alignment == 0) Alignment = 1;
+ uint8_t *NewPtr = (uint8_t*)RoundUpToAlignment((uintptr_t)CurBufferPtr,
+ Alignment);
+ // Fail if we don't have room.
+ if (NewPtr > BufferEnd) {
CurBufferPtr = BufferEnd;
+ return;
+ }
+ while (CurBufferPtr < NewPtr) {
+ *CurBufferPtr++ = Fill;
}
}
-
/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be
/// written to the output stream.
Modified: llvm/trunk/include/llvm/Support/Dwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Dwarf.h?rev=79674&r1=79673&r2=79674&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Dwarf.h (original)
+++ llvm/trunk/include/llvm/Support/Dwarf.h Fri Aug 21 16:03:57 2009
@@ -449,6 +449,7 @@
// Call frame instruction encodings
DW_CFA_extended = 0x00,
+ DW_CFA_nop = 0x00,
DW_CFA_advance_loc = 0x40,
DW_CFA_offset = 0x80,
DW_CFA_restore = 0xc0,
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp?rev=79674&r1=79673&r2=79674&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp Fri Aug 21 16:03:57 2009
@@ -396,20 +396,10 @@
TargetAsmInfo::getULEB128Size(SizeSites) +
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.
- JCE->emitAlignment(4);
- for (unsigned i = 0; i != SizeAlign; ++i) {
- JCE->emitByte(0);
- // Asm->EOL("Padding");
- }
-
+ JCE->emitAlignmentWithFill(4, 0);
+ // Asm->EOL("Padding");
+
unsigned char* DwarfExceptionTable = (unsigned char*)JCE->getCurrentPCValue();
// Emit the header.
@@ -496,8 +486,8 @@
JCE->emitULEB128Bytes(TypeID);
//Asm->EOL("Filter TypeInfo index");
}
-
- JCE->emitAlignment(4);
+
+ JCE->emitAlignmentWithFill(4, 0);
return DwarfExceptionTable;
}
@@ -546,11 +536,12 @@
std::vector<MachineMove> Moves;
RI->getInitialFrameState(Moves);
EmitFrameMoves(0, Moves);
- JCE->emitAlignment(PointerSize);
-
- JCE->emitInt32At((uintptr_t*)StartCommonPtr,
- (uintptr_t)((unsigned char*)JCE->getCurrentPCValue() -
- FrameCommonBeginPtr));
+
+ JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop);
+
+ JCE->emitInt32At((uintptr_t*)StartCommonPtr,
+ (uintptr_t)((unsigned char*)JCE->getCurrentPCValue() -
+ FrameCommonBeginPtr));
return StartCommonPtr;
}
@@ -590,14 +581,14 @@
// Indicate locations of function specific callee saved registers in
// frame.
EmitFrameMoves((intptr_t)StartFunction, MMI->getFrameMoves());
-
- JCE->emitAlignment(PointerSize);
-
+
+ JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop);
+
// Indicate the size of the table
- JCE->emitInt32At((uintptr_t*)StartEHPtr,
- (uintptr_t)((unsigned char*)JCE->getCurrentPCValue() -
- StartEHPtr));
-
+ JCE->emitInt32At((uintptr_t*)StartEHPtr,
+ (uintptr_t)((unsigned char*)JCE->getCurrentPCValue() -
+ StartEHPtr));
+
// Double zeroes for the unwind runtime
if (PointerSize == 8) {
JCE->emitInt64(0);
@@ -606,7 +597,6 @@
JCE->emitInt32(0);
JCE->emitInt32(0);
}
-
return StartEHPtr;
}
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp?rev=79674&r1=79673&r2=79674&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp Fri Aug 21 16:03:57 2009
@@ -650,6 +650,10 @@
}
LastSlab = B;
++NumSlabs;
+ // Initialize the slab to garbage when debugging.
+ if (PoisonMemory) {
+ memset(B.base(), 0xCD, B.size());
+ }
return B;
}
More information about the llvm-commits
mailing list