Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#9689 closed feature request (wontfix)

const_str support needed for hsc2hs in cross-compilation mode

Reported by: aosivitz Owned by:
Priority: normal Milestone:
Component: hsc2hs Version: 7.8.3
Keywords: zlib ios cross-compilation Cc:
Operating System: Unknown/Multiple Architecture: arm
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Building zlib- in cross-compilation mode using ghc-ios fails with the following message: Codec/Compression/Zlib/Stream.hsc:924 directive const_str cannot be handled in cross-compilation mode

Is it possible to add support for const_str so that zlib can be built? I am not an experienced GHC developer, but I would be happy to help however I can if it is possible.

Change History (5)

comment:1 Changed 4 years ago by aosivitz

Digging a little deeper...

The reason why const_str is not currently supported is that strings cannot be calculated for a cross-compiled target platform the same way numbers can.

Booleans can be calculated by attempting to compile a specific program that uses the boolean value in a static array size. The compiler must calculate the array size to determine if it is non-negative. (A negative array size is a compiler error.) This trick can be extended to numbers repeatedly using them to form boolean expressions and performing a binary search.

A const_str is something like #define VERSION "1.2.3"

Since a string is just an array of chars, shouldn't we be able to calculate it at compile time as well?

We can get the length of a string by testing for -Warray-bounds and -Werror. And then calculate the value of the array at each index.

comment:2 Changed 4 years ago by rwbarton

You can also get the length of a string with sizeof, but I don't think it's possible to extract the characters, at least not as far as anybody knows. The obvious attempts like /* const char s[]; */ int x[s[0]]; don't work because s[0] is not considered a constant expression.

IIRC I looked and didn't find a way to detect string constants when cross-compiling with autoconf either.

For zlib in particular, I have a patch that avoids the need for string constants:

comment:3 Changed 4 years ago by aosivitz

Resolution: wontfix
Status: newclosed

Yea, I ran into that as well. zlib is the only problem package I've personally encountered, so that patch is great for me. Thanks!

I'll close this, and pass on the patch to the zlib maintainer, unless you've already done so.

Thanks again!

comment:4 Changed 4 years ago by rwbarton

I've sent Duncan the patch, but if you have a chance to test it in earnest, that would be great (I've only tested that it builds under various configurations).

comment:5 Changed 4 years ago by aosivitz

Yep, it works for me (ghc 7.8.3, arm)

Note: See TracTickets for help on using tickets.