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

Evan Jones ejones at uwaterloo.ca
Tue Nov 22 15:20:51 PST 2005


On Nov 22, 2005, at 17:18, Reid Spencer wrote:
> Your patch uses an operating system call that is not portable. All 
> non-portable code needs to be located in the lib/System library.

Yep! I know. That is why I posted it for discussion. I'm not sure if 
this is the "right" way to fix the problem, or if there is a different 
fix that should be applied (like perhaps copying the data out of the 
mmap-ed archive?).

> I'm not sure why this problem appears on an old Red Hat system. 
> Perhaps the C++ io library is not up to snuff on that platform? What 
> compiler are you using?

It is very strange to me that it doesn't appear on other systems. I'll 
try to load LLVM on my bleeding edge Debian laptop tomorrow and see 
what happens there.

I am pretty certain that this has nothing to do with the C++ library, 
and everything to do with the behaviour of mmap when the file that was 
mmaped is modified. I actually can reproduce this behaviour with the 
attached C test case. The program mmaps a file called 'data,' prints 
the last byte, truncates the file, then tries to read the last byte 
again. It causes a Bus Error on both the RedHat system and my Mac OS X 
workstation. Hence, this appears to be valid (or at least common) mmap 
behaviour.

rn-spra1c07:~ ejones$ dd if=/dev/zero of=data bs=1 count=4096
4096+0 records in
4096+0 records out
4096 bytes transferred in 0.067263 secs (60895 bytes/sec)
rn-spra1c07:~ ejones$ ./mmaptest
last byte = 0x00
Bus error

I can also reproduce it with a minimal LLVM example, also attached. 
That program needs the "GNU.a" file in the current directory. It opens 
the archive and scans through all the members, printing out the first 
byte of each one. Then it truncates the file and repeats that 
experiment. It also causes a Bus Error.

Essentially, this is what happens in ArchiveWriter.cpp:429. This bug 
will be triggered by any archive that has a native symbol table, since 
that member (foreignST) references data that was mmaped from the 
original file. All the other members are copied from the temporary 
archive, so they are not a problem.

Evan Jones

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mmaptest.c
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20051122/fc0b2085/attachment.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: llvm-buserror.cpp
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20051122/fc0b2085/attachment.ksh>
-------------- next part --------------

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


More information about the llvm-dev mailing list