3

I know this a trivial question but I am having difficulties in running the m5ops in gem5, lets take for example the m5-exit.c file that has been provided by gem5, in the test programs, how would I compile it and link it to the file m5op_x86.S

Currently this is the way I am compiling and linking it:

gcc m5-exit.c -I ~/Desktop/gem5_86/gem5/include -o test ~/Desktop/gem5_86/gem5/util/m5/m5op_x86.S

the error i get:

/tmp/ccXsGX3d.o: relocation R_X86_64_16 against undefined symbol `M5OP_ARM' can not be used when making a PIE object; recompile with -fPIC

the directory i am in is:

gem5/tests/test-progs/m5-exit/src

the code for m5-exit.c is from the gem5 directory found here

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44
Weez Khan
  • 137
  • 1
  • 8
  • And what happens if you try the suggestion in the message? You *did* read the whole message? – Some programmer dude Jan 08 '20 at 15:45
  • 1
    yes I did, same error is displayed – Weez Khan Jan 08 '20 at 15:47
  • The error message assume the asm / relocations came from C compiler output. You have hand-written asm which apparently tries to put a 64-bit absolute address into a 16-bit immediate. You definitely can't do that in a PIE executable. It might let you truncate it to 16 if you build with `-no-pie`, since it at least won't need runtime fixups. ([32-bit absolute addresses no longer allowed in x86-64 Linux?](https://stackoverflow.com/q/43367427)). Are you sure that `.S` is not supposed to be assembled into 64-bit code at all, rather than 16-bit? – Peter Cordes Mar 24 '20 at 00:52
  • Possible duplicate: https://stackoverflow.com/questions/62757008/how-to-use-m5-in-gem5-20/62759204#62759204 – Topological Sort Sep 18 '20 at 15:34

1 Answers1

0

This is a copy of: How to use m5 in gem5-20 which was deleted on my other answer, since my previous DRY link-only answer was removed followed by an unsuccessful (although correct, but not enough users who care) dupe close attempt.

On gem5 046645a4db646ec30cc36b0f5433114e8777dc44 I can do:

scons -C util/m5 build/x86/out/m5
gcc -static -I include -o main.out main.c util/m5/build/x86/out/libm5.a

with:

main.c

#include <gem5/m5ops.h>

int main(void) {
    m5_exit(0);
}

Or for ARM:

sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
scons -C util/m5 build/aarch64/out/m5
aarch64-linux-gnu-gcc -static -I include -o main.out main.c \
  util/m5/build/aarch64/out/libm5.a

But in practice, I often just don't have the patience for this business, so I just misbehave and add raw assembly directly as shown here muahahaha e.g.:

#if defined(__x86_64__)

#define LKMC_M5OPS_CHECKPOINT __asm__ __volatile__ (".word 0x040F; .word 0x0043;" : : "D" (0), "S" (0) :)
#define LKMC_M5OPS_DUMPSTATS  __asm__ __volatile__ (".word 0x040F; .word 0x0041;" : : "D" (0), "S" (0) :)

#elif defined(__aarch64__)

#define LKMC_M5OPS_CHECKPOINT __asm__ __volatile__ ("mov x0, 0; mov x1, 0; .inst 0xFF000110 | (0x43 << 16);" : : : "x0", "x1")
#define LKMC_M5OPS_DUMPSTATS  __asm__ __volatile__ ("mov x0, 0; mov x1, 0; .inst 0xFF000110 | (0x41 << 16);" : : : "x0", "x1")

More general m5op information can also be found at: What are pseudo-instructions for in gem5?

Tested on Ubuntu 20.04.

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44