public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add CFI to x86_64 RTLD_START
@ 2016-07-04 17:39 Keno Fischer
  2016-07-04 18:23 ` Andreas Schwab
  0 siblings, 1 reply; 10+ messages in thread
From: Keno Fischer @ 2016-07-04 17:39 UTC (permalink / raw)
  To: libc-alpha

The application's entry point already has the appropriate CFI to
indicate to tools that the end of the stack has been reached. This
CFI was lacking from the dynamic linker, causing garbled backtraces
after hitting _dl_start. Fix this by adding the appropriate CFI.

Example gdb output before:

```
(gdb) bt
 #0  0x00007f10a2cee2d0 in _start () from /lib64/ld-linux-x86-64.so.2
 #1  0x0000000000000003 in ?? ()
 #2  0x00007ffd2ba54ce9 in ?? ()
 #3  0x00007ffd2ba54d04 in ?? ()
 #4  0x00007ffd2ba54d07 in ?? ()
 #5  0x0000000000000000 in ?? ()
```

after:
```
(gdb) bt
 #0  0x00007f36273551b0 in _start () from
/home/kfischer/replacement-usr/lib/ld-2.23.90.so
```

This is likely applicable to other architectures as well, but I only
have access to x86_64, so this patch is limited to that architecture.
---
 sysdeps/x86_64/dl-machine.h | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
index ed0c1a8..7a246d4 100644
--- a/sysdeps/x86_64/dl-machine.h
+++ b/sysdeps/x86_64/dl-machine.h
@@ -141,10 +141,15 @@ elf_machine_runtime_setup (struct link_map *l,
int lazy, int profile)
  .align 16\n\
 .globl _start\n\
 .globl _dl_start_user\n\
-_start:\n\
+_start:\n"\
+CFI_STARTPROC "\n"\
+CFI_UNDEFINED(%rip) "\n\
  movq %rsp, %rdi\n\
- call _dl_start\n\
-_dl_start_user:\n\
+ call _dl_start\n"\
+CFI_ENDPROC "\n\
+_dl_start_user:\n"\
+CFI_STARTPROC "\n"\
+CFI_UNDEFINED(%rip) "\n\
  # Save the user entry point address in %r12.\n\
  movq %rax, %r12\n\
  # See if we were run as a command with the executable file\n\
@@ -180,7 +185,8 @@ _dl_start_user:\n\
  # And make sure %rsp points to argc stored on the stack.\n\
  movq %r13, %rsp\n\
  # Jump to the user's entry point.\n\
- jmp *%r12\n\
+ jmp *%r12\n"\
+CFI_ENDPROC "\n\
 .previous\n\
 ");

-- 
2.6.4

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

* Re: [PATCH] Add CFI to x86_64 RTLD_START
  2016-07-04 17:39 [PATCH] Add CFI to x86_64 RTLD_START Keno Fischer
@ 2016-07-04 18:23 ` Andreas Schwab
  2016-07-04 18:28   ` Keno Fischer
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 2016-07-04 18:23 UTC (permalink / raw)
  To: Keno Fischer; +Cc: libc-alpha

Keno Fischer <keno@juliacomputing.com> writes:

> diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
> index ed0c1a8..7a246d4 100644
> --- a/sysdeps/x86_64/dl-machine.h
> +++ b/sysdeps/x86_64/dl-machine.h
> @@ -141,10 +141,15 @@ elf_machine_runtime_setup (struct link_map *l,
> int lazy, int profile)
>   .align 16\n\
>  .globl _start\n\
>  .globl _dl_start_user\n\
> -_start:\n\
> +_start:\n"\
> +CFI_STARTPROC "\n"\
> +CFI_UNDEFINED(%rip) "\n\

No need for backslash continuation outside of the string literals.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [PATCH] Add CFI to x86_64 RTLD_START
  2016-07-04 18:23 ` Andreas Schwab
@ 2016-07-04 18:28   ` Keno Fischer
  2016-07-04 19:38     ` Andreas Schwab
  0 siblings, 1 reply; 10+ messages in thread
From: Keno Fischer @ 2016-07-04 18:28 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

I should have probably sent this patch with more diff context, but
since this is part of a preprocessor `#define`, the backslashes are
still required, no?

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

* Re: [PATCH] Add CFI to x86_64 RTLD_START
  2016-07-04 18:28   ` Keno Fischer
@ 2016-07-04 19:38     ` Andreas Schwab
  2016-07-08 20:46       ` Keno Fischer
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 2016-07-04 19:38 UTC (permalink / raw)
  To: Keno Fischer; +Cc: libc-alpha

Keno Fischer <keno@juliacomputing.com> writes:

> I should have probably sent this patch with more diff context, but
> since this is part of a preprocessor `#define`, the backslashes are
> still required, no?

Yes, sorry, I missed that.  But please put a space before the
backslashes outside of the string literals.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [PATCH] Add CFI to x86_64 RTLD_START
  2016-07-04 19:38     ` Andreas Schwab
@ 2016-07-08 20:46       ` Keno Fischer
       [not found]         ` <CABV8kRwpe3k49Kk5bA-cfsF9vPj6y_1sSe_dWk8F3sTtkeDPGA@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Keno Fischer @ 2016-07-08 20:46 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

Might it make sense to change the macro to clearly
separate the string literals and the backslashes, i.e.

".globl _start\n"                 \
".globl _dl_start_user\n"   \
"_start:\n"                         \

etc.?

On Mon, Jul 4, 2016 at 3:37 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Keno Fischer <keno@juliacomputing.com> writes:
>
>> I should have probably sent this patch with more diff context, but
>> since this is part of a preprocessor `#define`, the backslashes are
>> still required, no?
>
> Yes, sorry, I missed that.  But please put a space before the
> backslashes outside of the string literals.
>
> Andreas.
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."

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

* Re: [PATCH] Add CFI to x86_64 RTLD_START
       [not found]         ` <CABV8kRwpe3k49Kk5bA-cfsF9vPj6y_1sSe_dWk8F3sTtkeDPGA@mail.gmail.com>
@ 2016-08-02  3:27           ` Keno Fischer
  2016-08-11 19:39             ` Keno Fischer
  0 siblings, 1 reply; 10+ messages in thread
From: Keno Fischer @ 2016-08-02  3:27 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

Hello again. I'd be happy to change this patch in whatever way you
deem best. Could you suggest what you would like me to do?

Thanks,
Keno

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

* Re: [PATCH] Add CFI to x86_64 RTLD_START
  2016-08-02  3:27           ` Keno Fischer
@ 2016-08-11 19:39             ` Keno Fischer
  2016-11-01 20:49               ` Keno Fischer
  0 siblings, 1 reply; 10+ messages in thread
From: Keno Fischer @ 2016-08-11 19:39 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

Bump again, I would like to make sure this doesn't get lost.
Please let me know how I should proceed.

On Mon, Aug 1, 2016 at 11:21 PM, Keno Fischer <keno@juliacomputing.com> wrote:
> Hello again. I'd be happy to change this patch in whatever way you
> deem best. Could you suggest what you would like me to do?
>
> Thanks,
> Keno

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

* Re: [PATCH] Add CFI to x86_64 RTLD_START
  2016-08-11 19:39             ` Keno Fischer
@ 2016-11-01 20:49               ` Keno Fischer
  2016-11-07 16:44                 ` H.J. Lu
  0 siblings, 1 reply; 10+ messages in thread
From: Keno Fischer @ 2016-11-01 20:49 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

Bump. Please let me know the stylistic preferences for the assembly
code as well as any other comments
on the patch.

On Thu, Aug 11, 2016 at 3:38 PM, Keno Fischer <keno@juliacomputing.com> wrote:
> Bump again, I would like to make sure this doesn't get lost.
> Please let me know how I should proceed.
>
> On Mon, Aug 1, 2016 at 11:21 PM, Keno Fischer <keno@juliacomputing.com> wrote:
>> Hello again. I'd be happy to change this patch in whatever way you
>> deem best. Could you suggest what you would like me to do?
>>
>> Thanks,
>> Keno

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

* Re: [PATCH] Add CFI to x86_64 RTLD_START
  2016-11-01 20:49               ` Keno Fischer
@ 2016-11-07 16:44                 ` H.J. Lu
  2016-11-16  3:52                   ` Keno Fischer
  0 siblings, 1 reply; 10+ messages in thread
From: H.J. Lu @ 2016-11-07 16:44 UTC (permalink / raw)
  To: Keno Fischer; +Cc: Andreas Schwab, GNU C Library

On Tue, Nov 1, 2016 at 1:48 PM, Keno Fischer <keno@juliacomputing.com> wrote:
> Bump. Please let me know the stylistic preferences for the assembly
> code as well as any other comments
> on the patch.
>
> On Thu, Aug 11, 2016 at 3:38 PM, Keno Fischer <keno@juliacomputing.com> wrote:
>> Bump again, I would like to make sure this doesn't get lost.
>> Please let me know how I should proceed.
>>
>> On Mon, Aug 1, 2016 at 11:21 PM, Keno Fischer <keno@juliacomputing.com> wrote:
>>> Hello again. I'd be happy to change this patch in whatever way you
>>> deem best. Could you suggest what you would like me to do?
>>>
>>> Thanks,
>>> Keno

It looks good to me.


-- 
H.J.

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

* Re: [PATCH] Add CFI to x86_64 RTLD_START
  2016-11-07 16:44                 ` H.J. Lu
@ 2016-11-16  3:52                   ` Keno Fischer
  0 siblings, 0 replies; 10+ messages in thread
From: Keno Fischer @ 2016-11-16  3:52 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Andreas Schwab, GNU C Library

Thanks for taking a look H.J. What's the next step? Can somebody
commit this (or the reformatted version I sent as v2)? I'd also be
happy to do another revision, if there are any further review comments
- just want to make sure this doesn't get forgotten.

Thanks,
Keno

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

end of thread, other threads:[~2016-11-16  3:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-04 17:39 [PATCH] Add CFI to x86_64 RTLD_START Keno Fischer
2016-07-04 18:23 ` Andreas Schwab
2016-07-04 18:28   ` Keno Fischer
2016-07-04 19:38     ` Andreas Schwab
2016-07-08 20:46       ` Keno Fischer
     [not found]         ` <CABV8kRwpe3k49Kk5bA-cfsF9vPj6y_1sSe_dWk8F3sTtkeDPGA@mail.gmail.com>
2016-08-02  3:27           ` Keno Fischer
2016-08-11 19:39             ` Keno Fischer
2016-11-01 20:49               ` Keno Fischer
2016-11-07 16:44                 ` H.J. Lu
2016-11-16  3:52                   ` Keno Fischer

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).