Tuesday, February 03, 2009

Building SimpleScalar/ARM cross compiler based on gcc-2.95.2

This entry talks about my experience in building the SimpleScalar/ARM cross compiler based on gcc-2.95.2

This was built on Ubuntu 8.10 with gcc-3.4 running on a Virtual Machine - Sun Virtual Box, XP Host, x86 Architecture

(The following instructions are an updated version to the instructions in ANNOUNCE.cross from http://www.eecs.umich.edu/~taustin/code/arm-cross/ANNOUNCE.cross)

--
1. Get all packages from http://www.simplescalar.com/v4test.html
cross compiler kit

http://www.eecs.umich.edu/~taustin/code/arm-cross/ANNOUNCE.cross
http://www.eecs.umich.edu/~taustin/code/arm-cross/gcc-2.95.2.tar.gz
http://www.eecs.umich.edu/~taustin/code/arm-cross/binutils-2.10.tar.gz
http://www.eecs.umich.edu/~taustin/code/arm-cross/glibc-2.1.3.tar.gz

2. Untar and expand all 3 .tar.gz files into a single folder. (/home/example/arm-cross)

3. Make sure you have gcc-3.4 installed on the system. (Ubuntu's GCC 4.3.2 did not compile this package)

4. Build and Install binutils

cd binutils-2.10
../configure --target=arm-linux --prefix=/home/example/arm-cross
make
make install
cd ..

5. You should now have a bin/ folder inside arm-cross/. Add this to your path. (If using bash shell, use the below command, modify to fit your shell)
export PATH=$PATH:/home/example/arm-cross/bin

6. Rehash the filesystem to see the newly created executables.
In Ubuntu 8.10, rehash is /usr/bin/c_rehash - no arguments, just executable

7. Now build the GNU GCC cross compiler (This is what gave me the most trouble- after lots of playing around, the following steps worked) [1]

7.a. inside arm-cross/

cd gcc-2.95.2
../configure --prefix=/home/example/arm-cross --target=arm-linux --with-as=/home/example/arm-cross/bin/arm-linux-as

This should configure without any errors.

7.b. Now, edit the Makefile. Inside the Makefile, find and replace 'rmdir' with 'rm -rf' (without the quotes)

7.c The current version of libgcc (as shipped with Ubuntu 8.10) seems to be incompatible with the build environment of the cross compiler, so we are going to build it with STATIC linkage. [2]

make LANGUAGES=c BOOT_LDFLAGS=-static

This should take a while, but should complete without any errors.

If you encounter any errors in this step, check the above steps carefully. Before reattempting to build, always do a 'make distclean'. This will purge all files that were created during the make process and allow you to start afresh. One of the side effects of make distclean is that it will also remove the Makefile. Hence you will have to begin at the ./configure step again.

If this passes successfully, install the package using the below:

make LANGUAGES=c install

At this point you have the compiler installed and working.

Here's the output of the version string as reported by the cross compiler at this stage:

example@machine:~/$ arm-linux-gcc -v
Reading specs from /home/example/arm-cross/lib/gcc-lib/arm-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)

8. Now follow the instructions in ANNOUNCE.cross to fix the specs

vim /home/example/arm-cross/lib/gcc-lib/arm-linux/2.95.2/specs

replace all occurrences of "elf32arm" with "armelf_linux",
this fixes an innocuous incompatibility between the most
recent GCC and GLIBC libraries...

9. You now have a working arm-cross compiler that can produce binaries that can be run on SimpleScalar/ARM

arm-linux-gcc example_code.c -o object_file.o

Now run object_file.o using the appropriate simplescalar tool.

-------------------------------------------------------------
[1]
To fix error with xgcc

from http://sourceware.org/ml/crossgcc/2001-02/msg00081.html
use an explicit "--with-as=/path/to/as" on the gcc configure line

[2]
This fixes the set of messages:

ibgcc1.S: Assembler messages:
libgcc1.S:1: Warning: rest of line ignored; first ignored character is `@'
libgcc1.S:2: Warning: rest of line ignored; first ignored character is `@'

from
https://www.linuxquestions.org/questions/linux-general-1/arm-toolchain-problem-350988/

use the BUILD_LDFLAGS=-static

27 comments:

Sazly Salfarina said...

Hi, thanks for the guide. I have some problem, hopefully you can help me with it.

On step 7.c, "make LANGUAGES=c BOOT_LDFLAGS=-static", i've got this error.
...
./config/arm/arm.c: In function ‘arm_override_options’:
./config/arm/arm.c:286: warning: assignment discards qualifiers from pointer target type
./config/arm/arm.c:530: error: lvalue required as left operand of assignment
make[1]: *** [arm.o] Error 1
make[1]: Leaving directory `/home/sanuar/arm_cross/gcc-2.95.3/gcc'
make: *** [all-gcc] Error 2

What sould I do? Can you help me with the problem? Pleaseee

Suneil said...

It could be that former install attempts messed up something. Can you try extracting a copy from the tarballs again and trying these steps onto a new directory?

Unknown said...

Hi there Sazly,
God knows I have been looking for a follow-up to the old ANNOUNCE.cross documentation.
Thank you very much for the blog post. It is very useful indeed.
However, I also got at step 7c the following error:

_udivsi3
_divsi3
_umodsi3
_modsi3
_dvmd_lnx
libgcc1.S:438: asm/unistd.h: No such file or directory
make[1]: *** [libgcc1-asm.a] Error 1
make[1]: Leaving directory `/home/example/simulator_sources/gcc-2.95.2/gcc'
make: *** [all-gcc] Error 2

If I do NOT build with static libraries, I get the same error as the friend above, thus the "lvalue required" error.

Any insights would be deeply appreciated. I am losing my sleep over arm crosstools..

kind regards,
chris

fangzheng said...

I come across the same error,why?
any advice is appreciated.
thank you!

Unknown said...

Same problem here...strange?

Unknown said...

I get the same unistd.h error. Trying to build in exactly the same environment (fresh ubuntu 8.10 in a VirtualBox, just added gcc-3.4 and lex)

Unknown said...

Solved by replacing the include of "asm/unistd.h" with including "/usr/src/linux/arch/arm/include/asm/unistd.h"

in "gcc/config/arm/lib1funcs.asm"

Unknown said...

For those who did not get anything to work like me. Just download

http://www.eecs.umich.edu/~taustin/code/arm-cross/glibc-2.1.3-armlinux.tar.gz

It includes the ALREADY COMPILED cross compiler and glibc. Workt out of the box for me.

Unknown said...

I'm getting the same problem with the lvalue required. Was there a fix for this? Thanks.

Unknown said...

I've spent almost 6 hours to figure out this 'unistd.h' problem.
Here is the thing.
just make sure you've done no2. Untar and expand all 3 .tar.gz files into a single folder. (/home/example/arm-cross)

thus you have arm-linux folder in your path(/home/example/arm-cross)

Ritesh said...

Regarding lvalue problem, try this link:
http://gcc.gnu.org/ml/gcc-help/2007-10/msg00231.html

It seems there is a bug in gcc 2.95

Regards

Unknown said...

Thanks very much. At first I also have the unistd.h error, then I realize that I have to extract the .tar.gz files into same folder with the installed folder (--prefix).

Everything works fine then^^.

abhi said...

Hi Suneil,

thanks for the detailed steps for ARM simplescalar installation. I tried the steps with ubuntu 11.04, GCC 4.5 but ran into errors so I switched to ubuntu 8.10, GCC 3.4 but I am not able to use apt-get update as the files are missing and I can't use bison. (flex-old worked instead of flex). Kindly let me know what can I do in this case.

if there is any new blog for latest versions, please point me there.

thanks in advance.

regards,
abhijeet

Anonymous said...

@A:
Try installing gcc 3.4 into newer version of Ubuntu. The latest version should have flex and bison available.

See this post on installing gcc-3.4 into Ubuntu 10.04: http://ubuntuforums.org/showthread.php?t=1530465

Anonymous said...

after do:
$ $ make LANGUAGES=c BOOT_LDFLAGS=-static

???????????// I got this message:
mkdir tmpcopy
if [ xlibgcc1-asm.a != x ]; \
then (cd tmpcopy; arm-linux-ar x ../libgcc1-asm.a); \
else true; \
fi
(cd tmpcopy; chmod +w * > /dev/null 2>&1)
make[2]: [stmp-multilib-sub] Error 1 (ignored)
(cd tmpcopy; arm-linux-ar x ../libgcc2.a)
(cd tmpcopy; arm-linux-ar rc ../tmplibgcc.a *.o)
arm-linux-ar: *.o: No such file or directory
make[2]: *** [stmp-multilib-sub] Error 1
make[2]: Leaving directory `/home/simplescalarARM/gcc-2.95.2/gcc'
make[1]: *** [stmp-multilib] Error 1
make[1]: Leaving directory `/home/simplescalarARM/gcc-2.95.2/gcc'
make: *** [all-gcc] Error 2

please, would you help me to fix this?
thank you in advance.

Lakshmi Vidya Peri said...

Hi,
I am trying to build the arm cross compiler.
I built the binutils and also set my path to arm-cross/bin.

I used the following to configure the gcc-2.95.2 by looking into instructions from various websites:
./configure --target=arm-linux --enable-languages=c --prefix=\home\lperi\Desktop\SimpleScalar1\arm-cross --with-as=\home\lperi\Desktop\SimpleScalar1\arm-cross\bin\arm-linux-as --disable-shared

When I do the make as follows:
$ make CC=gcc34 LANGUAGES=c BOOT_LDFLAGS=-static

I get this error:

make[1]: Entering directory `/home/lperi/Desktop/SimpleScalar1/arm-cross/gcc-2.95.2/libiberty'
if [ x"no" = xyes ] && [ ! -d pic ]; then \
mkdir pic; \
else true; fi
touch stamp-picdir
CONFIG_FILES= CONFIG_HEADERS=config.h:config.in /bin/sh ./config.status
creating config.h
make[1]: *** No rule to make target `../include/libiberty.h', needed by `argv.o'. Stop.
make[1]: Leaving directory `/home/lperi/Desktop/SimpleScalar1/arm-cross/gcc-2.95.2/libiberty'
make: *** [all-libiberty] Error 2

Please, would you help me to fix this? Your help would be greatful.
Thank you in advance.

Lakshmi Vidya Peri said...

Hi Suneil,

I am trying to build and run the MIBench on the SimpleScalar ARM simulator which I already built.
I am getting many configuration, build errors and even output errors for those which are built correctly.
I am using the MIBench Version 1.0 from http://www.eecs.umich.edu/mibench/ website.
Could you help me with this problem.

Thanks,
Lakshmi Vidya Peri.

Suneil said...

@Anonymous:
Your 'make' doesn't seem to be able to find the arm-linux-ar command.

Can you find whether there exists a file named "arm-linux-ar" on your machine? If yes, then make sure you didn't skip any of the sub-steps of (7) i.e the c_rehash and other small steps.
Also make sure that you have extracted all the files to the correct location(s).

Suneil said...

@abihijeet: I no longer work on this platform, so I don't have any updated info. The comments thread on this post is probably the most upto date information that I have.

If you are having issues getting an older version of gcc to install, search the web for how to do a manual (offline) installation of gcc. That should point you in the correct direction of getting the required subcomponents such as Bison and Flex.

Suneil said...

@lakshmi:
Your make is looking for a file named libiberty.h. See if such a file exists? (capitalization matters). Perhaps the issue is a broken previous step somewhere. Do a make purge and try again?

Also, I haven't worked with MIBENCH, so I don't think I'll be able to help much in this matter. Sorry.

-- Everyone --
If you follow kabelgleichung posted comment on Apr-13,2009, they point to an already compiled version of the simulator - that may be of use to you if you can no-longer build the code.
Alternatively, if someone can build this on a newer version of a linux OS, please document what you did and let people know. If you leave me a comment with a link to instructions, I'll be happy to update my post.

rashi said...

Hi Suneil
I am doing "make LANGUAGES=c BOOT_LDFLAGS=-static" ,I have got error as

In function ‘open’,
inlined from ‘collect_execute’ at collect2.c:1761:
/usr/include/bits/fcntl2.h:51: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments
make[1]: *** [collect2.o] Error 1
make[1]: Leaving directory `/home/rashi/crossdir/gcc-2.95.2/gcc'
make: *** [install-gcc] Error 2

what should i do to remove the error.Please help me with this problem

rashi said...

Hi Suneil
I am doing "make LANGUAGES=c BOOT_LDFLAGS=-static" ,I have got error as

In function ‘open’,
inlined from ‘collect_execute’ at collect2.c:1761:
/usr/include/bits/fcntl2.h:51: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments
make[1]: *** [collect2.o] Error 1
make[1]: Leaving directory `/home/rashi/crossdir/gcc-2.95.2/gcc'
make: *** [install-gcc] Error 2

what should i do to remove the error.Please help me with this problem

Suneil said...

@rashi: Are you using the correct version of gcc? I remember seeing on the web that a similar message appears for some versions of gcc. You should use the exact version of gcc as described in the post for this to work.

Inderjit Singh said...
This comment has been removed by the author.
Inderjit Singh said...

Hi Suneil,

I took birth later, but i too have same problem as Sazly Salfarina had:

On step 7.c, "make LANGUAGES=c BOOT_LDFLAGS=-static", i've got this error.
...
./config/arm/arm.c: In function ‘arm_override_options’:
./config/arm/arm.c:286: warning: assignment discards qualifiers from pointer target type
./config/arm/arm.c:530: error: lvalue required as left operand of assignment
make[1]: *** [arm.o] Error 1
make[1]: Leaving directory `/home/sanuar/arm_cross/gcc-2.95.3/gcc'
make: *** [all-gcc] Error 2

I am a Linux beginner, I have been working hard but unable to solve this problem.


ALSO OTHERWISE: How to use:
ttp://www.eecs.umich.edu/~taustin/code/arm-cross/glibc-2.1.3-armlinux.tar.gz


Plz help...

Suneil said...

Indejit: Try the step mentioned in http://gcc.gnu.org/ml/gcc-help/2007-10/msg00231.html to modify the offending line of code.

glibc-2.1.3-armlinux.tar.gz is the compiled version of this file. If you get that, you don't need any of the steps in my post. Just do what ever you want to do with simplescalar for ARM.

How to use simplescalar for ARM is beyond the scope of this blog post. I refer you to the documentation or your professor for guidance.

Inderjit Singh said...

Thanks Suneil for your kind reply:

But...

1. [! URGENT]
I am unable to get forward: glibc-2.1.3-armlinux.tar.gz, the compiled version, how can i generate ARM binaries using it???

2. [URGENT] (plz help)
I can use pre-generated ARM binaries (available online), but i need to generate trace of memory addresses using simplescalar/ARM tool. There is not much available online for this.

How to generate memory address access traces...?

Thanks Suneil