backported https://github.com/embecosm/avr-libc/commit/93f15d167faf4ee3019ddefbd520740c04bb3123