[LLVMdev] Exception handling question

Duncan Sands baldrick at free.fr
Fri Jan 22 00:29:59 PST 2010

Hi James,

> I've been trying to get a minimal test function to work, which simply 
> invokes _Unwind_RaiseException with a single clean-up landing pad. 
> However. when I run it my personality function is not getting called - 
> _Unwind_RaiseException simply returns apparently doing nothing. Looking 
> at the x86-64 assembly output from llc, I can see this is happening 
> because the personality function is not getting into the DWARF eh table 
> (the landing pad is there though).

do you mean that the personality function doesn't turn up in the assembler
at all?  It should be!  Consider the following simplified example:

declare void @g()

define void @f() {
   invoke void @g()
           to label %c unwind label %u

c:                                                ; preds = %e
   ret void

u:                                                ; preds = %e
   %ptr = tail call i8* @llvm.eh.exception() nounwind ; <i8*> [#uses=1]
   %select = tail call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %ptr, i8* 
bitcast (i32 (...)* @personality to i8*)) nounwind ; <i32> [#uses=0]
   ret void

declare i8* @llvm.eh.exception() nounwind readonly

declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind

declare i32 @personality(...)

This compiles down to the following, which has a "cleanup" noted in the
dwarf eh table, and has the personality function recorded in the CIE.
This is with llc from top-of-tree.  Do you see something different?



	.file	"selector.ll"

	.align	16
.globl f
	.type	f, at function
f:                                                          # @f
# BB#0:                                                     # %e
	subq	$8, %rsp
	callq	g
# BB#1:                                                     # %c
	addq	$8, %rsp
                                                             # %u
	addq	$8, %rsp
	.size	f, .-f
	.section	.gcc_except_table,"a", at progbits
	.align	4
	.byte	0
                                                             # Padding
	.byte	0
                                                             # Padding
	.byte	255
                                                             # @LPStart format 
	.byte	0
                                                             # @TType format 
	.uleb128	15                                  # @TType base offset
	.byte	3
                                                             # Call site format 
	.uleb128	13                                  # Call site table size
	.long	.Llabel1-.Leh_func_begin1                   # Region start
	.long	.Llabel2-.Llabel1                           # Region length
	.long	.Llabel3-.Leh_func_begin1                   # Landing pad
	.uleb128	0                                   # Action
	.align	4
	.section	.eh_frame,"aw", at progbits
	.long	.Leh_frame_common_end-.Leh_frame_common_begin # Length of Common 
Information Entry
	.long	0
                                                             # CIE Identifier Tag
	.byte	1
                                                             # CIE Version
	.asciz	"zPLR"                                      # CIE Augmentation
	.uleb128	1                                   # CIE Code Alignment Factor
	.sleb128	-8                                  # CIE Data Alignment Factor
	.byte	16
                                                             # CIE Return 
Address Column
	.uleb128	7                                   # Augmentation Size
	.byte	27
                                                             # Personality 
(pcrel sdata4)
	.long	personality-.Lpersonalityref_addr1_0        # Personality
	.byte	27
                                                             # LSDA Encoding 
(pcrel sdata4)
	.byte	27
                                                             # FDE Encoding 
(pcrel sdata4)
	.byte	12
                                                             # DW_CFA_def_cfa
	.uleb128	7                                   # Register
	.uleb128	8                                   # Offset
	.byte	144
                                                             # DW_CFA_offset + 
Reg (16)
	.uleb128	1                                   # Offset
	.align	8

	.long	.Leh_frame_end1-.Leh_frame_begin1           # Length of Frame Information 
	.long	.Leh_frame_begin1-.Leh_frame_common         # FDE CIE offset
	.long	.Leh_func_begin1-.                          # FDE initial location
	.long	.Leh_func_end1-.Leh_func_begin1             # FDE address range
	.uleb128	8                                   # Augmentation size
	.quad	.Lexception1-.                              # Language Specific Data Area
	.byte	4
                                                             # DW_CFA_advance_loc4
	.long	.Llabel4-.Leh_func_begin1
	.byte	14
                                                             # DW_CFA_def_cfa_offset
	.uleb128	16                                  # Offset
	.align	8

	.section	.note.GNU-stack,"", at progbits

More information about the llvm-dev mailing list