linux-stable/tools/include/nolibc
Willy Tarreau 141fe35cb1 tools/nolibc: prevent gcc from making memset() loop over itself
[ Upstream commit 1bfbe1f3e9 ]

When building on ARM in thumb mode with gcc-11.3 at -O2 or -O3,
nolibc-test segfaults during the select() tests. It turns out that at
this level, gcc recognizes an opportunity for using memset() to zero
the fd_set, but it miscompiles it because it also recognizes a memset
pattern as well, and decides to call memset() from the memset() code:

  000122bc <memset>:
     122bc:       b510            push    {r4, lr}
     122be:       0004            movs    r4, r0
     122c0:       2a00            cmp     r2, #0
     122c2:       d003            beq.n   122cc <memset+0x10>
     122c4:       23ff            movs    r3, #255        ; 0xff
     122c6:       4019            ands    r1, r3
     122c8:       f7ff fff8       bl      122bc <memset>
     122cc:       0020            movs    r0, r4
     122ce:       bd10            pop     {r4, pc}

Simply placing an empty asm() statement inside the loop suffices to
avoid this.

Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-02-01 08:34:31 +01:00
..
arch-aarch64.h tools/nolibc: Remove .global _start from the entry point code 2022-04-20 17:05:46 -07:00
arch-arm.h tools/nolibc: Remove .global _start from the entry point code 2022-04-20 17:05:46 -07:00
arch-i386.h tools/nolibc: i386: Implement syscall with 6 arguments 2022-04-20 17:05:46 -07:00
arch-mips.h tools/nolibc: restore mips branch ordering in the _start block 2023-01-18 11:58:27 +01:00
arch-riscv.h tools/nolibc: fix the O_* fcntl/open macro definitions for riscv 2023-01-18 11:58:27 +01:00
arch-x86_64.h tools/nolibc: Remove .global _start from the entry point code 2022-04-20 17:05:46 -07:00
arch.h tools/nolibc/arch: split arch-specific code into individual files 2022-04-20 17:05:43 -07:00
ctype.h tools/nolibc: fix missing includes causing build issues at -O0 2023-02-01 08:34:31 +01:00
errno.h tools/nolibc: fix missing includes causing build issues at -O0 2023-02-01 08:34:31 +01:00
Makefile tools/nolibc: add a help target to list supported targets 2022-06-20 09:43:19 -07:00
nolibc.h tools/nolibc: also mention how to build by just setting the include path 2022-04-20 17:05:45 -07:00
signal.h tools/nolibc: fix missing includes causing build issues at -O0 2023-02-01 08:34:31 +01:00
std.h tools/nolibc/std: move the standard type definitions to std.h 2022-04-20 17:05:33 -07:00
stdio.h tools/nolibc: fix missing includes causing build issues at -O0 2023-02-01 08:34:31 +01:00
stdlib.h tools/nolibc: fix missing includes causing build issues at -O0 2023-02-01 08:34:31 +01:00
string.h tools/nolibc: prevent gcc from making memset() loop over itself 2023-02-01 08:34:31 +01:00
sys.h tools/nolibc: fix missing includes causing build issues at -O0 2023-02-01 08:34:31 +01:00
time.h tools/nolibc: fix missing includes causing build issues at -O0 2023-02-01 08:34:31 +01:00
types.h tools/nolibc: fix missing includes causing build issues at -O0 2023-02-01 08:34:31 +01:00
unistd.h tools/nolibc: fix missing includes causing build issues at -O0 2023-02-01 08:34:31 +01:00