Skip to content

Use vsnprintf from dietlibc instead of stubs

Alex requested to merge branch/vsnprintf into branch/unified

One more small step towards standard C library in ML.

Reasons:

  • Canon's vsnprintf breaks on large numbers (try %02d with 12345)
  • non-standard handling of %% (requires extra dummy argument)
  • can't handle string alignment (%-20s)
  • can't handle %c
  • non-standard return value from (v)snprintf (see updated tests)
  • other less-known non-standard behaviors
  • fewer stubs = easier to port/maintain

Disadvantages:

  • increased binary size (todo: check how much). We can refactor some more stuff to modules if that's a problem.
  • some printfs might be broken, since they assume non-standard Canon behavior (potential for subtle, hard-to-find bugs)

This change also allowed me to enable gcc warnings about printf format strings. TODO: fix these warnings.

Example (identify.c from hdparm):

Canon's vsnprintf:

CompactFlash ATA device
	-20sSILICONMOTION SM2236AC                  
	-20sAA00000000000109928 
	-20s20121203
Standards:
	Likely used: u
Configuration:
	Logical		max	current
	cylinders	u	u
	heads		u	u
	sectors/track	u	u
	--
	CHS current addressable sectors:1u
	LBA    user addressable sectors:1u
	LBA48  user addressable sectors:1llu
	-31s 1u bytes
	device size with M = 1024*1024: 1llu MBytes
	device size with M = 1000*1000: 1llu MBytes (lu GB)
	cache/buffer size  = u KBytes (type=DualPort)
Capabilities:
	LBA, IORDY(may be)(cannot be disabled)
	bytes avail on r/w long: u
	Standby timer values: spec'd by Vendor
	R/W multiple sector transfer: Max = u	Current = u
	Advanced power management level: disabled
	DMA: not supported
	PIO: pio0 pio1 pio2 pio3 pio4 
	     Cycle time: no flow control=uns  IORDY flow control=uns
Commands/features:
	Enabled	Supported:
	                                                                                                                                                                                                                                                                  	Power Management feature set
	   ***************************************************************************************************************************************************************************************************************************************************************	Write cache
	                                                                                                                                                                                                                                                                  	WRITE_BUFFER command
	                                                                                                                                                                                                                                                                  	READ_BUFFER command
	                                                                                                                                                                                                                                                                  	NOP cmd
	                                                                                                                                                                                                                                                                  	CFA feature set
	                                                                                                                                                                                                                                                                  	Advanced Power Management feature set
	   ***************************************************************************************************************************************************************************************************************************************************************	48-bit Address feature set
	   ***************************************************************************************************************************************************************************************************************************************************************	Mandatory FLUSH_CACHE
	   ***************************************************************************************************************************************************************************************************************************************************************	FLUSH_CACHE_EXT
		CFA max advanced io_udma cycle time: uns
		CFA max advanced mem_udma cycle time: uns
	   *	CFA Power Level 1  (max umA)
Integrity word not set (found 0x0000, expected 0xaaa5)

dietlibc vsnprintf:

CompactFlash ATA device
	Model Number:       SILICONMOTION SM2236AC                  
	Serial Number:      AA00000000000109928 
	Firmware Revision:  20121203
Standards:
	Likely used: 6
Configuration:
	Logical		max	current
	cylinders	62041	62041
	heads		16	16
	sectors/track	63	63
	--
	CHS current addressable sectors:   62537328
	LBA    user addressable sectors:   62537328
	LBA48  user addressable sectors:          0
	Logical/Physical Sector size:           512 bytes
	device size with M = 1024*1024:         320 MBytes
	device size with M = 1000*1000:           0 MBytes (0 GB)
	cache/buffer size  = 1 KBytes (type=DualPort)
Capabilities:
	LBA, IORDY(may be)(cannot be disabled)
	bytes avail on r/w long: 4
	Standby timer values: spec'd by Vendor
	R/W multiple sector transfer: Max = 1	Current = 0
	Advanced power management level: disabled
	DMA: not supported
	PIO: pio0 pio1 pio2 pio3 pio4 
	     Cycle time: no flow control=120ns  IORDY flow control=120ns
Commands/features:
	Enabled	Supported:
	    	Power Management feature set
	   *	Write cache
	    	WRITE_BUFFER command
	    	READ_BUFFER command
	    	NOP cmd
	    	CFA feature set
	    	Advanced Power Management feature set
	   *	48-bit Address feature set
	   *	Mandatory FLUSH_CACHE
	   *	FLUSH_CACHE_EXT
		CFA max advanced io_udma cycle time: 80ns
		CFA max advanced mem_udma cycle time: 80ns
	   *	CFA Power Level 1  (max 500mA)
Integrity word not set (found 0x0000, expected 0xaaa5)

Note: dietlibc by default does not print int64 and floats, but these can be enabled (we would have to recompile dietlibc).

The changes from this branch also apply if we decide to use some other standard library (I also tried compiling ML with musl - that one prints the big numbers correctly).

Merge request reports