Building Static Cilk executable using GCC 4.8.0

Building Static Cilk executable using GCC 4.8.0

I have build a Cilk Plus capable gcc to a local directory.

@:~/cilk_plus_tests/fibonacci $ gcc -vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/raid/home//repository/sw/cilk_build/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapperTarget: x86_64-unknown-linux-gnuConfigured with: ./configure --prefix=/home//repository/sw/cilk_build/Thread model: posixgcc version 4.8.0 20120408 (experimental) (GCC)

I built the GCC with the following order

1. GMP2. MPFR3. MPC4. Libelf5. GCC6. Binutils

I am trying to build the fibonacci.c Cilk program that is known to work.

#include #include #include #include int fib(long long int n){ long long int x, y; if (n < 2) return n; else { x = cilk_spawn fib(n-1); y = cilk_spawn fib(n-2); cilk_sync; return x + y; }}int main(int argc, char *argv[]){ int n; long long int result; n = atoi(argv[1]); result = fib(n); printf("%d\\t%dn", n, result); return 0;}

When I build to create a shared executable:$BUILD_PATH/gcc -g -o parallel_shared fib_cilk.c -I $BUILD_PATH/include -lcilkrtsBuild fails with error:

/tmp/ccg1ZjDO.s: Assembler messages:/tmp/ccg1ZjDO.s: Error: .size expression for fib does not evaluate to a constant/tmp/ccg1ZjDO.s: Error: .size expression for __cilk_spawn_001.2925 does not evaluate to a constant/tmp/ccg1ZjDO.s: Error: .size expression for __cilk_spawn_002.2942 does not evaluate to a constantmake: *** [build] Error 1

When I try building this statically:$BUILD_PATH/gcc -g -o parallel_static fib_cilk.c -I $BUILD_PATH/include -L $BUILD_PATH/lib -sharedI still get the same error above.Can someone give me pointers to where it might be failing ?Also I want to know if static executables can be built at all with Cilk ?Rahul

9 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Hello Rahul,
Can you please tell me a bit about your environment? Are you trying to build a cross compiler? Why are you building binutils? If you want to build binutils, you must do that before you build the compiler and make sure the compiler points to the correct binutils (using --with-as command and making sure the path is set correctly to the install directory). Generally the host system binutils will suffice (assuming you are NOT building a cross compiler or making any assembler changes). I think the reason why you are getting this problem is because the assembler that was present when the compiler was built is different from the assembler that is present when you are trying to build the executable.

I hope this helps!


Balaji V. Iyer.

Thank you for a quick Reply.I realized I made a mistake writing the post.I build "binutils" before "gcc", not after.I am NOT trying to cross-compile this. The standard stable GCC in our environment is GCC 4.4 and I have compiled GCC 4.8 in order to get Cilk workingThis is the output of "uname -a" on my machine.

Linux 2.6.32-40-generic #87-Ubuntu SMP Tue Mar 6 00:56:56 UTC 2012 x86_64 GNU/Linux

I will rebuild Cilk with the old binutils and see if the error persists. I will report back here.Thank YouRahul

I have rebuilt my Cilk-gcc environment using the Cilk branch of GCC and the without changing binutils from the system.
The GOOD NEWS is that shared executables are generated and run without problems.
I am still facing issues with generating static executables for x86_64
I passed the command:

$BUILD_PATH/gcc -g -o parallel_static fib_cilk.c -static -I $BUILD_PATH/include/ -L $LD_LIBRARY_PATH/libcilkrts.a

I am now returned with the following error:

/tmp/ccyrQw40.o: In function `fib':/home//cilk_plus_tests/fibonacci/fib_cilk.c:17: undefined reference to `__cilkrts_enter_frame'/home//cilk_plus_tests/fibonacci/fib_cilk.c:32: undefined reference to `__cilkrts_sync'/home//cilk_plus_tests/fibonacci/fib_cilk.c:17: undefined reference to `__cilkrts_sync'/home//cilk_plus_tests/fibonacci/fib_cilk.c:17: undefined reference to `__cilkrts_leave_frame'/tmp/ccyrQw40.o: In function `__cilk_spawn_001.2925':/home//cilk_plus_tests/fibonacci/fib_cilk.c:59: undefined reference to `__cilkrts_enter_frame'/home//cilk_plus_tests/fibonacci/fib_cilk.c:26: undefined reference to `__cilkrts_leave_frame'/tmp/ccyrQw40.o: In function `__cilk_spawn_002.2942':/home//cilk_plus_tests/fibonacci/fib_cilk.c:26: undefined reference to `__cilkrts_enter_frame'/home//cilk_plus_tests/fibonacci/fib_cilk.c:29: undefined reference to `__cilkrts_leave_frame'collect2: error: ld returned 1 exit status

Can someone help me ?Rahul

Hello Rahul,
The best way to build executables are to do the following:

$BUILD_DIR/bin/gcc -ldl -lcilkrts

In your case add the 2 flags I have indicated in bold. You do not need to explicitly point to the include and load directories.

$BUILD_PATH/gcc -g -o parallel_static fib_cilk.c -static -lcilkrts -ldl


Balaji V. Iyer.

Hi again,Thank you for your answer.I am able to build shared executables.I am trying to build statically linked executables. Is this supported in GCC 4.8 Cilkplus ?I am using the command:

$(BUILD)/gcc fib_cilk.c -g -o parallel_static -static -l $LD_LIBRARY_PATH/libcilkrts.a

This yields:

collect2: error: ld returned 1 exit status

My goal is to profile some application code for my project including the time spend on cilk_spawn, cilk_sync and cilk_for. In Linux and GCC, what is the recommended way to do this ?Rahul

Best Reply

Hi Rahul,
If you want to use static please compile with g++. Also make sure that "-static" is the first argument after g++.You may geta warning, but I think you can ignore it.

Here is what I did to compile (Please note that my build directory is ./install-test):

./install-test/bin/g++ -static fib_cilk.c -g -o parallel_static -lcilkrts -lpthread -ldl

Then I set LD_LIBRARY_PATH the following way:

 export LD_LIBRARY_PATH=./install-test/lib

Then I executed the executable and I got the following result (I added a "\\n" in the printf for clarity):

./parallel_static  10

10      55


Balaji V. Iyer.

Hi BalajiThank You so much... I never thought that you needed g++ and lpthread. This was a very fruitful discussion.Rahul

Hi Rahul,
I am glad to hear it worked!


Balaji V. Iyer.

Connectez-vous pour laisser un commentaire.