Skip to content

"dl_main: Assertion 'main_map != NULL' failed!" when executing mipsel binary #325

@spidermana

Description

@spidermana

Hi, I encountered some difficulties recently. I sincerely ask for a help.

These days, I am trying to execute a binary compiled for mips, so I write a quite simple program below:

int main(){
	int a;
	a=32;
}

and then compile it by command:mipsel-linux-gnu-gcc ./tests/hello.c -o ./tests/hello-mipsel.

After that, I run the binary through ./usercorn run ./tests/hello_mipsel

But it doesn't work and throw an assertion error.:
Inconsistency detected by ld.so: rtld.c: 983: dl_main: Assertion 'main_map != NULL' failed!

Details for trace:

0xc23c80: lb $v0, ($s6)                                      |                 | R c338a4
0xc23c84: bnez $v0, 0xc23bcc                                 |                
0xc23c88: move $at, $at                                      |                
0xc23c8c: lw $a0, 0x270($fp)                                 | a0 = 0x00000002 | R bfffe980
R 0x00c338a4: 00                                             [.                   ] R
R 0xbfffe980: 02000000                                       [....                ] R
0xc23c90: addiu $a1, $fp, 0x20                               | a1 = 0xbfffe730
0xc23c94: move $a2, $s5                                      | a2 = 0x0000000a
0xc23c98: addiu $v0, $zero, 0x1032                           | v0 = 0x00001032
Inconsistency detected by ld.so: rtld.c: 983: dl_main: Assertion `main_map != NULL' failed!
[note : Actually you can see a fault here!!!!]
0xc23c9c: syscall                                            | v0 = 0x0000005c
writev(2, 0xbfffe730, 0xa) = 0x5c
0xc23ca0: move $sp, $fp                                      | sp = 0xbfffe710
0xc23ca4: lw $ra, 0x26c($sp)                                 | ra = 0x00c241ec | R bfffe97c
0xc23ca8: lw $fp, 0x268($sp)                                 | s8 = 0xbfffe9d8 | R bfffe978
0xc23cac: lw $s7, 0x264($sp)                                 | s7 = 0x00c31000 | R bfffe974
0xc23cb0: lw $s6, 0x260($sp)                                 | s6 = 0x00c44ef0 | R bfffe970
0xc23cb4: lw $s5, 0x25c($sp)                                 | s5 = 0x00400034 | R bfffe96c
0xc23cb8: lw $s4, 0x258($sp)                                 | s4 = 0x00c452c8 | R bfffe968
0xc23cbc: lw $s3, 0x254($sp)                                 | s3 = 0x00c2b810 | R bfffe964
0xc23cc0: lw $s2, 0x250($sp)                                 | s2 = 0x00c2ea30 | R bfffe960
0xc23cc4: lw $s1, 0x24c($sp)                                 | s1 = 0x00000000 | R bfffe95c
0xc23cc8: lw $s0, 0x248($sp)                                 |                 | R bfffe958
0xc23ccc: jr $ra                                             |                
0xc23cd0: addiu $sp, $sp, 0x270                              | sp = 0xbfffe980
0xc241ec: lw $ra, 0x24($sp)                                  | ra = 0x00c2bdfc | R bfffe9a4
R 0xbfffe958: 00000000 00000000 30eac200 10b8c200 c852c400   [........0........R..] R
   0xbfffe96c: 34004000 f04ec400 0010c300 d8e9ffbf ec41c200   [4.@..N...........A..]
0xc241f0: jr $ra                                             |                
0xc241f4: addiu $sp, $sp, 0x28                               | sp = 0xbfffe9a8
0xc2bdfc: lw $gp, 0x20($sp)                                  |                 | R bfffe9c8
R 0xbfffe9a4: fcbdc200                                       [....                ] R
0xc2be00: lw $t9, -0x7f8c($gp)                               | t9 = 0x00c2e0a0 | R c45074
0xc2be04: bal 0xc2e0a0                                       | ra = 0x00c2be0c
0xc2be08: addiu $a0, $zero, 0x7f                             | a0 = 0x0000007f
0xc2e0a0: lui $gp, 2                                         | gp = 0x00020000
R 0xbfffe9c8: 00d0c400                                       [....                ] R
R 0x00c45074: a0e0c200                                       [....                ] R
0xc2e0a4: addiu $gp, $gp, -0x10a0                            | gp = 0x0001ef60
0xc2e0a8: addu $gp, $gp, $t9                                 | gp = 0x00c4d000
0xc2e0ac: lw $a2, -0x7ea8($gp)                               | a2 = 0x00c45bd8 | R c45158
0xc2e0b0: move $a1, $a0                                      | a1 = 0x0000007f
0xc2e0b4: move $a0, $a1                                      |                
0xc2e0b8: addiu $v0, $zero, 0x1096                           | v0 = 0x00001096
exit_group(127)
0xc2e0bc: syscall                                            | v0 = 0x00000000
R 0x00c45158: d85bc400                                       [.[..                ] R

Later, I search the source code of glibc/elf/rtld.c and glibc/elf/dl-object.c

//from rtld.c 
	main_map = _dl_new_object ((char *) "", "", lt_executable, NULL,
                                 __RTLD_OPENEXEC, LM_ID_BASE);
    assert (main_map != NULL); 

//from dl-object.c
  new = (struct link_map *) calloc (sizeof (*new) + audit_space
                                    + sizeof (struct link_map *)
                                    + sizeof (*newname) + libname_len, 1);
  if (new == NULL)
    return NULL;

Function calloc may return a NULL point. Unfortunately, I can't figure out why this happens. Is this error relevant to the usercorn emulation of 32-bit MIPS?

Besides, I also try to use qemu-mipsel to run the hello_mipsel and it can work successfully. But there is something wrong when using usercorn to execute this binary.

I am a newbie at this and therefore I need your help.
Any help or remark (or question) would be appreciated.
Thanks.

Details for the binary:

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0x4005a0
  Start of program headers:          52 (bytes into file)
  Start of section headers:          6660 (bytes into file)
  Flags:                             0x10001007, noreorder, pic, cpic, o32, mips2
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         11
  Size of section headers:           40 (bytes)
  Number of section headers:         33
  Section header string table index: 30

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions