gnu: gcc@5, gcc@6: Work around use of 'movabs' for /gnu/store strings.
[jackhill/guix/guix.git] / gnu / packages / patches / gcc-strmov-store-file-names.patch
1 Make sure that statements such as:
2
3 strcpy (dst, "/gnu/store/…");
4
5 do not result in chunked /gnu/store strings that are undetectable by
6 Guix's GC and its grafting code. See <http://bugs.gnu.org/24703>.
7
8 --- gcc-5.3.0/gcc/builtins.c 2016-10-18 10:50:46.080616285 +0200
9 +++ gcc-5.3.0/gcc/builtins.c 2016-11-09 15:26:43.693042737 +0100
10 @@ -3192,6 +3192,42 @@ determine_block_size (tree len, rtx len_
11 GET_MODE_MASK (GET_MODE (len_rtx)));
12 }
13
14 +/* Return true if STR contains the string "/gnu/store". */
15 +
16 +static bool
17 +store_reference_p (tree str)
18 +{
19 + if (TREE_CODE (str) == ADDR_EXPR)
20 + str = TREE_OPERAND (str, 0);
21 +
22 + if (TREE_CODE (str) != STRING_CST)
23 + return false;
24 +
25 + int len;
26 + const char *store;
27 +
28 + store = getenv ("NIX_STORE") ? getenv ("NIX_STORE") : "/gnu/store";
29 + len = strlen (store);
30 +
31 + /* Size of the hash part of store file names, including leading slash and
32 + trailing hyphen. */
33 + const int hash_len = 34;
34 +
35 + if (TREE_STRING_LENGTH (str) < len + hash_len)
36 + return false;
37 +
38 + /* We cannot use 'strstr' because 'TREE_STRING_POINTER' returns a string
39 + that is not necessarily NUL-terminated. */
40 +
41 + for (int i = 0; i < TREE_STRING_LENGTH (str) - (len + hash_len); i++)
42 + {
43 + if (strncmp (TREE_STRING_POINTER (str) + i, store, len) == 0)
44 + return true;
45 + }
46 +
47 + return false;
48 +}
49 +
50 /* Helper function to do the actual work for expand_builtin_memcpy. */
51
52 static rtx
53 @@ -3207,6 +3243,13 @@ expand_builtin_memcpy_args (tree dest, t
54 unsigned HOST_WIDE_INT max_size;
55 unsigned HOST_WIDE_INT probable_max_size;
56
57 + /* Do not emit block moves, which translate to the 'movabs' instruction on
58 + x86_64, when SRC refers to store items. That way, store references
59 + remain visible to the Guix GC and grafting code. See
60 + <http://bugs.gnu.org/24703>. */
61 + if (store_reference_p (src))
62 + return NULL_RTX;
63 +
64 /* If DEST is not a pointer type, call the normal function. */
65 if (dest_align == 0)
66 return NULL_RTX;