Skip to content

Apple M1 shows inconsistent field offset after a primitive type #42326

@tkf

Description

@tkf

@anandijain noticed (JuliaConcurrent/ConcurrentCollections.jl#35) the following difference between ARM (Apple M1) and x86_64

julia> primitive type PadAfter64 448 end

julia> mutable struct CheckPadAfter64
           a::UInt64
           pad::PadAfter64
           b::UInt64
       end

julia> fieldoffset(CheckPadAfter64, 3)
0x0000000000000040  # x86_64
0x0000000000000050  # Apple M1?

It seems to be a specific behavior that occurs only when a primitive type is used as a field. That is to say, the following tests show no difference between Apple M1 (tested with 1.7.0-rc1) and x86_64:

julia> ofs = [fieldoffset(Tuple{UInt64,NTuple{n,UInt8},UInt64}, 3) for n in 1:64]
       idx = findall(diff(ofs) .> 0)
       idx .=> ofs[idx]
7-element Vector{Pair{Int64, UInt64}}:
  8 => 0x0000000000000010
 16 => 0x0000000000000018
 24 => 0x0000000000000020
 32 => 0x0000000000000028
 40 => 0x0000000000000030
 48 => 0x0000000000000038
 56 => 0x0000000000000040

julia> sizeof(PadAfter64)
56

julia> sizeof(Some{NTuple{56,UInt8}})
56

julia> mutable struct PadWithNTuple
           a::UInt64
           pad::NTuple{56,UInt8}
           b::UInt64
       end

julia> fieldoffset(PadWithNTuple, 3)
0x0000000000000040

I don't have access to Apple M1 so I can't check this myself. But this looks like a bug to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    system:apple siliconAffects Apple Silicon only (Darwin/ARM64) - e.g. M1 and other M-series chips

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions