remember_state_leak.pass.sh.s 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # REQUIRES: x86, linux
  2. # RUN: %{build} -target x86_64-unknown-linux-gnu
  3. # RUN: %{run}
  4. # The following assembly is a translation of this code:
  5. #
  6. # _Unwind_Reason_Code callback(int, _Unwind_Action, long unsigned int,
  7. # _Unwind_Exception*, _Unwind_Context*, void*) {
  8. # return _Unwind_Reason_Code(0);
  9. # }
  10. #
  11. # int main() {
  12. # asm(".cfi_remember_state\n\t");
  13. # _Unwind_Exception exc;
  14. # _Unwind_ForcedUnwind(&exc, callback, 0);
  15. # asm(".cfi_restore_state\n\t");
  16. # }
  17. #
  18. # When unwinding, the CFI parser will stop parsing opcodes after the current PC,
  19. # so in this case the DW_CFA_restore_state opcode will never be processed and,
  20. # if the library doesn't clean up properly, the store allocated by
  21. # DW_CFA_remember_state will be leaked.
  22. #
  23. # This test will fail when linked with an asan-enabled libunwind if the
  24. # remembered state is leaked.
  25. SIZEOF_UNWIND_EXCEPTION = 32
  26. .text
  27. callback:
  28. xorl %eax, %eax
  29. retq
  30. .globl main # -- Begin function main
  31. .p2align 4, 0x90
  32. .type main,@function
  33. main: # @main
  34. .cfi_startproc
  35. subq $8, %rsp # Adjust stack alignment
  36. subq $SIZEOF_UNWIND_EXCEPTION, %rsp
  37. .cfi_def_cfa_offset 48
  38. .cfi_remember_state
  39. movq %rsp, %rdi
  40. movabsq $callback, %rsi
  41. xorl %edx, %edx
  42. callq _Unwind_ForcedUnwind
  43. .cfi_restore_state
  44. xorl %eax, %eax
  45. addq $SIZEOF_UNWIND_EXCEPTION, %rsp
  46. addq $8, %rsp # Undo stack alignment adjustment
  47. .cfi_def_cfa_offset 8
  48. retq
  49. .Lfunc_end1:
  50. .size main, .Lfunc_end1-main
  51. .cfi_endproc
  52. # -- End function