* [PATCH v2] target/mips: Rewrite UHI errno_mips() using switch statement
@ 2021-07-06 13:07 Philippe Mathieu-Daudé
2021-07-06 13:35 ` Thomas Huth
0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-07-06 13:07 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Thomas Huth, Alexander von Gluck IV,
Alex Bennée, Aleksandar Rikalo, Richard Henderson,
Philippe Mathieu-Daudé,
Richard Zak, Leon Alrae, Aurelien Jarno
Linking on Haiku OS fails:
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
error: libqemu-mips-softmmu.fa.p/target_mips_tcg_sysemu_mips-semi.c.o(.rodata) is too large (0xffff405a bytes)
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
final link failed: memory exhausted
collect2: error: ld returned 1 exit status
This is because the host_to_mips_errno[] uses errno as index,
for example:
static const uint16_t host_to_mips_errno[] = {
[ENAMETOOLONG] = 91,
...
and Haiku defines [*] ENAMETOOLONG as:
12 /* Error baselines */
13 #define B_GENERAL_ERROR_BASE INT_MIN
..
22 #define B_STORAGE_ERROR_BASE (B_GENERAL_ERROR_BASE + 0x6000)
...
106 #define B_NAME_TOO_LONG (B_STORAGE_ERROR_BASE + 4)
...
211 #define ENAMETOOLONG B_TO_POSIX_ERROR(B_NAME_TOO_LONG)
so the array ends up beeing indeed too big.
Since POSIX errno can't be use as indexes on Haiku,
rewrite errno_mips() using a switch statement.
[*] https://github.com/haiku/haiku/blob/r1beta3/headers/os/support/Errors.h#L130
Reported-by: Richard Zak <richard.j.zak@gmail.com>
Suggested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Supersedes: <20210704170736.617895-4-f4bug@amsat.org>
---
target/mips/tcg/sysemu/mips-semi.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c
index 77108b0b1a9..b4a383ae90c 100644
--- a/target/mips/tcg/sysemu/mips-semi.c
+++ b/target/mips/tcg/sysemu/mips-semi.c
@@ -74,25 +74,19 @@ enum UHIOpenFlags {
UHIOpen_EXCL = 0x800
};
-/* Errno values taken from asm-mips/errno.h */
-static const uint16_t host_to_mips_errno[] = {
- [ENAMETOOLONG] = 78,
+static int errno_mips(int host_errno)
+{
+ /* Errno values taken from asm-mips/errno.h */
+ switch (host_errno) {
+ case 0: return 0;
+ case ENAMETOOLONG: return 78;
#ifdef EOVERFLOW
- [EOVERFLOW] = 79,
+ case EOVERFLOW: return 79;
#endif
#ifdef ELOOP
- [ELOOP] = 90,
+ case ELOOP: return 90;
#endif
-};
-
-static int errno_mips(int err)
-{
- if (err < 0 || err >= ARRAY_SIZE(host_to_mips_errno)) {
- return EINVAL;
- } else if (host_to_mips_errno[err]) {
- return host_to_mips_errno[err];
- } else {
- return err;
+ default: return EINVAL;
}
}
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] target/mips: Rewrite UHI errno_mips() using switch statement
2021-07-06 13:07 [PATCH v2] target/mips: Rewrite UHI errno_mips() using switch statement Philippe Mathieu-Daudé
@ 2021-07-06 13:35 ` Thomas Huth
2021-07-06 13:45 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Huth @ 2021-07-06 13:35 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Peter Maydell, Aleksandar Rikalo, Alexander von Gluck IV,
Alex Bennée, Richard Henderson, Richard Zak, Leon Alrae,
Aurelien Jarno
On 06/07/2021 15.07, Philippe Mathieu-Daudé wrote:
> Linking on Haiku OS fails:
>
> /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
> error: libqemu-mips-softmmu.fa.p/target_mips_tcg_sysemu_mips-semi.c.o(.rodata) is too large (0xffff405a bytes)
> /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
> final link failed: memory exhausted
> collect2: error: ld returned 1 exit status
>
> This is because the host_to_mips_errno[] uses errno as index,
> for example:
>
> static const uint16_t host_to_mips_errno[] = {
> [ENAMETOOLONG] = 91,
> ...
>
> and Haiku defines [*] ENAMETOOLONG as:
>
> 12 /* Error baselines */
> 13 #define B_GENERAL_ERROR_BASE INT_MIN
> ..
> 22 #define B_STORAGE_ERROR_BASE (B_GENERAL_ERROR_BASE + 0x6000)
> ...
> 106 #define B_NAME_TOO_LONG (B_STORAGE_ERROR_BASE + 4)
> ...
> 211 #define ENAMETOOLONG B_TO_POSIX_ERROR(B_NAME_TOO_LONG)
>
> so the array ends up beeing indeed too big.
>
> Since POSIX errno can't be use as indexes on Haiku,
> rewrite errno_mips() using a switch statement.
>
> [*] https://github.com/haiku/haiku/blob/r1beta3/headers/os/support/Errors.h#L130
>
> Reported-by: Richard Zak <richard.j.zak@gmail.com>
> Suggested-by: Thomas Huth <thuth@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> Supersedes: <20210704170736.617895-4-f4bug@amsat.org>
> ---
> target/mips/tcg/sysemu/mips-semi.c | 24 +++++++++---------------
> 1 file changed, 9 insertions(+), 15 deletions(-)
>
> diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c
> index 77108b0b1a9..b4a383ae90c 100644
> --- a/target/mips/tcg/sysemu/mips-semi.c
> +++ b/target/mips/tcg/sysemu/mips-semi.c
> @@ -74,25 +74,19 @@ enum UHIOpenFlags {
> UHIOpen_EXCL = 0x800
> };
>
> -/* Errno values taken from asm-mips/errno.h */
> -static const uint16_t host_to_mips_errno[] = {
> - [ENAMETOOLONG] = 78,
> +static int errno_mips(int host_errno)
> +{
> + /* Errno values taken from asm-mips/errno.h */
> + switch (host_errno) {
> + case 0: return 0;
> + case ENAMETOOLONG: return 78;
> #ifdef EOVERFLOW
> - [EOVERFLOW] = 79,
> + case EOVERFLOW: return 79;
> #endif
> #ifdef ELOOP
> - [ELOOP] = 90,
> + case ELOOP: return 90;
> #endif
> -};
> -
> -static int errno_mips(int err)
> -{
> - if (err < 0 || err >= ARRAY_SIZE(host_to_mips_errno)) {
> - return EINVAL;
> - } else if (host_to_mips_errno[err]) {
> - return host_to_mips_errno[err];
> - } else {
> - return err;
> + default: return EINVAL;
> }
> }
Reviewed-by: Thomas Huth <thuth@redhat.com>
I assume you'll do the number fixup (your previous "target/mips: Fix UHI
error values" patch) on top of this now?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] target/mips: Rewrite UHI errno_mips() using switch statement
2021-07-06 13:35 ` Thomas Huth
@ 2021-07-06 13:45 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-07-06 13:45 UTC (permalink / raw)
To: Thomas Huth, qemu-devel
Cc: Peter Maydell, Aleksandar Rikalo, Alexander von Gluck IV,
Leon Alrae, Richard Henderson, Richard Zak, Alex Bennée,
Aurelien Jarno
On 7/6/21 3:35 PM, Thomas Huth wrote:
> On 06/07/2021 15.07, Philippe Mathieu-Daudé wrote:
>> Linking on Haiku OS fails:
>>
>>
>> /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
>>
>> error:
>> libqemu-mips-softmmu.fa.p/target_mips_tcg_sysemu_mips-semi.c.o(.rodata) is
>> too large (0xffff405a bytes)
>>
>> /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
>>
>> final link failed: memory exhausted
>> collect2: error: ld returned 1 exit status
>>
>> This is because the host_to_mips_errno[] uses errno as index,
>> for example:
>>
>> static const uint16_t host_to_mips_errno[] = {
>> [ENAMETOOLONG] = 91,
>> ...
>>
>> and Haiku defines [*] ENAMETOOLONG as:
>>
>> 12 /* Error baselines */
>> 13 #define B_GENERAL_ERROR_BASE INT_MIN
>> ..
>> 22 #define B_STORAGE_ERROR_BASE (B_GENERAL_ERROR_BASE
>> + 0x6000)
>> ...
>> 106 #define B_NAME_TOO_LONG (B_STORAGE_ERROR_BASE
>> + 4)
>> ...
>> 211 #define ENAMETOOLONG
>> B_TO_POSIX_ERROR(B_NAME_TOO_LONG)
>>
>> so the array ends up beeing indeed too big.
>>
>> Since POSIX errno can't be use as indexes on Haiku,
>> rewrite errno_mips() using a switch statement.
>>
>> [*]
>> https://github.com/haiku/haiku/blob/r1beta3/headers/os/support/Errors.h#L130
>>
>>
>> Reported-by: Richard Zak <richard.j.zak@gmail.com>
>> Suggested-by: Thomas Huth <thuth@redhat.com>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> Supersedes: <20210704170736.617895-4-f4bug@amsat.org>
>> ---
>> target/mips/tcg/sysemu/mips-semi.c | 24 +++++++++---------------
>> 1 file changed, 9 insertions(+), 15 deletions(-)
>>
>> diff --git a/target/mips/tcg/sysemu/mips-semi.c
>> b/target/mips/tcg/sysemu/mips-semi.c
>> index 77108b0b1a9..b4a383ae90c 100644
>> --- a/target/mips/tcg/sysemu/mips-semi.c
>> +++ b/target/mips/tcg/sysemu/mips-semi.c
>> @@ -74,25 +74,19 @@ enum UHIOpenFlags {
>> UHIOpen_EXCL = 0x800
>> };
>> -/* Errno values taken from asm-mips/errno.h */
>> -static const uint16_t host_to_mips_errno[] = {
>> - [ENAMETOOLONG] = 78,
>> +static int errno_mips(int host_errno)
>> +{
>> + /* Errno values taken from asm-mips/errno.h */
>> + switch (host_errno) {
>> + case 0: return 0;
>> + case ENAMETOOLONG: return 78;
>> #ifdef EOVERFLOW
>> - [EOVERFLOW] = 79,
>> + case EOVERFLOW: return 79;
>> #endif
>> #ifdef ELOOP
>> - [ELOOP] = 90,
>> + case ELOOP: return 90;
>> #endif
>> -};
>> -
>> -static int errno_mips(int err)
>> -{
>> - if (err < 0 || err >= ARRAY_SIZE(host_to_mips_errno)) {
>> - return EINVAL;
>> - } else if (host_to_mips_errno[err]) {
>> - return host_to_mips_errno[err];
>> - } else {
>> - return err;
>> + default: return EINVAL;
>> }
>> }
>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
>
> I assume you'll do the number fixup (your previous "target/mips: Fix UHI
> error values" patch) on top of this now?
The semihosting errnos are incorrect since the feature got introduced,
so I suppose nobody really uses this code, and fixing it is not urgent.
Since soft-freeze is close, I prefer to simply unblock Richard build.
Thanks for the simple suggestion and review!
Phil.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-06 13:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 13:07 [PATCH v2] target/mips: Rewrite UHI errno_mips() using switch statement Philippe Mathieu-Daudé
2021-07-06 13:35 ` Thomas Huth
2021-07-06 13:45 ` Philippe Mathieu-Daudé
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.