Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unsafe.ReadUnaligned not working on armv5 #19142

@topschrott

Description

@topschrott

I'm getting wrong results when using the BitConverter to extract a 16-bit or 32-bit integer on my ARMv5 platform since moving from Mono 5 to version 6.

In Mono version 6, the BitConverter is using Unsafe.ReadUnaligned instead of implementing it directly, as in version 5.

To me, it looks like Unsafe.ReadUnaligned is not working properly and a simple type-cast is used from an unaligned address. Of course it is also possible that I am missing a build-option when compiling Mono?

Issue #18221 might be related, but I am not using the llvm.

Steps to Reproduce

I'm using the following test code:

byte[] buf = new byte[] {0x11, 0x22, 0x33, 0x44, 0x55};

for (int i=0; i<4; i++) {
    int v = BitConverter.ToUInt16(buf, i);
    Console.WriteLine(String.Format("{0}: {1:X}", i, v));
}

The output on the ARM platform is:

0: 2211
1: 2211
2: 4433
3: 4433

Of course, I expect it to say:

0: 2211
1: 3322
2: 4433
3: 5544

The Mono runtime is built by Buildroot with the following configure options:

        --with-mcs-docs=no \
        --enable-small-config=yes \
        --with-ikvm-native=no \
        --enable-minimal=attach,com,debug,profiler,shadow_copy,simd \
        --enable-static

I'm executing my test with:

mono -O=-float32 test.exe

On which platforms did you notice this

[ ] macOS
[x] Linux
[ ] Windows

Version Used:

mono --version
Mono JIT compiler version 6.8.0.105 (tarball Fri  6 Mar 11:04:59 UTC 2020)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+fallback
        Disabled:      attach,com,debug,profiler,shadow_copy,simd
        Misc:          smallconfig softdebug 
        Interpreter:   yes
        LLVM:          supported, not enabled.
        Suspend:       preemptive
        GC:            sgen (concurrent by default)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions