Strange Linking/Compiling Bug

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
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Strange Linking/Compiling Bug

Post by thepowersgang »

I have recently switched to a new linking system for Acess that combines both versions by keeping shared code in a separate folder.

When I tried to run the compiled binary I kept getting call instructions pointing into the middle of functions instead of the start. Here is a section of the code disassembled by objdump.

Code: Select all

...
00100f70 <_kmain>:
  100f70:	55                   	push   %ebp
  100f71:	89 e5                	mov    %esp,%ebp
  100f73:	57                   	push   %edi
  100f74:	56                   	push   %esi
  100f75:	53                   	push   %ebx
  100f76:	83 ec 1c             	sub    $0x1c,%esp
  100f79:	8b 75 0c             	mov    0xc(%ebp),%esi
  100f7c:	c7 45 f0 ff ff ff ff 	movl   $0xffffffff,0xfffffff0(%ebp)
  100f83:	e8 bd fa ff ff       	call   100a45 <_gdt_install+0x18>
  100f88:	e8 5a f4 ff ff       	call   1003e7 <_idt_install+0x1d>
  100f8d:	e8 96 f4 ff ff       	call   100428 <_isrs_install+0x22>
  100f92:	e8 a5 2f 00 00       	call   103f3c <_irq_install+0x27>
  100f97:	e8 14 3f 00 00       	call   104eb0 <_init_video+0x2c>
...
There should not be any offsets to those functions and the movl instruction confuses me.
This is a c function with the prototype:

Code: Select all

void kmain(Uint32 mbMagic, mboot_info *mboot);
Here is a link to the current source code: http://www.mutabah.net/new/projects.acess2.php
I use mingw32 and the binutils from Bran's Kernel Development Tutorial (http://www.osdever.net/bkerndev/index.php)

--- NOTE ---
Sorry if I sound like a noob, most probebly the answer is staring me in the face and I can't see it.
Last edited by thepowersgang on Thu Feb 18, 2010 4:11 am, edited 1 time in total.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Strange Linking/Compiling Bug

Post by itisiuk »

i dont use minwg, but in your makefile nasm's output is set to
ASFLAGS = -f aout

should this not be
ASFLAGS = -f elf32
as you are linking the file together as a elf file
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Strange Linking/Compiling Bug

Post by thepowersgang »

The final executable is an elf but aout is used because it is simple for an intermediate object file format.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Strange Linking/Compiling Bug

Post by itisiuk »

just checking, cos i used to use aout and coff with mine and it had linking problems when i change it to elf.
could have also been cos i changed from djgpp to cygwin at that time too.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Strange Linking/Compiling Bug

Post by Combuster »

"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Strange Linking/Compiling Bug

Post by thepowersgang »

The problem is not with compiling the kernel, that goes without errors or warnings and the toolkit I'm using compiled and ran acess before without a hitch. The problem is with the code having strange offsets in functions calls.

I have discovered that the offsets in _kmain are out by the number of bytes between the start of _kmain and the call in question e.g. there is 24 bytes before the call to _gdt_install
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Strange Linking/Compiling Bug

Post by thepowersgang »

Has anyone had experience with an effect of this kind when compiling?
I have been looking over my makefiles and build scripts like crazy and cannot seem to find the problem.

*NOTE* Sorry for the double post
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply