Broken RISC-V code in newlib
Jeff Law
jlaw@ventanamicro.com
Tue Mar 25 15:04:42 GMT 2025
On 3/25/25 8:23 AM, Kito Cheng wrote:
> Hi Eric:
>
>> diff --git a/newlib/libc/machine/riscv/sys/asm.h b/newlib/libc/machine/riscv/sys/asm.h
>> index 0a354b220517..a9792e964ebc 100644
>> --- a/newlib/libc/machine/riscv/sys/asm.h
>> +++ b/newlib/libc/machine/riscv/sys/asm.h
>> @@ -12,7 +12,9 @@
>> #ifndef _SYS_ASM_H
>> #define _SYS_ASM_H
>>
>> +#if !__ASSEMBLER__
>> #include <stdint.h>
>> +#endif
>>
>> /*
>> * Macros to handle different pointer/register sizes for 32/64-bit code
>> @@ -22,13 +24,17 @@
>> # define SZREG 8
>> # define REG_S sd
>> # define REG_L ld
>> +#if !__ASSEMBLER__
>> typedef uint64_t uintxlen_t;
>> +#endif
>> #elif __riscv_xlen == 32
>> # define PTRLOG 2
>> # define SZREG 4
>> # define REG_S sw
>> # define REG_L lw
>> +#if !__ASSEMBLER__
>> typedef uint32_t uintxlen_t;
>> +#endif
>> #else
>> # error __riscv_xlen must equal 32 or 64
>> #endif
>
> Seems like sys/asm.h is not the right place to put those C typedef and
> also including #include <stdint.h>
>
> Could you just create a xlenint.h in newlib/libc/machine/riscv/ then
> include that by #include "xlenint.h" in those places you want to use?
>
> Since uintxlen_t is not defined in either standard C or RISC-V
> conventions, so I would like to prevent exposing that to users if
> possible :)
In fact, the typedef really should be prefixed with underscores from a
namespace pollution standpoint. It's not OK for headers to be defining
types like this.
jeff
More information about the Newlib
mailing list