[v2] newlib: riscv: Fix build and reorganize header files
Commit Message
The sys/asm.h header file is included for certain assembly files, so
move the typedef to a separate header file due to the build breaking on
some systems. Also include the port's string header file (and move and
rename) instead of the system's version.
Addresses: https://sourceware.org/pipermail/newlib/2025/021591.html
Fixes: c3b9bb173c8c ("newlib: riscv: Add XLEN typedef and clean up types")
Reported-by: Jeff Law <jlaw@ventanamicro.com>
Suggested-by: Kito Cheng <kito.cheng@gmail.com>
Signed-off-by: Eric Salem <ericsalem@gmail.com>
---
Changes in v2:
- Move header files and rename string.h to avoid confusion
- Use "" for #include for header files in same directory
- Link to v1: https://sourceware.org/pipermail/newlib/2025/021609.html
.../machine/riscv/{sys/string.h => rv_string.h} | 8 ++++----
newlib/libc/machine/riscv/stpcpy.c | 2 +-
newlib/libc/machine/riscv/strcpy.c | 2 +-
newlib/libc/machine/riscv/strlen.c | 2 +-
newlib/libc/machine/riscv/sys/asm.h | 4 ----
newlib/libc/machine/riscv/xlenint.h | 14 ++++++++++++++
6 files changed, 21 insertions(+), 11 deletions(-)
rename newlib/libc/machine/riscv/{sys/string.h => rv_string.h} (97%)
create mode 100644 newlib/libc/machine/riscv/xlenint.h
Comments
On Apr 1 22:00, Eric Salem wrote:
> The sys/asm.h header file is included for certain assembly files, so
> move the typedef to a separate header file due to the build breaking on
> some systems. Also include the port's string header file (and move and
> rename) instead of the system's version.
>
> Addresses: https://sourceware.org/pipermail/newlib/2025/021591.html
> Fixes: c3b9bb173c8c ("newlib: riscv: Add XLEN typedef and clean up types")
> Reported-by: Jeff Law <jlaw@ventanamicro.com>
> Suggested-by: Kito Cheng <kito.cheng@gmail.com>
> Signed-off-by: Eric Salem <ericsalem@gmail.com>
> ---
> Changes in v2:
> - Move header files and rename string.h to avoid confusion
> - Use "" for #include for header files in same directory
> - Link to v1: https://sourceware.org/pipermail/newlib/2025/021609.html
>
> .../machine/riscv/{sys/string.h => rv_string.h} | 8 ++++----
> newlib/libc/machine/riscv/stpcpy.c | 2 +-
> newlib/libc/machine/riscv/strcpy.c | 2 +-
> newlib/libc/machine/riscv/strlen.c | 2 +-
> newlib/libc/machine/riscv/sys/asm.h | 4 ----
> newlib/libc/machine/riscv/xlenint.h | 14 ++++++++++++++
> 6 files changed, 21 insertions(+), 11 deletions(-)
> rename newlib/libc/machine/riscv/{sys/string.h => rv_string.h} (97%)
> create mode 100644 newlib/libc/machine/riscv/xlenint.h
Pushed.
Thanks,
Corinna
similarity index 97%
rename from newlib/libc/machine/riscv/sys/string.h
rename to newlib/libc/machine/riscv/rv_string.h
@@ -9,11 +9,11 @@
http://www.opensource.org/licenses.
*/
-#ifndef _SYS_STRING_H
-#define _SYS_STRING_H
+#ifndef _RV_STRING_H
+#define _RV_STRING_H
#include <stdbool.h>
-#include "asm.h"
+#include "xlenint.h"
#if __riscv_zbb
#include <riscv_bitmanip.h>
@@ -121,4 +121,4 @@ static __inline char *__libc_strcpy(char *dst, const char *src, bool ret_start)
}
-#endif
+#endif /* _RV_STRING_H */
@@ -1,5 +1,5 @@
-#include <string.h>
#include <stdbool.h>
+#include "rv_string.h"
char *stpcpy(char *dst, const char *src)
{
@@ -9,8 +9,8 @@
http://www.opensource.org/licenses.
*/
-#include <string.h>
#include <stdbool.h>
+#include "rv_string.h"
char *strcpy(char *dst, const char *src)
{
@@ -11,7 +11,7 @@
#include <string.h>
#include <stdint.h>
-#include "sys/asm.h"
+#include "rv_string.h"
size_t strlen(const char *str)
{
@@ -12,8 +12,6 @@
#ifndef _SYS_ASM_H
#define _SYS_ASM_H
-#include <stdint.h>
-
/*
* Macros to handle different pointer/register sizes for 32/64-bit code
*/
@@ -22,13 +20,11 @@
# define SZREG 8
# define REG_S sd
# define REG_L ld
-typedef uint64_t uintxlen_t;
#elif __riscv_xlen == 32
# define PTRLOG 2
# define SZREG 4
# define REG_S sw
# define REG_L lw
-typedef uint32_t uintxlen_t;
#else
# error __riscv_xlen must equal 32 or 64
#endif
new file mode 100644
@@ -0,0 +1,14 @@
+#ifndef _XLENINT_H
+#define _XLENINT_H
+
+#include <stdint.h>
+
+#if __riscv_xlen == 64
+typedef uint64_t uintxlen_t;
+#elif __riscv_xlen == 32
+typedef uint32_t uintxlen_t;
+#else
+# error __riscv_xlen must equal 32 or 64
+#endif
+
+#endif /* _XLENINT_H */