You are not logged in.

#1 2018-10-10 03:49:56

Deyyvon
Member
Registered: 2017-10-02
Posts: 10

Issue Compiling for ARM and Simulating with Gem5

Please move to this to the appropriate category if this is not the right one. As the title describes, I'm having trouble using the arm-linux-gnueabi-gcc cross compiler with gem5 on Arch. It is very straight forward on Ubuntu through installing build-essential and the arm-linux-gnueabi cross compiler, but seemingly not so on Arch.

First, I cloned and built gem5 from https://gem5.googlesource.com/public/gem5, then ran the test program in tests/test-progs/hello/bin/arm/linux/hello which worked flawlessly.
Second, I installed the arm-linux-gnueabi-gcc cross compiler from the AUR. I wrote a simple hello world program:

#include <stdio.h>

int main(void)
{
     printf("Hello, World!\n");
     return 0;
}

and attempted to cross compile with the following output:

$ arm-linux-gnueabi-gcc -o hello_world hello.c
hello.c:1:10: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
          ^~~~~~~~~
compilation terminated.

So, I attempted to install the glibc package along with the arm-linux-gnueabihf-gcc packages such that:

$ pacman -Qqs gnueabi
arm-linux-gnueabi-binutils
arm-linux-gnueabi-gcc
arm-linux-gnueabihf-binutils
arm-linux-gnueabihf-gcc
arm-linux-gnueabihf-glibc
arm-linux-gnueabihf-linux-api-headers

yet nothing changes. I downloaded and unpacked the ARM toolchain from the ARM website and got the output from this post and I tried running the cross compiler with the following command line:

$ arm-none-eabi-gcc --specs=rdimon.specs -lgcc -lc -lm -lrdimon -o hello_world hello.c

This compiles, but when I run it with gem5:

$ gem5/build/ARM/gem5.opt ./gem5/configs/example/se.py -c hello_world
gem5 Simulator System.  http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 compiled Sep 26 2018 16:55:23
gem5 started Oct  8 2018 01:56:39
gem5 executing on dev-thkpd-artix, pid 19611
command line: gem5/build/ARM/gem5.opt ./gem5/configs/example/se.py -c hello_world

Global frequency set at 1000000000000 ticks per second
warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
warn: Unknown operating system; assuming Linux.
0: system.remote_gdb: listening for remote gdb on port 7000
**** REAL SIMULATION ****
info: Entering event queue @ 0.  Starting simulation...
panic: Page table fault when accessing virtual address 0x7fff4
Memory Usage: 671688 KBytes
Program aborted at tick 10500
--- BEGIN LIBC BACKTRACE ---
gem5/build/ARM/gem5.opt(_Z15print_backtracev+0x2c)[0x563a4682379c]
gem5/build/ARM/gem5.opt(_Z12abortHandleri+0x4a)[0x563a46832d8a]
/usr/lib64/libpthread.so.0(+0x123c0)[0x7f18e6c7f3c0]
/usr/lib64/libc.so.6(gsignal+0x10f)[0x7f18e5e6bd7f]
/usr/lib64/libc.so.6(abort+0x125)[0x7f18e5e56672]
gem5/build/ARM/gem5.opt(+0x85389f)[0x563a4652f89f]
gem5/build/ARM/gem5.opt(_ZN21GenericPageTableFault6invokeEP13ThreadContextRK14RefCountingPtrI10StaticInstE+0x8e)[0x563a4685a18e]
gem5/build/ARM/gem5.opt(_ZN13BaseSimpleCPU9advancePCERKSt10shared_ptrI9FaultBaseE+0xe6)[0x563a4720a2f6]
gem5/build/ARM/gem5.opt(_ZN15AtomicSimpleCPU4tickEv+0x437)[0x563a47200447]
gem5/build/ARM/gem5.opt(_ZN10EventQueue10serviceOneEv+0x8c)[0x563a468298cc]
gem5/build/ARM/gem5.opt(_Z9doSimLoopP10EventQueue+0x108)[0x563a4683d258]
gem5/build/ARM/gem5.opt(_Z8simulatem+0xa5a)[0x563a4683dfaa]
gem5/build/ARM/gem5.opt(+0x1606e0d)[0x563a472e2e0d]
gem5/build/ARM/gem5.opt(+0xba5fe9)[0x563a46881fe9]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x751e)[0x7f18e6d5f12e]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x2ca)[0x7f18e6dcd43a]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x609c)[0x7f18e6d5dcac]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x2ca)[0x7f18e6dcd43a]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x609c)[0x7f18e6d5dcac]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x2ca)[0x7f18e6dcd43a]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x609c)[0x7f18e6d5dcac]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x2ca)[0x7f18e6dcd43a]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalCode+0x17)[0x7f18e6de30e7]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x4bc2)[0x7f18e6d5c7d2]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x2ca)[0x7f18e6dcd43a]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x609c)[0x7f18e6d5dcac]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x2ca)[0x7f18e6dcd43a]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalCode+0x17)[0x7f18e6de30e7]
/usr/lib64/libpython2.7.so.1.0(+0x16dd41)[0x7f18e6dfbd41]
/usr/lib64/libpython2.7.so.1.0(PyRun_StringFlags+0x66)[0x7f18e6dfd896]
gem5/build/ARM/gem5.opt(_Z6m5MainiPPc+0x83)[0x563a46831853]
gem5/build/ARM/gem5.opt(main+0x3f)[0x563a464d74cf]
--- END LIBC BACKTRACE ---
[1]    19611 abort      gem5/build/ARM/gem5.opt ./gem5/configs/example/se.py -c hello_world

I've also set the kernel version in gem5/src/arch/arm/linux/process.cc to the version output from 'uname -r' and rebuilt gem5:

strcpy(name->release, "4.18.12");

It seems that I'm very close, but I can't figure out what the problem is.

  1. Is there something up with the cross compiler in the AUR?

  2. How can I properly compile for ARM on Arch such that I can run it through gem5?

Offline

#2 2018-11-09 23:02:46

anatolik
Developer
Registered: 2012-09-27
Posts: 428

Re: Issue Compiling for ARM and Simulating with Gem5

Deyyvon wrote:

Second, I installed the arm-linux-gnueabi-gcc cross compiler from the AUR.

No need to install cross-tools from AUR. The official repo contains arm-none-eabi-gcc package. It should work pretty close to what you have in Ubuntu.

Offline

#3 2018-11-11 03:02:48

Deyyvon
Member
Registered: 2017-10-02
Posts: 10

Re: Issue Compiling for ARM and Simulating with Gem5

Thanks for responding, anatolik.

I got rid of the toolchain mess I had before and did:

$ sudo pacman -S arm-none-eabi-gcc

But now when I attempt to compile a simple hello.c:

#include <stdio.h>

int main()
{
    printf("Hello, World!\n");
    return 0;
}
$  arm-none-eabi-gcc hello.c
/usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): in function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0x18): undefined reference to `_sbrk'
/usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-writer.o): in function `_write_r':
writer.c:(.text._write_r+0x24): undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-closer.o): in function `_close_r':
closer.c:(.text._close_r+0x18): undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-lseekr.o): in function `_lseek_r':
lseekr.c:(.text._lseek_r+0x24): undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-readr.o): in function `_read_r':
readr.c:(.text._read_r+0x24): undefined reference to `_read'
/usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-fstatr.o): in function `_fstat_r':
fstatr.c:(.text._fstat_r+0x20): undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-isattyr.o): in function `_isatty_r':
isattyr.c:(.text._isatty_r+0x18): undefined reference to `_isatty'
collect2: error: ld returned 1 exit status

I also tried having just:

int main()
{
    return 0;
}

And the output is:

$ arm-none-eabi-gcc hello.c
/usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2: error: ld returned 1 exit status

Is this to be expected or is there something else I am missing? Do I need to use a different libc?

Offline

#4 2018-11-11 06:24:25

anatolik
Developer
Registered: 2012-09-27
Posts: 428

Re: Issue Compiling for ARM and Simulating with Gem5

Deyyvon wrote:

Is this to be expected or is there something else I am missing? Do I need to use a different libc?

You indeed need to specify the libc. Just use the command from your first post:

arm-none-eabi-gcc --specs=rdimon.specs -lgcc -lc -lm -lrdimon -o hello_world hello.c

Offline

#5 2018-11-11 21:28:16

Deyyvon
Member
Registered: 2017-10-02
Posts: 10

Re: Issue Compiling for ARM and Simulating with Gem5

anatolik wrote:

Just use the command from your first post:

arm-none-eabi-gcc --specs=rdimon.specs -lgcc -lc -lm -lrdimon -o hello_world hello.c

Both sample programs I mentioned earlier compile now with that command. Thank you!

However, running it yields:

$ gem5-lru/build/ARM/gem5.opt ./gem5-lru/configs/example/se.py -c hello_world
gem5 Simulator System.  http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 compiled Nov  8 2018 15:39:51
gem5 started Nov 11 2018 13:41:10
gem5 executing on dev-thkpd-artix, pid 11421
command line: gem5-lru/build/ARM/gem5.opt ./gem5-lru/configs/example/se.py -c hello_world

Global frequency set at 1000000000000 ticks per second
warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
warn: Unknown operating system; assuming Linux.
0: system.remote_gdb: listening for remote gdb on port 7000
**** REAL SIMULATION ****
info: Entering event queue @ 0.  Starting simulation...
fatal: syscall syscall (#0) unimplemented.
Memory Usage: 671724 KBytes

According to this, I either have to implement the missing syscalls or use a system image (specified here). I'm trying to avoid using my Ubuntu VM and implementation seems rather tedious for my scholastic purposes, so these won't suffice. It seems like gem5 has recently had a lot of issues on this.

Should I:

  • go for the crosstoll-ng solution mentioned in one of the aforementioned posts?

  • use my Ubuntu VM for now?

  • stop overthinking?

Offline

Board footer

Powered by FluxBB