Allow building usr.bin/vi with MK_ASAN

We have to namespace the regex functions to avoid duplicate symbol errors.
This also ensures that vi doesn't define the libc reg* functions with
mismatched signatures.

ld: error: duplicate symbol: regcomp
>>> defined at sanitizer_common_interceptors.inc:7519 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:7519)
>>>            asan_interceptors.o:(__interceptor_regcomp) in archive /usr/lib/clang/10.0.1/lib/freebsd/libclang_rt.asan-x86_64.a
>>> defined at regcomp.c
>>>            .../regex/regcomp.c.o:(.text+0x0)

ld: error: duplicate symbol: regerror
>>> defined at sanitizer_common_interceptors.inc:7543 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:7543)
>>>            asan_interceptors.o:(__interceptor_regerror) in archive /usr/lib/clang/10.0.1/lib/freebsd/libclang_rt.asan-x86_64.a
>>> defined at regerror.c
>>>            .../regex/regerror.c.o:(.text+0x0)

ld: error: duplicate symbol: regexec
>>> defined at sanitizer_common_interceptors.inc:7530 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:7530)
>>>            asan_interceptors.o:(__interceptor_regexec) in archive /usr/lib/clang/10.0.1/lib/freebsd/libclang_rt.asan-x86_64.a
>>> defined at regexec.c
>>>            .../regex/regexec.c.o:(.text+0x0)

ld: error: duplicate symbol: regfree
>>> defined at sanitizer_common_interceptors.inc:7553 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:7553)
>>>            asan_interceptors.o:(__interceptor_regfree) in archive /usr/lib/clang/10.0.1/lib/freebsd/libclang_rt.asan-x86_64.a
>>> defined at regfree.c
>>>            .../regex/regfree.c.o:(.text+0x0)

Committed upstream as https://github.com/lichray/nvi2/pull/92

Reviewed By:	bapt
Differential Revision: https://reviews.freebsd.org/D31050
This commit is contained in:
Alex Richardson 2021-07-19 15:04:19 +01:00
parent 2423585b1d
commit 8ef98a8045

View File

@ -96,6 +96,16 @@ typedef struct {
#define REG_LARGE 01000 /* force large representation */
#define REG_BACKR 02000 /* force use of backref code */
#ifdef USE_WIDECHAR
/*
* Avoid function name conflicts with the system regex functions.
* This is needed e.g. to build with AddressSanitizer.
*/
#define regcomp nvi_regcomp
#define regerror nvi_regerror
#define regexec nvi_regexec
#define regfree nvi_regfree
#endif
int regcomp(regex_t *, const RCHAR_T *, int);
size_t regerror(int, const regex_t *, char *, size_t);
int regexec(const regex_t *,