Bug 18956 - AOT compiler generates invalid .so files in ARM hardfp
Summary: AOT compiler generates invalid .so files in ARM hardfp
Status: NEW
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: 4.0.0
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-04-11 12:16 UTC by Andres G. Aragoneses
Modified: 2015-08-05 21:08 UTC (History)
7 users (show)

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


Attachments

Description Andres G. Aragoneses 2014-04-11 12:16:21 UTC
When using ldd in a .so file generated by `mono --aot=full` it gives me the following output:

	statically linked

However, in ARM hardfp, mono 3.2.8, this is the output:

	not a dynamic executable


Consequently, when trying to load this .so file in this architecture, I get the following error:

Mono: Assembly Loader probing location: '/usr/lib/mono/4.5/mscorlib.dll'.
Mono: Image addref mscorlib[0x28f360] -> /usr/lib/mono/4.5/mscorlib.dll[0x28e9e0]: 2
Mono: AOT module '/usr/lib/mono/4.5/mscorlib.dll.so' not found: /usr/lib/mono/4.5/mscorlib.dll.so: cannot open
shared object file: No such file or directory
Comment 1 Andres G. Aragoneses 2014-04-11 12:52:56 UTC
Full OS+hardware spec:

# uname -a
Linux udoo-debian-hfp 3.0.35 #1 SMP PREEMPT Wed Dec 11 12:37:27 CET 2013 armv7l GNU/Linux
Comment 2 Andres G. Aragoneses 2014-04-12 12:51:08 UTC
Hey Zoltan,

(In reply to bug 17017 comment #27)
> AOT on an armhf system works fine for me.

I assume you're talking about mono master. Do you know if mono 3.2.8 could have had any problem generating AOT libs in ARMhf? Have you fixed any issue recently about this in 3.2.8->HEAD interval? Thanks
Comment 3 Zoltan Varga 2014-04-12 18:03:13 UTC
3.2.8 will definitely not work on armhf systems, the armhf support is only in 3.4.0/master.

Also, this is not an error message:

Mono: AOT module '/usr/lib/mono/4.5/mscorlib.dll.so' not found:
/usr/lib/mono/4.5/mscorlib.dll.so: cannot open
shared object file: No such file or directory

It usually means the .so file is not there.
Comment 4 Andres G. Aragoneses 2014-04-12 18:30:24 UTC
> 3.2.8 will definitely not work on armhf systems, the armhf support is only in
3.4.0/master.

Ok thanks, will test on master.


> It usually means the .so file is not there.

In this case I swear it's there, and with 777 permissions.

In fact a single C program that tries to dlopen() it also throws the same error, which is what made me suspicious about the possible invalid nature of the file (that's why I tested with ldd, which under the hood runs  /lib/ld-linux.so.2 --verify $(theDotSoFile) and returns 1 for this case)
Comment 5 Dale 2014-05-07 09:37:40 UTC
I'm having the same issue with arm hard float. I'm running on Mono 3.4.0 which I've built Mono for targeting a TI Arago base system that can run on Beagle bones.

It aot is used the program simply returns the prompt with no error. Example:

for this HelloWorld.cs:
--------
using System;

namespace testapp
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			Console.WriteLine ("Hello World!");
		}
	}
}
--------

To reproduce on an ARM am335x device:

root@am335x-evm:~# mcs -sdk:2 HelloWorld.cs
root@am335x-evm:~# mono --runtime=2.0 HelloWorld.exe
WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v2.0.50727
Hello World!
root@am335x-evm:~# mono --aot --runtime=2.0 HelloWorld.exe
WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v2.0.50727
Mono Ahead of Time compiler - compiling assembly /home/root/HelloWorld.exe
Code: 60 Info: 5 Ex Info: 6 Unwind Info: 14 Class Info: 30 PLT: 2 GOT Info: 13 GOT: 28 Offsets: 49
Compiled: 2/2 (100%), No GOT slots: 1 (50%), Direct calls: 0 (100%)
JIT time: 2 ms, Generation time: 1 ms, Assembly+Link time: 1 ms.
root@am335x-evm:~# mono --runtime=2.0 HelloWorld.exe
WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v2.0.50727
<NO_OUTPUT_PRODUCED>
root@am335x-evm:~#
--------

No error at all. This all works for the 3.4.0 runtime I've created for Ubuntu 12.04.

Dale
Comment 6 Dale 2014-05-07 09:43:46 UTC
Some additional data:
--------
root@am335x-evm:~# MONO_LOG_LEVEL=debug mono --runtime=2.0 HelloWorld.exe
WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v2.0.50727
Mono: Assembly Loader probing location: '/usr/lib/mono/2.0/mscorlib.dll'.
Mono: Image addref mscorlib[0x326018] -> /usr/lib/mono/2.0/mscorlib.dll[0x3256e8]: 2
Mono: AOT module '/usr/lib/mono/2.0/mscorlib.dll.so' not found: /usr/lib/mono/2.0/mscorlib.dll.so: cannot open shared object file: No such file or directory

Mono: Assembly Loader loaded assembly from location: '/usr/lib/mono/2.0/mscorlib.dll'.
Mono: Config attempting to parse: '/usr/lib/mono/2.0/mscorlib.dll.config'.
Mono: Config attempting to parse: '/etc/mono/assemblies/mscorlib/mscorlib.config'.
Mono: Assembly mscorlib[0x326018] added to domain HelloWorld.exe, ref_count=1
Mono: Config attempting to parse: '/etc/mono/config'.
Mono: Config attempting to parse: '/home/root/.mono/config'.
Mono: Assembly Loader probing location: 'HelloWorld.exe'.
Mono: Image addref HelloWorld[0x35cd98] -> /home/root/HelloWorld.exe[0x35b070]: 2
Mono: Assembly HelloWorld[0x35cd98] added to domain HelloWorld.exe, ref_count=1
root@am335x-evm:~#
--------
Dale
Comment 7 Dale 2014-08-31 13:42:28 UTC
I've just verified that this is still broken in Mono's "master" branch (vintage 8/31/2014-5646004e39f1b4034448ed6e791b26d208135a12)found on Github.

I traced the failure to the "dlopen" call done by the mono runtime to load the *.so file. The call never returns and the program simply exits to the prompt. I created a simple test program that has the same results when attempting to load the AOT created file. I've tested this on a BeagleBone white card.

int main(void)
{
    void* solib = dlopen("/home/root/hello.exe.so", 0x101); // 0x101
    printf("solib = 0x%08x\n", (unsigned int)solib);
    if (solib == NULL)
    {
    	int err = errno;
    	printf("dlopen() - ERROR (%d) - %s\n", err, strerror(err));
    }
    else
    	printf("dlopen() - Succeeded.\n");

	return EXIT_SUCCESS;
}

I created the file with the command "mono --aot hello.exe" on the device. The Mono runtime version built from master looks like this:

root@am335x-evm:~# mono -V
Mono JIT compiler version 3.8.1 ((no/5646004 Sun Aug 31 12:11:19 CDT 2014)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+hard
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

An excerpt from STRACE of the run looks like this:

root@am335x-evm:~# strace mono hello.exe
execve("/usr/bin/mono", ["mono", "hello.exe"], [/* 13 vars */]) = 0
brk(0)                                  = 0x312000
uname({sys="Linux", node="am335x-evm", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f12000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=14499, ...}) = 0
mmap2(NULL, 14499, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6f0e000
close(3)                                = 0
:
:
:
mmap2(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb5c1c000
mprotect(0xb5c1c000, 4096, PROT_NONE)   = 0
clone(child_stack=0xb5d1af68, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0xb5d1b498, tls=0xb5d1b8f0, child_tidptr=0xb5d1b498) = 1501
futex(0xbed76a9c, FUTEX_WAIT_PRIVATE, 0, NULL) = 0
futex(0x327d34, FUTEX_WAIT_PRIVATE, 1, NULL) = 0
futex(0x327d14, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x327d14, FUTEX_WAKE_PRIVATE, 1)  = 0
open("/proc/self/task/1501/comm", O_RDWR) = 3
write(3, "Finalizer", 9)                = 9
close(3)                                = 0
open("/dev/null", O_RDWR|O_LARGEFILE)   = 3
close(3)                                = 0
open("/etc/mono/config", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=2353, ...}) = 0
read(3, "<configuration>\n\t<dllmap dll=\"i:"..., 2353) = 2353
close(3)                                = 0
open("/home/root/.mono/config", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=1182, ...}) = 0
read(3, "<?xml version=\"1.0\"?>\n<!--\n  Thi"..., 1182) = 1182
close(3)                                = 0
getcwd("/home/root", 32)                = 11
getcwd("/home/root", 32)                = 11
open("/home/root/hello.exe.so", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\20\0\0004\0\0\0"..., 512) = 512
lseek(3, 10764, SEEK_SET)               = 10764
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 800) = 800
exit_group(1)                           = ?
+++ exited with 1 +++
root@am335x-evm:~#
Comment 8 Zoltan Varga 2014-08-31 17:42:28 UTC
Could you try with
mono -O=asmwriter <dll>
?
Comment 9 Zoltan Varga 2014-08-31 17:42:41 UTC
I mean mono --aot=asmwriter <dll>
Comment 10 Dale 2014-08-31 17:46:29 UTC
You bet!...

root@am335x-evm:~# mono --aot=asmwriter hello.exe
Mono Ahead of Time compiler - compiling assembly /home/root/hello.exe
Code: 60(33%) Info: 5(2%) Ex Info: 6(3%) Unwind Info: 14(7%) Class Info: 30(16%) PLT: 2(0%) GOT Info: 13(7%) Offsets: 49(27%) GOT: 28
Compiled: 2/2 (100%), No GOT slots: 1 (50%), Direct calls: 0 (100%)
Executing the native assembler: as   -o /tmp/mono_aot_KZAqHo.o /tmp/mono_aot_KZAqHo
Executing the native linker: ld  -shared -o /home/root/hello.exe.so.tmp /tmp/mono_aot_KZAqHo.o
Stripping the binary: strip --strip-symbol=\$a --strip-symbol=\$d /home/root/hello.exe.so.tmp
JIT time: 2 ms, Generation time: 3 ms, Assembly+Link time: 91 ms.
root@am335x-evm:~#
Comment 11 Dale 2014-08-31 17:54:43 UTC
The generated .so file still causes the program to simply exit.

Dale
Comment 12 Alex Rønne Petersen 2015-05-07 20:19:28 UTC
Can you try again with Mono master? Some arm(hf) fixes have been done in the meantime that might affect this.
Comment 13 mgi 2015-08-05 16:19:11 UTC
I can repro the issue with Mono 4.0.2 on a Banana Pro board (Bananian 15.08 based on wheezy armhf) as described by the OP
the generated aot .so files just refuse to load, and ldd complains in the same way. 
same result with --aot=asmwriter 
i can provide more details if anyone is still interested

Note You need to log in before you can comment on or make changes to this bug.