cygwin64 gcc compile start address and variable address

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

cygwin64 gcc compile start address and variable address

Post by tsdnz »

Hi, I have read many sites and docs about how to do this, but I cannot find a simple solution
I am using cygwin64 in Windows 7
Can someone explain how to compile a c or c++ program into flat binary that starts at address 0x1234 and uses uninitalised variables starting at address 0x5678
A line-by-line example of the commands would be great.

I need to see the disassembled code to make sure everything is in the correct place.

The program is:

Code: Select all

int DummyValue; // Uninitalised, start at 0x5678

void start(void) // Code starts at 0x1234
{
    DummyValue = 1234;
}
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: cygwin64 gcc compile start address and variable address

Post by xenos »

You have already been pointed to using a proper cross compiler instead of the gcc shipped with Cygwin64 in your previous thread.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Hi, Thanks.
Can someone help with the errors I get below?

I have read all the attached pages.
I am having trouble getting it to work.
One reason I have found is some lines have "$HOME" while others have $HOME
One example is http://wiki.osdev.org/Building_GCC under Binutils,
cd $HOME/src (This does not work, but cd "$HOME/src" does)
As my username is xxxx yyyy it uses just the xxxx and crashes.
So I changed the export HOME = ????? to my first name and created a dir in windows.
I copied all the files and uploaded every package in Devel in cygwin64.
But I still cannot get it to work using the information provided.
I tried the same thing but used cygwin

This is the error I get when running make in build-binutils

There are more errors when running make in gcc.
*** BFD does not support target x86_64-unknown-cygwin.
*** Look in bfd/config.bfd for supported targets.
Makefile:2461: recipe for target `configure-bfd' failed
make[1]: *** [configure-bfd] Error 1
make[1]: Leaving directory `/home/Alistair/src/build-binutils'
Makefile:841: recipe for target `all' failed
make: *** [all] Error 2
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: cygwin64 gcc compile start address and variable address

Post by sortie »

The shell is sensitive to white-space. If you type

Code: Select all

cd $HOME/src
and your HOME variable is set to something like "/home/Firstname Lastname" then the shell will expand that to

Code: Select all

cd /home/Firstname Lastname/src
which the shell understands as running the shell builtin 'cd' with two paramterers '/home/Firstname' and 'Lastname/src'. This isn't what you intended. If you type

Code: Select all

cd "$HOME/src"
then the shell will expand the variable, but within the quotes, and the space in the name doesn't matter to the shell and is given to cd as a single argument. This means that you have to be careful when using shell variables that potentially contain spaces. I probably should update the tutorial to avoid other people encountering this silly problem.

The other problem is caused by you not providing the correct --target option to configure. See the "*** BFD does not support target x86_64-unknown-cygwin." message with says that the --target option parameter you gave was "x86_64-unknown-cygwin" (which is your current system, so it's likely just the default.)

Please read the cross-compiler tutorial more carefully and post the exact commands you used to try and compile binutils.
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Thanks, was after midnight when trying to get it done.

Just to let you know that in the configure files it must also be using $HOME instead of "$HOME"

Time to read again.

The command was

Code: Select all

 ../binutils-2.23/configure --prefix="$PREFIX" --disable-nls
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: cygwin64 gcc compile start address and variable address

Post by sortie »

Read the instructions carefully, you forgot to specify --target. Without this, you get a compiler for your current system, not a cross-compiler. And yes, the shell variable expansion rules apply to all commands. On Unix systems, you often don't have spaces in the main directory paths ($HOME, $PREFIX), so the quotes are usually left out and the user is expected to add them as needed.
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Thanks, looking at http://wiki.osdev.org/Building_GCC I cannot find --target.
Am I on the wrong page?
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: cygwin64 gcc compile start address and variable address

Post by sortie »

Right - I didn't consider that. The "Building GCC" tutorial upgrades your host compiler to the most recent version. It doesn't give you a cross-compiler.

You are having trouble because the binutils and gcc you downloaded doesn't understand cygwin64. The cygwin developers modify gcc with custom patches and they are likely not upstream yet in the official binutils and gcc releases. If you insist on upgrading your system compiler, you should get the latest cygwin64 compatible binutils and gcc source code from the cygwin developers.

However, your cygwin compiler is likely new enough to build the cross-compiler that you want. I recommend you skip upgrading your system compiler to the latest version and instead directly proceed to building the real cross-compiler. In short, you want to follow this tutorial:

http://wiki.osdev.org/GCC_Cross-Compiler

I'll be sure to add a notice that the "Building_GCC" tutorial doesn't give you a cross-compiler, it just upgrades your host compiler. Though, the tutorial should cleanly state that.
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Great, that makes more sense.
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Hi again?? Any ideas why?

It did not work witha username that has a space in it.

I created a new user account in windows "Dev" and binutils worked.

But I have an issue with gcc

Code: Select all

C:\cygwin64\home\Dev\src\gcc-4.8.1\mpfr-3.1.2
This folder is in my directory.

But I received this error, showing mpfr.h is the wrong version

Code: Select all

checking for the correct version of gmp.h... yes
checking for the correct version of mpfr.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.
This was the command

Code: Select all

../gcc-4.8.1/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Oops, looks like I need to be slapped with a wet bus ticket.

I copied the dirs using windows.
I need to rename them,

Sorry guys.
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Alrighty then??

I have the cross compiler ready.
How do I start at an address 0x1234 and have my data at address 0x5678??
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Figured it out.

This linked helped.
http://forum.osdev.org/viewtopic.php?f= ... _plugin.so

Thanks, everyone!!
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Guys, now I am stuck when compiling 64 bit

I get this error

Code: Select all

$ $TARGET-gcc -m64 -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs
kernel.c:1:0: sorry, unimplemented: 64-bit mode not compiled in
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: cygwin64 gcc compile start address and variable address

Post by tsdnz »

Found this also.

I see you have to change the Target

http://wiki.osdev.org/GCC_Cross-Compiler_for_x86_64
Locked