public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Eh_frame in Macro `RESTORE2`
@ 2020-06-07  1:01 Chengbin Pang
  2020-06-07  5:10 ` Florian Weimer
  0 siblings, 1 reply; 3+ messages in thread
From: Chengbin Pang @ 2020-06-07  1:01 UTC (permalink / raw)
  To: libc-help; +Cc: Jun Xu

Dear Community,


In file `sysdeps/unix/sysv/linux/x86_64/sigaction.c`, there exists a handwritten eh_frame record as below:


```

# define RESTORE2(name, syscall) \
1: asm \
   ( \
   /* `nop' for debuggers assuming `call' should not disalign the code.  */ \
   " nop\n" \
   ".align 16\n" \
   ".LSTART_" #name ":\n" \
   " .type __" #name ",@function\n" \
   "__" #name ":\n" \
   " movq $" #syscall ", %rax\n" \
   " syscall\n" \
   ".LEND_" #name ":\n" \
// eh_frame record
   ".section .eh_frame,\"a\",@progbits\n" \
   ".LSTARTFRAME_" #name ":\n" \
   " .long .LENDCIE_" #name "-.LSTARTCIE_" #name "\n" \
   ".LSTARTCIE_" #name ":\n" \
   " .long 0\n" /* CIE ID */ \
   " .byte 1\n" /* Version number */ \
   " .string \"zRS\"\n" /* NUL-terminated augmentation string */ \
   " .uleb128 1\n" /* Code alignment factor */ \
   " .sleb128 -8\n" /* Data alignment factor */ \
   " .uleb128 16\n" /* Return address register column (rip) */ \
   /* Augmentation value length */ \
   " .uleb128 .LENDAUGMNT_" #name "-.LSTARTAUGMNT_" #name "\n" \
   ".LSTARTAUGMNT_" #name ":\n" \
   " .byte 0x1b\n" /* DW_EH_PE_pcrel|DW_EH_PE_sdata4. */ \
   ".LENDAUGMNT_" #name ":\n" \
   " .align " LP_SIZE "\n" \
   ".LENDCIE_" #name ":\n" \
   " .long .LENDFDE_" #name "-.LSTARTFDE_" #name "\n" /* FDE len */ \
   ".LSTARTFDE_" #name ":\n" \
   " .long .LSTARTFDE_" #name "-.LSTARTFRAME_" #name "\n" /* CIE */ \
   /* `LSTART_' is subtracted 1 as debuggers assume a `call' here.  */ \
   " .long (.LSTART_" #name "-1)-.\n" /* PC-relative start addr.  */ \
   " .long .LEND_" #name "-(.LSTART_" #name "-1)\n" \
   " .uleb128 0\n" /* FDE augmentation length */ \
   ...
```


I am confused about why the `PC Begin' of above eh_frame is `.LSTART_" #name "-1` not `.LSTART_" #name "'.


Best regards,

Chengbin Pang

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Eh_frame in Macro `RESTORE2`
  2020-06-07  1:01 Eh_frame in Macro `RESTORE2` Chengbin Pang
@ 2020-06-07  5:10 ` Florian Weimer
  2020-06-07 19:12   ` Chengbin Pang
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2020-06-07  5:10 UTC (permalink / raw)
  To: Chengbin Pang; +Cc: libc-help, Jun Xu

* Chengbin Pang:

> I am confused about why the `PC Begin' of above eh_frame is
> `.LSTART_" #name "-1` not `.LSTART_" #name "'.

See the comment earlier in the file, and also code around
_Unwind_GetIPInfo in the libgcc personality function
(libgcc/unwind-c.c in the GCC sources).

Basically, what happens is that saved return addresses on the stack
point to *after* the corresponding call instruction.  But for the
purposes of exception handling, while the address is saved, the
program is still within the exception handling region that contains
the call instruction.  Therefore, the unwinder decrements the saved
address by one when unwinding through a regular call frame (not a
signal handler).  The code in sigaction.c makes the exception handling
region to cover that.

Does this answer your question?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Eh_frame in Macro `RESTORE2`
  2020-06-07  5:10 ` Florian Weimer
@ 2020-06-07 19:12   ` Chengbin Pang
  0 siblings, 0 replies; 3+ messages in thread
From: Chengbin Pang @ 2020-06-07 19:12 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-help, Jun Xu

Thanks Florian,


That really helps a lot!


Best,

Chengbin

________________________________
From: Florian Weimer <fw@deneb.enyo.de>
Sent: Sunday, June 7, 2020 1:10:39 AM
To: Chengbin Pang
Cc: libc-help@sourceware.org; Jun Xu
Subject: Re: Eh_frame in Macro `RESTORE2`

* Chengbin Pang:

> I am confused about why the `PC Begin' of above eh_frame is
> `.LSTART_" #name "-1` not `.LSTART_" #name "'.

See the comment earlier in the file, and also code around
_Unwind_GetIPInfo in the libgcc personality function
(libgcc/unwind-c.c in the GCC sources).

Basically, what happens is that saved return addresses on the stack
point to *after* the corresponding call instruction.  But for the
purposes of exception handling, while the address is saved, the
program is still within the exception handling region that contains
the call instruction.  Therefore, the unwinder decrements the saved
address by one when unwinding through a regular call frame (not a
signal handler).  The code in sigaction.c makes the exception handling
region to cover that.

Does this answer your question?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-07 19:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-07  1:01 Eh_frame in Macro `RESTORE2` Chengbin Pang
2020-06-07  5:10 ` Florian Weimer
2020-06-07 19:12   ` Chengbin Pang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).