On Mon, Apr 3, 2023 at 3:10 AM Sergey Bugaev <buga...@gmail.com> wrote:
>
> On Mon, Apr 3, 2023 at 2:09 AM Samuel Thibault <samuel.thiba...@gnu.org> 
> wrote:
> > Sergey Bugaev, le dim. 19 mars 2023 18:09:56 +0300, a ecrit:
> > > While we could/should implement MAP_32BIT for the Hurd port by setting
> > > all the high bits of mask in a vm_map () call, neither MAP_32BIT nor
> > > glibc.cpu.prefer_map_32bit_exec exist on the Hurd as of now. Compile
> > > this code out to fix build failures.
> >
> > Rather use defined(MAP_32BIT)? That way it will nicely work for BSD
> > ports as well, and when hurd eventually supports MAP_32BIT.
>
> Not really. What breaks compilation here is not missing MAP_32BIT, but
> rather the undefined set_prefer_map_32bit_exec tunable. It is defined
> declaratively in sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list
> (see commit 317f1c0a8a71a862b1e600ff5386b08e02cf4b95); so as-is, it
> really is x86_64 Linux specific.
>
> Is there some way to check if a specific tunable is defined, like #if
> HAVE_TUNABLE (prefer_map_32bit_exec)? AFAICS the generated
> dl-tunable-list.h defines the C enum members, but not any checkable
> preprocessor macros.
>
> Alternatively: maybe this part of cpu-features.c should be moved into
> sysdeps/unix/sysv/linux/x86_64/64/cpu-features.c and #include_next the
> common cpu-features.c?
>

Or something like this.

-- 
H.J.
From 24090a219d8bf902db530bfd9bd73e837f13c435 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.to...@gmail.com>
Date: Mon, 3 Apr 2023 11:54:30 -0700
Subject: [PATCH] x86-64: Make glibc.cpu.prefer_map_32bit_exec Linux specific

Add <map-32bit-exec.h> to make glibc.cpu.prefer_map_32bit_exec Linux
specific.
---
 .../sysv/linux/x86_64/64/map-32bit-exec.h     | 29 +++++++++++++++++++
 sysdeps/x86/cpu-features.c                    | 16 ++--------
 sysdeps/x86/map-32bit-exec.h                  | 19 ++++++++++++
 3 files changed, 50 insertions(+), 14 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/64/map-32bit-exec.h
 create mode 100644 sysdeps/x86/map-32bit-exec.h

diff --git a/sysdeps/unix/sysv/linux/x86_64/64/map-32bit-exec.h b/sysdeps/unix/sysv/linux/x86_64/64/map-32bit-exec.h
new file mode 100644
index 0000000000..74763853e1
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/64/map-32bit-exec.h
@@ -0,0 +1,29 @@
+/* Handle glibc.cpu.prefer_map_32bit_exec.  Linux/x86-64 version.
+   This file is part of the GNU C Library.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+static void
+TUNABLE_CALLBACK (set_prefer_map_32bit_exec) (tunable_val_t *valp)
+{
+  if (valp->numval)
+    GLRO(dl_x86_cpu_features).preferred[index_arch_Prefer_MAP_32BIT_EXEC]
+      |= bit_arch_Prefer_MAP_32BIT_EXEC;
+}
+
+#define TUNABLE_GET_prefer_map_32bit_exec() \
+  TUNABLE_GET (prefer_map_32bit_exec, tunable_val_t *, \
+	       TUNABLE_CALLBACK (set_prefer_map_32bit_exec));
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index 978eb29f72..75a011dab7 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -22,20 +22,11 @@
 #include <cacheinfo.h>
 #include <dl-cacheinfo.h>
 #include <dl-minsigstacksize.h>
+#include <map-32bit-exec.h>
 
 extern void TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *)
   attribute_hidden;
 
-#ifdef __LP64__
-static void
-TUNABLE_CALLBACK (set_prefer_map_32bit_exec) (tunable_val_t *valp)
-{
-  if (valp->numval)
-    GLRO(dl_x86_cpu_features).preferred[index_arch_Prefer_MAP_32BIT_EXEC]
-      |= bit_arch_Prefer_MAP_32BIT_EXEC;
-}
-#endif
-
 #if CET_ENABLED
 extern void TUNABLE_CALLBACK (set_x86_ibt) (tunable_val_t *)
   attribute_hidden;
@@ -710,10 +701,7 @@ no_cpuid:
 
   TUNABLE_GET (hwcaps, tunable_val_t *, TUNABLE_CALLBACK (set_hwcaps));
 
-#ifdef __LP64__
-  TUNABLE_GET (prefer_map_32bit_exec, tunable_val_t *,
-	       TUNABLE_CALLBACK (set_prefer_map_32bit_exec));
-#endif
+  TUNABLE_GET_prefer_map_32bit_exec ();
 
   bool disable_xsave_features = false;
 
diff --git a/sysdeps/x86/map-32bit-exec.h b/sysdeps/x86/map-32bit-exec.h
new file mode 100644
index 0000000000..9771338df3
--- /dev/null
+++ b/sysdeps/x86/map-32bit-exec.h
@@ -0,0 +1,19 @@
+/* Handle glibc.cpu.prefer_map_32bit_exec.  Generic x86 version.
+   This file is part of the GNU C Library.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define TUNABLE_GET_prefer_map_32bit_exec()
-- 
2.39.2

Reply via email to