[Haskell-cafe] cabal keeps relinking

Semen Trygubenko / Семен Тригубенко semen at trygub.com
Fri Jan 23 15:49:56 UTC 2015


On Tue, Nov 11, 2014 at 08:28:26PM +0100, Niklas Hambüchen wrote:
> Ok, so it seems like it works on Linux, but not FreeBSD.
> 
> To explain the situation a little bit:
> 
> The compiled object files (.o) are linked together in an archive file
> (.a) by the `ar` program (similar to `tar`).
> The file entries in the .a file by default contain timestamps of the
> files, which usually means the mtime (last modification time).
> The build only looks at the .a file as a whole, and if its contents
> changed from the last build, it has to relink. Of course if a timestamp
> inside the .a changed, that's treated as "the .a file is different".
> 
> Newer versions of `ar` have a -D option to avoid putting the mtimes of
> the .o files into the archive. But not all platforms supported by
> GHC/cabal support this flag. That's why we implemented a manual method
> to wipe the timestamps (set them to 0), so that they can no longer have
> an effect on the build.
> 
> Seems like that doesn't work for FreeBSD. That's a shame, because we did
> take special care to make sure that it works cross-platform.

Thanks for your reply!


> You could help debug it:
> 
> First, create an issue on cabal's Github so that we can track the bug,
> and explain the problem there and paste the output.

Done — see https://github.com/haskell/cabal/issues/2384 .

Also, I've re-run it with the latest cabal

cabal-install version 1.22.0.0
using version 1.22.0.0 of the Cabal library

and noticed a bit of a difference in behaviour this time. Namely, for the sequence
I've ran (as before):

cabal clean
cabal build
cabal test
cabal build
cabal test

There's an improvement in both "cabal test" steps when moving to 1.22 in the sense
that the following lines have disappeared from the output:

Building cabalTest-0.1.0.0...
Preprocessing executable 'cabalTest' for cabalTest-0.1.0.0...
Linking dist/build/cabalTest/cabalTest ...

(i.e., when running test target the exe itself (named cabalTest) is no longer relinked unnecessarily,
only the test for it (named cabalTestTest).

However, when compared with old output on Linux there are still some
extra relinks present:

For the second run of "cabal bulid" I still see

Linking dist/build/cabalTest/cabalTest …
Linking dist/build/CabalTestTest/CabalTestTest …

For the second run of "cabal test" I still see

Linking dist/build/CabalTestTest/CabalTestTest ...

So it seems that the problem is still present in the latest version,
it's just that test target no longer relinks the exes, only test exes.


> Then try to find the created .a file (the -v outputs should help you
> where it is, something like libHSyourlibrary.a or similar), and observe
> how its contents change across different builds (you could use `cmp` to
> check if the files are byte-identical or something like `diff -u <(xxd
> firstbuild.a) <(xxd secondbuild.a)` to view the contents as a hex diff).

I ran this:

cabal clean
cabal build
cp ./dist/build/libHScabalTest-0.1.0.0.a build.a
cabal test
cp ./dist/build/libHScabalTest-0.1.0.0.a test.a
cabal build
cp ./dist/build/libHScabalTest-0.1.0.0.a rebuild.a
cabal test
cp ./dist/build/libHScabalTest-0.1.0.0.a retest.a

All .a files are identical.


> Then try to see if this program I wrote:
>   http://hackage.haskell.org/package/ar-timestamp-wiper
> makes the two .a files byte-identical.

Installed ar-timestamp-wiper-0.1.0 .
Running e.g.

ar-timestamp-wiper build.a

does not change its md5.


> That will probably help us find the issue and get relinking-avoidance
> also on the BSDs.
> 
> On 11/11/14 13:01, Semen Trygubenko / Семен Тригубенко wrote:
> > So it seems that what I've observed is FreeBSD-specific — FreeBSD rebuild outputs have extra "Linking ..." messages in them…

Let me know if I could be of further help!

Thanks again,
S.


-- 
Семен Тригубенко http://trygub.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150123/87ed8a71/attachment.sig>


More information about the Haskell-Cafe mailing list