[PATCH] D16509: [DebugInfo] Fix DWARFDebugFrame instruction operand ordering

Igor Laevsky via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 23 08:51:57 PST 2016


igor-laevsky created this revision.
igor-laevsky added reviewers: pete, rafael.
igor-laevsky added a subscriber: llvm-commits.
igor-laevsky set the repository for this revision to rL LLVM.

When parsing DWARF instructions we can sometimes end up with instruction operands in reversed order. This was caused by two facts: 
1. getULEB128(Offset) changes Offset and
2. Evaluation order of function arguments is unspecified
It means that two getULEB128 calls embedded into function argument list were executed in any arbitrary order. Sometimes this was resulting in a reversed instruction operands.

This issue came up after _eh_frame changes http://reviews.llvm.org/D15535. However they are not directly related.

Repository:
  rL LLVM

http://reviews.llvm.org/D16509

Files:
  lib/DebugInfo/DWARF/DWARFDebugFrame.cpp

Index: lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
+++ lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
@@ -160,18 +160,28 @@
         case DW_CFA_offset_extended:
         case DW_CFA_register:
         case DW_CFA_def_cfa:
-        case DW_CFA_val_offset:
+        case DW_CFA_val_offset: {
           // Operands: ULEB128, ULEB128
-          addInstruction(Opcode, Data.getULEB128(Offset),
-                                 Data.getULEB128(Offset));
+          // Note: We can not embed getULEB128 directly into function
+          // argument list. getULEB128 changes Offset and order of evaluation
+          // for arguments is unspecified.
+          uint64_t op1, op2;
+          op1 = Data.getULEB128(Offset);
+          op2 = Data.getULEB128(Offset);
+          addInstruction(Opcode, op1, op2);
           break;
+        }
         case DW_CFA_offset_extended_sf:
         case DW_CFA_def_cfa_sf:
-        case DW_CFA_val_offset_sf:
+        case DW_CFA_val_offset_sf: {
           // Operands: ULEB128, SLEB128
-          addInstruction(Opcode, Data.getULEB128(Offset),
-                                 Data.getSLEB128(Offset));
+          // Note: see comment for previous case
+          uint64_t op1, op2;
+          op1 = Data.getULEB128(Offset);
+          op2 = (uint64_t)Data.getSLEB128(Offset);
+          addInstruction(Opcode, op1, op2);
           break;
+        }
         case DW_CFA_def_cfa_expression:
         case DW_CFA_expression:
         case DW_CFA_val_expression:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16509.45793.patch
Type: text/x-patch
Size: 1601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160123/c872a976/attachment.bin>


More information about the llvm-commits mailing list