SESC Tutorial – 2. Run HelloWorld
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
- How to Setup Building Environment
- How to compile a program and run it on SESC
- How to run multi-thread program
- How to visualize the report file
How to Setup Building Environment
- $vim setupSescEnvironment
- $source setupSescEnvironment
set +h export PATH=$HOME/sescutils/install/bin:$HOME/sesc-build:$PATH echo "Setup Finished!"
How to compile a program and run it on SESC
- $vim hellosesc.c
- Compile hellosesc.c by mips gcc
$mipseb-linux-gcc hellosesc.c - $mipseb-linux-gcc -O2 -mips2 -mabi=32 -fno-PIC -mno-abicalls hellosesc.c
- Success built, BUT THE OUTPUT EXECUTABLE CANNOT BE RUN IN SESC!
- SOLUTION
| #include <stdio.h>
int main() |
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:
| 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 |
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
- $cd $HOME/esesc/src/libapp
- add #include <stdint.h> to sescapi.h
- create object of sesc_thread.c
- build executable. Please note: we should use mint.x, which is the elf for sesc mips.
- $cd ~/sesc-build
- run the simulator
- show the report
| 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 |
| 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 |
| manio@jun-desktop:~/sesc-build$ ./sesc.smp -c ../esesc/confs/smp.conf.hello.multithread ../esesc/src/libapp/hello.sesc |
| manio@jun-desktop:~/sesc-build$ ../esesc/scripts/report.pl -last |
References:
https://lists.soe.ucsc.edu/pipermail/sesc/2007-October/000308.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 |
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:
June 10th, 2010 at 12:17 pm
@Yu Zhang, thanks :)
[Reply]