Bug 12541 - (bisected) Assertion at mini-amd64.c:487, condition `amd64_is_imm32 (disp)' not met
Summary: (bisected) Assertion at mini-amd64.c:487, condition `amd64_is_imm32 (disp)' n...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-06-04 13:56 UTC by Micael Dias
Modified: 2015-02-24 11:42 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Micael Dias 2013-06-04 13:56:44 UTC
This is a regression.

I have an app that embeds Mono to use C# DLL scripts. When I instantiate a C# object using mono_object_new() and then call mono_runtime_object_init() on it it crashes at mini-amd64.c:487.

I bisected this crash to this commit: https://github.com/mono/mono/commit/6285a057a248e65301def835dfc5971e6df29a39
and as far as I could debug it, it happens because a call is marked as near call but the target value is > 2^32 or something like that (I'm not an expert with compilers, sorry).

When it crashes I get this on the console (Timer.ctor is the ctor of the object being initialized, and all the ctor does is print a line of simple text to the console):

TYPE: 32
* Assertion at mini-amd64.c:487, condition `amd64_is_imm32 (disp)' not met

Stacktrace:

  at <unknown> <0xffffffff>
  at System.Console..cctor () <0x0001b>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
  at <unknown> <0xffffffff>
  at MyEngine.Timer..ctor () <0x0001f>
  at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <0xffffffff>
Comment 1 Micael Dias 2013-06-04 14:01:02 UTC
Stacktrace of the crashing thread:

Thread 1 (Thread 0x7ff04e5f47c0 (LWP 23156)):
#0  0x00007ff04bc307f9 in waitpid () from /usr/lib/libc.so.6
#1  0x00007ff04d3ef4bc in mono_handle_native_sigsegv (signal=<optimized out>, ctx=<optimized out>) at mini-exceptions.c:2344
#2  <signal handler called>
#3  0x00007ff04bbaf1c9 in raise () from /usr/lib/libc.so.6
#4  0x00007ff04bbb05c8 in abort () from /usr/lib/libc.so.6
#5  0x00007ff04d5496d5 in monoeg_g_logv (log_domain=log_domain@entry=0x0, log_level=log_level@entry=G_LOG_LEVEL_ERROR, format=format@entry=0x7ff04d564978 "* Assertion at %s:%d, condition `%s' not met\n", args=args@entry=0x7fffa16b3868) at goutput.c:175
#6  0x00007ff04d549816 in monoeg_assertion_message (format=format@entry=0x7ff04d564978 "* Assertion at %s:%d, condition `%s' not met\n") at goutput.c:195
#7  0x00007ff04d427501 in amd64_patch (target=<optimized out>, code=0x41e2f012 "\350Iج\375H\213\f$L\213\\$\bI\211\vL\213|$PH\203\304", <incomplete sequence \303>) at mini-amd64.c:487
#8  mono_arch_patch_code (method=0x2529340, domain=0x7ff04e4f7cc0, code=0x41e2efc0 "H\203\354XH\211d$0H\211\\$ H\211l$(L\211d$8L\211l$@L\211t$HL\211|$PL\213\377I\273", ji=<optimized out>, dyn_code_mp=<optimized out>, run_cctors=1) at mini-amd64.c:6531
#9  0x00007ff04d35b9c6 in mono_codegen (cfg=cfg@entry=0x2523ea0) at mini.c:3956
#10 0x00007ff04d35c929 in mini_method_compile (method=<optimized out>, opts=opts@entry=101805055, domain=domain@entry=0x7ff04e4f7cc0, run_cctors=run_cctors@entry=1, compile_aot=compile_aot@entry=0, parts=parts@entry=0) at mini.c:5367
#11 0x00007ff04d35fe63 in mono_jit_compile_method_inner (jit_ex=0x7fffa16b3c48, opt=101805055, target_domain=0x7ff04e4f7cc0, method=0x2529340) at mini.c:5689
#12 mono_jit_compile_method_with_opt (method=0x2529340, opt=101805055, ex=ex@entry=0x7fffa16b3c48) at mini.c:5953
#13 0x00007ff04d3609ed in mono_jit_compile_method (method=<optimized out>) at mini.c:5981
#14 0x00007ff04d3f129b in common_call_trampoline (regs=0x7fffa16b3f08, code=0x41e2edcc "H\213\310H\307A(0\211R\002H\307A8\240lQ\002H\307A\030\226\355\342AH\270\250\217QN\360\177", m=0x2529340, vt=0x0, vtable_slot=<optimized out>, need_rgctx_tramp=0, tramp=<optimized out>) at mini-trampolines.c:567
#15 0x0000000041d79192 in ?? ()
#16 0x0000000000000000 in ?? ()
Comment 2 Zoltan Varga 2013-06-06 11:25:55 UTC
Fixed in master by 2424b67a3b55df01a3d70e31d1455429247dfa66.
Comment 3 Mimi 2015-02-24 10:46:27 UTC
I got the same problem here.

Scenario:

1)On Os X 10.8.5, download mono-3.12.0.tar.bz2 and MonoFramework-MDK-3.12.0.macos10.xamarin.x86.pkg. Build Mono 64 bits disabling nls and mcs-build. Install Mono 32 bits and merge it with Mono 64 bits. Test with hello.cs and Mono works fine.

2)Create a C# class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class Class1
    {
        public Class1() { }
        public void GreetPeople()
        {
            Console.WriteLine("Hello World\n");
        }
    }
}

3)Embed Mono in C++ code:

#include "mainwindow.h"
#include <QApplication>

#include <Headers/glib-2.0/glib.h>
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

        MonoDomain * domain = mono_jit_init ("Domain");

        MonoAssembly * assembly = NULL;
        assembly = mono_domain_assembly_open (domain, "/Users/mac1/Downloads/zachary/TestLib/libs/ClassLibrary1.dll");
        if (!assembly)
        {
            printf("Open assembly error\n");
        }
        else
        {
            printf("Assembly is loaded\n");
        }

        MonoImage * image = NULL;
        image = mono_assembly_get_image(assembly);
        if (!image)
        {
            printf("Get image error\n");
        }
        else
        {
            printf("Get image successfully\n");
        }

        MonoClass* classHandle = NULL;
        classHandle = mono_class_from_name(image, "ClassLibrary1", "Class1");
        if (!classHandle)
        {
            printf("Get class error\n");
        }
        else
        {
            printf("Get class successfully\n");
        }


        MonoObject* object = NULL;
        object = mono_object_new(domain, classHandle);
        if (!classHandle)
        {
            printf("Get object error\n");
        }
        else
        {
            printf("Get object successfully\n");
        }

        mono_runtime_object_init(object);

        printf("Happy New Year!\n");

    return a.exec();
}

4)Console output:

Debugging starts
Assembly is loaded
Get image successfully
Get class successfully
Get object successfully
Can't find custom attr constructor image: /Users/mac1/Downloads/zachary/TestLib/libs/ClassLibrary1.dll mtoken: 0x0a000001
* Assertion at class.c:5695, condition `!mono_loader_get_last_error ()' not met

Debugging has finished


I made some research and learnt that the bug was fixed. Does anybody know what is going on here? Any help is appreciated.

Zachary
Comment 4 Mimi 2015-02-24 11:42:51 UTC
Sorry. There is an error in the original c++ code. It should be read as:

        MonoObject* object = NULL;
        object = mono_object_new(domain, classHandle);
        if (!object)
        {
            printf("Get object error\n");
        }
        else
        {
            printf("Get object successfully\n");
        }

The console outputs are the same, though.

Zachary