public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Sergey Bugaev <bugaevc@gmail.com>
To: Samuel Thibault <samuel.thibault@gnu.org>
Cc: bug-hurd@gnu.org, libc-alpha@sourceware.org,
	"Flávio Cruz" <flaviocruz@gmail.com>
Subject: Re: [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64
Date: Mon, 20 Feb 2023 20:10:29 +0300	[thread overview]
Message-ID: <CAN9u=HeqxTx44oNzvmHCge9=pBohVpk0j526bYtyMVeQUZM-Tw@mail.gmail.com> (raw)
In-Reply-To: <CAN9u=HfAOMiZtg3fgVMex7FhLXadwWDVVPxRedn2hNvMUahhUA@mail.gmail.com>

> I wish I had a better understanding of just what's going on in this
> file. Maybe a lot of the hacks can be rewritten in a nicer way. For
> instance, do we really need to hijack the return addresses and jump to
> init1 in this weird way, only to enable it to access argc/arg0? Since
> we know where they are on our stack (__builtin_frame_address (0) + 2
> or something like that), can't we just pass it a pointer?
>
> Let me actually try just that...

Eh, no, let's start even earlier than that. Please correct me if I
(inevitably) get things wrong.

_dl_init_first is Hurd-specific. It is called from the assembly code
in dl-machine.h, specifically there's a RTLD_START_SPECIAL_INIT macro
that's defined to call _dl_init_first on the Hurd, and to nothing
otherwise. This RTLD_START_SPECIAL_INIT is used ("invoked") in
i386/dl-machine.h, s390/s390-{32,64}/dl-machine.h, ia64/dl-machine.h,
and alpha/dl-machine.h (but notably not in x86_64/dl-machine.h). In
all cases, it's emphasized that "The special initializer gets called
with the stack just as the application's entry point will see it; it
can switch stacks if it moves these contents over."

But I conclude that:
- s390-gnu, ia64-gnu, and alpha-gnu ports are nonexistent, nor are
they realistically ever going to happen, so we can ignore them
completely
- the implementation does not seem to actually switch stacks (in fact,
I have removed the unused switch_stacks function in the last commit)
-- so the "gets called with the stack just as the application's entry
point will see it" property may not be important anymore?

The only thing it really needs, it seems, is a pointer to
argc/argv/envp & Hurd data block *somewhere*. It does not have to be
on the stack (though where else would it be), or immediately preceding
its call frame -- all that really matters is that there's a pointer.

So my thinking goes, why don't we just hook into _dl_start, which
already has this very pointer? And in fact, _dl_start calls
_dl_sysdep_start, for which there is already a Hurd version. Can't we
just call our logic from there, and not worry about the stack layout
and overwriting return addresses?

That would work for the SHARED case; we also need to do something for
the static case. In that case, we are invoked by static-start.S; do I
understand it right that the argc/argv/whatever is still located
on-stack even on x86_64 in this case, and not passed in registers
according to the calling convention? Then again, we should be able to
just use __builtin_frame_address (0) + 2 and avoid most of the hacks?

Please tell me if this makes any sense.

Sergey

  reply	other threads:[~2023-02-20 17:10 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new () Sergey Bugaev
2023-02-19 23:32   ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 2/9] hurd: Use proper integer types Sergey Bugaev
2023-02-19 23:33   ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 3/9] hurd: Fix xattr function return type Sergey Bugaev
2023-02-19 23:34   ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 4/9] hurd: Make timer_t pointer-sized Sergey Bugaev
2023-02-19 23:35   ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 5/9] hurd: Simplify init-first.c a bit Sergey Bugaev
2023-02-19 23:45   ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 6/9] mach: Use PAGE_SIZE Sergey Bugaev
2023-02-19 23:47   ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64 Sergey Bugaev
2023-02-20  0:01   ` Samuel Thibault
2023-02-20 16:16     ` Sergey Bugaev
2023-02-20 17:10       ` Sergey Bugaev [this message]
2023-02-20 17:31         ` Samuel Thibault
2023-02-20 17:27   ` Noah Goldstein
2023-02-18 20:37 ` [RFC PATCH 8/9 gnumach] Add i386_fsgs_base_state Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 9/9] hurd, htl: Add some more x86_64-specific code Sergey Bugaev
2023-02-20  0:30   ` Samuel Thibault

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN9u=HeqxTx44oNzvmHCge9=pBohVpk0j526bYtyMVeQUZM-Tw@mail.gmail.com' \
    --to=bugaevc@gmail.com \
    --cc=bug-hurd@gnu.org \
    --cc=flaviocruz@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=samuel.thibault@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).