On 4/18/25 10:29, Philippe Mathieu-Daudé wrote:
Add a helper to distinct the binary is targetting
Aarch64 or not.
Start with a dump strcmp() implementation, leaving
room for future optimizations.
Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org>
---
include/qemu/target_info.h | 7 +++++++
target_info.c | 5 +++++
2 files changed, 12 insertions(+)
diff --git a/include/qemu/target_info.h b/include/qemu/target_info.h
index c67b97d66f3..9b7575ce632 100644
--- a/include/qemu/target_info.h
+++ b/include/qemu/target_info.h
@@ -24,4 +24,11 @@ const char *target_name(void);
*/
const char *target_machine_typename(void);
+/**
+ * target_aarch64:
+ *
+ * Returns whether the target architecture is Aarch64.
+ */
+bool target_aarch64(void);
+
#endif
diff --git a/target_info.c b/target_info.c
index 1de4334ecc5..87dd1d51778 100644
--- a/target_info.c
+++ b/target_info.c
@@ -19,3 +19,8 @@ const char *target_machine_typename(void)
{
return target_info()->machine_typename;
}
+
+bool target_aarch64(void)
+{
+ return !strcmp(target_name(), "aarch64");
I don't think doing strcmp is a good move here, even temporarily.
A short term solution is making target_info.c target specific, and use:
return TARGET_AARCH64;
The long term solution, is to have a create target_current() that
returns an enum, and target_aarch64() would become:
return target_current() == {ENUM}_AARCH64. We just need to find a good
name for {enum} which is not Target, since it's a poisoned identifier.
This way, we can easily convert the simple
#ifdef TARGET_AARCH64 by if target_aarch64(),
and more complicated combinations by a switch on target_current().
For a first version, I think that the first solution is enough.