Skip to contentSkip to conversation

Misc compile error/warning fixes

PATCH Superseded Anup Patel 5 participants 12 messages Dec 2, 2021 – Dec 3, 2021 Kbuild

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v3 cover Misc compile error/warning fixes

This series does few compile error/warning fixes which I discovered trying CLANG with OpenSBI.

These patches can also be found in clang_fixes_v3 branch at:
https://github.com/riscv-software-src/opensbi.git

Changes since v2:
- Make memcpy() and memset() as weak-alias of sbi_memcpy() and sbi_memset() respectively in PATCH2

Changes since v1:
- Use explicit inline macro sbi_trap_info_init() in PATCH2 for initializing struct sbi_trap_info.

Anup Patel (2):
Makefile: Fix -mno-save-restore compile warning with CLANG
lib: sbi: Fix compile errors using -Os option

 Makefile             | 12 ++++++++----
 lib/sbi/sbi_string.c |  6 ++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v3 1/2 Makefile: Fix -mno-save-restore compile warning with CLANG

The riscv target of CLANG does not support -m(no-)save-restore option so we get compile warnings. This patch fixes compile warning by using -m(no-)save-restore option only for GCC.

---
 Makefile | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
Makefile +8 -4
index 8623c1c..1e35dc0 100644
@@ -275,8 +275,10 @@ GENFLAGS	+=	$(platform-genflags-y)
 GENFLAGS	+=	$(firmware-genflags-y)
 
 CFLAGS		=	-g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -O2
-CFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls
-CFLAGS		+=	-mno-save-restore -mstrict-align
+CFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls -mstrict-align
+ifneq ($(CC_IS_CLANG),y)
+CFLAGS		+=	-mno-save-restore
+endif
 CFLAGS		+=	-mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA)
 CFLAGS		+=	-mcmodel=$(PLATFORM_RISCV_CODE_MODEL)
 CFLAGS		+=	$(RELAX_FLAG)
@@ -290,8 +292,10 @@ CPPFLAGS	+=	$(platform-cppflags-y)
 CPPFLAGS	+=	$(firmware-cppflags-y)
 
 ASFLAGS		=	-g -Wall -nostdlib
-ASFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls
-ASFLAGS		+=	-mno-save-restore -mstrict-align
+ASFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls -mstrict-align
+ifneq ($(CC_IS_CLANG),y)
+ASFLAGS		+=	-mno-save-restore
+endif
 ASFLAGS		+=	-mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA)
 ASFLAGS		+=	-mcmodel=$(PLATFORM_RISCV_CODE_MODEL)
 ASFLAGS		+=	$(RELAX_FLAG)
Signature · 1 line
2.25.1
#2 lore raw

PATCH v3 1/2 Makefile: Fix -mno-save-restore compile warning with CLANG

Quoted 5 lines · anup patel anup.patel at wdc.com

The riscv target of CLANG does not support -m(no-)save-restore option so we get compile warnings. This patch fixes compile warning by using -m(no-)save-restore option only for GCC.

Looks good to me.

Quoted 43 lines

---
Makefile | 12 ++++++++----

1 file changed, 8 insertions(+), 4 deletions(-)
Makefile +0 -0
index 8623c1c..1e35dc0 100644
@@ -275,8 +275,10 @@ GENFLAGS	+=	$(platform-genflags-y)
 GENFLAGS	+=	$(firmware-genflags-y)
 

CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector

Makefile +4 -3
-fno-strict-aliasing -O2
-CFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls
-CFLAGS		+=	-mno-save-restore -mstrict-align
+CFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls -mstrict-align
+ifneq ($(CC_IS_CLANG),y)
+CFLAGS		+=	-mno-save-restore
+endif

CFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA)
CFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL)
CFLAGS += $(RELAX_FLAG)

Makefile +0 -0
@@ -290,8 +292,10 @@ CPPFLAGS	+=	$(platform-cppflags-y)
 CPPFLAGS	+=	$(firmware-cppflags-y)
 

ASFLAGS = -g -Wall -nostdlib

Makefile +4 -2
-ASFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls
-ASFLAGS		+=	-mno-save-restore -mstrict-align
+ASFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls -mstrict-align
+ifneq ($(CC_IS_CLANG),y)
+ASFLAGS		+=	-mno-save-restore
+endif

ASFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA)
ASFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL)
ASFLAGS += $(RELAX_FLAG)
--
2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#3 lore raw

PATCH v3 1/2 Makefile: Fix -mno-save-restore compile warning with CLANG

In reply to Anup Patel

? 2021-12-02???? 17:59 +0530?Anup Patel???

Quoted 5 lines

The riscv target of CLANG does not support -m(no-)save-restore option so we get compile warnings. This patch fixes compile warning by using -m(no-)save-restore option only for GCC.

?  /tmp clang -target riscv64 -mno-save-restore -O2 -S test.c
?  /tmp clang -target riscv64 -msave-restore -O2 -S test.c 
?  /tmp clang --version                                      

Debian clang version 11.0.1-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
? /tmp lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
? /tmp

clang supports -m(no-)save-restore option on my computer

Regards,
Xiang W

Quoted 45 lines

---
?Makefile | 12 ++++++++----
?1 file changed, 8 insertions(+), 4 deletions(-)

Makefile +0 -0
index 8623c1c..1e35dc0 100644
@@ -275,8 +275,10 @@ GENFLAGS???+=??????$(platform-genflags-y)
 ?GENFLAGS???????+=??????$(firmware-genflags-y)

?
?CFLAGS?????????=???????-g -Wall -Werror -ffreestanding -nostdlib - fno-stack-protector -fno-strict-aliasing -O2 -CFLAGS?????????+=??????-fno-omit-frame-pointer -fno-optimize- sibling-calls

Makefile +1 -1
-CFLAGS?????????+=??????-mno-save-restore -mstrict-align
+CFLAGS?????????+=??????-fno-omit-frame-pointer -fno-optimize-

sibling-calls -mstrict-align

Makefile +3 -0
+ifneq ($(CC_IS_CLANG),y)
+CFLAGS?????????+=??????-mno-save-restore
+endif

?CFLAGS?????????+=??????-mabi=$(PLATFORM_RISCV_ABI) - march=$(PLATFORM_RISCV_ISA) ?CFLAGS?????????+=??????-mcmodel=$(PLATFORM_RISCV_CODE_MODEL) ?CFLAGS?????????+=??????$(RELAX_FLAG)

Makefile +0 -0
@@ -290,8 +292,10 @@ CPPFLAGS???+=??????$(platform-cppflags-y)
 ?CPPFLAGS???????+=??????$(firmware-cppflags-y)

?
?ASFLAGS????????????????=???????-g -Wall -nostdlib -ASFLAGS????????????????+=??????-fno-omit-frame-pointer -fno- optimize-sibling-calls

Makefile +1 -1
-ASFLAGS????????????????+=??????-mno-save-restore -mstrict-align
+ASFLAGS????????????????+=??????-fno-omit-frame-pointer -fno-

optimize-sibling-calls -mstrict-align

Makefile +3 -0
+ifneq ($(CC_IS_CLANG),y)
+ASFLAGS????????????????+=??????-mno-save-restore
+endif

?ASFLAGS????????????????+=??????-mabi=$(PLATFORM_RISCV_ABI) - march=$(PLATFORM_RISCV_ISA) ?ASFLAGS????????????????+=??????-mcmodel=$(PLATFORM_RISCV_CODE_MODEL) ?ASFLAGS????????????????+=??????$(RELAX_FLAG)

Signature · 1 line
2.25.1
#4 lore raw

PATCH v3 1/2 Makefile: Fix -mno-save-restore compile warning with CLANG

Quoted 23 lines · Xiang W

? 2021-12-02???? 17:59 +0530?Anup Patel???

Quoted 5 lines

The riscv target of CLANG does not support -m(no-)save-restore option so we get compile warnings. This patch fixes compile warning by using -m(no-)save-restore option only for GCC.

?  /tmp clang -target riscv64 -mno-save-restore -O2 -S test.c
?  /tmp clang -target riscv64 -msave-restore -O2 -S test.c 
?  /tmp clang --version                                      

Debian clang version 11.0.1-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
? /tmp lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
? /tmp

Quoted 1 line

clang supports -m(no-)save-restore option on my computer

Yes, Clang 11 and above support -m(no-)save-restore. Clang 9 and 10 support the driver option but were buggy and would cause the backend to give several warnings even if you just gave -mno-save-restore
(https://reviews.llvm.org/D64008, which did make it into Clang 9, was not a complete fix for that, see my comment there). Clang 8 and below didn?t support the option in the driver, but the RISCV backend only graduated from experimental status in Clang 9 so, whilst it was in relatively decent shape before then, such versions should probably be discouraged.

In theory not passing the option is fine, there isn?t currently a way to configure Clang to default to -msave-restore other than patching it, though only skipping it for Clang 10 and below would be preferable. Either way the commit message needs updating.

Or you could just say it?s not worth caring and leave the warnings for Clang 9 and 10; with time they?ll stop being relevant, and they?re stderr output, not real diagnostics, so -Werror doesn?t make them fatal. That?s probably the approach I?d take, but I don?t have to work with old versions of Clang on RISC-V.

Jess

#5 lore raw

PATCH v3 1/2 Makefile: Fix -mno-save-restore compile warning with CLANG

Quoted 37 lines · Jessica Clarke
Quoted 17 lines · Xiang W

? 2021-12-02???? 17:59 +0530?Anup Patel???

Quoted 5 lines

The riscv target of CLANG does not support -m(no-)save-restore option so we get compile warnings. This patch fixes compile warning by using -m(no-)save-restore option only for GCC.

?  /tmp clang -target riscv64 -mno-save-restore -O2 -S test.c
?  /tmp clang -target riscv64 -msave-restore -O2 -S test.c
?  /tmp clang --version

Debian clang version 11.0.1-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
? /tmp lsb_release -a
No LSB modules are available.

Quoted 7 lines
Distributor ID:       Debian
Description:  Debian GNU/Linux 11 (bullseye)
Release:      11
Codename:     bullseye

? /tmp

clang supports -m(no-)save-restore option on my computer

Yes, Clang 11 and above support -m(no-)save-restore. Clang 9 and 10 support the driver option but were buggy and would cause the backend to give several warnings even if you just gave -mno-save-restore
(https://reviews.llvm.org/D64008, which did make it into Clang 9, was not a complete fix for that, see my comment there). Clang 8 and below didn?t support the option in the driver, but the RISCV backend only graduated from experimental status in Clang 9 so, whilst it was in relatively decent shape before then, such versions should probably be discouraged.

Quoted 4 lines

In theory not passing the option is fine, there isn?t currently a way to configure Clang to default to -msave-restore other than patching it, though only skipping it for Clang 10 and below would be preferable. Either way the commit message needs updating.

Okay, I will update the commit message and also add a comment in Makefile.

Quoted 6 lines

Or you could just say it?s not worth caring and leave the warnings for Clang 9 and 10; with time they?ll stop being relevant, and they?re stderr output, not real diagnostics, so -Werror doesn?t make them fatal. That?s probably the approach I?d take, but I don?t have to work with old versions of Clang on RISC-V.

I am inclined towards suppressing this warning for now because apart from this warning OpenSBI works fine with clang-10. Once all major distros have moved to clang-11 (or higher), we can update the Makefile (maybe after 6-12 months).

Regards,
Anup

Quoted 3 lines

Jess

#6 lore raw

PATCH v3 1/2 Makefile: Fix -mno-save-restore compile warning with CLANG

In reply to Jessica Clarke

? 2021-12-02???? 15:12 +0000?Jessica Clarke???

Quoted 53 lines · Xiang W
Quoted 25 lines

? 2021-12-02???? 17:59 +0530?Anup Patel???

Quoted 7 lines

The riscv target of CLANG does not support -m(no-)save-restore option
so we get compile warnings. This patch fixes compile warning by using
-m(no-)save-restore option only for GCC.

?? /tmp clang -target riscv64 -mno-save-restore -O2 -S test.c ?? /tmp clang -target riscv64 -msave-restore -O2 -S test.c ?? /tmp clang --version????????????????????????????????????? Debian clang version 11.0.1-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
?? /tmp lsb_release -a
No LSB modules are available.
Distributor ID:?Debian
Description:????Debian GNU/Linux 11 (bullseye) Release:????????11
Codename:???????bullseye
?? /tmp

Quoted 1 line

clang supports -m(no-)save-restore option on my computer

Yes, Clang 11 and above support -m(no-)save-restore. Clang 9 and 10 support the driver option but were buggy and would cause the backend to
give several warnings even if you just gave -mno-save-restore
(https://reviews.llvm.org/D64008, which did make it into Clang 9, was not a complete fix for that, see my comment there). Clang 8 and below didn?t support the option in the driver, but the RISCV backend only graduated from experimental status in Clang 9 so, whilst it was in relatively decent shape before then, such versions should probably be discouraged.

In theory not passing the option is fine, there isn?t currently a way to configure Clang to default to -msave-restore other than patching it,
though only skipping it for Clang 10 and below would be preferable. Either way the commit message needs updating.

Or you could just say it?s not worth caring and leave the warnings for
Clang 9 and 10; with time they?ll stop being relevant, and they?re stderr output, not real diagnostics, so -Werror doesn?t make them fatal.
That?s probably the approach I?d take, but I don?t have to work with old versions of Clang on RISC-V.

Quoted 1 line

Jess

Thanks for the reply.

Regards,
Xiang W

#7 lore raw

PATCH v3 1/2 Makefile: Fix -mno-save-restore compile warning with CLANG

In reply to Xiang W
Quoted 17 lines · Xiang W

? 2021-12-02???? 17:59 +0530?Anup Patel???

Quoted 5 lines

The riscv target of CLANG does not support -m(no-)save-restore option so we get compile warnings. This patch fixes compile warning by using -m(no-)save-restore option only for GCC.

?  /tmp clang -target riscv64 -mno-save-restore -O2 -S test.c
?  /tmp clang -target riscv64 -msave-restore -O2 -S test.c
?  /tmp clang --version

Debian clang version 11.0.1-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
? /tmp lsb_release -a
No LSB modules are available.

Quoted 7 lines
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

? /tmp

clang supports -m(no-)save-restore option on my computer

I am using clang package available on Ubuntu-20.04 LTS which is still at clang-10.

Regards,
Anup

Quoted 50 lines

Regards,
Xiang W

Quoted 45 lines
---
 Makefile | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
Makefile +0 -0
index 8623c1c..1e35dc0 100644
@@ -275,8 +275,10 @@ GENFLAGS   +=      $(platform-genflags-y)
 GENFLAGS       +=      $(firmware-genflags-y)
 
 CFLAGS         =       -g -Wall -Werror -ffreestanding -nostdlib -

fno-stack-protector -fno-strict-aliasing -O2
-CFLAGS += -fno-omit-frame-pointer -fno-optimize-
sibling-calls

Makefile +1 -1
-CFLAGS         +=      -mno-save-restore -mstrict-align
+CFLAGS         +=      -fno-omit-frame-pointer -fno-optimize-

sibling-calls -mstrict-align

Makefile +3 -0
+ifneq ($(CC_IS_CLANG),y)
+CFLAGS         +=      -mno-save-restore
+endif
 CFLAGS         +=      -mabi=$(PLATFORM_RISCV_ABI) -

march=$(PLATFORM_RISCV_ISA)

 CFLAGS         +=      -mcmodel=$(PLATFORM_RISCV_CODE_MODEL)
 CFLAGS         +=      $(RELAX_FLAG)
Makefile +0 -1
@@ -290,8 +292,10 @@ CPPFLAGS   +=      $(platform-cppflags-y)
 CPPFLAGS       +=      $(firmware-cppflags-y)
 
 ASFLAGS                =       -g -Wall -nostdlib
-ASFLAGS                +=      -fno-omit-frame-pointer -fno-

optimize-sibling-calls

Makefile +1 -1
-ASFLAGS                +=      -mno-save-restore -mstrict-align
+ASFLAGS                +=      -fno-omit-frame-pointer -fno-

optimize-sibling-calls -mstrict-align

Makefile +3 -0
+ifneq ($(CC_IS_CLANG),y)
+ASFLAGS                +=      -mno-save-restore
+endif
 ASFLAGS                +=      -mabi=$(PLATFORM_RISCV_ABI) -

march=$(PLATFORM_RISCV_ISA)

 ASFLAGS                +=      -mcmodel=$(PLATFORM_RISCV_CODE_MODEL)
 ASFLAGS                +=      $(RELAX_FLAG)

--
2.25.1

author
#8 lore raw

PATCH v3 2/2 lib: sbi: Fix compile errors using -Os option

In reply to Anup Patel

When building with -Os option along with -ffreestanding, both GCC and clang will add implicit calls to memcpy() and memcpy() for stack variables initialized in declaration.

The C standard as per Clause 4, the compiler cannot necessarily assume that anything beyond:

* float.h
* iso646.h
* limits.h
* stdalign.h
* stdarg.h
* stdbool.h
* stddef.h
* stdint.h
* stdnoreturn.h
* fenv.h
* math.h
* and the numeric conversion functions of stdlib.h.

This patch maps memcpy() and memset() as weak-alias of sbi_memcpy() and sbi_memset() respectively so that implicit calls to memcpy() and memset() will compile properly.

---
 lib/sbi/sbi_string.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/sbi/sbi_string.c +6 -0
index c87bce9..c67c02e 100644
@@ -122,6 +122,9 @@ void *sbi_memset(void *s, int c, size_t count)
 	return s;
 }
 
+void *memset(void *s, int c, size_t count) \
+__attribute__((weak, alias("sbi_memset")));
+
 void *sbi_memcpy(void *dest, const void *src, size_t count)
 {
 	char *temp1	  = dest;
@@ -135,6 +138,9 @@ void *sbi_memcpy(void *dest, const void *src, size_t count)
 	return dest;
 }
 
+void *memcpy(void *dest, const void *src, size_t count) \
+__attribute__((weak, alias("sbi_memcpy")));
+
 void *sbi_memmove(void *dest, const void *src, size_t count)
 {
 	char *temp1	  = (char *)dest;
Signature · 1 line
2.25.1
#9 lore raw

PATCH v3 2/2 lib: sbi: Fix compile errors using -Os option

Quoted 2 lines · anup patel anup.patel at wdc.com

When building with -Os option along with -ffreestanding, both GCC and clang will add implicit calls to memcpy() and memcpy() for stack

twice memcpy(), should be: memcpy() and memset()

Quoted 18 lines

variables initialized in declaration.

The C standard as per Clause 4, the compiler cannot necessarily assume that anything beyond:

* float.h
* iso646.h
* limits.h
* stdalign.h
* stdarg.h
* stdbool.h
* stddef.h
* stdint.h
* stdnoreturn.h
* fenv.h
* math.h
* and the numeric conversion functions of stdlib.h.

Quoted 5 lines

This patch maps memcpy() and memset() as weak-alias of sbi_memcpy() and sbi_memset() respectively so that implicit calls to memcpy() and memset() will compile properly.

Besides the above nits, looks good to me.

Quoted 36 lines

---
lib/sbi/sbi_string.c | 6 ++++++

1 file changed, 6 insertions(+)
lib/sbi/sbi_string.c +6 -1
index c87bce9..c67c02e 100644
@@ -122,6 +122,9 @@ void *sbi_memset(void *s, int c, size_t count)
 	return s;
 }
 
+void *memset(void *s, int c, size_t count) \
+__attribute__((weak, alias("sbi_memset")));
+
 void *sbi_memcpy(void *dest, const void *src, size_t count)
 {
 	char *temp1	  = dest;
@@ -135,6 +138,9 @@ void *sbi_memcpy(void *dest, const void *src, size_t count)
 	return dest;
 }
 
+void *memcpy(void *dest, const void *src, size_t count) \
+__attribute__((weak, alias("sbi_memcpy")));
+
 void *sbi_memmove(void *dest, const void *src, size_t count)
 {
 	char *temp1	  = (char *)dest;
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#10 lore raw

PATCH v3 2/2 lib: sbi: Fix compile errors using -Os option

Quoted 9 lines · Dong Du
Quoted 2 lines · anup patel anup.patel at wdc.com

When building with -Os option along with -ffreestanding, both GCC and clang will add implicit calls to memcpy() and memcpy() for stack

twice memcpy(), should be: memcpy() and memset()

Okay, will update in next revision.

Quoted 23 lines
Quoted 23 lines

variables initialized in declaration.

The C standard as per Clause 4, the compiler cannot necessarily assume that anything beyond:

* float.h
* iso646.h
* limits.h
* stdalign.h
* stdarg.h
* stdbool.h
* stddef.h
* stdint.h
* stdnoreturn.h
* fenv.h
* math.h
* and the numeric conversion functions of stdlib.h.

This patch maps memcpy() and memset() as weak-alias of sbi_memcpy() and sbi_memset() respectively so that implicit calls to memcpy() and memset() will compile properly.

Quoted 5 lines
Quoted 1 line

Besides the above nits, looks good to me.

Regards,
Anup

Quoted 37 lines
Quoted 37 lines

---
lib/sbi/sbi_string.c | 6 ++++++

1 file changed, 6 insertions(+)
lib/sbi/sbi_string.c +6 -1
index c87bce9..c67c02e 100644
@@ -122,6 +122,9 @@ void *sbi_memset(void *s, int c, size_t count)
      return s;
 }
 
+void *memset(void *s, int c, size_t count) \
+__attribute__((weak, alias("sbi_memset")));
+
 void *sbi_memcpy(void *dest, const void *src, size_t count)
 {
      char *temp1       = dest;
@@ -135,6 +138,9 @@ void *sbi_memcpy(void *dest, const void *src, size_t count)
      return dest;
 }
 
+void *memcpy(void *dest, const void *src, size_t count) \
+__attribute__((weak, alias("sbi_memcpy")));
+
 void *sbi_memmove(void *dest, const void *src, size_t count)
 {
      char *temp1       = (char *)dest;
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#11 lore raw

PATCH v3 2/2 lib: sbi: Fix compile errors using -Os option

In reply to Anup Patel

? 2021-12-02???? 17:59 +0530?Anup Patel???

Quoted 20 lines

When building with -Os option along with -ffreestanding, both GCC and clang will add implicit calls to memcpy() and memcpy() for stack variables initialized in declaration.

The C standard as per Clause 4, the compiler cannot necessarily assume that anything beyond:

?* float.h
?* iso646.h
?* limits.h
?* stdalign.h
?* stdarg.h
?* stdbool.h
?* stddef.h
?* stdint.h
?* stdnoreturn.h
?* fenv.h
?* math.h
?* and the numeric conversion functions of stdlib.h.

Quoted 5 lines

This patch maps memcpy() and memset() as weak-alias of sbi_memcpy() and sbi_memset() respectively so that implicit calls to memcpy() and memset() will compile properly.

Quoted 33 lines

---
?lib/sbi/sbi_string.c | 6 ++++++
?1 file changed, 6 insertions(+)

lib/sbi/sbi_string.c +0 -0
index c87bce9..c67c02e 100644
@@ -122,6 +122,9 @@ void *sbi_memset(void *s, int c, size_t count)
 ????????return s;
 ?}

?

lib/sbi/sbi_string.c +3 -0
+void *memset(void *s, int c, size_t count) \
+__attribute__((weak, alias("sbi_memset")));
+

?void *sbi_memcpy(void *dest, const void *src, size_t count) ?{
????????char *temp1?????? = dest;

lib/sbi/sbi_string.c +0 -0
@@ -135,6 +138,9 @@ void *sbi_memcpy(void *dest, const void *src,
 size_t count)
 ????????return dest;
 ?}

?

lib/sbi/sbi_string.c +3 -0
+void *memcpy(void *dest, const void *src, size_t count) \
+__attribute__((weak, alias("sbi_memcpy")));
+

?void *sbi_memmove(void *dest, const void *src, size_t count) ?{
????????char *temp1?????? = (char *)dest;

Signature · 1 line
2.25.1