Page 1 of 1

gcc section error

Posted: Fri Jul 26, 2013 4:30 am
by tsdnz
Hi Guys, I have my OS running using assembly language.
My next step is to create all the code for my next project and optimise the current code.
So I thought I would look into gcc.
I am using Cygwin64.
gcc looks good but I have spent a few hours now on trying to get it to compile code at a starting address.
I have googled and searched this site.
Being unfamiliar with Linux it has held me back a bit.

My source code is:

Code: Select all

int start(void)
{
mylabel:
  goto mylabel;
}
The gcc commandline and error are:
$ gcc -Wall -pedantic-errors kernel.c -o kernel.exe -nostdlib -Wl,-Ttext=0x20000
/tmp/ccD98StI.o:kernel.c:(.pdata+0x0): relocation truncated to fit: rva32 against `.text'
/tmp/ccD98StI.o:kernel.c:(.pdata+0x4): relocation truncated to fit: rva32 against `.text'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccD98StI.o: bad reloc address 0x8 in section `.pdata'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/../../../../x86_64-pc-cygwin/bin/ld: final link failed: Invalid operation
collect2: error: ld returned 1 exit status
Can someone help me out?

Re: gcc section error

Posted: Fri Jul 26, 2013 4:44 am
by tsdnz
Wow, just about to go to sleep and noticed I missed -c

This compiles.
gcc -Wall -pedantic-errors -c kernel.c -o kernel.exe -nostdlib -Wl,-Ttext=0x20000
I did an objdump which shows the starting address as 000
Is this correct?
objdump --disassemble --disassembler-options intel kernel.exe

kernel.exe: file format pe-x86-64


Disassembly of section .text:

0000000000000000 <start>:
0: 55 push rbp
1: 48 89 e5 mov rbp,rsp
4: b8 ff ff ff ff mov eax,0xffffffff
9: 5d pop rbp
a: c3 ret
b: 90 nop
c: 90 nop
d: 90 nop
e: 90 nop
f: 90 nop

Re: gcc section error

Posted: Sat Jul 27, 2013 6:42 am
by xenos
No. You did not link whatever you compiled there, so your addresses will be bogus. Apart from that, you should use a cross compiler, since your Cygwin64 gcc will cause you even more trouble that it already did in this first exercise.

Re: gcc section error

Posted: Sat Jul 27, 2013 7:13 am
by sortie
I recommend you follow the http://wiki.osdev.org/Bare_Bones tutorial (including setting up a cross-compiler).