Based on patch from H.J. Lu <hjl@gnu.org>: