Re: [PATCH v3 4/6] hurd: Add expected abilist files for x86_64

2023-05-06 Thread Samuel Thibault
Sergey Bugaev, le mar. 02 mai 2023 17:10:17 +0300, a ecrit:
> As for the best way to implement this... I have always thought gnumach
> should have a bootscript directive to expose a multiboot module as a
> memobj. Then there would be a task, /hurd/ramdisk, that would expose
> it over the device (and possibly I/O) protocols:
> 
> module /boot/initrd.img $(initrd-image=vm-object-create)

So to release the content you would just close the port? That looks
interesting to me indeed.

But do we really need this intermediate translator? libstore already
has a memobj backend, so it would probably be a matter of passing
memobj:$(initrd-image=vm-object-create)

Samuel



Re: [PATCH glibc] Update hurd/hurdselect.c to be more portable.

2023-05-06 Thread Samuel Thibault
Applied, thanks!

Flavio Cruz, le sam. 06 mai 2023 16:55:10 -0400, a ecrit:
> Summary of changes:
> - Use BAD_TYPECHECK to perform type checking in a cleaner way.
>   BAD_TYPECHECK is moved into sysdeps/mach/rpc.h to avoid duplication.
> - Remove assertions for mach_msg_type_t since those won't work for
>   x86_64.
> - Update message structs to use mach_msg_type_t directly.
> - Use designated initializers.
> ---
>  hurd/hurdselect.c | 30 ++
>  hurd/intr-msg.c   |  6 +-
>  sysdeps/mach/hurd/ioctl.c |  6 +-
>  sysdeps/mach/mach_rpc.h   | 31 +++
>  4 files changed, 47 insertions(+), 26 deletions(-)
>  create mode 100644 sysdeps/mach/mach_rpc.h
> 
> diff --git a/hurd/hurdselect.c b/hurd/hurdselect.c
> index 08fcc92170..9630cae474 100644
> --- a/hurd/hurdselect.c
> +++ b/hurd/hurdselect.c
> @@ -22,6 +22,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -69,14 +70,6 @@ _hurd_select (int nfds,
>sigset_t oset;
>struct hurd_sigstate *ss = NULL;
>  
> -  union typeword /* Use this to avoid unkosher casts.  */
> -{
> -  mach_msg_type_t type;
> -  uint32_t word;
> -};
> -  assert (sizeof (union typeword) == sizeof (mach_msg_type_t));
> -  assert (sizeof (uint32_t) == sizeof (mach_msg_type_t));
> -
>if (nfds < 0 || (pollfds == NULL && nfds > FD_SETSIZE))
>  {
>errno = EINVAL;
> @@ -404,15 +397,15 @@ _hurd_select (int nfds,
> struct
>   {
> mach_msg_header_t head;
> -   union typeword err_type;
> +   mach_msg_type_t err_type;
> error_t err;
>   } error;
> struct
>   {
> mach_msg_header_t head;
> -   union typeword err_type;
> +   mach_msg_type_t err_type;
> error_t err;
> -   union typeword result_type;
> +   mach_msg_type_t result_type;
> int result;
>   } success;
>  #endif
> @@ -443,9 +436,14 @@ _hurd_select (int nfds,
>  
> /* We got a message.  Decode it.  */
>  #ifdef MACH_MSG_TYPE_BIT
> -   const union typeword inttype =
> -   { type:
> - { MACH_MSG_TYPE_INTEGER_T, sizeof (integer_t) * 8, 1, 1, 0, 0 }
> +   static const mach_msg_type_t inttype = {
> + .msgt_name = MACH_MSG_TYPE_INTEGER_T,
> + .msgt_size = sizeof (integer_t) * 8,
> + .msgt_number = 1,
> + .msgt_inline = TRUE,
> + .msgt_longform = FALSE,
> + .msgt_deallocate = FALSE,
> + .msgt_unused = 0
> };
>  #endif
>  
> @@ -462,7 +460,7 @@ _hurd_select (int nfds,
> && msg.head.msgh_size >= sizeof msg.error
> && !(msg.head.msgh_bits & MACH_MSGH_BITS_COMPLEX)
>  #ifdef MACH_MSG_TYPE_BIT
> -   && msg.error.err_type.word == inttype.word
> +   && !BAD_TYPECHECK (_type, )
>  #endif
> )
>   {
> @@ -480,7 +478,7 @@ _hurd_select (int nfds,
>occurred.  */
> if (msg.error.err
>  #ifdef MACH_MSG_TYPE_BIT
> -   || msg.success.result_type.word != inttype.word
> +   || BAD_TYPECHECK (_type, )
>  #endif
> || msg.head.msgh_size != sizeof msg.success)
>   {
> diff --git a/hurd/intr-msg.c b/hurd/intr-msg.c
> index b535397bfb..bc1f43d383 100644
> --- a/hurd/intr-msg.c
> +++ b/hurd/intr-msg.c
> @@ -17,6 +17,7 @@
> .  */
>  
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -28,11 +29,6 @@
>  # define mig_reply_header_t  mig_reply_error_t
>  #endif
>  
> -/* Macro used by MIG to cleanly check the type.  */
> -#define BAD_TYPECHECK(type, check) __glibc_unlikely (({  \
> -  union { mach_msg_type_t t; uint32_t w; } _t, _c;   \
> -  _t.t = *(type); _c.t = *(check);_t.w != _c.w; }))
> -
>  error_t
>  _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg,
>mach_msg_option_t option,
> diff --git a/sysdeps/mach/hurd/ioctl.c b/sysdeps/mach/hurd/ioctl.c
> index 66daaa751e..752cfa60f4 100644
> --- a/sysdeps/mach/hurd/ioctl.c
> +++ b/sysdeps/mach/hurd/ioctl.c
> @@ -28,6 +28,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  
>  #include 
> @@ -35,11 +36,6 @@
>  #define msg_align(x) ALIGN_UP (x, __alignof__ (uintptr_t))
>  #define typesize(type)   (1 << (type))
>  
> -/* Macro used by MIG to cleanly check the type.  */
> -#define BAD_TYPECHECK(type, check) __glibc_unlikely (({  \
> -  union { mach_msg_type_t t; uint32_t w; } _t, _c;   \
> -  _t.t = *(type); _c.t = *(check);_t.w != _c.w; }))
> -
>  /* Perform the I/O control operation specified by REQUEST on FD.
> The actual type and use of ARG and the return value depend on REQUEST.  */
>  int
> diff --git a/sysdeps/mach/mach_rpc.h b/sysdeps/mach/mach_rpc.h
> new file mode 100644
> index 00..ff1ee1cae9
> --- /dev/null
> +++ b/sysdeps/mach/mach_rpc.h
> @@ -0,0 +1,31 

[PATCH glibc] Update hurd/hurdselect.c to be more portable.

2023-05-06 Thread Flavio Cruz
Summary of changes:
- Use BAD_TYPECHECK to perform type checking in a cleaner way.
  BAD_TYPECHECK is moved into sysdeps/mach/rpc.h to avoid duplication.
- Remove assertions for mach_msg_type_t since those won't work for
  x86_64.
- Update message structs to use mach_msg_type_t directly.
- Use designated initializers.
---
 hurd/hurdselect.c | 30 ++
 hurd/intr-msg.c   |  6 +-
 sysdeps/mach/hurd/ioctl.c |  6 +-
 sysdeps/mach/mach_rpc.h   | 31 +++
 4 files changed, 47 insertions(+), 26 deletions(-)
 create mode 100644 sysdeps/mach/mach_rpc.h

diff --git a/hurd/hurdselect.c b/hurd/hurdselect.c
index 08fcc92170..9630cae474 100644
--- a/hurd/hurdselect.c
+++ b/hurd/hurdselect.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -69,14 +70,6 @@ _hurd_select (int nfds,
   sigset_t oset;
   struct hurd_sigstate *ss = NULL;
 
-  union typeword   /* Use this to avoid unkosher casts.  */
-{
-  mach_msg_type_t type;
-  uint32_t word;
-};
-  assert (sizeof (union typeword) == sizeof (mach_msg_type_t));
-  assert (sizeof (uint32_t) == sizeof (mach_msg_type_t));
-
   if (nfds < 0 || (pollfds == NULL && nfds > FD_SETSIZE))
 {
   errno = EINVAL;
@@ -404,15 +397,15 @@ _hurd_select (int nfds,
  struct
{
  mach_msg_header_t head;
- union typeword err_type;
+ mach_msg_type_t err_type;
  error_t err;
} error;
  struct
{
  mach_msg_header_t head;
- union typeword err_type;
+ mach_msg_type_t err_type;
  error_t err;
- union typeword result_type;
+ mach_msg_type_t result_type;
  int result;
} success;
 #endif
@@ -443,9 +436,14 @@ _hurd_select (int nfds,
 
  /* We got a message.  Decode it.  */
 #ifdef MACH_MSG_TYPE_BIT
- const union typeword inttype =
- { type:
-   { MACH_MSG_TYPE_INTEGER_T, sizeof (integer_t) * 8, 1, 1, 0, 0 }
+ static const mach_msg_type_t inttype = {
+   .msgt_name = MACH_MSG_TYPE_INTEGER_T,
+   .msgt_size = sizeof (integer_t) * 8,
+   .msgt_number = 1,
+   .msgt_inline = TRUE,
+   .msgt_longform = FALSE,
+   .msgt_deallocate = FALSE,
+   .msgt_unused = 0
  };
 #endif
 
@@ -462,7 +460,7 @@ _hurd_select (int nfds,
  && msg.head.msgh_size >= sizeof msg.error
  && !(msg.head.msgh_bits & MACH_MSGH_BITS_COMPLEX)
 #ifdef MACH_MSG_TYPE_BIT
- && msg.error.err_type.word == inttype.word
+ && !BAD_TYPECHECK (_type, )
 #endif
  )
{
@@ -480,7 +478,7 @@ _hurd_select (int nfds,
 occurred.  */
  if (msg.error.err
 #ifdef MACH_MSG_TYPE_BIT
- || msg.success.result_type.word != inttype.word
+ || BAD_TYPECHECK (_type, )
 #endif
  || msg.head.msgh_size != sizeof msg.success)
{
diff --git a/hurd/intr-msg.c b/hurd/intr-msg.c
index b535397bfb..bc1f43d383 100644
--- a/hurd/intr-msg.c
+++ b/hurd/intr-msg.c
@@ -17,6 +17,7 @@
.  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -28,11 +29,6 @@
 # define mig_reply_header_tmig_reply_error_t
 #endif
 
-/* Macro used by MIG to cleanly check the type.  */
-#define BAD_TYPECHECK(type, check) __glibc_unlikely (({\
-  union { mach_msg_type_t t; uint32_t w; } _t, _c; \
-  _t.t = *(type); _c.t = *(check);_t.w != _c.w; }))
-
 error_t
 _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg,
 mach_msg_option_t option,
diff --git a/sysdeps/mach/hurd/ioctl.c b/sysdeps/mach/hurd/ioctl.c
index 66daaa751e..752cfa60f4 100644
--- a/sysdeps/mach/hurd/ioctl.c
+++ b/sysdeps/mach/hurd/ioctl.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -35,11 +36,6 @@
 #define msg_align(x) ALIGN_UP (x, __alignof__ (uintptr_t))
 #define typesize(type) (1 << (type))
 
-/* Macro used by MIG to cleanly check the type.  */
-#define BAD_TYPECHECK(type, check) __glibc_unlikely (({\
-  union { mach_msg_type_t t; uint32_t w; } _t, _c; \
-  _t.t = *(type); _c.t = *(check);_t.w != _c.w; }))
-
 /* Perform the I/O control operation specified by REQUEST on FD.
The actual type and use of ARG and the return value depend on REQUEST.  */
 int
diff --git a/sysdeps/mach/mach_rpc.h b/sysdeps/mach/mach_rpc.h
new file mode 100644
index 00..ff1ee1cae9
--- /dev/null
+++ b/sysdeps/mach/mach_rpc.h
@@ -0,0 +1,31 @@
+/* Macros for handling Mach RPC messages.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   

Re: [PATCH v3 4/6] hurd: Add expected abilist files for x86_64

2023-05-06 Thread Samuel Thibault
Samuel Thibault, le sam. 06 mai 2023 17:20:03 +0200, a ecrit:
> Samuel Thibault, le ven. 05 mai 2023 19:23:57 +0200, a ecrit:
> > Samuel Thibault, le ven. 05 mai 2023 17:30:11 +0200, a ecrit:
> > > Sergey Bugaev, le ven. 05 mai 2023 18:15:00 +0300, a ecrit:
> > > > On Fri, May 5, 2023 at 4:30 PM Samuel Thibault 
> > > >  wrote:
> > > > > FI, I'm having debian hurd-amd64 packages cross-built, I'm getting 
> > > > > e.g.
> > > > > dash built, I'll probably have rumpkernel built too. Essentially, we
> > > > > should be able to debootstrap a whole chroot.
> > > > 
> > > > Awesome!
> > > > 
> > > > Are these (binaries? debs?) available for download somewhere?
> > > 
> > > When I'll get them I'll make a repo, yes, but hopefully hurd-amd64 will
> > > get opened on debian-ports soon so I can just put them there.
> > 
> > I have put what I already have on
> > https://people.debian.org/~sthibault/tmp/hurd-amd64/
> 
> coreutils is in :)

rumpkernel is in!

Samuel



Re: [PATCH glibc] Update hurd/hurdselect.c to be more portable.

2023-05-06 Thread Samuel Thibault
Flavio Cruz, le ven. 05 mai 2023 00:20:39 -0400, a ecrit:
> +  /* TODO: add this assertion for x86_64.  */
> +#ifndef __x86_64__
> +  _Static_assert (sizeof (uint32_t) == sizeof (mach_msg_type_t),
> +  "mach_msg_type_t needs to be the same size as uint32_t");
> +#endif

Now that it is static, rather move it to

> +++ b/sysdeps/mach/mach_rpc.h
> +
> +/* Macro used by MIG to cleanly check the type.  */
> +#define BAD_TYPECHECK(type, check) __glibc_unlikely (({  \
> +  union { mach_msg_type_t t; uint32_t w; } _t, _c;   \
> +  _t.t = *(type); _c.t = *(check);_t.w != _c.w; }))

so it is tied to what it matters for?



Re: [PATCH hurd] Update eth-multiplexer/vdev.c to be more portable

2023-05-06 Thread Samuel Thibault
Applied, thanks!

Flavio Cruz, le ven. 05 mai 2023 00:43:36 -0400, a ecrit:
> * Perform the correct alignment for x86_64.
> * Use designated initializers.
> ---
>  eth-multiplexer/vdev.c | 39 ++-
>  1 file changed, 22 insertions(+), 17 deletions(-)
> 
> diff --git a/eth-multiplexer/vdev.c b/eth-multiplexer/vdev.c
> index 548af9d2..f441803d 100644
> --- a/eth-multiplexer/vdev.c
> +++ b/eth-multiplexer/vdev.c
> @@ -46,25 +46,29 @@ static int dev_num;
>   * TODO every device structure should has its own lock to protect itself. */
>  static pthread_mutex_t dev_list_lock = PTHREAD_MUTEX_INITIALIZER;
>  
> -mach_msg_type_t header_type =
> +/* Should match MiG's desired_complex_alignof */
> +#define MSG_ALIGNMENT __alignof__(uintptr_t)
> +
> +static const mach_msg_type_t header_type =
>  {
> -  MACH_MSG_TYPE_BYTE,
> -  8,
> -  NET_HDW_HDR_MAX,
> -  TRUE,
> -  FALSE,
> -  FALSE,
> -  0
> +  .msgt_name = MACH_MSG_TYPE_BYTE,
> +  .msgt_size = 8,
> +  .msgt_number = NET_HDW_HDR_MAX,
> +  .msgt_inline = TRUE,
> +  .msgt_longform = FALSE,
> +  .msgt_deallocate = FALSE,
> +  .msgt_unused = 0
>  };
>  
> -mach_msg_type_t packet_type =
> +static const mach_msg_type_t packet_type =
>  {
> -  MACH_MSG_TYPE_BYTE,/* name */
> -  8, /* size */
> -  0, /* number */
> -  TRUE,  /* inline */
> -  FALSE, /* longform */
> -  FALSE  /* deallocate */
> +  .msgt_name = MACH_MSG_TYPE_BYTE,
> +  .msgt_size = 8,
> +  .msgt_number = 0,
> +  .msgt_inline = TRUE,
> +  .msgt_longform = FALSE,
> +  .msgt_deallocate = FALSE,
> +  .msgt_unused = 0
>  };
>  
>  int
> @@ -208,8 +212,9 @@ broadcast_pack (char *data, int datalen, struct 
> vether_device *from_vdev)
>  
>pack_size = datalen - sizeof (struct ethhdr);
>/* remember message sizes must be rounded up */
> -  msg.msg_hdr.msgh_size = (((mach_msg_size_t) (sizeof(struct net_rcv_msg)
> -- NET_RCV_MAX + pack_size)) + 3) 
> & ~3;
> +  msg.msg_hdr.msgh_size = sizeof (struct net_rcv_msg) - NET_RCV_MAX + 
> pack_size;
> +  msg.msg_hdr.msgh_size = (mach_msg_size_t) ((msg.msg_hdr.msgh_size +
> +  MSG_ALIGNMENT - 1) & ~(MSG_ALIGNMENT - 1));
>  
>header = (struct ethhdr *) msg.header;
>packet = (struct packet_header *) msg.packet;
> -- 
> 2.39.2
> 
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



Re: [PATCH gnumach] Delete include/mach/rpc.h

2023-05-06 Thread Samuel Thibault
Applied, thanks!

Flavio Cruz, le ven. 05 mai 2023 01:21:48 -0400, a ecrit:
> File is unused.
> ---
>  Makefrag.am|  1 -
>  include/mach/rpc.h | 34 --
>  ipc/ipc_port.h |  1 -
>  ipc/ipc_target.h   |  1 -
>  ipc/mach_port.c|  1 -
>  5 files changed, 38 deletions(-)
>  delete mode 100644 include/mach/rpc.h
> 
> diff --git a/Makefrag.am b/Makefrag.am
> index 50389ad7..5b61a1d6 100644
> --- a/Makefrag.am
> +++ b/Makefrag.am
> @@ -403,7 +403,6 @@ include_mach_HEADERS = \
>   include/mach/processor_info.h \
>   include/mach/profil.h \
>   include/mach/profilparam.h \
> - include/mach/rpc.h \
>   include/mach/std_types.h \
>   include/mach/syscall_sw.h \
>   include/mach/task_info.h \
> diff --git a/include/mach/rpc.h b/include/mach/rpc.h
> deleted file mode 100644
> index 36eb5921..
> --- a/include/mach/rpc.h
> +++ /dev/null
> @@ -1,34 +0,0 @@
> -/*
> - * Copyright (c) 1993,1994 The University of Utah and
> - * the Computer Systems Laboratory (CSL).  All rights reserved.
> - *
> - * Permission to use, copy, modify and distribute this software and its
> - * documentation is hereby granted, provided that both the copyright
> - * notice and this permission notice appear in all copies of the
> - * software, derivative works or modified versions, and any portions
> - * thereof, and that both notices appear in supporting documentation.
> - *
> - * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
> - * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
> - * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS 
> SOFTWARE.
> - *
> - * CSL requests users of this software to return to csl-d...@cs.utah.edu any
> - * improvements that they make and grant CSL redistribution rights.
> - */
> -
> -#ifndef MACH_RPC_H
> -#define MACH_RPC_H
> -
> -#include 
> -#include 
> -
> -/*
> - * Description of a port passed up by the leaky-register RPC path
> - * when it needs to perform translation.
> - */
> -struct rpc_port_desc {
> - mach_port_t name;
> - mach_msg_type_name_t msgt_name;
> -};
> -
> -#endif   /* MACH_RPC_H */
> diff --git a/ipc/ipc_port.h b/ipc/ipc_port.h
> index 022921f7..192d8806 100644
> --- a/ipc/ipc_port.h
> +++ b/ipc/ipc_port.h
> @@ -50,7 +50,6 @@
>  #include 
>  #include 
>  #include "ipc_target.h"
> -#include 
>  
>  /*
>   *  A receive right (port) can be in four states:
> diff --git a/ipc/ipc_target.h b/ipc/ipc_target.h
> index 86a0e44b..c2cc9241 100644
> --- a/ipc/ipc_target.h
> +++ b/ipc/ipc_target.h
> @@ -27,7 +27,6 @@
>  
>  #include "ipc_mqueue.h"
>  #include "ipc_object.h"
> -#include 
>  
>  typedef struct ipc_target {
>  
> diff --git a/ipc/mach_port.c b/ipc/mach_port.c
> index b35d8bcf..db6dae61 100644
> --- a/ipc/mach_port.c
> +++ b/ipc/mach_port.c
> @@ -45,7 +45,6 @@
>  #include 
>  #include 
>  #ifdef MIGRATING_THREADS
> -#include 
>  #include 
>  #include 
>  #endif /* MIGRATING_THREADS */
> -- 
> 2.39.2
> 
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



Re: [PATCH v3 4/6] hurd: Add expected abilist files for x86_64

2023-05-06 Thread Samuel Thibault
Samuel Thibault, le ven. 05 mai 2023 19:23:57 +0200, a ecrit:
> Samuel Thibault, le ven. 05 mai 2023 17:30:11 +0200, a ecrit:
> > Sergey Bugaev, le ven. 05 mai 2023 18:15:00 +0300, a ecrit:
> > > On Fri, May 5, 2023 at 4:30 PM Samuel Thibault  
> > > wrote:
> > > > FI, I'm having debian hurd-amd64 packages cross-built, I'm getting e.g.
> > > > dash built, I'll probably have rumpkernel built too. Essentially, we
> > > > should be able to debootstrap a whole chroot.
> > > 
> > > Awesome!
> > > 
> > > Are these (binaries? debs?) available for download somewhere?
> > 
> > When I'll get them I'll make a repo, yes, but hopefully hurd-amd64 will
> > get opened on debian-ports soon so I can just put them there.
> 
> I have put what I already have on
> https://people.debian.org/~sthibault/tmp/hurd-amd64/

coreutils is in :)

Samuel



[PATCH] Add hurd-amd64 support

2023-05-06 Thread Samuel Thibault
This adds SIGSEGV_FAULT_STACKPOINTER for the hurd-amd64 case

--- ./lib/sigsegv.c.original2023-05-05 10:45:54.673751100 +
+++ ./lib/sigsegv.c 2023-05-05 10:48:47.903577554 +
@@ -351,6 +351,17 @@
"old esp, if trapped from user".  */
 #  define SIGSEGV_FAULT_STACKPOINTER  scp->sc_uesp
 
+# elif defined __x86_64__
+
+/* scp points to a 'struct sigcontext' (defined in
+   glibc/sysdeps/mach/hurd/x86_64/bits/sigcontext.h).
+   The registers of this struct get pushed on the stack through
+   gnumach/x86_64/i386/locore.S:trapall.  */
+/* Both sc_rsp and sc_ursp appear to have the same value.
+   It appears more reliable to use sc_ursp because it is labelled as
+   "old rsp, if trapped from user".  */
+#  define SIGSEGV_FAULT_STACKPOINTER  scp->sc_ursp
+
 # endif
 
 #endif



[PATCH] hurd-amd64 support

2023-05-06 Thread Samuel Thibault
This adds support for passing -m elf32_x86_64 vs -m elf_x86_64 to the
linker on hurd-amd64

Changelog:

* m4/libtool.m4: dd x86_64-gnu* case to pass -m elf32_x86_64 vs
-m elf_x86_64 to linker.

--- m4/libtool.m4.orig  2023-05-03 18:33:23.949698403 +0200
+++ m4/libtool.m4   2023-05-03 18:35:30.760510012 +0200
@@ -1367,7 +1367,7 @@
   ;;
 
 x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \
-s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*|x86_64-gnu*)
   # Find out what ABI is being produced by ac_compile, and set linker
   # options accordingly.  Note that the listed cases only cover the
   # situations where additional linker options are needed (such as when
@@ -1382,7 +1382,7 @@
  x86_64-*kfreebsd*-gnu)
LD="${LD-ld} -m elf_i386_fbsd"
;;
- x86_64-*linux*)
+ x86_64-*linux*|x86_64-gnu*)
case `$FILECMD conftest.o` in
  *x86-64*)
LD="${LD-ld} -m elf32_x86_64"
@@ -1411,7 +1411,7 @@
  x86_64-*kfreebsd*-gnu)
LD="${LD-ld} -m elf_x86_64_fbsd"
;;
- x86_64-*linux*)
+ x86_64-*linux*|x86_64-gnu*)
LD="${LD-ld} -m elf_x86_64"
;;
  powerpcle-*linux*)



[PATCH libgpg-error] hurd-amd64 support

2023-05-06 Thread Samuel Thibault
This supports the x86_64-pc-gnu triplet

Signed-off-by: Samuel Thibault 
---

Index: libgpg-error-1.46/src/Makefile.am
===
--- libgpg-error-1.46.orig/src/Makefile.am
+++ libgpg-error-1.46/src/Makefile.am
@@ -67,6 +67,7 @@ lock_obj_pub = \
 syscfg/lock-obj-pub.sparc-unknown-linux-gnu.h   \
 syscfg/lock-obj-pub.sparc64-unknown-linux-gnu.h \
syscfg/lock-obj-pub.x86_64-apple-darwin.h   \
+syscfg/lock-obj-pub.x86_64-unknown-gnu.h  \
 syscfg/lock-obj-pub.x86_64-unknown-kfreebsd-gnu.h   \
 syscfg/lock-obj-pub.x86_64-unknown-linux-gnu.h  \
 syscfg/lock-obj-pub.x86_64-unknown-linux-gnux32.h   \
Index: libgpg-error-1.46/src/mkheader.c
===
--- libgpg-error-1.46.orig/src/mkheader.c
+++ libgpg-error-1.46/src/mkheader.c
@@ -108,6 +108,8 @@ canon_host_triplet (const char *triplet,
 {"x86_64-pc-linux-gnuhardened1", "x86_64-unknown-linux-gnu" },
 {"x86_64-pc-linux-gnu" },
 
+{"x86_64-pc-gnu"},
+
 {"powerpc-unknown-linux-gnuspe", "powerpc-unknown-linux-gnu" },
 
 {"arm-unknown-linux-gnueabihf",  "arm-unknown-linux-gnueabi" },
Index: libgpg-error-1.46/src/syscfg/lock-obj-pub.x86_64-unknown-gnu.h
===
--- /dev/null
+++ libgpg-error-1.46/src/syscfg/lock-obj-pub.x86_64-unknown-gnu.h
@@ -0,0 +1,24 @@
+## lock-obj-pub.x86_64-pc-gnu.h
+## File created by gen-posix-lock-obj - DO NOT EDIT
+## To be included by mkheader into gpg-error.h
+
+typedef struct
+{
+  long _vers;
+  union {
+volatile char _priv[32];
+long _x_align;
+long *_xp_align;
+  } u;
+} gpgrt_lock_t;
+
+#define GPGRT_LOCK_INITIALIZER {1,{{0,0,0,0,0,0,0,0, \
+0,0,0,0,0,0,0,0, \
+0,0,0,0,0,0,0,0, \
+0,0,0,0,0,0,0,0}}}
+##
+## Local Variables:
+## mode: c
+## buffer-read-only: t
+## End:
+##
Index: libgpg-error-1.46/src/Makefile.am
===
--- libgpg-error-1.46.orig/src/Makefile.am
+++ libgpg-error-1.46/src/Makefile.am
@@ -67,6 +67,7 @@ lock_obj_pub = \
 syscfg/lock-obj-pub.sparc-unknown-linux-gnu.h   \
 syscfg/lock-obj-pub.sparc64-unknown-linux-gnu.h \
syscfg/lock-obj-pub.x86_64-apple-darwin.h   \
+syscfg/lock-obj-pub.x86_64-unknown-gnu.h  \
 syscfg/lock-obj-pub.x86_64-unknown-kfreebsd-gnu.h   \
 syscfg/lock-obj-pub.x86_64-unknown-linux-gnu.h  \
 syscfg/lock-obj-pub.x86_64-unknown-linux-gnux32.h   \
Index: libgpg-error-1.46/src/mkheader.c
===
--- libgpg-error-1.46.orig/src/mkheader.c
+++ libgpg-error-1.46/src/mkheader.c
@@ -108,6 +108,8 @@ canon_host_triplet (const char *triplet,
 {"x86_64-pc-linux-gnuhardened1", "x86_64-unknown-linux-gnu" },
 {"x86_64-pc-linux-gnu" },
 
+{"x86_64-pc-gnu"},
+
 {"powerpc-unknown-linux-gnuspe", "powerpc-unknown-linux-gnu" },
 
 {"arm-unknown-linux-gnueabihf",  "arm-unknown-linux-gnueabi" },
Index: libgpg-error-1.46/src/syscfg/lock-obj-pub.x86_64-unknown-gnu.h
===
--- /dev/null
+++ libgpg-error-1.46/src/syscfg/lock-obj-pub.x86_64-unknown-gnu.h
@@ -0,0 +1,24 @@
+## lock-obj-pub.x86_64-pc-gnu.h
+## File created by gen-posix-lock-obj - DO NOT EDIT
+## To be included by mkheader into gpg-error.h
+
+typedef struct
+{
+  long _vers;
+  union {
+volatile char _priv[32];
+long _x_align;
+long *_xp_align;
+  } u;
+} gpgrt_lock_t;
+
+#define GPGRT_LOCK_INITIALIZER {1,{{0,0,0,0,0,0,0,0, \
+0,0,0,0,0,0,0,0, \
+0,0,0,0,0,0,0,0, \
+0,0,0,0,0,0,0,0}}}
+##
+## Local Variables:
+## mode: c
+## buffer-read-only: t
+## End:
+##


Re: [PATCH] hurd: Add multilib paths for gnu-x86_64

2023-05-06 Thread Samuel Thibault
(and it'd be useful to have it backported to the 13 branch)

Samuel Thibault, le sam. 06 mai 2023 13:50:36 +0200, a ecrit:
> We need the multilib paths in gcc to find e.g. glibc crt files on
> Debian.  This is essentially based on t-linux64 version.
> 
> gcc/ChangeLog:
> 
>   * gcc/config/i386/t-gnu64: New file.
>   * gcc/config.gcc [x86_64-*-gnu*): Add i386/t-gnu64 to
>   tmake_file.
> 
> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index 671c7e3b018..6b1939b9f09 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -5828,6 +5828,9 @@ case ${target} in
>   visium-*-*)
>   target_cpu_default2="TARGET_CPU_$with_cpu"
>   ;;
> + x86_64-*-gnu*)
> + tmake_file="$tmake_file i386/t-gnu64"
> + ;;
>  esac
>  
>  t=
> diff --git a/gcc/config/i386/t-gnu64 b/gcc/config/i386/t-gnu64
> index e69de29bb2d..23ee6823d65 100644
> --- a/gcc/config/i386/t-gnu64
> +++ b/gcc/config/i386/t-gnu64
> @@ -0,0 +1,38 @@
> +# Copyright (C) 2002-2023 Free Software Foundation, Inc.
> +#
> +# This file is part of GCC.
> +#
> +# GCC is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3, or (at your option)
> +# any later version.
> +#
> +# GCC is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with GCC; see the file COPYING3.  If not see
> +# .
> +
> +# On Debian, Ubuntu and other derivative distributions, the 32bit libraries
> +# are found in /lib32 and /usr/lib32, /lib64 and /usr/lib64 are symlinks to
> +# /lib and /usr/lib, while other distributions install libraries into /lib64
> +# and /usr/lib64.  The LSB does not enforce the use of /lib64 and /usr/lib64,
> +# it doesn't tell anything about the 32bit libraries on those systems.  Set
> +# MULTILIB_OSDIRNAMES according to what is found on the target.
> +
> +# To support i386, x86-64 and x32 libraries, the directory structrue
> +# should be:
> +#
> +#/lib has i386 libraries.
> +#/lib64 has x86-64 libraries.
> +#/libx32 has x32 libraries.
> +#
> +comma=,
> +MULTILIB_OPTIONS= $(subst $(comma),/,$(TM_MULTILIB_CONFIG))
> +MULTILIB_DIRNAMES   = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
> +MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-gnu)
> +MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo 
> $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call 
> if_multiarch,:i386-gnu)
> +MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x86_64-gnux32)

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



Re: [PATCH 5/5] add setting gs/fsbase

2023-05-06 Thread Sergey Bugaev
On Sat, May 6, 2023 at 1:12 PM Sergey Bugaev  wrote:
> This is ld.so in the exec server task trying to dir_lookup
> ("/hurd/exec") -- it then crashes ext2fs when it tries to access the
> TCB. But before that, ext2fs starts up, spawns all those
> libports/libpager worker threads (which now start up correctly),
> resumes exec, and ld.so begins starting up, which means the SHARED /
> IS_IN (rtld) build is not super broken either \o/

I now have exec server loading and initializing and binding all the
shared libraries, then starting all the way to main (), then
trivfs_startup (), successfully handshaking with ext2fs!

Then something goes wrong; I have not yet investigated, but it's
probably because ext2fs expects to find /hurd/startup next, and I
haven't put that into my ramdisk.

Anyway, I declare this a huge success :) I'll send the glibc fixes
some time soon, and I should keep working on the Hurd patches,
hopefully there isn't too much work left, then we can upstream it, and
then test with something that resembles a more complete Debian
installation.

Sergey



[PATCH] hurd: Ad default-pie and static-pie support

2023-05-06 Thread Samuel Thibault
This fixes the Hurd spec in the default-pie case, and adds static-pie
support.

gcc/ChangeLog:

* gcc/config/i386/gnu.h: Use PIE_SPEC, add static-pie case.
* gcc/config/i386/gnu64.h: Use PIE_SPEC, add static-pie case.

diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h
index 8dc6d9ee4e3..e776144f96c 100644
--- a/gcc/config/i386/gnu.h
+++ b/gcc/config/i386/gnu.h
@@ -27,12 +27,12 @@ along with GCC.  If not, see .
 #undef STARTFILE_SPEC
 #if defined HAVE_LD_PIE
 #define STARTFILE_SPEC \
-  "%{!shared: 
%{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};pie:Scrt1.o%s;static:crt0.o%s;:crt1.o%s}}
 \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
+  "%{!shared: 
%{pg|p|profile:%{static-pie:grcrt0.o%s;static:gcrt0.o%s;:gcrt1.o%s};static-pie:rcrt0.o%s;static:crt0.o%s;"
 PIE_SPEC ":Scrt1.o%s;:crt1.o%s}} \
+   crti.o%s %{static:crtbeginT.o%s;shared|static-pie|" PIE_SPEC 
":crtbeginS.o%s;:crtbegin.o%s}"
 #else
 #define STARTFILE_SPEC \
   "%{!shared: 
%{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};static:crt0.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
+   crti.o%s %{static:crtbeginT.o%s;shared:crtbeginS.o%s;:crtbegin.o%s}"
 #endif
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
diff --git a/gcc/config/i386/gnu64.h b/gcc/config/i386/gnu64.h
index a411f0e802a..332372fa067 100644
--- a/gcc/config/i386/gnu64.h
+++ b/gcc/config/i386/gnu64.h
@@ -31,10 +31,10 @@ along with GCC.  If not, see .
 #undef STARTFILE_SPEC
 #if defined HAVE_LD_PIE
 #define STARTFILE_SPEC \
-  "%{!shared: 
%{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};pie:Scrt1.o%s;static:crt0.o%s;:crt1.o%s}}
 \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
+  "%{!shared: 
%{pg|p|profile:%{static-pie:grcrt0.o%s;static:gcrt0.o%s;:gcrt1.o%s};static-pie:rcrt0.o%s;static:crt0.o%s;"
 PIE_SPEC ":Scrt1.o%s;:crt1.o%s}} \
+   crti.o%s %{static:crtbeginT.o%s;shared|static-pie|" PIE_SPEC 
":crtbeginS.o%s;:crtbegin.o%s}"
 #else
 #define STARTFILE_SPEC \
   "%{!shared: 
%{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};static:crt0.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
+   crti.o%s %{static:crtbeginT.o%s;shared|static-pie|" PIE_SPEC 
":crtbeginS.o%s;:crtbegin.o%s}"
 #endif



[PATCH] hurd: Add multilib paths for gnu-x86_64

2023-05-06 Thread Samuel Thibault
We need the multilib paths in gcc to find e.g. glibc crt files on
Debian.  This is essentially based on t-linux64 version.

gcc/ChangeLog:

* gcc/config/i386/t-gnu64: New file.
* gcc/config.gcc [x86_64-*-gnu*): Add i386/t-gnu64 to
tmake_file.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 671c7e3b018..6b1939b9f09 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5828,6 +5828,9 @@ case ${target} in
visium-*-*)
target_cpu_default2="TARGET_CPU_$with_cpu"
;;
+   x86_64-*-gnu*)
+   tmake_file="$tmake_file i386/t-gnu64"
+   ;;
 esac
 
 t=
diff --git a/gcc/config/i386/t-gnu64 b/gcc/config/i386/t-gnu64
index e69de29bb2d..23ee6823d65 100644
--- a/gcc/config/i386/t-gnu64
+++ b/gcc/config/i386/t-gnu64
@@ -0,0 +1,38 @@
+# Copyright (C) 2002-2023 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# On Debian, Ubuntu and other derivative distributions, the 32bit libraries
+# are found in /lib32 and /usr/lib32, /lib64 and /usr/lib64 are symlinks to
+# /lib and /usr/lib, while other distributions install libraries into /lib64
+# and /usr/lib64.  The LSB does not enforce the use of /lib64 and /usr/lib64,
+# it doesn't tell anything about the 32bit libraries on those systems.  Set
+# MULTILIB_OSDIRNAMES according to what is found on the target.
+
+# To support i386, x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+#  /lib has i386 libraries.
+#  /lib64 has x86-64 libraries.
+#  /libx32 has x32 libraries.
+#
+comma=,
+MULTILIB_OPTIONS= $(subst $(comma),/,$(TM_MULTILIB_CONFIG))
+MULTILIB_DIRNAMES   = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
+MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-gnu)
+MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo 
$(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call 
if_multiarch,:i386-gnu)
+MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x86_64-gnux32)



Re: [PATCH 5/5] add setting gs/fsbase

2023-05-06 Thread Sergey Bugaev
Hello,

On Tue, Apr 25, 2023 at 1:59 PM Samuel Thibault  wrote:
> Sergey Bugaev, le mar. 25 avril 2023 13:25:02 +0300, a ecrit:
> > @@ -733,6 +734,10 @@ boolean_t thread_invoke(
> >
> > counter(c_thread_invoke_hits++);
> > (void) spl0();
> > +#ifdef __x86_64__
> > +   wrmsr(MSR_REG_FSBASE, new_thread->pcb->iss.fsbase);
> > +   wrmsr(MSR_REG_GSBASE, new_thread->pcb->iss.gsbase);
> > +#endif
>
> I guess it could belong to switch_ktss?

I'm now hitting this same issue with the fast RPC codepath:

#0  stack_handoff (old=old@entry=0x90ecd828,
new=new@entry=0x90ecd620) at ../i386/i386/pcb.c:301
#1  0x8104f6c4 in thread_handoff
(old=old@entry=0x90ecd828,
continuation=continuation@entry=0x81046f30
,
new=new@entry=0x90ecd620) at ../kern/ipc_sched.c:239
#2  0x810485b4 in mach_msg_trap (msg=0xbfffeca0,
option=, send_size=1096, rcv_size=,
rcv_name=3, time_out=,
notify=) at ../ipc/mach_msg.c:830
#3  0x81011eb2 in syscall64 () at ../x86_64/locore.S:1430

This is ld.so in the exec server task trying to dir_lookup
("/hurd/exec") -- it then crashes ext2fs when it tries to access the
TCB. But before that, ext2fs starts up, spawns all those
libports/libpager worker threads (which now start up correctly),
resumes exec, and ld.so begins starting up, which means the SHARED /
IS_IN (rtld) build is not super broken either \o/

Indeed it looks like switch_ktss is a better place for setting
fsgs_base, I'm going to try that next.

Sergey



Re: Prospectives (Was: hurd: Add expected abilist files for x86_64)

2023-05-06 Thread Samuel Thibault
Svante Signell, le sam. 06 mai 2023 10:59:06 +0200, a ecrit:
> On Wed, 2023-05-03 at 19:56 +0200, Samuel Thibault wrote:
> > Samuel Thibault, le mer. 03 mai 2023 13:09:25 +0200, a ecrit:
> > > Sergey Bugaev, le mer. 03 mai 2023 13:26:56 +0300, a ecrit:
> > > > > To put another perspective: I have been doing that less funny part 
> > > > > for a
> > > > > long time already. I can't do everything alone.
> > > > 
> > > > I appreciate that! -- and I'm sure everyone else does. Are there any
> > > > other tasks that are not fun to you that we could help you with?
> > > 
> > > E.g. fixing the remaining git and vim testsuite bugs.
> > 
> > And more generally fix the build of the top of 
> > 
> > https://people.debian.org/~sthibault/graph-total-top.txt
> > 
> > Some of these are mostly hopeless (java), others should really be fixed
> > (perl, help2man, mesa, pam, util-linux, etc.). I'm currently hitting the
> > pam issue to be able to bootstrap hurd-amd64, for instance.
> 
> Did you see the Debian pam Bug#1029097?

No, it didn't reach the debian-hurd list. X-Debbugs-CC: needs to be in
the mail headers, not in the bts pseudo-headers.

Samuel



Re: Prospectives (Was: hurd: Add expected abilist files for x86_64)

2023-05-06 Thread Svante Signell
On Wed, 2023-05-03 at 19:56 +0200, Samuel Thibault wrote:
> Samuel Thibault, le mer. 03 mai 2023 13:09:25 +0200, a ecrit:
> > Sergey Bugaev, le mer. 03 mai 2023 13:26:56 +0300, a ecrit:
> > > > To put another perspective: I have been doing that less funny part for a
> > > > long time already. I can't do everything alone.
> > > 
> > > I appreciate that! -- and I'm sure everyone else does. Are there any
> > > other tasks that are not fun to you that we could help you with?
> > 
> > E.g. fixing the remaining git and vim testsuite bugs.
> 
> And more generally fix the build of the top of 
> 
> https://people.debian.org/~sthibault/graph-total-top.txt
> 
> Some of these are mostly hopeless (java), others should really be fixed
> (perl, help2man, mesa, pam, util-linux, etc.). I'm currently hitting the
> pam issue to be able to bootstrap hurd-amd64, for instance.

Did you see the Debian pam Bug#1029097?