Skip to content

Commit d81c615

Browse files
committed
Travis build 60 on Fri Dec 18 06:22:07 UTC 2015
1 parent b1cdfd2 commit d81c615

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

atom.xml

+18-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,31 @@
4848
...
4949
</code></pre>
5050
<p>Yeah, that will work. Using the cross compiler above, and the ARM Gentoo environment set up below I was able to compile my program just fine using:</p>
51-
<pre><code>export QEMU_LD_PREFIX=$home/arm-chroot
51+
<pre><code>export QEMU_LD_PREFIX=$HOME/arm-chroot
5252

5353
cabal sandbox init
5454
cabal --with-ghc=arm-unknown-linux-gnueabihf-ghc --with-ghc-pkg=arm-unknown-linux-gnueabihf-ghc-pkg --with-ld=arm-linux-gnueabihf-ld --with-strip=arm-linux-gnueabihf-strip install</code></pre>
5555
<p>Which is <em>AWESOME</em> because the native compiler is <em>so</em> much faster than the one emulated with QEMU. This is not without caveats. For instance when compiling with multiple jobs it took forever and then ran out of memory, setting <code>-j1</code> with <code>cabal install</code> fixed this particular issue.</p>
5656
<p>A bigger problem is that there appears to be issues with the C FFI. I’m not yet sure how this works, but when I try to run an ARM binary which uses JuicyPixels to write a PNG (which relies upon zlib), I get this error:</p>
5757
<pre><code>user error (Codec.Compression.Zlib: incompatible zlib version)</code></pre>
5858
<p>but otherwise this works surprisingly well.</p>
59+
<p>After a bit of digging I have found that this error comes from <a href="https://github.com/haskell/zlib/blob/85f2d95396ff884ff22af62e5e0d6029c789db63/Codec/Compression/Zlib/Stream.hsc#L549">here</a>, and since we have got an actual failure, it’s probably from calling the <code>failIfError</code> function. That means our issue is from <a href="https://github.com/haskell/zlib/blob/85f2d95396ff884ff22af62e5e0d6029c789db63/Codec/Compression/Zlib/Stream.hsc#L953">here</a>.</p>
60+
<p>I have checked the zlib version on all of my environments, and the version is 1.2.8 everywhere. So the <em>version</em> isn’t the issue. In fact if we look at the <a href="https://github.com/madler/zlib/blob/e8fee0ea7bf62e595bd5518b7b22e3e16397278c/deflate.c#L233">code</a> for <code>c_deflateInit2_</code> we’ll notice that it’s only checking the first version number anyway:</p>
61+
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="kw">if</span> (version == Z_NULL || version[<span class="dv">0</span>] != my_version[<span class="dv">0</span>] ||
62+
stream_size != <span class="kw">sizeof</span>(z_stream)) {
63+
<span class="kw">return</span> Z_VERSION_ERROR;
64+
}</code></pre></div>
65+
<p>But there’s our problem. The size of our <code>z_stream</code> must differ somehow. If we check the <a href="https://github.com/haskell/zlib/blob/85f2d95396ff884ff22af62e5e0d6029c789db63/Codec/Compression/Zlib/Stream.hsc#L1039">Haskell Zlib library</a> we notice the following:</p>
66+
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">
67+
<span class="ot">c_deflateInit2 ::</span> <span class="dt">StreamState</span>
68+
<span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">CInt</span>
69+
c_deflateInit2 z a b c d e <span class="fu">=</span>
70+
withCAString <span class="fu">#</span>{const_str <span class="dt">ZLIB_VERSION</span>} <span class="fu">$</span> \versionStr <span class="ot">-&gt;</span>
71+
c_deflateInit2_ z a b c d e versionStr (<span class="fu">#</span>{const sizeof(z_stream)}<span class="ot"> ::</span> <span class="dt">CInt</span>)</code></pre></div>
72+
<p>I’m on an x86_64 machine, so it’s pretty much guaranteed that the <code>z_stream</code> structure on my machine differs in size to the one on the 32 bit ARM machines. This should be processed by <code>hsc2hs</code>, so that’s where the issue is. I need to be running an <code>hsc2hs</code> that targets ARM, not my native one. I had an <code>arm-unknown-linux-gnueabihf-hsc2hs</code>, but it seemed to loop forever, as did the <code>hsc2hs</code> from my chroot (but not when running it in my chroot). So that’s no good either.</p>
73+
<p>I can pass <code>hsc2hs</code> options with cabal, however, which means I can tell the native one to compile using a <code>gcc</code> cross compiler, and you know what… It takes a linker too, so let’s throw that in for good measure too!</p>
74+
<pre><code>--hsc2hs-option=&quot;-c arm-linux-gnueabihf-gcc -l arm-linux-gnueabihf-ld&quot;</code></pre>
75+
<p>Unfortunately that still doesn’t work! We’re on the right track, but not quite there yet.</p>
5976
<h1 id="running-on-the-raspberry-pi">Running on the Raspberry Pi</h1>
6077
<p>Raspbian has an old version of GHC in its repos, GHC 7.6.3, which works with simple pieces of code. For instance “Hello, World!” might compile and run perfectly well. However, my small image processing program encountered nasty, randomly changing, run time errors, and segmentation faults. Sometimes, if the stars aligned, the program would run to completion producing correct results, other times it seemed to loop forever. This is not good. One such error that I received was:</p>
6178
<pre><code>allocGroup: free list corrupted</code></pre>

posts/2015-12-15-arm.html

+18-1
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,31 @@ <h2 id="cross-compilation-with-qemu">Cross-Compilation with QEMU</h2>
8383
...
8484
</code></pre>
8585
<p>Yeah, that will work. Using the cross compiler above, and the ARM Gentoo environment set up below I was able to compile my program just fine using:</p>
86-
<pre><code>export QEMU_LD_PREFIX=$home/arm-chroot
86+
<pre><code>export QEMU_LD_PREFIX=$HOME/arm-chroot
8787

8888
cabal sandbox init
8989
cabal --with-ghc=arm-unknown-linux-gnueabihf-ghc --with-ghc-pkg=arm-unknown-linux-gnueabihf-ghc-pkg --with-ld=arm-linux-gnueabihf-ld --with-strip=arm-linux-gnueabihf-strip install</code></pre>
9090
<p>Which is <em>AWESOME</em> because the native compiler is <em>so</em> much faster than the one emulated with QEMU. This is not without caveats. For instance when compiling with multiple jobs it took forever and then ran out of memory, setting <code>-j1</code> with <code>cabal install</code> fixed this particular issue.</p>
9191
<p>A bigger problem is that there appears to be issues with the C FFI. I’m not yet sure how this works, but when I try to run an ARM binary which uses JuicyPixels to write a PNG (which relies upon zlib), I get this error:</p>
9292
<pre><code>user error (Codec.Compression.Zlib: incompatible zlib version)</code></pre>
9393
<p>but otherwise this works surprisingly well.</p>
94+
<p>After a bit of digging I have found that this error comes from <a href="https://github.com/haskell/zlib/blob/85f2d95396ff884ff22af62e5e0d6029c789db63/Codec/Compression/Zlib/Stream.hsc#L549">here</a>, and since we have got an actual failure, it’s probably from calling the <code>failIfError</code> function. That means our issue is from <a href="https://github.com/haskell/zlib/blob/85f2d95396ff884ff22af62e5e0d6029c789db63/Codec/Compression/Zlib/Stream.hsc#L953">here</a>.</p>
95+
<p>I have checked the zlib version on all of my environments, and the version is 1.2.8 everywhere. So the <em>version</em> isn’t the issue. In fact if we look at the <a href="https://github.com/madler/zlib/blob/e8fee0ea7bf62e595bd5518b7b22e3e16397278c/deflate.c#L233">code</a> for <code>c_deflateInit2_</code> we’ll notice that it’s only checking the first version number anyway:</p>
96+
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="kw">if</span> (version == Z_NULL || version[<span class="dv">0</span>] != my_version[<span class="dv">0</span>] ||
97+
stream_size != <span class="kw">sizeof</span>(z_stream)) {
98+
<span class="kw">return</span> Z_VERSION_ERROR;
99+
}</code></pre></div>
100+
<p>But there’s our problem. The size of our <code>z_stream</code> must differ somehow. If we check the <a href="https://github.com/haskell/zlib/blob/85f2d95396ff884ff22af62e5e0d6029c789db63/Codec/Compression/Zlib/Stream.hsc#L1039">Haskell Zlib library</a> we notice the following:</p>
101+
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">
102+
<span class="ot">c_deflateInit2 ::</span> <span class="dt">StreamState</span>
103+
<span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">CInt</span>
104+
c_deflateInit2 z a b c d e <span class="fu">=</span>
105+
withCAString <span class="fu">#</span>{const_str <span class="dt">ZLIB_VERSION</span>} <span class="fu">$</span> \versionStr <span class="ot">-&gt;</span>
106+
c_deflateInit2_ z a b c d e versionStr (<span class="fu">#</span>{const sizeof(z_stream)}<span class="ot"> ::</span> <span class="dt">CInt</span>)</code></pre></div>
107+
<p>I’m on an x86_64 machine, so it’s pretty much guaranteed that the <code>z_stream</code> structure on my machine differs in size to the one on the 32 bit ARM machines. This should be processed by <code>hsc2hs</code>, so that’s where the issue is. I need to be running an <code>hsc2hs</code> that targets ARM, not my native one. I had an <code>arm-unknown-linux-gnueabihf-hsc2hs</code>, but it seemed to loop forever, as did the <code>hsc2hs</code> from my chroot (but not when running it in my chroot). So that’s no good either.</p>
108+
<p>I can pass <code>hsc2hs</code> options with cabal, however, which means I can tell the native one to compile using a <code>gcc</code> cross compiler, and you know what… It takes a linker too, so let’s throw that in for good measure too!</p>
109+
<pre><code>--hsc2hs-option=&quot;-c arm-linux-gnueabihf-gcc -l arm-linux-gnueabihf-ld&quot;</code></pre>
110+
<p>Unfortunately that still doesn’t work! We’re on the right track, but not quite there yet.</p>
94111
<h1 id="running-on-the-raspberry-pi">Running on the Raspberry Pi</h1>
95112
<p>Raspbian has an old version of GHC in its repos, GHC 7.6.3, which works with simple pieces of code. For instance “Hello, World!” might compile and run perfectly well. However, my small image processing program encountered nasty, randomly changing, run time errors, and segmentation faults. Sometimes, if the stars aligned, the program would run to completion producing correct results, other times it seemed to loop forever. This is not good. One such error that I received was:</p>
96113
<pre><code>allocGroup: free list corrupted</code></pre>

rss.xml

+18-1
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,31 @@
4444
...
4545
</code></pre>
4646
<p>Yeah, that will work. Using the cross compiler above, and the ARM Gentoo environment set up below I was able to compile my program just fine using:</p>
47-
<pre><code>export QEMU_LD_PREFIX=$home/arm-chroot
47+
<pre><code>export QEMU_LD_PREFIX=$HOME/arm-chroot
4848

4949
cabal sandbox init
5050
cabal --with-ghc=arm-unknown-linux-gnueabihf-ghc --with-ghc-pkg=arm-unknown-linux-gnueabihf-ghc-pkg --with-ld=arm-linux-gnueabihf-ld --with-strip=arm-linux-gnueabihf-strip install</code></pre>
5151
<p>Which is <em>AWESOME</em> because the native compiler is <em>so</em> much faster than the one emulated with QEMU. This is not without caveats. For instance when compiling with multiple jobs it took forever and then ran out of memory, setting <code>-j1</code> with <code>cabal install</code> fixed this particular issue.</p>
5252
<p>A bigger problem is that there appears to be issues with the C FFI. I’m not yet sure how this works, but when I try to run an ARM binary which uses JuicyPixels to write a PNG (which relies upon zlib), I get this error:</p>
5353
<pre><code>user error (Codec.Compression.Zlib: incompatible zlib version)</code></pre>
5454
<p>but otherwise this works surprisingly well.</p>
55+
<p>After a bit of digging I have found that this error comes from <a href="https://github.com/haskell/zlib/blob/85f2d95396ff884ff22af62e5e0d6029c789db63/Codec/Compression/Zlib/Stream.hsc#L549">here</a>, and since we have got an actual failure, it’s probably from calling the <code>failIfError</code> function. That means our issue is from <a href="https://github.com/haskell/zlib/blob/85f2d95396ff884ff22af62e5e0d6029c789db63/Codec/Compression/Zlib/Stream.hsc#L953">here</a>.</p>
56+
<p>I have checked the zlib version on all of my environments, and the version is 1.2.8 everywhere. So the <em>version</em> isn’t the issue. In fact if we look at the <a href="https://github.com/madler/zlib/blob/e8fee0ea7bf62e595bd5518b7b22e3e16397278c/deflate.c#L233">code</a> for <code>c_deflateInit2_</code> we’ll notice that it’s only checking the first version number anyway:</p>
57+
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="kw">if</span> (version == Z_NULL || version[<span class="dv">0</span>] != my_version[<span class="dv">0</span>] ||
58+
stream_size != <span class="kw">sizeof</span>(z_stream)) {
59+
<span class="kw">return</span> Z_VERSION_ERROR;
60+
}</code></pre></div>
61+
<p>But there’s our problem. The size of our <code>z_stream</code> must differ somehow. If we check the <a href="https://github.com/haskell/zlib/blob/85f2d95396ff884ff22af62e5e0d6029c789db63/Codec/Compression/Zlib/Stream.hsc#L1039">Haskell Zlib library</a> we notice the following:</p>
62+
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">
63+
<span class="ot">c_deflateInit2 ::</span> <span class="dt">StreamState</span>
64+
<span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">CInt</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">CInt</span>
65+
c_deflateInit2 z a b c d e <span class="fu">=</span>
66+
withCAString <span class="fu">#</span>{const_str <span class="dt">ZLIB_VERSION</span>} <span class="fu">$</span> \versionStr <span class="ot">-&gt;</span>
67+
c_deflateInit2_ z a b c d e versionStr (<span class="fu">#</span>{const sizeof(z_stream)}<span class="ot"> ::</span> <span class="dt">CInt</span>)</code></pre></div>
68+
<p>I’m on an x86_64 machine, so it’s pretty much guaranteed that the <code>z_stream</code> structure on my machine differs in size to the one on the 32 bit ARM machines. This should be processed by <code>hsc2hs</code>, so that’s where the issue is. I need to be running an <code>hsc2hs</code> that targets ARM, not my native one. I had an <code>arm-unknown-linux-gnueabihf-hsc2hs</code>, but it seemed to loop forever, as did the <code>hsc2hs</code> from my chroot (but not when running it in my chroot). So that’s no good either.</p>
69+
<p>I can pass <code>hsc2hs</code> options with cabal, however, which means I can tell the native one to compile using a <code>gcc</code> cross compiler, and you know what… It takes a linker too, so let’s throw that in for good measure too!</p>
70+
<pre><code>--hsc2hs-option=&quot;-c arm-linux-gnueabihf-gcc -l arm-linux-gnueabihf-ld&quot;</code></pre>
71+
<p>Unfortunately that still doesn’t work! We’re on the right track, but not quite there yet.</p>
5572
<h1 id="running-on-the-raspberry-pi">Running on the Raspberry Pi</h1>
5673
<p>Raspbian has an old version of GHC in its repos, GHC 7.6.3, which works with simple pieces of code. For instance “Hello, World!” might compile and run perfectly well. However, my small image processing program encountered nasty, randomly changing, run time errors, and segmentation faults. Sometimes, if the stars aligned, the program would run to completion producing correct results, other times it seemed to loop forever. This is not good. One such error that I received was:</p>
5774
<pre><code>allocGroup: free list corrupted</code></pre>

0 commit comments

Comments
 (0)