toolchain: gcc: enable sanitizers for glibc toolchain

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
This commit is contained in:
Yousong Zhou 2019-10-19 12:00:43 +00:00
parent ed6ba2801c
commit 69b9f0161e
2 changed files with 176 additions and 1 deletions

View 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 define Package/libc/Default
SECTION:=libs SECTION:=libs
CATEGORY:=Base system CATEGORY:=Base system
@ -413,6 +529,26 @@ ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
$(CP) $(TOOLCHAIN_DIR)/lib/libstdc++.so.* $(1)/usr/lib/ $(CP) $(TOOLCHAIN_DIR)/lib/libstdc++.so.* $(1)/usr/lib/
endef 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 define Package/glibc/install
$(CP) ./glibc-files/* $(1)/ $(CP) ./glibc-files/* $(1)/
rm -f $(1)/etc/localtime rm -f $(1)/etc/localtime
@ -550,6 +686,38 @@ else
exit 0 exit 0
endef 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 define Package/libc/install
for file in $(call qstrip,$(CONFIG_LIBC_FILE_SPEC)); do \ for file in $(call qstrip,$(CONFIG_LIBC_FILE_SPEC)); do \
$(INSTALL_DIR) $(1)/lib ; \ $(INSTALL_DIR) $(1)/lib ; \
@ -623,6 +791,10 @@ $(eval $(call BuildPackage,libgcc))
$(eval $(call BuildPackage,libatomic)) $(eval $(call BuildPackage,libatomic))
$(eval $(call BuildPackage,libssp)) $(eval $(call BuildPackage,libssp))
$(eval $(call BuildPackage,libstdcpp)) $(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,libpthread))
$(eval $(call BuildPackage,libthread-db)) $(eval $(call BuildPackage,libthread-db))
$(eval $(call BuildPackage,librt)) $(eval $(call BuildPackage,librt))

View File

@ -4,7 +4,6 @@ include ../common.mk
GCC_CONFIGURE += \ GCC_CONFIGURE += \
--with-headers=$(TOOLCHAIN_DIR)/include \ --with-headers=$(TOOLCHAIN_DIR)/include \
--disable-libsanitizer \
--enable-languages=$(TARGET_LANGUAGES) \ --enable-languages=$(TARGET_LANGUAGES) \
--enable-shared \ --enable-shared \
--enable-threads \ --enable-threads \
@ -12,6 +11,10 @@ GCC_CONFIGURE += \
--enable-lto \ --enable-lto \
--with-libelf=$(TOPDIR)/staging_dir/host --with-libelf=$(TOPDIR)/staging_dir/host
ifndef CONFIG_USE_GLIBC
GCC_CONFIGURE += --disable-libsanitizer
endif
ifdef CONFIG_USE_MUSL ifdef CONFIG_USE_MUSL
GCC_MAKE += gcc_cv_libc_provides_ssp=yes GCC_MAKE += gcc_cv_libc_provides_ssp=yes
endif endif