* [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku
@ 2021-07-06 8:18 Thomas Huth
2021-07-06 8:24 ` Philippe Mathieu-Daudé
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Thomas Huth @ 2021-07-06 8:18 UTC (permalink / raw
To: qemu-devel, Max Filippov
Cc: qemu-trivial, Richard Zak, Philippe Mathieu-Daudé
The errno numbers are very large on Haiku, so the linking currently
fails there with a "final link failed: memory exhausted" error
message. We should not use the errno number as array indexes here,
thus convert the code to a switch-case statement instead. A clever
compiler should be able to optimize this code in a similar way
anway.
Reported-by: Richard Zak <richard.j.zak@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
target/xtensa/xtensa-semi.c | 84 +++++++++++++++++--------------------
1 file changed, 39 insertions(+), 45 deletions(-)
diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c
index 79f2b043f2..fa21b7e11f 100644
--- a/target/xtensa/xtensa-semi.c
+++ b/target/xtensa/xtensa-semi.c
@@ -95,59 +95,53 @@ enum {
static uint32_t errno_h2g(int host_errno)
{
- static const uint32_t guest_errno[] = {
- [EPERM] = TARGET_EPERM,
- [ENOENT] = TARGET_ENOENT,
- [ESRCH] = TARGET_ESRCH,
- [EINTR] = TARGET_EINTR,
- [EIO] = TARGET_EIO,
- [ENXIO] = TARGET_ENXIO,
- [E2BIG] = TARGET_E2BIG,
- [ENOEXEC] = TARGET_ENOEXEC,
- [EBADF] = TARGET_EBADF,
- [ECHILD] = TARGET_ECHILD,
- [EAGAIN] = TARGET_EAGAIN,
- [ENOMEM] = TARGET_ENOMEM,
- [EACCES] = TARGET_EACCES,
- [EFAULT] = TARGET_EFAULT,
+ switch (host_errno) {
+ case 0: return 0;
+ case EPERM: return TARGET_EPERM;
+ case ENOENT: return TARGET_ENOENT;
+ case ESRCH: return TARGET_ESRCH;
+ case EINTR: return TARGET_EINTR;
+ case EIO: return TARGET_EIO;
+ case ENXIO: return TARGET_ENXIO;
+ case E2BIG: return TARGET_E2BIG;
+ case ENOEXEC: return TARGET_ENOEXEC;
+ case EBADF: return TARGET_EBADF;
+ case ECHILD: return TARGET_ECHILD;
+ case EAGAIN: return TARGET_EAGAIN;
+ case ENOMEM: return TARGET_ENOMEM;
+ case EACCES: return TARGET_EACCES;
+ case EFAULT: return TARGET_EFAULT;
#ifdef ENOTBLK
- [ENOTBLK] = TARGET_ENOTBLK,
+ case ENOTBLK: return TARGET_ENOTBLK;
#endif
- [EBUSY] = TARGET_EBUSY,
- [EEXIST] = TARGET_EEXIST,
- [EXDEV] = TARGET_EXDEV,
- [ENODEV] = TARGET_ENODEV,
- [ENOTDIR] = TARGET_ENOTDIR,
- [EISDIR] = TARGET_EISDIR,
- [EINVAL] = TARGET_EINVAL,
- [ENFILE] = TARGET_ENFILE,
- [EMFILE] = TARGET_EMFILE,
- [ENOTTY] = TARGET_ENOTTY,
+ case EBUSY: return TARGET_EBUSY;
+ case EEXIST: return TARGET_EEXIST;
+ case EXDEV: return TARGET_EXDEV;
+ case ENODEV: return TARGET_ENODEV;
+ case ENOTDIR: return TARGET_ENOTDIR;
+ case EISDIR: return TARGET_EISDIR;
+ case EINVAL: return TARGET_EINVAL;
+ case ENFILE: return TARGET_ENFILE;
+ case EMFILE: return TARGET_EMFILE;
+ case ENOTTY: return TARGET_ENOTTY;
#ifdef ETXTBSY
- [ETXTBSY] = TARGET_ETXTBSY,
+ case ETXTBSY: return TARGET_ETXTBSY;
#endif
- [EFBIG] = TARGET_EFBIG,
- [ENOSPC] = TARGET_ENOSPC,
- [ESPIPE] = TARGET_ESPIPE,
- [EROFS] = TARGET_EROFS,
- [EMLINK] = TARGET_EMLINK,
- [EPIPE] = TARGET_EPIPE,
- [EDOM] = TARGET_EDOM,
- [ERANGE] = TARGET_ERANGE,
- [ENOSYS] = TARGET_ENOSYS,
+ case EFBIG: return TARGET_EFBIG;
+ case ENOSPC: return TARGET_ENOSPC;
+ case ESPIPE: return TARGET_ESPIPE;
+ case EROFS: return TARGET_EROFS;
+ case EMLINK: return TARGET_EMLINK;
+ case EPIPE: return TARGET_EPIPE;
+ case EDOM: return TARGET_EDOM;
+ case ERANGE: return TARGET_ERANGE;
+ case ENOSYS: return TARGET_ENOSYS;
#ifdef ELOOP
- [ELOOP] = TARGET_ELOOP,
+ case ELOOP: return TARGET_ELOOP;
#endif
};
- if (host_errno == 0) {
- return 0;
- } else if (host_errno > 0 && host_errno < ARRAY_SIZE(guest_errno) &&
- guest_errno[host_errno]) {
- return guest_errno[host_errno];
- } else {
- return TARGET_EINVAL;
- }
+ return TARGET_EINVAL;
}
typedef struct XtensaSimConsole {
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku
2021-07-06 8:18 [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku Thomas Huth
@ 2021-07-06 8:24 ` Philippe Mathieu-Daudé
2021-07-06 10:16 ` Max Filippov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-07-06 8:24 UTC (permalink / raw
To: Thomas Huth, qemu-devel, Max Filippov; +Cc: qemu-trivial, Richard Zak
On 7/6/21 10:18 AM, Thomas Huth wrote:
> The errno numbers are very large on Haiku, so the linking currently
> fails there with a "final link failed: memory exhausted" error
> message. We should not use the errno number as array indexes here,
> thus convert the code to a switch-case statement instead. A clever
> compiler should be able to optimize this code in a similar way
> anway.
>
> Reported-by: Richard Zak <richard.j.zak@gmail.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> target/xtensa/xtensa-semi.c | 84 +++++++++++++++++--------------------
> 1 file changed, 39 insertions(+), 45 deletions(-)
>
> diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c
> index 79f2b043f2..fa21b7e11f 100644
> --- a/target/xtensa/xtensa-semi.c
> +++ b/target/xtensa/xtensa-semi.c
> @@ -95,59 +95,53 @@ enum {
>
> static uint32_t errno_h2g(int host_errno)
> {
> - [EFBIG] = TARGET_EFBIG,
> - [ENOSPC] = TARGET_ENOSPC,
> - [ESPIPE] = TARGET_ESPIPE,
> - [EROFS] = TARGET_EROFS,
> - [EMLINK] = TARGET_EMLINK,
> - [EPIPE] = TARGET_EPIPE,
> - [EDOM] = TARGET_EDOM,
> - [ERANGE] = TARGET_ERANGE,
> - [ENOSYS] = TARGET_ENOSYS,
> + case EFBIG: return TARGET_EFBIG;
> + case ENOSPC: return TARGET_ENOSPC;
> + case ESPIPE: return TARGET_ESPIPE;
> + case EROFS: return TARGET_EROFS;
> + case EMLINK: return TARGET_EMLINK;
> + case EPIPE: return TARGET_EPIPE;
> + case EDOM: return TARGET_EDOM;
> + case ERANGE: return TARGET_ERANGE;
> + case ENOSYS: return TARGET_ENOSYS;
> #ifdef ELOOP
> - [ELOOP] = TARGET_ELOOP,
> + case ELOOP: return TARGET_ELOOP;
> #endif
> };
>
> - if (host_errno == 0) {
> - return 0;
> - } else if (host_errno > 0 && host_errno < ARRAY_SIZE(guest_errno) &&
> - guest_errno[host_errno]) {
> - return guest_errno[host_errno];
> - } else {
> - return TARGET_EINVAL;
> - }
> + return TARGET_EINVAL;
Matter of aesthetic taste, I'd have use a 'default' case here ;)
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku
2021-07-06 8:18 [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku Thomas Huth
2021-07-06 8:24 ` Philippe Mathieu-Daudé
@ 2021-07-06 10:16 ` Max Filippov
2021-07-06 21:07 ` Richard Henderson
2021-07-09 9:13 ` Laurent Vivier
3 siblings, 0 replies; 5+ messages in thread
From: Max Filippov @ 2021-07-06 10:16 UTC (permalink / raw
To: Thomas Huth
Cc: QEMU Trivial, Richard Zak, qemu-devel,
Philippe Mathieu-Daudé
On Tue, Jul 6, 2021 at 1:18 AM Thomas Huth <thuth@redhat.com> wrote:
>
> The errno numbers are very large on Haiku, so the linking currently
> fails there with a "final link failed: memory exhausted" error
> message. We should not use the errno number as array indexes here,
> thus convert the code to a switch-case statement instead. A clever
> compiler should be able to optimize this code in a similar way
> anway.
>
> Reported-by: Richard Zak <richard.j.zak@gmail.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> target/xtensa/xtensa-semi.c | 84 +++++++++++++++++--------------------
> 1 file changed, 39 insertions(+), 45 deletions(-)
Acked-by: Max Filippov <jcmvbkbc@gmail.com>
--
Thanks.
-- Max
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku
2021-07-06 8:18 [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku Thomas Huth
2021-07-06 8:24 ` Philippe Mathieu-Daudé
2021-07-06 10:16 ` Max Filippov
@ 2021-07-06 21:07 ` Richard Henderson
2021-07-09 9:13 ` Laurent Vivier
3 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2021-07-06 21:07 UTC (permalink / raw
To: Thomas Huth, qemu-devel, Max Filippov
Cc: qemu-trivial, Richard Zak, Philippe Mathieu-Daudé
On 7/6/21 1:18 AM, Thomas Huth wrote:
> The errno numbers are very large on Haiku, so the linking currently
> fails there with a "final link failed: memory exhausted" error
> message. We should not use the errno number as array indexes here,
> thus convert the code to a switch-case statement instead. A clever
> compiler should be able to optimize this code in a similar way
> anway.
>
> Reported-by: Richard Zak<richard.j.zak@gmail.com>
> Signed-off-by: Thomas Huth<thuth@redhat.com>
> ---
> target/xtensa/xtensa-semi.c | 84 +++++++++++++++++--------------------
> 1 file changed, 39 insertions(+), 45 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku
2021-07-06 8:18 [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku Thomas Huth
` (2 preceding siblings ...)
2021-07-06 21:07 ` Richard Henderson
@ 2021-07-09 9:13 ` Laurent Vivier
3 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2021-07-09 9:13 UTC (permalink / raw
To: Thomas Huth, qemu-devel, Max Filippov
Cc: qemu-trivial, Richard Zak, Philippe Mathieu-Daudé
Le 06/07/2021 à 10:18, Thomas Huth a écrit :
> The errno numbers are very large on Haiku, so the linking currently
> fails there with a "final link failed: memory exhausted" error
> message. We should not use the errno number as array indexes here,
> thus convert the code to a switch-case statement instead. A clever
> compiler should be able to optimize this code in a similar way
> anway.
>
> Reported-by: Richard Zak <richard.j.zak@gmail.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> target/xtensa/xtensa-semi.c | 84 +++++++++++++++++--------------------
> 1 file changed, 39 insertions(+), 45 deletions(-)
>
> diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c
> index 79f2b043f2..fa21b7e11f 100644
> --- a/target/xtensa/xtensa-semi.c
> +++ b/target/xtensa/xtensa-semi.c
> @@ -95,59 +95,53 @@ enum {
>
> static uint32_t errno_h2g(int host_errno)
> {
> - static const uint32_t guest_errno[] = {
> - [EPERM] = TARGET_EPERM,
> - [ENOENT] = TARGET_ENOENT,
> - [ESRCH] = TARGET_ESRCH,
> - [EINTR] = TARGET_EINTR,
> - [EIO] = TARGET_EIO,
> - [ENXIO] = TARGET_ENXIO,
> - [E2BIG] = TARGET_E2BIG,
> - [ENOEXEC] = TARGET_ENOEXEC,
> - [EBADF] = TARGET_EBADF,
> - [ECHILD] = TARGET_ECHILD,
> - [EAGAIN] = TARGET_EAGAIN,
> - [ENOMEM] = TARGET_ENOMEM,
> - [EACCES] = TARGET_EACCES,
> - [EFAULT] = TARGET_EFAULT,
> + switch (host_errno) {
> + case 0: return 0;
> + case EPERM: return TARGET_EPERM;
> + case ENOENT: return TARGET_ENOENT;
> + case ESRCH: return TARGET_ESRCH;
> + case EINTR: return TARGET_EINTR;
> + case EIO: return TARGET_EIO;
> + case ENXIO: return TARGET_ENXIO;
> + case E2BIG: return TARGET_E2BIG;
> + case ENOEXEC: return TARGET_ENOEXEC;
> + case EBADF: return TARGET_EBADF;
> + case ECHILD: return TARGET_ECHILD;
> + case EAGAIN: return TARGET_EAGAIN;
> + case ENOMEM: return TARGET_ENOMEM;
> + case EACCES: return TARGET_EACCES;
> + case EFAULT: return TARGET_EFAULT;
> #ifdef ENOTBLK
> - [ENOTBLK] = TARGET_ENOTBLK,
> + case ENOTBLK: return TARGET_ENOTBLK;
> #endif
> - [EBUSY] = TARGET_EBUSY,
> - [EEXIST] = TARGET_EEXIST,
> - [EXDEV] = TARGET_EXDEV,
> - [ENODEV] = TARGET_ENODEV,
> - [ENOTDIR] = TARGET_ENOTDIR,
> - [EISDIR] = TARGET_EISDIR,
> - [EINVAL] = TARGET_EINVAL,
> - [ENFILE] = TARGET_ENFILE,
> - [EMFILE] = TARGET_EMFILE,
> - [ENOTTY] = TARGET_ENOTTY,
> + case EBUSY: return TARGET_EBUSY;
> + case EEXIST: return TARGET_EEXIST;
> + case EXDEV: return TARGET_EXDEV;
> + case ENODEV: return TARGET_ENODEV;
> + case ENOTDIR: return TARGET_ENOTDIR;
> + case EISDIR: return TARGET_EISDIR;
> + case EINVAL: return TARGET_EINVAL;
> + case ENFILE: return TARGET_ENFILE;
> + case EMFILE: return TARGET_EMFILE;
> + case ENOTTY: return TARGET_ENOTTY;
> #ifdef ETXTBSY
> - [ETXTBSY] = TARGET_ETXTBSY,
> + case ETXTBSY: return TARGET_ETXTBSY;
> #endif
> - [EFBIG] = TARGET_EFBIG,
> - [ENOSPC] = TARGET_ENOSPC,
> - [ESPIPE] = TARGET_ESPIPE,
> - [EROFS] = TARGET_EROFS,
> - [EMLINK] = TARGET_EMLINK,
> - [EPIPE] = TARGET_EPIPE,
> - [EDOM] = TARGET_EDOM,
> - [ERANGE] = TARGET_ERANGE,
> - [ENOSYS] = TARGET_ENOSYS,
> + case EFBIG: return TARGET_EFBIG;
> + case ENOSPC: return TARGET_ENOSPC;
> + case ESPIPE: return TARGET_ESPIPE;
> + case EROFS: return TARGET_EROFS;
> + case EMLINK: return TARGET_EMLINK;
> + case EPIPE: return TARGET_EPIPE;
> + case EDOM: return TARGET_EDOM;
> + case ERANGE: return TARGET_ERANGE;
> + case ENOSYS: return TARGET_ENOSYS;
> #ifdef ELOOP
> - [ELOOP] = TARGET_ELOOP,
> + case ELOOP: return TARGET_ELOOP;
> #endif
> };
>
> - if (host_errno == 0) {
> - return 0;
> - } else if (host_errno > 0 && host_errno < ARRAY_SIZE(guest_errno) &&
> - guest_errno[host_errno]) {
> - return guest_errno[host_errno];
> - } else {
> - return TARGET_EINVAL;
> - }
> + return TARGET_EINVAL;
> }
>
> typedef struct XtensaSimConsole {
>
Applied to my trivial-patches branch.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-07-09 9:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-06 8:18 [PATCH] target/xtensa/xtensa-semi: Fix compilation problem on Haiku Thomas Huth
2021-07-06 8:24 ` Philippe Mathieu-Daudé
2021-07-06 10:16 ` Max Filippov
2021-07-06 21:07 ` Richard Henderson
2021-07-09 9:13 ` Laurent Vivier
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.