Page 1 of 1

Strange Linking/Compiling Bug

Posted: Wed Jul 16, 2008 11:32 pm
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.

Re: Strange Linking/Compiling Bug

Posted: Thu Jul 17, 2008 5:50 am
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

Re: Strange Linking/Compiling Bug

Posted: Thu Jul 17, 2008 6:31 am
by thepowersgang
The final executable is an elf but aout is used because it is simple for an intermediate object file format.

Re: Strange Linking/Compiling Bug

Posted: Thu Jul 17, 2008 7:19 am
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.

Re: Strange Linking/Compiling Bug

Posted: Thu Jul 17, 2008 7:32 am
by Combuster

Re: Strange Linking/Compiling Bug

Posted: Thu Jul 17, 2008 7:59 am
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

Re: Strange Linking/Compiling Bug

Posted: Fri Jul 25, 2008 6:05 am
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