OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 3:23 pm

All times are UTC - 6 hours




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: cygwin64 gcc compile start address and variable address
PostPosted: Sat Jul 27, 2013 7:14 pm 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
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:
int DummyValue; // Uninitalised, start at 0x5678

void start(void) // Code starts at 0x1234
{
    DummyValue = 1234;
}


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 12:59 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
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


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 2:41 pm 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
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.

Quote:
*** 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


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 3:41 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
The shell is sensitive to white-space. If you type

Code:
cd $HOME/src


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

Code:
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:
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.


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 3:53 pm 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
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:
../binutils-2.23/configure --prefix="$PREFIX" --disable-nls


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 4:04 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
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.


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 4:08 pm 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
Thanks, looking at http://wiki.osdev.org/Building_GCC I cannot find --target.
Am I on the wrong page?


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 4:25 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
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.


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 4:33 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 5:17 pm 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
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:
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:
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:
../gcc-4.8.1/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 5:29 pm 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
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.


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Sun Jul 28, 2013 8:25 pm 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
Alrighty then??

I have the cross compiler ready.
How do I start at an address 0x1234 and have my data at address 0x5678??


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Mon Jul 29, 2013 12:48 am 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
Figured it out.

This linked helped.
http://forum.osdev.org/viewtopic.php?f=1&t=26918&hilit=liblto_plugin.so

Thanks, everyone!!


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Mon Jul 29, 2013 1:07 am 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
Guys, now I am stuck when compiling 64 bit

I get this error

Code:
$ $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


Top
 Profile  
 
 Post subject: Re: cygwin64 gcc compile start address and variable address
PostPosted: Mon Jul 29, 2013 2:58 am 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
Found this also.

I see you have to change the Target

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], FrankRay78 and 151 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group