[llvm-commits] PCH fix

Anton Korobeynikov asl at math.spbu.ru
Thu May 17 02:53:35 PDT 2007


Hello, Everyone.

Attached patch fixes PCHs for both TOT and 2.0 release.

There were 2 problems:

1. flush() method of oFILEstream doesn't actually flush the file. This
can lead to incorrect offsets calculations in the PCH handling code and
junk output. This problem seems to be highly platform-dependent: it
fails for linux & mingw32, but passes for darwin.

There are two possible solutions: either use stdio_sync_buf for
oFILEstream or flush the asm_out_file by hands. I preferred second.

2. This problem is not platform specific. We have the following sequence
of calls during PCH's read:

 1) llvm_start_asm_file()
 2) llvm_read_pch()
 3) llvm_end_asm_file()

In llvm_start_asm_file() routine 2 FunctionPassManagers
(PerFunctionPasses and CodeGenPasses) are created having TheModule used
during construction, later in the llvm_read_pch() TheModule is freed and
recreated, but ... PassManagers still holds pointer to old module. This
causes uninitialised memory reads (and segfaults later) during
doFinalization() calls in the llvm_end_asm_file().

The solutions was: factor out passmanagers' creation code to separate
routine and call it in llvm_read_pch() in order to recreate passes.

I think, this patch should be propagated to 2.0 release branch, or,
otherwise PCHs should be marked as "broken in 2.0".

Patch tested with Qt compilation on x86/linux.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pch_fix.diff
Type: text/x-patch
Size: 2454 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20070517/975bde4c/attachment.bin>


More information about the llvm-commits mailing list