[U-Boot] [PATCH 1/8] UBSAN: run-time undefined behavior sanity checker

Eugeniu Rosca roscaeugeniu at gmail.com
Mon Aug 20 21:00:01 UTC 2018


On Mon, Aug 20, 2018 at 03:00:31PM +0000, York Sun wrote:
> On 08/19/2018 05:04 PM, Eugeniu Rosca wrote:
> <snip>
> > 
> > The size increase of sanbox U-Boot (gcc 8.1.0):
> > $ size u-boot.sandbox.*
> >    text	   data	    bss	    dec	    hex	filename
> > 1234958	  80048	 291472	1606478	 18834e	u-boot.sandbox.default
> > 1422710	 272240	 291472	1986422	 1e4f76	u-boot.sandbox.ubsan
> > +187752 +192192       0 +379944
> > 
> > The size increase of H3 Salvator-X U-Boot (aarch64-linux-gnu-gcc 7.2.1):
> > $ size u-boot.r8a7795-salvator-x.*
> >    text	   data	    bss	    dec	    hex	filename
> >  589954	  23504	 263984	 877442	  d6382	u-boot.r8a7795-salvator-x.default
> >  810968	 103304	 263984	1178256	 11fa90	u-boot.r8a7795-salvator-x.ubsan
> > +221014  +79800       0 +300814
> >
> I wonder if SPL can take advantage of this. Size is sensitive for SPL.

To build SPL, below fix is required (will be squashed into v2):

diff --git a/lib/Makefile b/lib/Makefile
index 099a49032a02..0ae2c121cacf 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -18,9 +18,6 @@ obj-$(CONFIG_CMD_DHRYSTONE) += dhry/
 obj-$(CONFIG_ARCH_AT91) += at91/
 obj-$(CONFIG_OPTEE) += optee/
 
-obj-$(CONFIG_UBSAN) += ubsan.o
-UBSAN_SANITIZE_ubsan.o := n
-
 obj-$(CONFIG_AES) += aes.o
 obj-y += charset.o
 obj-$(CONFIG_USB_TTY) += circbuf.o
@@ -54,6 +51,8 @@ endif
 obj-$(CONFIG_RSA) += rsa/
 obj-$(CONFIG_SHA1) += sha1.o
 obj-$(CONFIG_SHA256) += sha256.o
+obj-$(CONFIG_UBSAN) += ubsan.o
+UBSAN_SANITIZE_ubsan.o := n
 
 obj-$(CONFIG_$(SPL_)ZLIB) += zlib/
 obj-$(CONFIG_$(SPL_)GZIP) += gunzip.o

With respect to the ELF/BIN size, I get below numbers using
sandbox_spl_defconfig:

$ size u-boot-spl.default u-boot-spl.ubsan
   text	   data	    bss	    dec	    hex	filename
  58097	   5552	    672	  64321	   fb41	u-boot-spl.default
  74041	  25456	    672	 100169	  18749	u-boot-spl.ubsan

$ du -b u-boot-spl-nodtb.bin.default u-boot-spl-nodtb.bin.ubsan
2163064	u-boot-spl-nodtb.bin.default
2199352	u-boot-spl-nodtb.bin.ubsan

FWIW https://github.com/google/bloaty reports:

$ bloaty u-boot-spl.ubsan -- u-boot-spl.default
     VM SIZE                      FILE SIZE
 --------------                --------------
  [ = ]       0 .debug_info    +41.8Ki  +6.7%
  +727% +19.4Ki .data          +19.4Ki  +727%
  [ = ]       0 .debug_loc     +10.1Ki  +3.1%
   +32% +10.1Ki .text          +10.1Ki   +32%
  [ = ]       0 .debug_line    +7.38Ki  +4.9%
   +46% +3.78Ki .rodata        +3.78Ki   +46%
  [ = ]       0 .debug_abbrev  +2.25Ki  +2.6%
  [ = ]       0 .debug_str     +1.63Ki  +3.1%
   +15% +1.56Ki .eh_frame      +1.56Ki   +15%
  [ = ]       0 .debug_ranges     +880  +2.3%
  [ = ]       0 .symtab           +624  +4.2%
  [ = ]       0 .strtab           +548  +6.3%
  [ = ]       0 .debug_aranges    +416  +2.4%
  [ = ]       0 [Unmapped]        +416   +19%
  +6.7%    +152 .eh_frame_hdr     +152  +6.7%
   +37%     +16 [LOAD [RX]]        +16   +37%
   +55% +35.0Ki TOTAL           +101Ki  +7.3%

Except for some untreated UBs, I experienced no issues running
the sandbox SPL U-Boot.

> York

Best regards,
Eugeniu.


More information about the U-Boot mailing list