diff --git a/Makefile b/Makefile index c2d9e28913..e92339cd55 100644 --- a/Makefile +++ b/Makefile @@ -84,6 +84,17 @@ endif @$(BR_MAKE) sdk -j$(shell nproc) @$(call BUNDLE_SDK) +toolchain-asan: defconfig +ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y) + @cp -rf $(PWD)/general/package/gcc $(TARGET)/buildroot-$(BR_VER)/package + @$(MAKE) -f $(PWD)/general/toolchain.mk BR_CONF=$(BR_CONF) CONFIG=$(PWD)/$(CONFIG) + @$(BR_MAKE) BR2_DEFCONFIG=$(BR_CONF) defconfig +endif + @echo 'BR2_EXTRA_GCC_CONFIG_OPTIONS="--enable-libsanitizer"' >> $(BR_CONF) + @$(BR_MAKE) BR2_DEFCONFIG=$(BR_CONF) defconfig + @$(BR_MAKE) sdk -j$(shell nproc) + @$(call BUNDLE_SDK) + repack: ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS),y) ifeq ($(BR2_OPENIPC_SOC_VENDOR),"rockchip") diff --git a/general/package/all-patches/gcc/0001-libsanitizer-musl-compat.patch b/general/package/all-patches/gcc/0001-libsanitizer-musl-compat.patch new file mode 100644 index 0000000000..c8e8ad58eb --- /dev/null +++ b/general/package/all-patches/gcc/0001-libsanitizer-musl-compat.patch @@ -0,0 +1,106 @@ +libsanitizer: guard musl-incompatible headers and structs + +musl libc headers conflict with kernel headers (struct sysinfo, +linux/if_ppp.h, linux/sysctl.h). Guard these with SANITIZER_GLIBC +and provide zero-value fallbacks so libsanitizer builds on musl. + +These changes are harmless when libsanitizer is disabled (the patched +files are only compiled when --enable-libsanitizer is active). + +Signed-off-by: Dmitry Ilyin <6576495+widgetii@users.noreply.github.com> + +--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp 2026-04-13 23:37:27.004985453 +0300 ++++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp 2026-04-13 23:37:27.022582860 +0300 +@@ -69,7 +69,9 @@ + #include + #include + #include ++#if SANITIZER_GLIBC + #include ++#endif + #include + #include + #include +@@ -80,7 +82,9 @@ + #include + #include + #include ++#if SANITIZER_GLIBC + #include ++#endif + #include + #include + #include +@@ -126,9 +130,11 @@ + #endif + #include + #else ++#if SANITIZER_GLIBC + #include + #include + #include ++#endif + #endif // SANITIZER_GLIBC + + #if SANITIZER_ANDROID +@@ -244,7 +250,11 @@ + + # if SANITIZER_LINUX + unsigned struct_epoll_event_sz = sizeof(struct epoll_event); ++#if SANITIZER_GLIBC + unsigned struct_sysinfo_sz = sizeof(struct sysinfo); ++#else ++ unsigned struct_sysinfo_sz = 0; ++#endif + unsigned __user_cap_header_struct_sz = + sizeof(struct __user_cap_header_struct); + unsigned __user_cap_data_struct_sz = sizeof(struct __user_cap_data_struct); +@@ -518,7 +528,11 @@ + unsigned struct_unimapinit_sz = sizeof(struct unimapinit); + + unsigned struct_audio_buf_info_sz = sizeof(struct audio_buf_info); ++#if SANITIZER_GLIBC + unsigned struct_ppp_stats_sz = sizeof(struct ppp_stats); ++#else ++ unsigned struct_ppp_stats_sz = 0; ++#endif + #endif // SANITIZER_GLIBC + + #if !SANITIZER_ANDROID && !SANITIZER_APPLE +@@ -678,6 +692,7 @@ + unsigned IOCTL_HDIO_SET_NOWERR = HDIO_SET_NOWERR; + unsigned IOCTL_HDIO_SET_UNMASKINTR = HDIO_SET_UNMASKINTR; + unsigned IOCTL_MTIOCPOS = MTIOCPOS; ++#if SANITIZER_GLIBC + unsigned IOCTL_PPPIOCGASYNCMAP = PPPIOCGASYNCMAP; + unsigned IOCTL_PPPIOCGDEBUG = PPPIOCGDEBUG; + unsigned IOCTL_PPPIOCGFLAGS = PPPIOCGFLAGS; +@@ -689,6 +704,19 @@ + unsigned IOCTL_PPPIOCSMAXCID = PPPIOCSMAXCID; + unsigned IOCTL_PPPIOCSMRU = PPPIOCSMRU; + unsigned IOCTL_PPPIOCSXASYNCMAP = PPPIOCSXASYNCMAP; ++#else ++ unsigned IOCTL_PPPIOCGASYNCMAP = 0; ++ unsigned IOCTL_PPPIOCGDEBUG = 0; ++ unsigned IOCTL_PPPIOCGFLAGS = 0; ++ unsigned IOCTL_PPPIOCGUNIT = 0; ++ unsigned IOCTL_PPPIOCGXASYNCMAP = 0; ++ unsigned IOCTL_PPPIOCSASYNCMAP = 0; ++ unsigned IOCTL_PPPIOCSDEBUG = 0; ++ unsigned IOCTL_PPPIOCSFLAGS = 0; ++ unsigned IOCTL_PPPIOCSMAXCID = 0; ++ unsigned IOCTL_PPPIOCSMRU = 0; ++ unsigned IOCTL_PPPIOCSXASYNCMAP = 0; ++#endif + unsigned IOCTL_SIOCADDRT = SIOCADDRT; + unsigned IOCTL_SIOCDARP = SIOCDARP; + unsigned IOCTL_SIOCDELRT = SIOCDELRT; +@@ -1122,7 +1150,7 @@ + CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_restorer); + #endif + +-#if SANITIZER_LINUX ++#if SANITIZER_GLIBC + CHECK_TYPE_SIZE(__sysctl_args); + CHECK_SIZE_AND_OFFSET(__sysctl_args, name); + CHECK_SIZE_AND_OFFSET(__sysctl_args, nlen);