Free Downloads, Community Forum,
FAQs and Developer Resources


Make /Tools Your Home | Link to us

Today's posts | Posts since last visit | Most Active Topics

All Forums Register Login Search Subscriptions My Profile Inbox
Tool Warehouse FAQs Resources Help Member List Address Book Logout

cross compiling on linux for interix

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> cross compiling on linux for interix Page: [1]
Login
Message << Older Topic   Newer Topic >>
cross compiling on linux for interix - May 28, '06, 6:10:59 PM   
mkoeppe

 

Posts: 46
Joined: Dec. 8, '05,
Status: offline
Hello,

I tried to build a cross compiler on linux to build tools for interix 3.5.
I managed to build such a compiler and linker, and the compiler seems to work fine, but the linker doesn't. Maybe you can help me.

Linux platform is Debian etch, kernel 2.6.11, gcc-4.0.

I used binutils 2.16.91 20060413 and configured with
--target=i586-pc-interix3 --with-gnu-as --with-gnu-ld


For cross-gcc, I used gcc-4.1.0 and configured with
--target=i586-pc-interix3 --enable-languages=c --enable-threads=no --disable-shared --with-stabs --enable-nls --disable-libssp --with-gnu-as --with-gnu-ld


I tried the following short program:
int main()
{
    return 3;
}


and got:
$ i586-pc-interix3-gcc -c hello.c


so compiling is ok, but ...
$ i586-pc-interix3-gcc hello.o
collect2: ld terminated with signal 11 [Segmentation fault]
/usr/local/lib/gcc/i586-pc-interix3/4.1.0/libgcc.a(__main.o): In function `__do_global_ctors':
/srv/src/gcc-4.1/build2/gcc/../../src/gcc/libgcc2.c:1956: undefined reference to `_atexit'
/usr/local/lib/gcc/i586-pc-interix3/4.1.0/../../../../i586-pc-interix3/lib/libpsxdll.a(PSXDLL.dll.a):(.idata$2+0x0): undefined reference to `.idata$4'


... linking segfaults.

The .../lib/libpsxdll.a and all other libs I copied over from an interix 3.5 installation's /usr/lib/* to /usr/local/i586-pc-interix3/lib/*.
Post #: 1
RE: cross compiling on linux for interix - Jul. 16, '06, 8:26:08 AM   
franz

 

Posts: 2
Joined: Jul. 16, '06,
Status: offline
To achieve the goal of cross-compiling you have to go a long way. In short
- Generate ld and as from the GNU-sources of interix 3.5
- Generate the other binutils from the GNU-binutils
- Prepare the interix-libs
- Generate gcc from the GCC-sources

I made a cross-compiler under cygwin. All the steps should be performed for
cross-compiling under debian-linux.

1. Generate ld and as from GNU-sources of interix 3.5
You have to locate the file GCC.TGZ from interix-3.5 Installation-CD. After
expansion you have the directories dejagnu and gcc-source. You have further
to expand binutils-2.16.1.tar.gz. This gives the directory binutils-2.16.1.
A suiteable expansion-command under interix is 'gunzip -c <file> | pax -r'.
In the directory gcc-source/queued there are the patches to be applied to
the directories in gcc-source. In order to generate ld and as we have to
apply patches at bfd, include, ld and gas.
And so it goes

cd gcc-source
cp ../binutils-2.16.1/* .
mkdir etc
cp -r ../binutils-2.16.1/etc/* etc

cd bfd
touch interix-core.c
patch -N -l -p 2 < ../queued/bfd/02.*
patch -N -l -p 0 < ../queued/bfd/10.*
patch -N -l -p 2 < ../queued/bfd/12.*
patch -N -l -p 2 < ../queued/bfd/14.*
patch -N -l -p 2 < ../queued/bfd/16.*
patch -N -l -p 2 < ../queued/bfd/39.*
patch -N -l -p 2 < ../queued/bfd/43.*
patch -N -l -p 2 < ../queued/bfd/44.*
patch -N -l -p 2 < ../queued/bfd/46.*
patch -N -l -p 2 < ../queued/bfd/47.*
patch -N -l -p 1 < ../queued/bfd/48.*
patch -N -l -p 2 < ../queued/bfd/49.*
patch -N -l -p 1 < ../queued/bfd/50.*
patch -N -l -p 2 < ../queued/bfd/51.*
patch -N -l -p 1 < ../queued/bfd/53.*
patch -N -l -p 0 < ../queued/bfd/54.*
patch -N -l -p 0 < ../queued/bfd/55.*
patch -N -l -p 0 < ../queued/bfd/56.*
patch -N -l -p 1 < ../queued/bfd/57.*
patch -N -l -p 0 < ../queued/bfd/58.*
patch -N -l -p 1 < ../queued/bfd/60.*
patch -N -l -p 0 < ../queued/bfd/61.*
patch -N -l -p 0 < ../queued/bfd/62.*
patch -N -l -p 0 < ../queued/bfd/63.*
patch -N -l -p 0 < ../queued/bfd/65.*

cd ../include
patch -N -l -p 2 < ../queued/include/01.*
patch -N -l -p 2 < ../queued/include/30.*

cd ../ld
patch -N -l -p 1 < ../queued/ld/02.*
patch -N -l -p 1 < ../queued/ld/08.*
patch -N -l -p 5 < ../queued/ld/22.*
patch -N -l -p 5 < ../queued/ld/23.*
patch -N -l -p 5 < ../queued/ld/24.*
patch -N -l -p 5 < ../queued/ld/26.*
patch -N -l -p 1 < ../queued/ld/30.*
patch -N -l -p 0 < ../queued/ld/31.*
patch -N -l -p 5 < ../queued/ld/40.*
patch -N -l -p 0 < ../queued/ld/41.*
patch -N -l -p 0 < ../queued/ld/42.*
patch -N -l -p 1 < ../queued/ld/43.*
patch -N -l -p 0 < ../queued/ld/44.*

cd ../gas
patch -N -l -p 1 < ../queued/gas/13.*
patch -N -l -p 1 < ../queued/gas/17.*
patch -N -l -p 1 < ../queued/gas/18.*
patch -N -l -p 1 < ../queued/gas/21.*
patch -N -l -p 0 < ../queued/gas/33.*
patch -N -l -p 1 < ../queued/gas/34.*
patch -N -l -p 1 < ../queued/gas/36.*
patch -N -l -p 0 < ../queued/gas/37.*

This sequence of commands can be made inside interix. The actual build
has to be made inside the environment for cross-compiling.

cd ../bfd
./configure --prefix=/opt --disable-nls --target=i586-pc-interix3
make headers
make

cd ../libiberty
./configure --prefix=/opt --disable-nls --target=i586-pc-interix3
make

cd ../ld
./configure --prefix=/opt --disable-nls --target=i586-pc-interix3
make
make install

cd ../gas
./configure --prefix=/opt --disable-nls --target=i586-pc-interix3
make
make install

After this sequence of commands you have in /opt/bin a useable ld and as. These 2
Programs are able to compile and link programs for interix. The reason of using
/opt (or whatever you want) as prefix comes from the fact, that we need to have
/opt/lib as additional search-path for library-searches. This becomes clear at
step 3 (Prepare the interix-libs).

2. Generate the other binutils from the GNU-binutils
Then you go on to build your binutils. Remember, you have to replace ld and as with
the versions fom interix.

3. Prepare the interix-libs
The interix-libs have a lot of problems. If you look at libc.so, you will see, that
this file is NOT a symbolic link to libc.so.3.5 (as it should be), but a ld-script.
This script closes a compatibility-gap: The gcc-compiler puts "-lgcc -lc -lpsxdll",
but not the necessary "-lcompat30" to linker. In order to insert libcompat30.a, there
exists the ld-script on libc.so. But such a setup breaks assumptions of configure-scripts.
So I have decided to put the ld-script on libpsxdll.a and rename the original libpsxdll.a
to psxdll.lib.

cd /usr/lib
ln -sf libc.so.3.5 libc.so
mv libpsxdll.a psxlib.lib
cat > libpsxdll.a << "EOF"
INPUT (/usr/lib/libcompat30.a /usr/lib/psxdll.lib)
EOF

Now this setup guaranties a valid program with the command
ld /lib/crt0.o test.o -lgcc -lc -lpsxdll

We can expect such a command from gcc, but not from configure-scripts. So the situation
is still not satisfactory. Now it helps, that we have an additional search-path (also
the first search-path) in /opt/lib. So I have put two addional ld-scripts into /opt/lib:

cd /opt/lib
cat > libc.a < "EOF"
INPUT (libgcc.a /usr/lib/libc.a /usr/lib/libpsxdll.a)
EOF

cat > libc.so < "EOF"
INPUT (libgcc.a /usr/lib/libc.so /usr/lib/libpsxdll.a)
EOF

NOTE: In the original installation we have to put these scripts into /opt/gcc.3.3/lib. It
is also necessary to do all the descibed steps .

The libgcc.a must be copied into /opt/lib. Now we have a setup that satisfies nearly
all expactions:

gcc -static test.c ... generates a static linked a.out
gcc test.c ... generates a dynamic linked a.out
ld --static /lib/crt0.o test.o -lc ... generates a static linked a.out
ld /lib/crt0.o test.o -lc ... generates a dynamic linked a.out

Linking of a shared library with
ld -S --shared -o libxxx.so /lib/crti.o --whole-archive libxxx.a --no-whole-archive -lc

still does not work, we have a core-dump. This core-dump comes from an illegal libpsxdll.a
(now psxdll.lib). The input-lib is in Microsoft-format, NOT in GNU-format.

In the MinGW-Installation, there exists a program "reimp.exe". This program transforms a import-
lib from Microsoft-format into GNU-format.

From cmd.exe:
reimp psxdll.lib

Now we have psxdll.a and psxdll.def. If we copy psxdll.a into /lib/psxdll.lib, we are ready.
Now ALL is working as expected, including linking of shared-libs.

The original GNU-ld from binutils now does no longer trap, but declares undefined symbols.
But because we have a suiteable ld from interix-source, this imposes no problem.

4. Generate gcc from source


Hope, this helps

(in reply to mkoeppe)
Post #: 2
RE: cross compiling on linux for interix - Jul. 16, '06, 11:55:18 AM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
Hey Franz, thanks for for posting this information -- especially such fine details.
It looks like it was a lot of work!

(in reply to mkoeppe)
Post #: 3
RE: cross compiling on linux for interix - Jul. 16, '06, 5:48:23 PM   
mkoeppe

 

Posts: 46
Joined: Dec. 8, '05,
Status: offline
Hi franz,

thank you very much for the information.
Currently I'm on holiday, so I can't try now.
But I definitely will try it when I'm back,
i.e. end of August / beginning of September.

Martin

(in reply to franz)
Post #: 4
RE: cross compiling on linux for interix - Aug. 29, '06, 4:21:47 AM   
mkoeppe

 

Posts: 46
Joined: Dec. 8, '05,
Status: offline
Hi Franz,

I'm now testing your instructions on linux. I did manage to build ld and gas from the original ms sources, but after applying the ms patches you mention, there are compile errors. I had a closer look and saw that several hunks of the patches don't apply. I think the compile errors come from that.

Just to make sure I wanted to ask you if you could md5sum your gcc.tgz file. Mine is
846170fdc109f0067b21888e4b6f26aa gcc.tgz

Thank you very much

Martin

(in reply to franz)
Post #: 5
RE: cross compiling on linux for interix - Sep. 1, '06, 12:46:21 PM   
franz

 

Posts: 2
Joined: Jul. 16, '06,
Status: offline
The md5sum of GCC.TGZ is correct. I will now also try to build ld and as under debian 3.1 (sarge). Maybe you should apply the patches under interix, as i did. The interix-tools are bsd-based, the linux-tools gnu-based, maybe there is a mismatch.

(in reply to mkoeppe)
Post #: 6
Page:   [1]
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> cross compiling on linux for interix Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Search All Forums -

Advanced search


SPONSORS



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.078