Bug 26645 - dwz does not remove a tmp file when working on perf
Summary: dwz does not remove a tmp file when working on perf
Status: RESOLVED DUPLICATE of bug 24275
Alias: None
Product: dwz
Classification: Unclassified
Component: default (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-22 10:54 UTC by Jiri Slaby
Modified: 2021-02-13 22:57 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Slaby 2020-09-22 10:54:51 UTC
Our (openSUSE) build of perf results in 2 binaries trace & perf (ls -li):
> 43866954 -rwxr-xr-x 2 abuild abuild 16704336 zář 22 09:15 perf
> 43866954 -rwxr-xr-x 2 abuild abuild 16704336 zář 22 09:15 trace

They are hard links. The same holds for separated debuginfo binaries:
> 43844091 -rwxr-xr-x 3 abuild abuild 28341208 zář 22 09:15 perf-5.8.7-0.x86_64.debug
> 43844091 -rwxr-xr-x 3 abuild abuild 28341208 zář 22 09:15 trace-5.8.7-0.x86_64.debug

Now when dwz is run:
$ dwz -h -r -m .dwz/perf-5.8.7-0.x86_64 -l 10000000 -L 50000000 ./usr/bin/perf-5.8.7-0.x86_64.debug ./usr/bin/trace-5.8.7-0.x86_64.debug ....
it results in (strace):
> openat(AT_FDCWD, "./usr/bin/trace-5.8.7-0.x86_64.debug", O_RDONLY) = 8
> fstat(8, {st_mode=S_IFREG|0755, st_size=28341208, ...}) = 0
> getpid()                                = 26887
> openat(AT_FDCWD, "./usr/bin/trace-5.8.7-0.x86_64.debug.#dwz#.maMA6e", O_RDWR|O_CREAT|O_EXCL, 0600) = 9
> close(9)                                = 0
> unlink("./usr/bin/trace-5.8.7-0.x86_64.debug.#dwz#.maMA6e") = 0
> link("./usr/bin/perf-5.8.7-0.x86_64.debug", "./usr/bin/trace-5.8.7-0.x86_64.debug.#dwz#.maMA6e") = 0
> rename("./usr/bin/trace-5.8.7-0.x86_64.debug.#dwz#.maMA6e", "./usr/bin/trace-5.8.7-0.x86_64.debug") = 0

The thing is that the rename is thought to actually remove 'oldpath' (first argument), but in case of hardlinks, it is documented it does nothing:
> If oldpath and newpath are existing hard links referring to the
> same file, then rename() does nothing, and returns a success status.

Sure, perf-5.8.7-0.x86_64.debug and trace-5.8.7-0.x86_64.debug are hard links and you create trace-5.8.7-0.x86_64.debug.#dwz#.maMA6e (which links to perf-*) and then rename it to trace-5.8.7-0.x86_64.debug which is still the same hard link.

Should you remove newpath first? Or do not create the link if it exists already?

Note that perf is special: 
> dwz: ./usr/bin/perf-5.8.7-0.x86_64.debug: DWARF compression not beneficial - old size 9932364 new size 9932655

So this is likely reason, why perf-5.8.7-0.x86_64.debug is left unchanged and trace -> perf hard link still exists.
Comment 1 Mark Wielaard 2020-10-01 13:19:07 UTC
I believe this is PR24275
Which has a proposed patch:
https://sourceware.org/legacy-ml/dwz/2019-q1/msg00060.html
But that has never been applied?
Comment 2 Mark Wielaard 2021-02-13 22:57:38 UTC
This is indeed PR24275. But the proposed patch there doesn't apply anymore to the current code.

*** This bug has been marked as a duplicate of bug 24275 ***