Manio 马牛不是人 Computer science and life of Manio

SESC Tutorial – 2. Run HelloWorld

06.08.2010 · Posted in SESC Tutorial, System

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

Written by Jun He (jhe24(at)iit.edu), June 2010.

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
  2. set +h
     
    export PATH=$HOME/sescutils/install/bin:$HOME/sesc-build:$PATH
     
    echo "Setup Finished!"
  3. $source setupSescEnvironment

How to compile a program and run it on SESC

  1. $vim hellosesc.c
  2. #include <stdio.h>

    int main()
    {
    printf(“hello sesc\n”);
    return 0;
    }

  3. Compile hellosesc.c by mips gcc
    $mipseb-linux-gcc hellosesc.c
  4. 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:

  5. $mipseb-linux-gcc -O2 -mips2 -mabi=32 -fno-PIC -mno-abicalls hellosesc.c
  6. Success built, BUT THE OUTPUT EXECUTABLE CANNOT BE RUN IN SESC!
  7. manio@jun-desktop:~/sescworkdir$ sesc.tst -h0×800000 -c../esesc/confs/mem.conf ./a.out <../esesc/tests/tt.in

    ERROR: .ctors data sections not contiguous

    Segmentation 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
  8. SOLUTION
  9. 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.6

    manio@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
  4. 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
  5. build executable. Please note: we should use mint.x, which is the elf for sesc mips.
  6. 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
  7. $cd ~/sesc-build
  8. run the simulator
  9. manio@jun-desktop:~/sesc-build$ ./sesc.smp -c ../esesc/confs/smp.conf.hello.multithread ../esesc/src/libapp/hello.sesc
  10. show the report
  11. 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
分享家:Addthis中国

Related Posts

2 Responses to “SESC Tutorial – 2. Run HelloWorld”

  1. Yu Zhang says:

    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!

    [Reply]

    admin reply:

    @Yu Zhang, thanks :)

    [Reply]

Leave a Reply