backport part of abe39e9 to fix compilation