[LLVMdev] llvm-ranlib: Bus Error in regressions + fix

Evan Jones ejones at uwaterloo.ca
Wed Nov 23 08:44:16 PST 2005


On Nov 23, 2005, at 8:16, Evan Jones wrote:
> (4) Write the foreignST into the TmpArchive file. Is there any reason 
> that this isn't possible? Then the final archive would be created in a 
> single pass, and it could just be moved into place.

Ah. I see: It needs to be written in order to compute the offsets. 
However, it would be possible to use a stringstream for this.

I think the best thing to do is to write the final archive to a 
temporary file, and then move it into place. This has the advantage 
that if something goes wrong the original archive will not be 
corrupted. Additionally, all the members of the current archive object 
instance stay valid, since the original mmap is still valid.

One disadvantage of this approach is that if CreateSymbolTable is 
false, it will be slightly more expensive as it will build the archive 
in memory before writing it to disk, instead of just writing it out to 
disk directly.

> Also, since writeToDisk() invalidates the mapped file that was 
> originally used to create the archive, shouldn't this function also 
> unmap that file and erase all its members? This would prevent and 
> further bugs like this from happening.

This is not necessary using the replace method described above. 
However, it *would* be necessary on Windows since you can't 
unlink/replace an open file on that platform. To fix this, the original 
archive file must be closed before performing the move.

I've attached a patch that builds the temporary archive in a 
stringstream, then writes the temporary file and moves it into place. 
It fixes the bug on the old RedHat system.

Evan Jones
-------------- next part --------------
A non-text attachment was scrubbed...
Name: archive.patch
Type: application/octet-stream
Size: 5759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20051123/7855778c/attachment.obj>
-------------- next part --------------

--
Evan Jones
http://evanjones.ca/


More information about the llvm-dev mailing list