Software Archive
Read-only legacy content
17061 Discussions

Building Static Cilk executable using GCC 4.8.0

rahulrs
Beginner
1,331 Views
I have build a Cilk Plus capable gcc to a local directory.
@:~/cilk_plus_tests/fibonacci $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/raid/home//repository/sw/cilk_build/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/home//repository/sw/cilk_build/
Thread model: posix
gcc version 4.8.0 20120408 (experimental) (GCC)
I built the GCC with the following order
1. GMP
2. MPFR
3. MPC
4. Libelf
5. GCC
6. 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 -lcilkrts
Build 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 constant
make: *** [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 -shared
I 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
0 Kudos
1 Solution
Balaji_I_Intel
Employee
1,331 Views

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):

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


Then I set LD_LIBRARY_PATH the following way:

[bash] export LD_LIBRARY_PATH=./install-test/lib[/bash]



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

[bash]./parallel_static 10 10 55 [/bash]





Thanks,

Balaji V. Iyer.

View solution in original post

0 Kudos
8 Replies
Balaji_I_Intel
Employee
1,331 Views
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!

Thanks,

Balaji V. Iyer.
0 Kudos
rahulrs
Beginner
1,331 Views
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 working
This 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 You
Rahul
0 Kudos
rahulrs
Beginner
1,331 Views
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
0 Kudos
Balaji_I_Intel
Employee
1,331 Views
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

Thanks,

Balaji V. Iyer.
0 Kudos
rahulrs
Beginner
1,331 Views
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
0 Kudos
Balaji_I_Intel
Employee
1,332 Views

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):

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


Then I set LD_LIBRARY_PATH the following way:

[bash] export LD_LIBRARY_PATH=./install-test/lib[/bash]



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

[bash]./parallel_static 10 10 55 [/bash]





Thanks,

Balaji V. Iyer.

0 Kudos
rahulrs
Beginner
1,331 Views
Hi Balaji
Thank You so much... I never thought that you needed g++ and lpthread. This was a very fruitful discussion.
Rahul
0 Kudos
Balaji_I_Intel
Employee
1,331 Views
Hi Rahul,
I am glad to hear it worked!

Thanks,

Balaji V. Iyer.
0 Kudos
Reply