From: Yousong Zhou Date: Sat, 19 Oct 2019 12:00:43 +0000 (+0000) Subject: toolchain: gcc: enable sanitizers for glibc toolchain X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=69b9f0161e147d566b3b9572a0bc39a97c257fc0;p=openwrt%2Fstaging%2Fzorun.git toolchain: gcc: enable sanitizers for glibc toolchain Signed-off-by: Yousong Zhou --- diff --git a/package/libs/toolchain/Makefile b/package/libs/toolchain/Makefile index a63746c448..c13e9e4928 100644 --- a/package/libs/toolchain/Makefile +++ b/package/libs/toolchain/Makefile @@ -138,6 +138,122 @@ define Package/libstdcpp/config 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 @@ -413,6 +529,26 @@ ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),) $(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 @@ -550,6 +686,38 @@ else 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 ; \ @@ -623,6 +791,10 @@ $(eval $(call BuildPackage,libgcc)) $(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)) diff --git a/toolchain/gcc/final/Makefile b/toolchain/gcc/final/Makefile index b815f677d6..0315b9d1f1 100644 --- a/toolchain/gcc/final/Makefile +++ b/toolchain/gcc/final/Makefile @@ -4,7 +4,6 @@ include ../common.mk GCC_CONFIGURE += \ --with-headers=$(TOOLCHAIN_DIR)/include \ - --disable-libsanitizer \ --enable-languages=$(TARGET_LANGUAGES) \ --enable-shared \ --enable-threads \ @@ -12,6 +11,10 @@ GCC_CONFIGURE += \ --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