From 035fc2d9c2fa6f5ff71c94e10045f62b0716b12d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Wed, 21 Dec 2022 13:42:05 +0000 Subject: [PATCH] setarch: use kernel address size if possible If setarch is running as 32bit userspace on a 64bit kernel we should use the kernel personality. --- meson.build | 1 + sys-utils/Makemodule.am | 1 + sys-utils/setarch.c | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 38e59bd9ae..ae91338b43 100644 --- a/meson.build +++ b/meson.build @@ -1439,6 +1439,7 @@ exe = executable( 'setarch', setarch_sources, include_directories : includes, + link_with : [lib_common], install_dir : usrbin_exec_dir, install : true) exes += exe diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am index 22047d9bd4..a0bf6cb7b0 100644 --- a/sys-utils/Makemodule.am +++ b/sys-utils/Makemodule.am @@ -231,6 +231,7 @@ usrbin_exec_PROGRAMS += setarch MANPAGES += sys-utils/setarch.8 dist_noinst_DATA += sys-utils/setarch.8.adoc setarch_SOURCES = sys-utils/setarch.c +setarch_LDADD = $(LDADD) libcommon.la SETARCH_LINKS = uname26 linux32 linux64 diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c index b86be1e29d..d6789d05e8 100644 --- a/sys-utils/setarch.c +++ b/sys-utils/setarch.c @@ -35,6 +35,7 @@ #include "nls.h" #include "c.h" #include "closestream.h" +#include "sysfs.h" #ifndef HAVE_PERSONALITY # include @@ -232,7 +233,9 @@ static struct arch_domain *init_arch_domains(void) if (!strcmp(un.machine, transitions[i].target_arch)) break; if (transitions[i].perval < 0) { - unsigned long wrdsz = CHAR_BIT * sizeof(void *); + int wrdsz = sysfs_get_address_bits(NULL); + if (wrdsz < 0) + wrdsz = CHAR_BIT * sizeof(void *); if (wrdsz == 32 || wrdsz == 64) { /* fill up the place holder */ transitions[i].perval = wrdsz == 32 ? PER_LINUX32 : PER_LINUX; -- 2.47.3