Skip to content

Commit

Permalink
Add support for other typeinfo encodings in the ExceptionDemo.
Browse files Browse the repository at this point in the history
The old jit always uses DW_EH_PE_absptr, but MCJIT can use other encodings.
This is in preparation for adding EH support to MCJIT, but not directly
related, so I am committing it first.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180883 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed May 1, 2013
1 parent de39312 commit 58c3aa2
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions examples/ExceptionDemo/ExceptionDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,30 @@ static uintptr_t readSLEB128(const uint8_t **data) {
return result;
}

unsigned getEncodingSize(uint8_t Encoding) {
if (Encoding == llvm::dwarf::DW_EH_PE_omit)
return 0;

switch (Encoding & 0x0F) {
case llvm::dwarf::DW_EH_PE_absptr:
return sizeof(uintptr_t);
case llvm::dwarf::DW_EH_PE_udata2:
return sizeof(uint16_t);
case llvm::dwarf::DW_EH_PE_udata4:
return sizeof(uint32_t);
case llvm::dwarf::DW_EH_PE_udata8:
return sizeof(uint64_t);
case llvm::dwarf::DW_EH_PE_sdata2:
return sizeof(int16_t);
case llvm::dwarf::DW_EH_PE_sdata4:
return sizeof(int32_t);
case llvm::dwarf::DW_EH_PE_sdata8:
return sizeof(int64_t);
default:
// not supported
abort();
}
}

/// Read a pointer encoded value and advance pointer
/// See Variable Length Data in:
Expand Down Expand Up @@ -523,7 +547,8 @@ static uintptr_t readEncodedPointer(const uint8_t **data, uint8_t encoding) {
/// @returns whether or not a type info was found. False is returned if only
/// a cleanup was found
static bool handleActionValue(int64_t *resultAction,
struct OurExceptionType_t **classInfo,
uint8_t TTypeEncoding,
const uint8_t *ClassInfo,
uintptr_t actionEntry,
uint64_t exceptionClass,
struct _Unwind_Exception *exceptionObject) {
Expand Down Expand Up @@ -572,16 +597,22 @@ static bool handleActionValue(int64_t *resultAction,

// Note: A typeOffset == 0 implies that a cleanup llvm.eh.selector
// argument has been matched.
if ((typeOffset > 0) &&
(type == (classInfo[-typeOffset])->type)) {
if (typeOffset > 0) {
#ifdef DEBUG
fprintf(stderr,
"handleActionValue(...):actionValue <%d> found.\n",
i);
#endif
*resultAction = i + 1;
ret = true;
break;
unsigned EncSize = getEncodingSize(TTypeEncoding);
const uint8_t *EntryP = ClassInfo - typeOffset * EncSize;
uintptr_t P = readEncodedPointer(&EntryP, TTypeEncoding);
struct OurExceptionType_t *ThisClassInfo =
reinterpret_cast<struct OurExceptionType_t *>(P);
if (ThisClassInfo->type == type) {
*resultAction = i + 1;
ret = true;
break;
}
}

#ifdef DEBUG
Expand Down Expand Up @@ -633,7 +664,7 @@ static _Unwind_Reason_Code handleLsda(int version,
// emitted dwarf code)
uintptr_t funcStart = _Unwind_GetRegionStart(context);
uintptr_t pcOffset = pc - funcStart;
struct OurExceptionType_t **classInfo = NULL;
const uint8_t *ClassInfo = NULL;

// Note: See JITDwarfEmitter::EmitExceptionTable(...) for corresponding
// dwarf emission
Expand All @@ -653,7 +684,7 @@ static _Unwind_Reason_Code handleLsda(int version,
// were flagged by type info arguments to llvm.eh.selector
// intrinsic
classInfoOffset = readULEB128(&lsda);
classInfo = (struct OurExceptionType_t**) (lsda + classInfoOffset);
ClassInfo = lsda + classInfoOffset;
}

// Walk call-site table looking for range that
Expand Down Expand Up @@ -714,7 +745,8 @@ static _Unwind_Reason_Code handleLsda(int version,

if (actionEntry) {
exceptionMatched = handleActionValue(&actionValue,
classInfo,
ttypeEncoding,
ClassInfo,
actionEntry,
exceptionClass,
exceptionObject);
Expand Down

0 comments on commit 58c3aa2

Please sign in to comment.