Re: [DynInst_API:] Rewriter output file naming question


Date: Thu, 29 Nov 2012 19:40:50 -0600
From: Andrew Bernat <bernat@xxxxxxxxxxx>
Subject: Re: [DynInst_API:] Rewriter output file naming question
On Nov 29, 2012, at 7:35 PM, Josh Stone <jistone@xxxxxxxxxx> wrote:

OK, I see.  Well disallowing the same input and output is an easy
heuristic, but it shouldn't be too bad to make it work, if you want.

Just do the writing into a mkstemp()-opened file, so you know the
destination is unique to you.  Then, do an fsync() for data consistency
and rename() to the final output filename.  Even if the old file is
still mmaped in libelf, it will refer to the old (now deleted) contents.
This scheme should work whether or not input==output, so you don't need
to make a special case for it.

That definitely works. We're thinking of disallowing it to start with because you can get really odd side-effects since we effectively destroy the original file. 

Where it gets nasty is in dependent libraries. For example, if you were rewriting foo with a library libbar.so in the same directory, modify both foo and libbar, and then write foo to foo.out, we will also write libbar.so - however, there is no interface to change the name of libbar.so and so the original is destroyed. Clearly this can't be a common operation, but it came up in testing. 

So we can certainly do it technically; the question is do we want to allow it. 

Drew




[← Prev in Thread] Current Thread [Next in Thread→]