1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
permissions: 0.996
semantic: 0.995
debug: 0.994
performance: 0.994
arm: 0.994
alpha: 0.994
PID: 0.993
device: 0.993
socket: 0.993
architecture: 0.992
assembly: 0.992
boot: 0.992
hypervisor: 0.991
virtual: 0.990
network: 0.989
VMM: 0.989
peripherals: 0.989
register: 0.989
operating system: 0.988
risc-v: 0.988
graphic: 0.986
files: 0.986
user-level: 0.985
kernel: 0.983
KVM: 0.982
vnc: 0.981
ppc: 0.981
TCG: 0.974
mistranslation: 0.974
x86: 0.968
i386: 0.958
[Qemu-devel] Fwd: [BUG] Failed to compile using gcc7.1
Hi all,
I encountered the same problem on gcc 7.1.1 and found Qu's mail in
this list from google search.
Temporarily fix it by specifying the string length in snprintf
directive. Hope this is helpful to other people encountered the same
problem.
@@ -1,9 +1,7 @@
---
--- a/block/blkdebug.c
- "blkdebug:%s:%s", s->config_file ?: "",
--- a/block/blkverify.c
- "blkverify:%s:%s",
--- a/hw/usb/bus.c
- snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
- snprintf(downstream->path, sizeof(downstream->path), "%d", portnr);
--
+++ b/block/blkdebug.c
+ "blkdebug:%.2037s:%.2037s", s->config_file ?: "",
+++ b/block/blkverify.c
+ "blkverify:%.2038s:%.2038s",
+++ b/hw/usb/bus.c
+ snprintf(downstream->path, sizeof(downstream->path), "%.12s.%d",
+ snprintf(downstream->path, sizeof(downstream->path), "%.12d", portnr);
Tsung-en Hsiao
>
Qu Wenruo Wrote:
>
>
Hi all,
>
>
After upgrading gcc from 6.3.1 to 7.1.1, qemu can't be compiled with gcc.
>
>
The error is:
>
>
------
>
CC block/blkdebug.o
>
block/blkdebug.c: In function 'blkdebug_refresh_filename':
>
>
block/blkdebug.c:693:31: error: '%s' directive output may be truncated
>
writing up to 4095 bytes into a region of size 4086
>
[-Werror=format-truncation=]
>
>
"blkdebug:%s:%s", s->config_file ?: "",
>
^~
>
In file included from /usr/include/stdio.h:939:0,
>
from /home/adam/qemu/include/qemu/osdep.h:68,
>
from block/blkdebug.c:25:
>
>
/usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output 11
>
or more bytes (assuming 4106) into a destination of size 4096
>
>
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
__bos (__s), __fmt, __va_arg_pack ());
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
cc1: all warnings being treated as errors
>
make: *** [/home/adam/qemu/rules.mak:69: block/blkdebug.o] Error 1
>
------
>
>
It seems that gcc 7 is introducing more restrict check for printf.
>
>
If using clang, although there are some extra warning, it can at least pass
>
the compile.
>
>
Thanks,
>
Qu
Hi Tsung-en,
On 06/11/2017 04:08 PM, Tsung-en Hsiao wrote:
Hi all,
I encountered the same problem on gcc 7.1.1 and found Qu's mail in
this list from google search.
Temporarily fix it by specifying the string length in snprintf
directive. Hope this is helpful to other people encountered the same
problem.
Thank your for sharing this.
@@ -1,9 +1,7 @@
---
--- a/block/blkdebug.c
- "blkdebug:%s:%s", s->config_file ?: "",
--- a/block/blkverify.c
- "blkverify:%s:%s",
--- a/hw/usb/bus.c
- snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
- snprintf(downstream->path, sizeof(downstream->path), "%d", portnr);
--
+++ b/block/blkdebug.c
+ "blkdebug:%.2037s:%.2037s", s->config_file ?: "",
It is a rather funny way to silent this warning :) Truncating the
filename until it fits.
However I don't think it is the correct way since there is indeed an
overflow of bs->exact_filename.
Apparently exact_filename from "block/block_int.h" is defined to hold a
pathname:
char exact_filename[PATH_MAX];
but is used for more than that (for example in blkdebug.c it might use
until 10+2*PATH_MAX chars).
I suppose it started as a buffer to hold a pathname then more block
drivers were added and this buffer ended used differently.
If it is a multi-purpose buffer one safer option might be to declare it
as a GString* and use g_string_printf().
I CC'ed the block folks to have their feedback.
Regards,
Phil.
+++ b/block/blkverify.c
+ "blkverify:%.2038s:%.2038s",
+++ b/hw/usb/bus.c
+ snprintf(downstream->path, sizeof(downstream->path), "%.12s.%d",
+ snprintf(downstream->path, sizeof(downstream->path), "%.12d", portnr);
Tsung-en Hsiao
Qu Wenruo Wrote:
Hi all,
After upgrading gcc from 6.3.1 to 7.1.1, qemu can't be compiled with gcc.
The error is:
------
CC block/blkdebug.o
block/blkdebug.c: In function 'blkdebug_refresh_filename':
block/blkdebug.c:693:31: error: '%s' directive output may be truncated writing
up to 4095 bytes into a region of size 4086 [-Werror=format-truncation=]
"blkdebug:%s:%s", s->config_file ?: "",
^~
In file included from /usr/include/stdio.h:939:0,
from /home/adam/qemu/include/qemu/osdep.h:68,
from block/blkdebug.c:25:
/usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output 11 or
more bytes (assuming 4106) into a destination of size 4096
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [/home/adam/qemu/rules.mak:69: block/blkdebug.o] Error 1
------
It seems that gcc 7 is introducing more restrict check for printf.
If using clang, although there are some extra warning, it can at least pass the
compile.
Thanks,
Qu
On 2017-06-12 05:19, Philippe Mathieu-Daudé wrote:
>
Hi Tsung-en,
>
>
On 06/11/2017 04:08 PM, Tsung-en Hsiao wrote:
>
> Hi all,
>
> I encountered the same problem on gcc 7.1.1 and found Qu's mail in
>
> this list from google search.
>
>
>
> Temporarily fix it by specifying the string length in snprintf
>
> directive. Hope this is helpful to other people encountered the same
>
> problem.
>
>
Thank your for sharing this.
>
>
>
>
> @@ -1,9 +1,7 @@
>
> ---
>
> --- a/block/blkdebug.c
>
> - "blkdebug:%s:%s", s->config_file ?: "",
>
> --- a/block/blkverify.c
>
> - "blkverify:%s:%s",
>
> --- a/hw/usb/bus.c
>
> - snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
>
> - snprintf(downstream->path, sizeof(downstream->path), "%d",
>
> portnr);
>
> --
>
> +++ b/block/blkdebug.c
>
> + "blkdebug:%.2037s:%.2037s", s->config_file ?: "",
>
>
It is a rather funny way to silent this warning :) Truncating the
>
filename until it fits.
>
>
However I don't think it is the correct way since there is indeed an
>
overflow of bs->exact_filename.
>
>
Apparently exact_filename from "block/block_int.h" is defined to hold a
>
pathname:
>
char exact_filename[PATH_MAX];
>
>
but is used for more than that (for example in blkdebug.c it might use
>
until 10+2*PATH_MAX chars).
In any case, truncating the filenames will do just as much as truncating
the result: You'll get an unusable filename.
>
I suppose it started as a buffer to hold a pathname then more block
>
drivers were added and this buffer ended used differently.
>
>
If it is a multi-purpose buffer one safer option might be to declare it
>
as a GString* and use g_string_printf().
What it is supposed to be now is just an information string we can print
to the user, because strings are nicer than JSON objects. There are some
commands that take a filename for identifying a block node, but I dream
we can get rid of them in 3.0...
The right solution is to remove it altogether and have a
"char *bdrv_filename(BlockDriverState *bs)" function (which generates
the filename every time it's called). I've been working on this for some
years now, actually, but it was never pressing enough to get it finished
(so I never had enough time).
What we can do in the meantime is to not generate a plain filename if it
won't fit into bs->exact_filename.
(The easiest way to do this probably would be to truncate
bs->exact_filename back to an empty string if snprintf() returns a value
greater than or equal to the length of bs->exact_filename.)
What to do about hw/usb/bus.c I don't know (I guess the best solution
would be to ignore the warning, but I don't suppose that is going to work).
Max
>
>
I CC'ed the block folks to have their feedback.
>
>
Regards,
>
>
Phil.
>
>
> +++ b/block/blkverify.c
>
> + "blkverify:%.2038s:%.2038s",
>
> +++ b/hw/usb/bus.c
>
> + snprintf(downstream->path, sizeof(downstream->path), "%.12s.%d",
>
> + snprintf(downstream->path, sizeof(downstream->path), "%.12d",
>
> portnr);
>
>
>
> Tsung-en Hsiao
>
>
>
>> Qu Wenruo Wrote:
>
>>
>
>> Hi all,
>
>>
>
>> After upgrading gcc from 6.3.1 to 7.1.1, qemu can't be compiled with
>
>> gcc.
>
>>
>
>> The error is:
>
>>
>
>> ------
>
>> CC block/blkdebug.o
>
>> block/blkdebug.c: In function 'blkdebug_refresh_filename':
>
>>
>
>> block/blkdebug.c:693:31: error: '%s' directive output may be
>
>> truncated writing up to 4095 bytes into a region of size 4086
>
>> [-Werror=format-truncation=]
>
>>
>
>> "blkdebug:%s:%s", s->config_file ?: "",
>
>> ^~
>
>> In file included from /usr/include/stdio.h:939:0,
>
>> from /home/adam/qemu/include/qemu/osdep.h:68,
>
>> from block/blkdebug.c:25:
>
>>
>
>> /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk'
>
>> output 11 or more bytes (assuming 4106) into a destination of size 4096
>
>>
>
>> return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
>
>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>> __bos (__s), __fmt, __va_arg_pack ());
>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>> cc1: all warnings being treated as errors
>
>> make: *** [/home/adam/qemu/rules.mak:69: block/blkdebug.o] Error 1
>
>> ------
>
>>
>
>> It seems that gcc 7 is introducing more restrict check for printf.
>
>>
>
>> If using clang, although there are some extra warning, it can at
>
>> least pass the compile.
>
>>
>
>> Thanks,
>
>> Qu
>
>
signature.asc
Description:
OpenPGP digital signature
|