[GHC] #9689: const_str support needed for hsc2hs in cross-compilation mode

#9689: const_str support needed for hsc2hs in cross-compilation mode -------------------------------------+------------------------------------- Reporter: aosivitz | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: hsc2hs | Version: 7.8.3 Keywords: zlib ios cross- | Operating System: compilation | Unknown/Multiple Architecture: arm | Type of failure: Other Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Building zlib-0.5.4.1 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. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9689 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9689: const_str support needed for hsc2hs in cross-compilation mode -------------------------------------+------------------------------------- Reporter: aosivitz | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.3 Component: hsc2hs | Keywords: zlib ios cross- Resolution: | compilation Operating System: | Architecture: arm Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (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. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9689#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9689: const_str support needed for hsc2hs in cross-compilation mode -------------------------------------+------------------------------------- Reporter: aosivitz | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.3 Component: hsc2hs | Keywords: zlib ios cross- Resolution: | compilation Operating System: | Architecture: arm Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (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: http://lpaste.net/8287391336118616064 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9689#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9689: const_str support needed for hsc2hs in cross-compilation mode -------------------------------------+------------------------------------- Reporter: aosivitz | Owner: Type: feature | Status: closed request | Milestone: Priority: normal | Version: 7.8.3 Component: hsc2hs | Keywords: zlib ios cross- Resolution: wontfix | compilation Operating System: | Architecture: arm Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by aosivitz): * status: new => closed * resolution: => wontfix Comment: 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! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9689#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9689: const_str support needed for hsc2hs in cross-compilation mode -------------------------------------+------------------------------------- Reporter: aosivitz | Owner: Type: feature | Status: closed request | Milestone: Priority: normal | Version: 7.8.3 Component: hsc2hs | Keywords: zlib ios cross- Resolution: wontfix | compilation Operating System: | Architecture: arm Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (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). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9689#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9689: const_str support needed for hsc2hs in cross-compilation mode -------------------------------------+------------------------------------- Reporter: aosivitz | Owner: Type: feature | Status: closed request | Milestone: Priority: normal | Version: 7.8.3 Component: hsc2hs | Keywords: zlib ios cross- Resolution: wontfix | compilation Operating System: | Architecture: arm Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by aosivitz): Yep, it works for me (ghc 7.8.3, arm) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9689#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC