* [PATCH 0/2] semihosting/uaccess: Compile once
@ 2025-05-02 22:05 Philippe Mathieu-Daudé
2025-05-02 22:05 ` [PATCH 1/2] semihosting/uaccess: Remove uses of target_ulong type Philippe Mathieu-Daudé
2025-05-02 22:05 ` [PATCH 2/2] semihosting/uaccess: Compile once Philippe Mathieu-Daudé
0 siblings, 2 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-02 22:05 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Anton Johansson,
Richard Henderson, Philippe Mathieu-Daudé
Replace target_ulong -> vaddr/size_t to compile once.
Philippe Mathieu-Daudé (2):
semihosting/uaccess: Remove uses of target_ulong type
semihosting/uaccess: Compile once
include/semihosting/uaccess.h | 12 ++++++------
semihosting/uaccess.c | 10 +++++-----
semihosting/meson.build | 4 +---
3 files changed, 12 insertions(+), 14 deletions(-)
--
2.47.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] semihosting/uaccess: Remove uses of target_ulong type
2025-05-02 22:05 [PATCH 0/2] semihosting/uaccess: Compile once Philippe Mathieu-Daudé
@ 2025-05-02 22:05 ` Philippe Mathieu-Daudé
2025-05-03 21:04 ` Pierrick Bouvier
2025-05-02 22:05 ` [PATCH 2/2] semihosting/uaccess: Compile once Philippe Mathieu-Daudé
1 sibling, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-02 22:05 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Anton Johansson,
Richard Henderson, Philippe Mathieu-Daudé
Replace target_ulong by vaddr or size_t types to match
cpu_memory_rw_debug() prototype in "exec/cpu-common.h":
int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
void *ptr, size_t len,
bool is_write);
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/semihosting/uaccess.h | 12 ++++++------
semihosting/uaccess.c | 10 +++++-----
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/include/semihosting/uaccess.h b/include/semihosting/uaccess.h
index 6bc90b12d6f..2093a498277 100644
--- a/include/semihosting/uaccess.h
+++ b/include/semihosting/uaccess.h
@@ -15,9 +15,9 @@
#endif
#include "exec/cpu-common.h"
-#include "exec/cpu-defs.h"
#include "exec/tswap.h"
#include "exec/page-protection.h"
+#include "exec/vaddr.h"
/**
* get_user_u64:
@@ -89,8 +89,8 @@
*
* The returned pointer should be freed using uaccess_unlock_user().
*/
-void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
- target_ulong len, bool copy);
+void *uaccess_lock_user(CPUArchState *env, vaddr addr,
+ size_t len, bool copy);
/**
* lock_user:
*
@@ -103,7 +103,7 @@ void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
*
* The returned string should be freed using uaccess_unlock_user().
*/
-char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr);
+char *uaccess_lock_user_string(CPUArchState *env, vaddr addr);
/**
* uaccess_lock_user_string:
*
@@ -112,10 +112,10 @@ char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr);
#define lock_user_string(p) uaccess_lock_user_string(env, p)
void uaccess_unlock_user(CPUArchState *env, void *p,
- target_ulong addr, target_ulong len);
+ vaddr addr, size_t len);
#define unlock_user(s, args, len) uaccess_unlock_user(env, s, args, len)
-ssize_t uaccess_strlen_user(CPUArchState *env, target_ulong addr);
+ssize_t uaccess_strlen_user(CPUArchState *env, vaddr addr);
#define target_strlen(p) uaccess_strlen_user(env, p)
#endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */
diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c
index 4554844e15b..ff944d8c2f7 100644
--- a/semihosting/uaccess.c
+++ b/semihosting/uaccess.c
@@ -14,8 +14,8 @@
#include "exec/tlb-flags.h"
#include "semihosting/uaccess.h"
-void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
- target_ulong len, bool copy)
+void *uaccess_lock_user(CPUArchState *env, vaddr addr,
+ size_t len, bool copy)
{
void *p = malloc(len);
if (p && copy) {
@@ -27,7 +27,7 @@ void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
return p;
}
-ssize_t uaccess_strlen_user(CPUArchState *env, target_ulong addr)
+ssize_t uaccess_strlen_user(CPUArchState *env, vaddr addr)
{
int mmu_idx = cpu_mmu_index(env_cpu(env), false);
size_t len = 0;
@@ -75,7 +75,7 @@ ssize_t uaccess_strlen_user(CPUArchState *env, target_ulong addr)
}
}
-char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr)
+char *uaccess_lock_user_string(CPUArchState *env, vaddr addr)
{
ssize_t len = uaccess_strlen_user(env, addr);
if (len < 0) {
@@ -85,7 +85,7 @@ char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr)
}
void uaccess_unlock_user(CPUArchState *env, void *p,
- target_ulong addr, target_ulong len)
+ vaddr addr, size_t len)
{
if (len) {
cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1);
--
2.47.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] semihosting/uaccess: Compile once
2025-05-02 22:05 [PATCH 0/2] semihosting/uaccess: Compile once Philippe Mathieu-Daudé
2025-05-02 22:05 ` [PATCH 1/2] semihosting/uaccess: Remove uses of target_ulong type Philippe Mathieu-Daudé
@ 2025-05-02 22:05 ` Philippe Mathieu-Daudé
2025-05-03 21:04 ` Pierrick Bouvier
1 sibling, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-02 22:05 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Anton Johansson,
Richard Henderson, Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
semihosting/meson.build | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/semihosting/meson.build b/semihosting/meson.build
index f3d38dda91d..a0a1c081f43 100644
--- a/semihosting/meson.build
+++ b/semihosting/meson.build
@@ -3,9 +3,7 @@ specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
'syscalls.c',
))
-specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SYSTEM_ONLY'], if_true: files(
- 'uaccess.c',
-))
+libsystem_ss.add(files('uaccess.c'))
common_ss.add(when: 'CONFIG_SEMIHOSTING', if_false: files('stubs-all.c'))
user_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files('user.c'))
--
2.47.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] semihosting/uaccess: Compile once
2025-05-02 22:05 ` [PATCH 2/2] semihosting/uaccess: Compile once Philippe Mathieu-Daudé
@ 2025-05-03 21:04 ` Pierrick Bouvier
0 siblings, 0 replies; 5+ messages in thread
From: Pierrick Bouvier @ 2025-05-03 21:04 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Anton Johansson, Richard Henderson
[-- Attachment #1: Type: text/plain, Size: 1868 bytes --]
On 5/2/25 3:05 PM, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> semihosting/meson.build | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/semihosting/meson.build b/semihosting/meson.build
> index f3d38dda91d..a0a1c081f43 100644
> --- a/semihosting/meson.build
> +++ b/semihosting/meson.build
> @@ -3,9 +3,7 @@ specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
> 'syscalls.c',
> ))
>
> -specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SYSTEM_ONLY'], if_true: files(
> - 'uaccess.c',
> -))
> +libsystem_ss.add(files('uaccess.c'))
>
> common_ss.add(when: 'CONFIG_SEMIHOSTING', if_false: files('stubs-all.c'))
> user_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files('user.c'))
Fails to build with:
./configure --disable-tcg && ninja -C build
FAILED: libsystem.a.p/semihosting_uaccess.c.o
../semihosting/uaccess.c
../semihosting/uaccess.c: In function ‘uaccess_strlen_user’:
../semihosting/uaccess.c:43:17: error: implicit declaration of function
‘probe_access_flags’ [-Wimplicit-function-declaration]
43 | flags = probe_access_flags(env, addr, 0, MMU_DATA_LOAD,
| ^~~~~~~~~~~~~~~~~~
../semihosting/uaccess.c:43:17: error: nested extern declaration of
‘probe_access_flags’ [-Werror=nested-externs]
CONFIG_SEMIHOSTING conditional must be kept.
-libsystem_ss.add(files('uaccess.c'))
+libsystem_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files('uaccess.c'))
However, it will fail as libsystem cannot apply target configuration for
now, so we need to modify its definition (and libuser while we are at it).
Please apply the two patches attached (only the second is needed
strictly, but it's currently stacked on the first one in my series for
target/arm). I'll post it as well when updating my series.
[-- Attachment #2: 0001-meson-add-common-libs-for-target-and-target_system.patch --]
[-- Type: text/x-patch, Size: 5329 bytes --]
From 8f3fdd9e262d36b22545d0f28305b9ff7cf49cb5 Mon Sep 17 00:00:00 2001
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Date: Fri, 25 Apr 2025 18:26:08 -0700
Subject: [PATCH 1/2] meson: add common libs for target and target_system
Following what we did for hw/, we need target specific common libraries
for target. We need 2 different libraries:
- code common to a base architecture
- system code common to a base architecture
For user code, it can stay compiled per target for now.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
meson.build | 78 +++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 61 insertions(+), 17 deletions(-)
diff --git a/meson.build b/meson.build
index 64778edeb2c..6f4129826af 100644
--- a/meson.build
+++ b/meson.build
@@ -3685,6 +3685,8 @@ target_arch = {}
target_system_arch = {}
target_user_arch = {}
hw_common_arch = {}
+target_common_arch = {}
+target_common_system_arch = {}
# NOTE: the trace/ subdirectory needs the qapi_trace_events variable
# that is filled in by qapi/.
@@ -4088,29 +4090,59 @@ common_all = static_library('common',
# construct common libraries per base architecture
hw_common_arch_libs = {}
+target_common_arch_libs = {}
+target_common_system_arch_libs = {}
foreach target : target_dirs
config_target = config_target_mak[target]
target_base_arch = config_target['TARGET_BASE_ARCH']
+ target_inc = [include_directories('target' / target_base_arch)]
+ inc = [common_user_inc + target_inc]
- # check if already generated
- if target_base_arch in hw_common_arch_libs
- continue
- endif
+ # prevent common code to access cpu compile time definition,
+ # but still allow access to cpu.h
+ target_c_args = ['-DCPU_DEFS_H']
+ target_system_c_args = target_c_args + ['-DCOMPILING_SYSTEM_VS_USER', '-DCONFIG_SOFTMMU']
if target_base_arch in hw_common_arch
- target_inc = [include_directories('target' / target_base_arch)]
- src = hw_common_arch[target_base_arch]
- lib = static_library(
- 'hw_' + target_base_arch,
- build_by_default: false,
- sources: src.all_sources() + genh,
- include_directories: common_user_inc + target_inc,
- implicit_include_directories: false,
- # prevent common code to access cpu compile time
- # definition, but still allow access to cpu.h
- c_args: ['-DCPU_DEFS_H', '-DCOMPILING_SYSTEM_VS_USER', '-DCONFIG_SOFTMMU'],
- dependencies: src.all_dependencies())
- hw_common_arch_libs += {target_base_arch: lib}
+ if target_base_arch not in hw_common_arch_libs
+ src = hw_common_arch[target_base_arch]
+ lib = static_library(
+ 'hw_' + target_base_arch,
+ build_by_default: false,
+ sources: src.all_sources() + genh,
+ include_directories: inc,
+ c_args: target_system_c_args,
+ dependencies: src.all_dependencies())
+ hw_common_arch_libs += {target_base_arch: lib}
+ endif
+ endif
+
+ if target_base_arch in target_common_arch
+ if target_base_arch not in target_common_arch_libs
+ src = target_common_arch[target_base_arch]
+ lib = static_library(
+ 'target_' + target_base_arch,
+ build_by_default: false,
+ sources: src.all_sources() + genh,
+ include_directories: inc,
+ c_args: target_c_args,
+ dependencies: src.all_dependencies())
+ target_common_arch_libs += {target_base_arch: lib}
+ endif
+ endif
+
+ if target_base_arch in target_common_system_arch
+ if target_base_arch not in target_common_system_arch_libs
+ src = target_common_system_arch[target_base_arch]
+ lib = static_library(
+ 'target_system_' + target_base_arch,
+ build_by_default: false,
+ sources: src.all_sources() + genh,
+ include_directories: inc,
+ c_args: target_system_c_args,
+ dependencies: src.all_dependencies())
+ target_common_system_arch_libs += {target_base_arch: lib}
+ endif
endif
endforeach
@@ -4283,12 +4315,24 @@ foreach target : target_dirs
target_common = common_ss.apply(config_target, strict: false)
objects = [common_all.extract_objects(target_common.sources())]
arch_deps += target_common.dependencies()
+ if target_base_arch in target_common_arch_libs
+ src = target_common_arch[target_base_arch].apply(config_target, strict: false)
+ lib = target_common_arch_libs[target_base_arch]
+ objects += lib.extract_objects(src.sources())
+ arch_deps += src.dependencies()
+ endif
if target_type == 'system' and target_base_arch in hw_common_arch_libs
src = hw_common_arch[target_base_arch].apply(config_target, strict: false)
lib = hw_common_arch_libs[target_base_arch]
objects += lib.extract_objects(src.sources())
arch_deps += src.dependencies()
endif
+ if target_type == 'system' and target_base_arch in target_common_system_arch_libs
+ src = target_common_system_arch[target_base_arch].apply(config_target, strict: false)
+ lib = target_common_system_arch_libs[target_base_arch]
+ objects += lib.extract_objects(src.sources())
+ arch_deps += src.dependencies()
+ endif
target_specific = specific_ss.apply(config_target, strict: false)
arch_srcs += target_specific.sources()
--
2.47.2
[-- Attachment #3: 0002-meson-apply-target-config-for-picking-files-from-lib.patch --]
[-- Type: text/x-patch, Size: 3327 bytes --]
From 34fe4d28938de4df9923a089596e7b66979eb34e Mon Sep 17 00:00:00 2001
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Date: Sat, 3 May 2025 13:56:47 -0700
Subject: [PATCH 2/2] meson: apply target config for picking files from
libsystem and libuser
semihosting code needs to be included only if CONFIG_SEMIHOSTING is set.
However, this is a target configuration, so we need to apply it to the
libsystem libuser source sets.
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
meson.build | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/meson.build b/meson.build
index 6f4129826af..59c520de359 100644
--- a/meson.build
+++ b/meson.build
@@ -4056,27 +4056,19 @@ common_ss.add(qom, qemuutil)
common_ss.add_all(when: 'CONFIG_SYSTEM_ONLY', if_true: [system_ss])
common_ss.add_all(when: 'CONFIG_USER_ONLY', if_true: user_ss)
-libuser_ss = libuser_ss.apply({})
libuser = static_library('user',
- libuser_ss.sources() + genh,
+ libuser_ss.all_sources() + genh,
c_args: ['-DCONFIG_USER_ONLY',
'-DCOMPILING_SYSTEM_VS_USER'],
- dependencies: libuser_ss.dependencies(),
+ dependencies: libuser_ss.all_dependencies(),
build_by_default: false)
-libuser = declare_dependency(objects: libuser.extract_all_objects(recursive: false),
- dependencies: libuser_ss.dependencies())
-common_ss.add(when: 'CONFIG_USER_ONLY', if_true: libuser)
-libsystem_ss = libsystem_ss.apply({})
libsystem = static_library('system',
- libsystem_ss.sources() + genh,
+ libsystem_ss.all_sources() + genh,
c_args: ['-DCONFIG_SOFTMMU',
'-DCOMPILING_SYSTEM_VS_USER'],
- dependencies: libsystem_ss.dependencies(),
+ dependencies: libsystem_ss.all_dependencies(),
build_by_default: false)
-libsystem = declare_dependency(objects: libsystem.extract_all_objects(recursive: false),
- dependencies: libsystem_ss.dependencies())
-common_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: libsystem)
# Note that this library is never used directly (only through extract_objects)
# and is not built by default; therefore, source files not used by the build
@@ -4315,6 +4307,16 @@ foreach target : target_dirs
target_common = common_ss.apply(config_target, strict: false)
objects = [common_all.extract_objects(target_common.sources())]
arch_deps += target_common.dependencies()
+ if target_type == 'system'
+ src = libsystem_ss.apply(config_target, strict: false)
+ objects += libsystem.extract_objects(src.sources())
+ arch_deps += src.dependencies()
+ endif
+ if target_type == 'user'
+ src = libuser_ss.apply(config_target, strict: false)
+ objects += libuser.extract_objects(src.sources())
+ arch_deps += src.dependencies()
+ endif
if target_base_arch in target_common_arch_libs
src = target_common_arch[target_base_arch].apply(config_target, strict: false)
lib = target_common_arch_libs[target_base_arch]
--
2.47.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] semihosting/uaccess: Remove uses of target_ulong type
2025-05-02 22:05 ` [PATCH 1/2] semihosting/uaccess: Remove uses of target_ulong type Philippe Mathieu-Daudé
@ 2025-05-03 21:04 ` Pierrick Bouvier
0 siblings, 0 replies; 5+ messages in thread
From: Pierrick Bouvier @ 2025-05-03 21:04 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Anton Johansson, Richard Henderson
On 5/2/25 3:05 PM, Philippe Mathieu-Daudé wrote:
> Replace target_ulong by vaddr or size_t types to match
> cpu_memory_rw_debug() prototype in "exec/cpu-common.h":
>
> int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
> void *ptr, size_t len,
> bool is_write);
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/semihosting/uaccess.h | 12 ++++++------
> semihosting/uaccess.c | 10 +++++-----
> 2 files changed, 11 insertions(+), 11 deletions(-)
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-03 21:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-02 22:05 [PATCH 0/2] semihosting/uaccess: Compile once Philippe Mathieu-Daudé
2025-05-02 22:05 ` [PATCH 1/2] semihosting/uaccess: Remove uses of target_ulong type Philippe Mathieu-Daudé
2025-05-03 21:04 ` Pierrick Bouvier
2025-05-02 22:05 ` [PATCH 2/2] semihosting/uaccess: Compile once Philippe Mathieu-Daudé
2025-05-03 21:04 ` Pierrick Bouvier
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 NNTP newsgroup(s).