From 01248e671100fbd6eac6bc3646096dc75ec885d1 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 21 Aug 2009 21:03:57 +0000 Subject: 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 --- include/llvm/CodeGen/JITCodeEmitter.h | 24 +++++++++++++++++------- include/llvm/Support/Dwarf.h | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/llvm/CodeGen/JITCodeEmitter.h b/include/llvm/CodeGen/JITCodeEmitter.h index c3f95b4198..180783a4d6 100644 --- a/include/llvm/CodeGen/JITCodeEmitter.h +++ b/include/llvm/CodeGen/JITCodeEmitter.h @@ -19,6 +19,7 @@ #include #include "llvm/Support/DataTypes.h" +#include "llvm/Support/MathExtras.h" #include "llvm/CodeGen/MachineCodeEmitter.h" using namespace std; @@ -161,17 +162,26 @@ public: /// 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. diff --git a/include/llvm/Support/Dwarf.h b/include/llvm/Support/Dwarf.h index 55838b8144..bfccc522b9 100644 --- a/include/llvm/Support/Dwarf.h +++ b/include/llvm/Support/Dwarf.h @@ -449,6 +449,7 @@ enum dwarf_constants { // 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, -- cgit v1.2.3