target/xtensa/xtensa-semi: Fix compilation problem on Haiku

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>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Max Filippov <jcmvbkbc@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20210706081822.1316551-1-thuth@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Thomas Huth 2021-07-06 10:18:22 +02:00 committed by Laurent Vivier
parent 4c6dd9a026
commit 3b51b50668

View File

@ -95,60 +95,54 @@ enum {
static uint32_t errno_h2g(int host_errno) static uint32_t errno_h2g(int host_errno)
{ {
static const uint32_t guest_errno[] = { switch (host_errno) {
[EPERM] = TARGET_EPERM, case 0: return 0;
[ENOENT] = TARGET_ENOENT, case EPERM: return TARGET_EPERM;
[ESRCH] = TARGET_ESRCH, case ENOENT: return TARGET_ENOENT;
[EINTR] = TARGET_EINTR, case ESRCH: return TARGET_ESRCH;
[EIO] = TARGET_EIO, case EINTR: return TARGET_EINTR;
[ENXIO] = TARGET_ENXIO, case EIO: return TARGET_EIO;
[E2BIG] = TARGET_E2BIG, case ENXIO: return TARGET_ENXIO;
[ENOEXEC] = TARGET_ENOEXEC, case E2BIG: return TARGET_E2BIG;
[EBADF] = TARGET_EBADF, case ENOEXEC: return TARGET_ENOEXEC;
[ECHILD] = TARGET_ECHILD, case EBADF: return TARGET_EBADF;
[EAGAIN] = TARGET_EAGAIN, case ECHILD: return TARGET_ECHILD;
[ENOMEM] = TARGET_ENOMEM, case EAGAIN: return TARGET_EAGAIN;
[EACCES] = TARGET_EACCES, case ENOMEM: return TARGET_ENOMEM;
[EFAULT] = TARGET_EFAULT, case EACCES: return TARGET_EACCES;
case EFAULT: return TARGET_EFAULT;
#ifdef ENOTBLK #ifdef ENOTBLK
[ENOTBLK] = TARGET_ENOTBLK, case ENOTBLK: return TARGET_ENOTBLK;
#endif #endif
[EBUSY] = TARGET_EBUSY, case EBUSY: return TARGET_EBUSY;
[EEXIST] = TARGET_EEXIST, case EEXIST: return TARGET_EEXIST;
[EXDEV] = TARGET_EXDEV, case EXDEV: return TARGET_EXDEV;
[ENODEV] = TARGET_ENODEV, case ENODEV: return TARGET_ENODEV;
[ENOTDIR] = TARGET_ENOTDIR, case ENOTDIR: return TARGET_ENOTDIR;
[EISDIR] = TARGET_EISDIR, case EISDIR: return TARGET_EISDIR;
[EINVAL] = TARGET_EINVAL, case EINVAL: return TARGET_EINVAL;
[ENFILE] = TARGET_ENFILE, case ENFILE: return TARGET_ENFILE;
[EMFILE] = TARGET_EMFILE, case EMFILE: return TARGET_EMFILE;
[ENOTTY] = TARGET_ENOTTY, case ENOTTY: return TARGET_ENOTTY;
#ifdef ETXTBSY #ifdef ETXTBSY
[ETXTBSY] = TARGET_ETXTBSY, case ETXTBSY: return TARGET_ETXTBSY;
#endif #endif
[EFBIG] = TARGET_EFBIG, case EFBIG: return TARGET_EFBIG;
[ENOSPC] = TARGET_ENOSPC, case ENOSPC: return TARGET_ENOSPC;
[ESPIPE] = TARGET_ESPIPE, case ESPIPE: return TARGET_ESPIPE;
[EROFS] = TARGET_EROFS, case EROFS: return TARGET_EROFS;
[EMLINK] = TARGET_EMLINK, case EMLINK: return TARGET_EMLINK;
[EPIPE] = TARGET_EPIPE, case EPIPE: return TARGET_EPIPE;
[EDOM] = TARGET_EDOM, case EDOM: return TARGET_EDOM;
[ERANGE] = TARGET_ERANGE, case ERANGE: return TARGET_ERANGE;
[ENOSYS] = TARGET_ENOSYS, case ENOSYS: return TARGET_ENOSYS;
#ifdef ELOOP #ifdef ELOOP
[ELOOP] = TARGET_ELOOP, case ELOOP: return TARGET_ELOOP;
#endif #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 { typedef struct XtensaSimConsole {
CharBackend be; CharBackend be;