We've got three places already that provide a prototype for this
function in a .c file - that's ugly. Let's provide a proper prototype
in a header instead, with a proper description why this function should
not be used in most cases.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
NB: I've tried to replace the "utterly broken" comment with something
better, as suggested by Laszlo... not sure whether I've really got the
message right here, so feel free to provide some better wording if you
like!
exec.c | 5 -----
hw/virtio/virtio.c | 1 -
include/qom/cpu.h | 11 +++++++++++
qom/cpu.c | 1 -
4 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/exec.c b/exec.c
index d0821e6..5d99ef5 100644
--- a/exec.c
+++ b/exec.c
@@ -3906,11 +3906,6 @@ int qemu_target_page_bits_min(void)
}
#endif
-/*
- * A helper function for the _utterly broken_ virtio device model to find out if
- * it's running on a big endian machine. Don't do this at home kids!
- */
-bool target_words_bigendian(void);
bool target_words_bigendian(void)
{
#if defined(TARGET_WORDS_BIGENDIAN)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 94f5c8e..4e61944 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1169,7 +1169,6 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)
return 0;
}
-bool target_words_bigendian(void);
static enum virtio_device_endian virtio_default_endian(void)
{
if (target_words_bigendian()) {
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index dc130cd..6d35c37 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -1085,6 +1085,17 @@ void cpu_exec_initfn(CPUState *cpu);
void cpu_exec_realizefn(CPUState *cpu, Error **errp);
void cpu_exec_unrealizefn(CPUState *cpu);
+/**
+ * target_words_bigendian:
+ * Returns true if the (default) endianness of the target is big endian,
+ * false otherwise. Note that in target-specifc code, you can use
+ * TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common
+ * code should normally never need to know about the endianness of the
+ * target, so please do *not* use this function unless you know very well
+ * what you are doing!
+ */
+bool target_words_bigendian(void);
+
#ifdef NEED_CPU_H
#ifdef CONFIG_SOFTMMU
diff --git a/qom/cpu.c b/qom/cpu.c
index 92599f3..f774654 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -194,7 +194,6 @@ static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)
return true;
}
-bool target_words_bigendian(void);
static bool cpu_common_virtio_is_big_endian(CPUState *cpu)
{
return target_words_bigendian();
--
1.8.3.1
On 05/10/2018 15:01, Thomas Huth wrote:
> We've got three places already that provide a prototype for this
> function in a .c file - that's ugly. Let's provide a proper prototype
> in a header instead, with a proper description why this function should
> not be used in most cases.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> NB: I've tried to replace the "utterly broken" comment with something
> better, as suggested by Laszlo... not sure whether I've really got the
> message right here, so feel free to provide some better wording if you
> like!
>
> exec.c | 5 -----
> hw/virtio/virtio.c | 1 -
> include/qom/cpu.h | 11 +++++++++++
> qom/cpu.c | 1 -
> 4 files changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index d0821e6..5d99ef5 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -3906,11 +3906,6 @@ int qemu_target_page_bits_min(void)
> }
> #endif
>
> -/*
> - * A helper function for the _utterly broken_ virtio device model to find out if
> - * it's running on a big endian machine. Don't do this at home kids!
> - */
> -bool target_words_bigendian(void);
> bool target_words_bigendian(void)
> {
> #if defined(TARGET_WORDS_BIGENDIAN)
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 94f5c8e..4e61944 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -1169,7 +1169,6 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)
> return 0;
> }
>
> -bool target_words_bigendian(void);
> static enum virtio_device_endian virtio_default_endian(void)
> {
> if (target_words_bigendian()) {
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index dc130cd..6d35c37 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -1085,6 +1085,17 @@ void cpu_exec_initfn(CPUState *cpu);
> void cpu_exec_realizefn(CPUState *cpu, Error **errp);
> void cpu_exec_unrealizefn(CPUState *cpu);
>
> +/**
> + * target_words_bigendian:
> + * Returns true if the (default) endianness of the target is big endian,
> + * false otherwise. Note that in target-specifc code, you can use
> + * TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common
> + * code should normally never need to know about the endianness of the
> + * target, so please do *not* use this function unless you know very well
> + * what you are doing!
> + */
Thanks for this cleanup!
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> +bool target_words_bigendian(void);
> +
> #ifdef NEED_CPU_H
>
> #ifdef CONFIG_SOFTMMU
> diff --git a/qom/cpu.c b/qom/cpu.c
> index 92599f3..f774654 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -194,7 +194,6 @@ static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)
> return true;
> }
>
> -bool target_words_bigendian(void);
> static bool cpu_common_virtio_is_big_endian(CPUState *cpu)
> {
> return target_words_bigendian();
>
On 10/05/18 15:01, Thomas Huth wrote:
> We've got three places already that provide a prototype for this
> function in a .c file - that's ugly. Let's provide a proper prototype
> in a header instead, with a proper description why this function should
> not be used in most cases.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> NB: I've tried to replace the "utterly broken" comment with something
> better, as suggested by Laszlo... not sure whether I've really got the
> message right here, so feel free to provide some better wording if you
> like!
>
> exec.c | 5 -----
> hw/virtio/virtio.c | 1 -
> include/qom/cpu.h | 11 +++++++++++
> qom/cpu.c | 1 -
> 4 files changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index d0821e6..5d99ef5 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -3906,11 +3906,6 @@ int qemu_target_page_bits_min(void)
> }
> #endif
>
> -/*
> - * A helper function for the _utterly broken_ virtio device model to find out if
> - * it's running on a big endian machine. Don't do this at home kids!
> - */
> -bool target_words_bigendian(void);
> bool target_words_bigendian(void)
> {
> #if defined(TARGET_WORDS_BIGENDIAN)
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 94f5c8e..4e61944 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -1169,7 +1169,6 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)
> return 0;
> }
>
> -bool target_words_bigendian(void);
> static enum virtio_device_endian virtio_default_endian(void)
> {
> if (target_words_bigendian()) {
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index dc130cd..6d35c37 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -1085,6 +1085,17 @@ void cpu_exec_initfn(CPUState *cpu);
> void cpu_exec_realizefn(CPUState *cpu, Error **errp);
> void cpu_exec_unrealizefn(CPUState *cpu);
>
> +/**
> + * target_words_bigendian:
> + * Returns true if the (default) endianness of the target is big endian,
> + * false otherwise. Note that in target-specifc code, you can use
> + * TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common
> + * code should normally never need to know about the endianness of the
> + * target, so please do *not* use this function unless you know very well
> + * what you are doing!
> + */
> +bool target_words_bigendian(void);
> +
> #ifdef NEED_CPU_H
>
> #ifdef CONFIG_SOFTMMU
> diff --git a/qom/cpu.c b/qom/cpu.c
> index 92599f3..f774654 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -194,7 +194,6 @@ static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)
> return true;
> }
>
> -bool target_words_bigendian(void);
> static bool cpu_common_virtio_is_big_endian(CPUState *cpu)
> {
> return target_words_bigendian();
>
This makes sense to me. First I wasn't convinced, because I didn't
immediately get "target-specifc code". However, after looking at the 2nd
patch, I think I understand better (= the obj-XXX vs. common-obj-XXX
distinction). I also think that distinction is clear to any practicing
QEMU developers.
So, for what it's worth (which is admittedly not too much), for the series:
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
On 5 October 2018 at 14:20, Laszlo Ersek <lersek@redhat.com> wrote:
> On 10/05/18 15:01, Thomas Huth wrote:
>> We've got three places already that provide a prototype for this
>> function in a .c file - that's ugly. Let's provide a proper prototype
>> in a header instead, with a proper description why this function should
>> not be used in most cases.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>> +/**
>> + * target_words_bigendian:
>> + * Returns true if the (default) endianness of the target is big endian,
>> + * false otherwise. Note that in target-specifc code, you can use
"specific"
>> + * TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common
>> + * code should normally never need to know about the endianness of the
>> + * target, so please do *not* use this function unless you know very well
>> + * what you are doing!
>> + */
>> +bool target_words_bigendian(void);
>> +
>> #ifdef NEED_CPU_H
>>
>> #ifdef CONFIG_SOFTMMU
>> diff --git a/qom/cpu.c b/qom/cpu.c
>> index 92599f3..f774654 100644
>> --- a/qom/cpu.c
>> +++ b/qom/cpu.c
>> @@ -194,7 +194,6 @@ static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)
>> return true;
>> }
>>
>> -bool target_words_bigendian(void);
>> static bool cpu_common_virtio_is_big_endian(CPUState *cpu)
>> {
>> return target_words_bigendian();
>>
>
> This makes sense to me. First I wasn't convinced, because I didn't
> immediately get "target-specifc code". However, after looking at the 2nd
> patch, I think I understand better (= the obj-XXX vs. common-obj-XXX
> distinction). I also think that distinction is clear to any practicing
> QEMU developers.
Yes; target-specific code is compiled for each qemu-system-*
executable (and has access to #defines and so on that relate
specifically to that target); common code is built just once
and the same .o linked into each executable.
thanks
-- PMM
© 2016 - 2025 Red Hat, Inc.