haskell / haskell/bytestring

storableToF should use target instead of host arch?

Open
#530 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
301
Forks
144
Avg merge
7d 22h
Merged PRs (30d)
1

Description

Currently we have:

```
{-# INLINE CONLIKE storableToF #-}
storableToF :: forall a. Storable a => FixedPrim a
-- Not all architectures are forgiving of unaligned accesses; whitelist ones
-- which are known not to trap (either to the kernel for emulation, or crash).
#if defined(i386_HOST_ARCH) || defined(x86_64_HOST_ARCH) \
|| ((defined(arm_HOST_ARCH) || defined(aarch64_HOST_ARCH)) \
&& defined(__ARM_FEATURE_UNALIGNED)) \
|| defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) \
|| defined(powerpc64le_HOST_ARCH)
storableToF = FP (sizeOf (undefined :: a)) (\x op -> poke (castPtr op) x)
#else
storableToF = FP (sizeOf (undefined :: a)) $ \x op ->
if ptrToWordPtr op `mod` fromIntegral (alignment (undefined :: a)) == 0 then poke (castPtr op) x
else with x $ \tp -> copyBytes op (castPtr tp) (sizeOf (undefined :: a))
#endif
```

Isn't this broken during cross compilation? E.g. if I compile on powerpc_HOST_ARCH targeting a platform that doesn't support unaligned access wouldn't this fall over?

I'm not an expert on cross compilation but seemed wrong to me.

Contributor guide

No contributing guide indexed for this repository

Research direction

Locate storableToF and the architecture conditionals shown in the issue; first verify whether HOST_ARCH refers to the build or target architecture during cross compilation. Inspect or reproduce a cross-compilation setup where target alignment differs, then confirm the safe unaligned-access path is selected for the target; done means behavior is correct for that target.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.