gcc section error

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

gcc section error

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

Re: gcc section error

Post 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
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: gcc section error

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: gcc section error

Post by sortie »

I recommend you follow the http://wiki.osdev.org/Bare_Bones tutorial (including setting up a cross-compiler).
Post Reply