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
|
semantic: 0.700
other: 0.582
mistranslation: 0.574
instruction: 0.522
device: 0.396
graphic: 0.335
network: 0.333
boot: 0.296
vnc: 0.276
socket: 0.269
assembly: 0.224
KVM: 0.173
Access to /proc/self/exe in linux-user mode
This is based on a recent bug in GCC Bugzilla: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60681
It looks like libbacktrace (GCC runtime library used for obtaining stack traces) uses /proc/self/exe for error reporting. Currently this is mapped to qemu-arm which effectively disables libbacktrace on linux-user.
It seems that QEMU already supports /proc/self/{maps,stat,auxv} so addition of /proc/self/exe may be trivial.
This tiny patch seems to work.
I think the problem is not in libbacktrace per se but rather libsanitizer initializing libbacktrace with contents of /proc/self/exe. Patch is still relevant though.
Looks good, I'll get this to linux-user que once QEMU 2.0 is released.
That patch will copy the whole of the target executable into a temporary file without changing any of it -- the fake_open mechanism is really intended for cases where we need to return modified results. Wouldn't it be easier to just have something in do_open() that said:
if (is_proc_myself(pathname, "exe")) {
return get_errno(open(exec_path), flags, mode);
}
That will then give the right behaviour for read-only executables and other error-related corner cases.
(See also the logic in the readlink/readlinkat handling which already specialcases /proc/self/exe using exec_path.)
(I got the bracket placement wrong there so as you can tell the code is untested :-))
Yes, it works. Here is updated patch.
Some nits:
The "(CPUArchState *)" cast isn't necessary
We should use exec_path, not ts->bprm->argv[0] (the guest argv[0] isn't necessarily the executable path)
We don't want to call path() here -- exec_path is a host path, and only guest filename paths need to go through path().
Looking a little more closely at the logic in main.c I wonder if we actually want:
if (is_proc_myself(pathname, "exe")) {
execfd = qemu_getauxval(AT_EXECFD);
if (execfd) {
return execfd;
}
return get_errno(open(exec_path, flags, mode));
}
Also if you'd like us to apply your patches we'll need at least a "Signed-off-by: " line from you.
Ok, fixed.
Thanks. That version
Reviewed-by: Peter Maydell <email address hidden>
Hi,
Is this patch deployed in new version of QEMU?
Thanks,
Maxim
This bug was fixed by commit aa07f5ecf9828 in 2014 and has been released in QEMU.
|