--- gcc-5.3.0/gcc/builtins.c.orig 2016-10-18 10:45:35.042826368 +0200 +++ gcc-5.3.0/gcc/builtins.c 2016-10-18 10:50:46.080616285 +0200 @@ -3470,6 +3470,19 @@ expand_builtin_mempcpy_args (tree dest, # define CODE_FOR_movstr CODE_FOR_nothing #endif +/* Return true if STR is a string denoting a "/gnu/store" file name. */ + +static bool +store_reference_p (tree str) +{ + const char *store; + + store = getenv ("NIX_STORE") ?: "/gnu/store"; + + return (TREE_STRING_LENGTH (str) > strlen (store) + && strncmp (TREE_STRING_POINTER (str), store, strlen (store))); +} + /* Expand into a movstr instruction, if one is available. Return NULL_RTX if we failed, the caller should emit a normal call, otherwise try to get the result in TARGET, if convenient. If ENDP is 0 return the @@ -3484,7 +3497,9 @@ expand_movstr (tree dest, tree src, rtx rtx dest_mem; rtx src_mem; - if (!HAVE_movstr) + /* When SRC denotes a store item, do not perform any optimization. See + for background. */ + if (!HAVE_movstr || store_reference_p (src)) return NULL_RTX; dest_mem = get_memory_rtx (dest, NULL);