changes for compiling with toolchain 4.7 taken from loosethisskin