SESC Tutorial – 2. Run HelloWorld

http://manio.org/blog/category/computer-science/sesc-tutorial

In this chapter, we compile and run the first program on SESC. After that, we can get a report from SESC and check the performance.

Index

  1. How to Setup Building Environment
  2. How to compile a program and run it on SESC
  3. How to run multi-thread program
  4. How to visualize the report file

How to Setup Building Environment

  1. $vim setupSescEnvironment
    set +h
    export PATH=$HOME/sescutils/install/bin:$HOME/sesc-build:$PATH
    echo "Setup Finished!"
  2. $source setupSescEnvironment

How to compile a program and run it on SESC

1. $vim hellosesc.c
#include <stdio.h>int main()
{
printf("hello sescn");
return 0;
}
2. Compile hellosesc.c by mips gcc
$mipseb-linux-gcc hellosesc.c

ERROR

/home/manio/sescutils/install/lib/gcc/mipseb-linux/3.4.4/../../../../mipseb-linux/bin/ld: /home/manio/sescutils/install/lib/gcc/mipseb-linux/3.4.4/crtend.o: warning: linking PIC files with non-PIC files/home/manio/sescutils/install/lib/gcc/mipseb-linux/3.4.4/../../../../mipseb-linux/bin/ld: /home/manio/sescutils/install/lib/gcc/mipseb-linux/3.4.4/../../../../mipseb-linux/lib/crtn.o: warning: linking PIC files with non-PIC files

Note: This is because you do not compile the .c file with the same options of glibc. So refer to the build options of glibc (build-3-glibc) and set the gcc options as follows:

1. $mipseb-linux-gcc -O2 -mips2 -mabi=32 -fno-PIC -mno-abicalls hellosesc.c

2. Success built, BUT THE OUTPUT EXECUTABLE CANNOT BE RUN IN SESC!

manio@jun-desktop:~/sescworkdir$ sesc.tst -h0x800000 -c../esesc/confs/mem.conf ./a.out <../esesc/tests/tt.inERROR: .ctors data sections not contiguousSegmentation fault

The following references can help you understand this problem.

Reference 1:

https://lists.soe.ucsc.edu/pipermail/sesc/2008-May/000466.html

When you compile you need to use "-static -Wa,-non_shared"
Also, when you link, make sure that all the sections are continues.
You can do it
adding this option to the linking process.
-Wl,--script=$(XTOOLSPREFIX)/mipseb-linux/lib/ldscripts/mint.x,-static

Reference 2

https://lists.soe.ucsc.edu/pipermail/sesc/2007-October/000329.html

I am not sure about the reason for the problem. My guess is that
SESC/MINT interface
requires continuous data sections (.bss,.data.text....). Your program
may have very large
static data allocation and gcc may decide not to have continuous
sections.
If you use the "mipseb-linux-readelf -S foo" command where foo is
your binary, it will
tell you the sections.
If you look at the mint.x file from gcc, it shows how to change it.
Maybe your program
uses some section not addressed on mint.x.

Reference 3

https://lists.soe.ucsc.edu/pipermail/sesc/2007-October/000328.html

/usr/local/bin/mipseb-linux-g++ -mips2 -mno-abicalls -mabi=32 -mtune=r6000
-msplit-addresses -I. -Wa,-non_shared -I.
-I/usr/local/mipseb-linux/include/c++/3.2
-I/usr/local/mipseb-linux/include/c++/3.2/backward
-I/usr/local/mipseb-linux/include/c++/3.2/mips-linux-gnu -static SOURCE
FILES HERE -o test -Wl,--script=/usr/local/mipseb-linux/lib/ldscripts/mint.x

SOLUTION

mint.x should be used to link the objects.

manio@jun-desktop:~/sescworkdir$ mipseb-linux-gcc -mips2 -mabi=32 -static -Wa,-non_shared -mno-abicalls -Wl,--script=/home/manio/sescutils/install/mipseb-linux/lib/ldscripts/mint.x,-static hellosesc.c -o hellosesc.6manio@jun-desktop:~/sescworkdir$

In this solution, gcc passes some options to the linker(ld) by -Wl.

-Wl,option

Pass option as an option to the linker.? If option contains commas, it is split into multiple options at the commas.

–script=scriptfile

Use? scriptfile as the linker script.? This script replaces ld’s default linker script (rather than adding??????????? to it), so commandfile must specify everything necessary to describe the? output? file.???? If? scriptfile does not exist in the current directory, “ld” looks for it in the directories specified by any preceding -L options.? Multiple -T options accumulate.

-static

Do not link against shared libraries.? This is only meaningful on platforms for which shared libraries are supported.? The different variants of this option are for compatibility with various systems.? You may use this? option? multiple times on the command line: it affects library searching for -l options which follow it. This option also implies –unresolved-symbols=report-all.? This option? can? be? used? with? -shared. Doing? so? means? that a shared library is being created but that all of the library’s external references must be resolved by pulling in entries from static libraries.

How to run multi-thread program

1. $cd $HOME/esesc/src/libapp
2. add #include <stdint.h> to sescapi.h
3. create object of sesc_thread.c

manio@jun-desktop:~/esesc/src/libapp$ mipseb-linux-gcc -g -mips2 -mabi=32 -Wa,-non_shared -mno-abicalls -c -o sesc_thread.o sesc_thread.c

4. build executable. Please note: we should use mint.x, which is the elf for sesc mips.

manio@jun-desktop:~/esesc/src/libapp$ mipseb-linux-gcc -o hello.sesc hello.c -g -mips2 -mabi=32 -Wa,-non_shared -mno-abicalls sesc_thread.o -static -Wl,--script=/home/manio/sescutils/install/mipseb-linux/lib/ldscripts/mint.x,-static

5. $cd ~/sesc-build
6. run the simulator

manio@jun-desktop:~/sesc-build$ ./sesc.smp -c ../esesc/confs/smp.conf.hello.multithread ../esesc/src/libapp/hello.sesc

7. show the report

manio@jun-desktop:~/sesc-build$ ../esesc/scripts/report.pl -last


References:

https://lists.soe.ucsc.edu/pipermail/sesc/2007-October/000308.html

http://ce.et.tudelft.nl/~pepijn/doc/sesc.html

How to visualize the report file

Each line of the report file is consisted of:

Object which generated the data: field1 = value1: field2 = value2

manio@jun-desktop:~/sesc-build$ ../esesc/scripts/report.pl sesc_hellosesc.6.uJN6k3
  • Yu Zhang

    very nice tutorial…I almost struggled the same way as yours a few years ago when I was in school. I got quite some tips and references too at that time, but never thought about posting them online, now I guess I lost them all…But anyway, nice work!

    • admin

      @Yu Zhang, thanks :)

  • bobomo

    Thanks very much, my sesc works well following your tutorial.

  • Ben

    In step 6, run the simulator:
    I got below error.
    ——————————————-
    ERROR: EF_MIPS_32BITMODE not set for EF_MIPS_ABI_O32
    Segmentation fault
    ——————————————-

    What is “smp.conf.hello.multithread” ?
    conf file needs to be changed?

    • Sandeep

      Thanks for tutorial. They were quite helpful but I too am stuck in the same issue as Ben. Not sure if this has to do with the conf file.

  • AS

    Hi, I am not clear at the step 4. what is sesc.tst?? what i want to ask is how to run the executable using sesc?? thanks

    • AS

      Got it . sorry for my stupid question.

  • John

    Hey guys,

    When I try to run this for Step 5:

    $/home/jonny/sescutils/install/bin/mipseb-linux-gcc -mips2 -mabi=32 -static -Wa,-non_shared -mno-abicalls -Wl,-script=/home/jonny/sescutils/install/mipseb-linux/lib/ldscripts/mint.x, -static hellosesc.c -o hellosesc.6

    I get this error

    $/home/jonny/sescutils/install/lib/gcc/mipseb-linux/3.4.4/../../../../mipseb-linux/bin/ld: : No such file: No such file or directory
    collect2: ld returned 1 exit status

    What am I doing wrong?

    • fede

      @John, I have the same problem. I solved changing the gcc to 3.4 again (control your gcc -v version). Bye.

      • lq

        @fede, I changed the gcc to 3.4 again ,but I face the same problem .How can I do?

        • zach

          in step 5 “–script=/home/manio/sescutils/install/mipseb-linux/lib/ldscripts/mint.x,-static hellosesc.c -o hellosesc.6” where the “–” before “script” should be two dashes not one.

  • John

    Thanks Fede.

  • lq

    I don not understand the step 4.
    I meet the problem ,”sesc.tst:commond not found”
    what is sesc.tst? Where can i find it ?
    I am a beginnner.so i need your help.

  • Neha

    hello,

    I am stuck on the step 3. i am getting an error in

    desktop:~/esesc/src/libapp$ mipseb-linux-gcc -o hello.sesc hello.c -g -mips2 -mabi=32 -Wa,-non_shared -mno-abicalls sesc_thread.o -static -Wl,–script=/home/manio/sescutils/install/mipseb-linux/lib/ldscripts/mint.x,-static

    i get error :
    mipseb-linux-gcc:hello.c file not found

    please help. its very urgent.

    • Neha

      hey

      i have solved the following error by giving the entire path of hello.c.
      however im stuck at “run the simulator step”
      it says impossible “smp.conf.hello.multithread.
      can anyone help?

  • sahar

    hi
    when i do $mipseb-linux-gcc hellosesc.c
    i get these errors, please help me to solve this problem.
    hellosesc.c:1:19: warning: null character(s) ignored
    hellosesc.c:2:11: warning: null character(s) ignored
    hellosesc.c:3:2: warning: null character(s) ignored
    hellosesc.c: In function `main’:
    hellosesc.c:4: error: stray ‘226’ in program
    hellosesc.c:4: error: stray ‘128’ in program
    hellosesc.c:4: error: stray ‘156’ in program
    hellosesc.c:4: error: `hello’ undeclared (first use in this function)
    hellosesc.c:4: error: (Each undeclared identifier is reported only once
    hellosesc.c:4: error: for each function it appears in.)
    hellosesc.c:4: error: syntax error before “sescn”
    hellosesc.c:4: error: stray ‘226’ in program
    hellosesc.c:4: error: stray ‘128’ in program
    hellosesc.c:4: error: stray ‘157’ in program
    hellosesc.c:4:27: warning: null character(s) ignored
    hellosesc.c:5:10: warning: null character(s) ignored
    hellosesc.c:6:2: warning: null character(s) ignored
    hellosesc.c: At top level:
    hellosesc.c:7: error: syntax error before ‘~’ token
    hellosesc.c:21:1: warning: null character(s) ignored
    hellosesc.c:21:63: warning: null character(s) ignored

    please help me

    • sahar

      Im sorry because of my stupid question.
      I should just type hellosesc.c by my self not copy from this site