Don't preload rarely seen large images
[chromium-blink-merge.git] / third_party / elfutils / clang.patch
blob553a52dd28ba4f529db63e8058dbbc10a3ff5ad8
1 diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
2 index b39e284..31c4850 100644
3 --- a/libelf/elf32_updatefile.c
4 +++ b/libelf/elf32_updatefile.c
5 @@ -101,6 +101,33 @@ sort_sections (Elf_Scn **scns, Elf_ScnList *list)
9 +static void
10 +fill_mmap (char *last_position,
11 + char *shdr_start,
12 + char *shdr_end,
13 + char *scn_start,
14 + size_t offset)
16 + size_t written = 0;
18 + if (last_position < shdr_start)
19 + {
20 + written = MIN (scn_start + offset - last_position,
21 + shdr_start - last_position);
23 + memset (last_position, __libelf_fill_byte, written);
24 + }
26 + if (last_position + written != scn_start + offset
27 + && shdr_end < scn_start + offset)
28 + {
29 + char *fill_start = MAX (shdr_end, scn_start);
30 + memset (fill_start, __libelf_fill_byte,
31 + scn_start + offset - fill_start);
32 + }
36 int
37 internal_function
38 __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
39 @@ -290,27 +317,6 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
40 Elf_Data_List *dl = &scn->data_list;
41 bool scn_changed = false;
43 - void fill_mmap (size_t offset)
44 - {
45 - size_t written = 0;
47 - if (last_position < shdr_start)
48 - {
49 - written = MIN (scn_start + offset - last_position,
50 - shdr_start - last_position);
52 - memset (last_position, __libelf_fill_byte, written);
53 - }
55 - if (last_position + written != scn_start + offset
56 - && shdr_end < scn_start + offset)
57 - {
58 - char *fill_start = MAX (shdr_end, scn_start);
59 - memset (fill_start, __libelf_fill_byte,
60 - scn_start + offset - fill_start);
61 - }
62 - }
64 if (scn->data_list_rear != NULL)
67 @@ -325,7 +331,8 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
68 || ((scn->flags | dl->flags | elf->flags)
69 & ELF_F_DIRTY) != 0))
71 - fill_mmap (dl->data.d.d_off);
72 + fill_mmap (last_position, shdr_start, shdr_end,
73 + scn_start, dl->data.d.d_off);
74 last_position = scn_start + dl->data.d.d_off;
77 @@ -377,7 +384,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
78 /* If the previous section (or the ELF/program
79 header) changed we might have to fill the gap. */
80 if (scn_start > last_position && previous_scn_changed)
81 - fill_mmap (0);
82 + fill_mmap (last_position, shdr_start, shdr_end, scn_start, 0);
84 /* We have to trust the existing section header information. */
85 last_position = scn_start + shdr->sh_size;
86 diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
87 index b9d5cea..62aa54a 100644
88 --- a/libelf/elf_begin.c
89 +++ b/libelf/elf_begin.c
90 @@ -985,6 +985,22 @@ write_file (int fd, Elf_Cmd cmd)
94 +/* Duplicate the descriptor, with write lock if an archive. */
95 +static Elf *
96 +lock_dup_elf (int fildes, Elf_Cmd cmd, Elf *ref)
98 + /* We need wrlock to dup an archive. */
99 + if (ref->kind == ELF_K_AR)
101 + rwlock_unlock (ref->lock);
102 + rwlock_wrlock (ref->lock);
105 + /* Duplicate the descriptor. */
106 + return dup_elf (fildes, cmd, ref);
110 /* Return a descriptor for the file belonging to FILDES. */
111 Elf *
112 elf_begin (fildes, cmd, ref)
113 @@ -1011,19 +1027,6 @@ elf_begin (fildes, cmd, ref)
114 return NULL;
117 - Elf *lock_dup_elf ()
119 - /* We need wrlock to dup an archive. */
120 - if (ref->kind == ELF_K_AR)
122 - rwlock_unlock (ref->lock);
123 - rwlock_wrlock (ref->lock);
126 - /* Duplicate the descriptor. */
127 - return dup_elf (fildes, cmd, ref);
130 switch (cmd)
132 case ELF_C_NULL:
133 @@ -1044,7 +1047,7 @@ elf_begin (fildes, cmd, ref)
134 case ELF_C_READ:
135 case ELF_C_READ_MMAP:
136 if (ref != NULL)
137 - retval = lock_dup_elf ();
138 + retval = lock_dup_elf (fildes, cmd, ref);
139 else
140 /* Create descriptor for existing file. */
141 retval = read_file (fildes, 0, ~((size_t) 0), cmd, NULL);
142 @@ -1065,7 +1068,7 @@ elf_begin (fildes, cmd, ref)
143 retval = NULL;
145 else
146 - retval = lock_dup_elf ();
147 + retval = lock_dup_elf (fildes, cmd, ref);
149 else
150 /* Create descriptor for existing file. */
151 diff --git a/libelf/elf_getarsym.c b/libelf/elf_getarsym.c
152 index d0bb28a..a9bbb9d 100644
153 --- a/libelf/elf_getarsym.c
154 +++ b/libelf/elf_getarsym.c
155 @@ -196,18 +196,15 @@ elf_getarsym (elf, ptr)
156 elf->state.ar.ar_sym = (Elf_Arsym *) malloc (ar_sym_len);
157 if (elf->state.ar.ar_sym != NULL)
159 - union
161 - uint32_t u32[n];
162 - uint64_t u64[n];
163 - } *file_data;
164 + uint8_t file_data_buffer[n * sizeof(uint64_t)];
165 + void *file_data = (void *) file_data_buffer;
166 + uint64_t *file_data_u64 = (uint64_t *) file_data;
167 + uint32_t *file_data_u32 = (uint32_t *) file_data;
168 char *str_data;
169 size_t sz = n * w;
171 if (elf->map_address == NULL)
173 - file_data = alloca (sz);
175 ar_sym_len += index_size - n * w;
176 Elf_Arsym *newp = (Elf_Arsym *) realloc (elf->state.ar.ar_sym,
177 ar_sym_len);
178 @@ -241,8 +238,12 @@ elf_getarsym (elf, ptr)
180 file_data = (void *) (elf->map_address + off);
181 if (!ALLOW_UNALIGNED
182 - && ((uintptr_t) file_data & -(uintptr_t) n) != 0)
183 - file_data = memcpy (alloca (sz), elf->map_address + off, sz);
184 + && ((uintptr_t) file_data & -(uintptr_t) n) != 0) {
185 + file_data = (void *) file_data_buffer;
186 + memcpy(file_data, elf->map_address + off, sz);
188 + file_data_u64 = (uint64_t *) file_data;
189 + file_data_u32 = (uint32_t *) file_data;
190 str_data = (char *) (elf->map_address + off + sz);
193 @@ -253,7 +254,7 @@ elf_getarsym (elf, ptr)
194 arsym[cnt].as_name = str_data;
195 if (index64_p)
197 - uint64_t tmp = file_data->u64[cnt];
198 + uint64_t tmp = file_data_u64[cnt];
199 if (__BYTE_ORDER == __LITTLE_ENDIAN)
200 tmp = bswap_64 (tmp);
202 @@ -275,9 +276,9 @@ elf_getarsym (elf, ptr)
205 else if (__BYTE_ORDER == __LITTLE_ENDIAN)
206 - arsym[cnt].as_off = bswap_32 (file_data->u32[cnt]);
207 + arsym[cnt].as_off = bswap_32 (file_data_u32[cnt]);
208 else
209 - arsym[cnt].as_off = file_data->u32[cnt];
210 + arsym[cnt].as_off = file_data_u32[cnt];
212 arsym[cnt].as_hash = _dl_elf_hash (str_data);
213 str_data = rawmemchr (str_data, '\0') + 1;