-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Build error with GCC10 in mux.c: missing memmove, memset and memcpy #3880
Comments
@fredoh9 @lgirdwood I am not sure if this is GCC compiler issue, SOF code issue or Docker build issue. Will try to reproduce with local GCC compiler. |
@xiulipan it looks like we are assigning a > 32bit variable and hence GCC will try and call the C library. Quickest way to solve is to define memmove() |
@lgirdwood do we need to add memmove.S like memcopy.S (src/arch/xtensa/hal/memcopy.S). Do you have one? |
After resolving memmove error, now linker complains memset().
|
After resolving memset(), now I'm able to build build_apl_gcc/sof-apl.ri. And I tried with byt cnl icl jsl tgl tgl-h, all are working fine. So it looks memmove() and memset() are only the problem. @lgirdwood I made a quick workaround on src/audio/mux/mux.c and src/platform/intel/cavs/boot_loader.c respectively. I copied the function from gcc library below. |
@fredoh9 you cant copy due to license, can you re-implement both functions and add them. Look at existing memcopy_s for guidance. Thanks |
Interesting, when compiling with gcc8 -O3 I noticed this:
|
GCC8 also have same problem? I didn't notice. Let me try with GCC8 local setup. |
only when you manually hardcode -O3 in CMake |
Not worth wasting time with GCC -O3 (xtensa optimisation bugs) |
There's no optimization bug with xtensa-gcc 8.1, it is rather almost as you said:
The source location is wrong but the rest of the error message makes sense and the behavior is documented. By trial and error I isolated the missing --- a/src/platform/intel/cavs/boot_loader.c
+++ b/src/platform/intel/cavs/boot_loader.c
@@ -73,7 +73,7 @@ static inline void bbzero(void *dest, size_t bytes)
int i;
for (i = 0; i < (bytes >> 2); i++)
- d[i] = 0;
+ d[i] = 1;
dcache_writeback_region(dest, bytes);
} @fredoh9 can you test this one character change with gcc10? Of course this is not a fix but just a demonstration of the issue which is: even in freestanding mode (no libc) gcc feels free to optimize code into a Some references:
[*] EDIT: no, |
BTW I did not look for other |
Initial commit c0dfb4e added cc: @cujomalainey of clang "fame" (fd398c9, 149adda, ...) |
@fredoh9 can you apply this test, then rebuild after a build clean. I've altered the CT-ng C library config for GCC10 so we can now take the code from the C library. You may need to rename the other funcs too (and build clean) diff --git a/src/arch/xtensa/CMakeLists.txt b/src/arch/xtensa/CMakeLists.txt
index 1ae3f88b9..1d58be9b3 100644
--- a/src/arch/xtensa/CMakeLists.txt
+++ b/src/arch/xtensa/CMakeLists.txt
@@ -216,7 +216,7 @@ else()
target_link_libraries(sof_static_libraries INTERFACE reset)
endif()
-target_link_libraries(sof_ld_flags INTERFACE "-Wl,-Map=sof.map")
+target_link_libraries(sof_ld_flags INTERFACE "-Wl,-Map=sof.map -lc")
target_link_libraries(sof_ld_flags INTERFACE "-T${PROJECT_BINARY_DIR}/${platform_ld_script}")
add_custom_target(
diff --git a/src/lib/lib.c b/src/lib/lib.c
index 09a1adec6..8de101451 100644
--- a/src/lib/lib.c
+++ b/src/lib/lib.c
@@ -9,6 +9,8 @@
#include <stddef.h>
#include <stdint.h>
+void *memset1(void *s, int c, size_t n);
+
/* Not needed for host or Zephyr */
#if !CONFIG_LIBRARY && !__ZEPHYR__
/* used by gcc - but uses arch_memcpy internally */
@@ -19,7 +21,7 @@ void *memcpy(void *dest, const void *src, size_t n)
}
/* generic memset */
-void *memset(void *s, int c, size_t n)
+void *memset1(void *s, int c, size_t n)
{
uint8_t *d8 = s;
uint8_t v = c; |
@marc-hb thanks for the FYI, once we have a solution here I will test it against the fuzzer build to see if we will break that |
Sorry, wrong keyboard shortcut |
@fredoh9 we will need
So here's the GCC output if anyone is interested, a nice recusive crash picked up by qemu here. /* generic memset */
void *memset(void *s, int c, size_t n)
{
ff2cb3d4: 004136 entry a1, 32
uint8_t *d8 = s;
uint8_t v = c;
int i;
for (i = 0; i < n; i++)
ff2cb3d7: 948c beqz.n a4, ff2cb3e4 <memset+0x10>
d8[i] = v;
ff2cb3d9: 04cd mov.n a12, a4
ff2cb3db: 74b030 extui a11, a3, 0, 8
ff2cb3de: 20a220 or a10, a2, a2
ff2cb3e1: ffff25 call8 ff2cb3d4 <memset> <<<< WRONG, confusion over this being a local branch or external call
return s;
}
ff2cb3e4: f01d retw.n
... |
for the information, Latest #3938 patch is compiled with GCC 10 toolchains.
QEMU boot test also passed. |
Very scary |
@marc-hb good find ! |
Describe the bug
After #3848 merged, when build SOF with latest GCC10 binary, got below error on all cavs platform
To Reproduce
Reproduction Rate
10/10
Expected behavior
Build pass without error
Impact
GCC10 docker image could not be used in CI
The text was updated successfully, but these errors were encountered: