toolchain: gcc: enable sanitizers for glibc toolchain
authorYousong Zhou <yszhou4tech@gmail.com>
Sat, 19 Oct 2019 12:00:43 +0000 (12:00 +0000)
committerYousong Zhou <yszhou4tech@gmail.com>
Thu, 24 Oct 2019 11:40:00 +0000 (11:40 +0000)
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
package/libs/toolchain/Makefile
toolchain/gcc/final/Makefile

index a63746c448f7013bde59904c98b14b04ee451fd2..c13e9e4928ce09ae19a08e5b6e8d616572a68eb9 100644 (file)
@@ -138,6 +138,122 @@ define Package/libstdcpp/config
 endef
 
 
 endef
 
 
+define Package/libasan
+$(call Package/gcc/Default)
+  NAME:=libasan
+  TITLE:=Runtime library for AddressSanitizer in GCC
+  DEPENDS:=@USE_GLIBC +librt +libstdcpp
+  ABI_VERSION:=5
+endef
+
+define Package/libasan/config
+       menu "Configuration"
+       depends on EXTERNAL_TOOLCHAIN && PACKAGE_libasan
+
+       config LIBASAN_ROOT_DIR
+               string
+               prompt "libasan shared library base directory"
+               depends on EXTERNAL_TOOLCHAIN && PACKAGE_libasan
+               default TOOLCHAIN_ROOT  if !NATIVE_TOOLCHAIN
+               default "/"  if NATIVE_TOOLCHAIN
+
+       config LIBASAN_FILE_SPEC
+               string
+               prompt "libasan shared library files (use wildcards)"
+               depends on EXTERNAL_TOOLCHAIN && PACKAGE_libasan
+               default "./lib/libasan.so.*"
+
+       endmenu
+endef
+
+
+define Package/libtsan
+$(call Package/gcc/Default)
+  NAME:=libtsan
+  TITLE:=Runtime library for ThreadSanitizer in GCC
+  DEPENDS:=@USE_GLIBC +librt +libstdcpp
+  ABI_VERSION:=0
+endef
+
+define Package/libtsan/config
+       menu "Configuration"
+       depends on EXTERNAL_TOOLCHAIN && PACKAGE_libtsan
+
+       config LIBTSAN_ROOT_DIR
+               string
+               prompt "libtsan shared library base directory"
+               depends on EXTERNAL_TOOLCHAIN && PACKAGE_libtsan
+               default TOOLCHAIN_ROOT  if !NATIVE_TOOLCHAIN
+               default "/"  if NATIVE_TOOLCHAIN
+
+       config LIBTSAN_FILE_SPEC
+               string
+               prompt "libtsan shared library files (use wildcards)"
+               depends on EXTERNAL_TOOLCHAIN && PACKAGE_libtsan
+               default "./lib/libtsan.so.*"
+
+       endmenu
+endef
+
+
+define Package/liblsan
+$(call Package/gcc/Default)
+  NAME:=liblsan
+  TITLE:=Runtime library for LeakSanitizer in GCC
+  DEPENDS:=@USE_GLIBC +librt +libstdcpp
+  ABI_VERSION:=0
+endef
+
+define Package/liblsan/config
+       menu "Configuration"
+       depends on EXTERNAL_TOOLCHAIN && PACKAGE_liblsan
+
+       config LIBLSAN_ROOT_DIR
+               string
+               prompt "liblsan shared library base directory"
+               depends on EXTERNAL_TOOLCHAIN && PACKAGE_liblsan
+               default TOOLCHAIN_ROOT  if !NATIVE_TOOLCHAIN
+               default "/"  if NATIVE_TOOLCHAIN
+
+       config LIBLSAN_FILE_SPEC
+               string
+               prompt "liblsan shared library files (use wildcards)"
+               depends on EXTERNAL_TOOLCHAIN && PACKAGE_liblsan
+               default "./lib/liblsan.so.*"
+
+       endmenu
+endef
+
+
+define Package/libubsan
+$(call Package/gcc/Default)
+  NAME:=libubsan
+  TITLE:=Runtime library for UndefinedBehaviorSanitizer in GCC
+  DEPENDS:=@USE_GLIBC +librt +libstdcpp
+  ABI_VERSION:=1
+endef
+
+define Package/libubsan/config
+       menu "Configuration"
+       depends on EXTERNAL_TOOLCHAIN && PACKAGE_libubsan
+
+       config LIBUBSAN_ROOT_DIR
+               string
+               prompt "libubsan shared library base directory"
+               depends on EXTERNAL_TOOLCHAIN && PACKAGE_libubsan
+               default TOOLCHAIN_ROOT  if !NATIVE_TOOLCHAIN
+               default "/"  if NATIVE_TOOLCHAIN
+
+       config LIBUBSAN_FILE_SPEC
+               string
+               prompt "libubsan shared library files (use wildcards)"
+               depends on EXTERNAL_TOOLCHAIN && PACKAGE_libubsan
+               default "./lib/libubsan.so.*"
+
+       endmenu
+endef
+
+
 define Package/libc/Default
   SECTION:=libs
   CATEGORY:=Base system
 define Package/libc/Default
   SECTION:=libs
   CATEGORY:=Base system
@@ -413,6 +529,26 @@ ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
        $(CP) $(TOOLCHAIN_DIR)/lib/libstdc++.so.* $(1)/usr/lib/
   endef
 
        $(CP) $(TOOLCHAIN_DIR)/lib/libstdc++.so.* $(1)/usr/lib/
   endef
 
+  define Package/libasan/install
+       $(INSTALL_DIR) $(1)/lib
+       $(CP) $(TOOLCHAIN_DIR)/lib/libasan.so.* $(1)/lib/
+  endef
+
+  define Package/libtsan/install
+       $(INSTALL_DIR) $(1)/lib
+       $(CP) $(TOOLCHAIN_DIR)/lib/libtsan.so.* $(1)/lib/
+  endef
+
+  define Package/liblsan/install
+       $(INSTALL_DIR) $(1)/lib
+       $(CP) $(TOOLCHAIN_DIR)/lib/liblsan.so.* $(1)/lib/
+  endef
+
+  define Package/libubsan/install
+       $(INSTALL_DIR) $(1)/lib
+       $(CP) $(TOOLCHAIN_DIR)/lib/libubsan.so.* $(1)/lib/
+  endef
+
   define Package/glibc/install
        $(CP) ./glibc-files/* $(1)/
        rm -f $(1)/etc/localtime
   define Package/glibc/install
        $(CP) ./glibc-files/* $(1)/
        rm -f $(1)/etc/localtime
@@ -550,6 +686,38 @@ else
        exit 0
   endef
 
        exit 0
   endef
 
+  define Package/libasan/install
+       for file in $(call qstrip,$(CONFIG_LIBASAN_FILE_SPEC)); do \
+               $(INSTALL_DIR) $(1)/lib ; \
+               $(CP) $(call qstrip,$(CONFIG_LIBASAN_ROOT_DIR))/$$$$file $(1)/lib/ ; \
+       done ; \
+       exit 0
+  endef
+
+  define Package/libtsan/install
+       for file in $(call qstrip,$(CONFIG_LIBTSAN_FILE_SPEC)); do \
+               $(INSTALL_DIR) $(1)/lib ; \
+               $(CP) $(call qstrip,$(CONFIG_LIBTSAN_ROOT_DIR))/$$$$file $(1)/lib/ ; \
+       done ; \
+       exit 0
+  endef
+
+  define Package/liblsan/install
+       for file in $(call qstrip,$(CONFIG_LIBLSAN_FILE_SPEC)); do \
+               $(INSTALL_DIR) $(1)/lib ; \
+               $(CP) $(call qstrip,$(CONFIG_LIBLSAN_ROOT_DIR))/$$$$file $(1)/lib/ ; \
+       done ; \
+       exit 0
+  endef
+
+  define Package/libubsan/install
+       for file in $(call qstrip,$(CONFIG_LIBUBSAN_FILE_SPEC)); do \
+               $(INSTALL_DIR) $(1)/lib ; \
+               $(CP) $(call qstrip,$(CONFIG_LIBUBSAN_ROOT_DIR))/$$$$file $(1)/lib/ ; \
+       done ; \
+       exit 0
+  endef
+
   define Package/libc/install
        for file in $(call qstrip,$(CONFIG_LIBC_FILE_SPEC)); do \
                $(INSTALL_DIR) $(1)/lib ; \
   define Package/libc/install
        for file in $(call qstrip,$(CONFIG_LIBC_FILE_SPEC)); do \
                $(INSTALL_DIR) $(1)/lib ; \
@@ -623,6 +791,10 @@ $(eval $(call BuildPackage,libgcc))
 $(eval $(call BuildPackage,libatomic))
 $(eval $(call BuildPackage,libssp))
 $(eval $(call BuildPackage,libstdcpp))
 $(eval $(call BuildPackage,libatomic))
 $(eval $(call BuildPackage,libssp))
 $(eval $(call BuildPackage,libstdcpp))
+$(eval $(call BuildPackage,libasan))
+$(eval $(call BuildPackage,libtsan))
+$(eval $(call BuildPackage,liblsan))
+$(eval $(call BuildPackage,libubsan))
 $(eval $(call BuildPackage,libpthread))
 $(eval $(call BuildPackage,libthread-db))
 $(eval $(call BuildPackage,librt))
 $(eval $(call BuildPackage,libpthread))
 $(eval $(call BuildPackage,libthread-db))
 $(eval $(call BuildPackage,librt))
index b815f677d669c8cac479d365f52449f64564637c..0315b9d1f163b9d61c48929360763a82b7263602 100644 (file)
@@ -4,7 +4,6 @@ include ../common.mk
 
 GCC_CONFIGURE += \
        --with-headers=$(TOOLCHAIN_DIR)/include \
 
 GCC_CONFIGURE += \
        --with-headers=$(TOOLCHAIN_DIR)/include \
-       --disable-libsanitizer \
        --enable-languages=$(TARGET_LANGUAGES) \
        --enable-shared \
        --enable-threads \
        --enable-languages=$(TARGET_LANGUAGES) \
        --enable-shared \
        --enable-threads \
@@ -12,6 +11,10 @@ GCC_CONFIGURE += \
        --enable-lto \
        --with-libelf=$(TOPDIR)/staging_dir/host
 
        --enable-lto \
        --with-libelf=$(TOPDIR)/staging_dir/host
 
+ifndef CONFIG_USE_GLIBC
+  GCC_CONFIGURE += --disable-libsanitizer
+endif
+
 ifdef CONFIG_USE_MUSL
   GCC_MAKE += gcc_cv_libc_provides_ssp=yes
 endif
 ifdef CONFIG_USE_MUSL
   GCC_MAKE += gcc_cv_libc_provides_ssp=yes
 endif