Ld & Ar errors

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.
Slasher

Ld & Ar errors

Post by Slasher »

Hi,
I have been working on this and can't get it to work!
The thing is, I want to create a single library file containg all the kernel code from all the seperate files containing code for floppy,dma,video etc
But when i use AR to create an archieve KERNEL.lib ->
ar rsc kernel.lib *.o
and then use this file with ld -> ld -T klink.ld -o kmain.bin kmain.o kernel.lib
i get the following error on my screen

Exiting Due To Signal SIGSEGV
General Protection Fault at eip=0005b475
eax=eb0006b2 ebx=0000fd00 ecx=00000005 edx=0000001e
esi=cb7211a0 edi=0011f178 ebp=000f1e98 esp=000f 1e88 program=C:\Djgpp\bin\LD.exe
cs: sel=00af base=82c80000 limit=0012ffff
ds: sel=00b7 base=82c80000 limit=0012ffff
es: sel=00b7 base=82c80000 limit=0012ffff
fs: sel=0087 base=00000000 limit=0000ffff
gs: sel=00c7 base=82c80000 limit=0010ffff
ss: sel=00b7 base=82c80000 limit=0012ffff
App stack: [000f20a8.....000720a8]
Exception stacK: [00071ffc...000700bc]

Call Frame traceback EIPs:
0x0005b475
0x0002d208
0x0003d09a
0x0003e3db
0x00026903
0x0003e34f
0x0001353f
0x00013e40
0x00016c12
0x0001988f
0x0005adc8
Can anyone PLEASE show me how to create a library file with AR (or any other program) that will link with LD without causeing an error!
Also I'd like to know if Djgpp outputs Elf files and How.
I'm using Djgpp version 3.03 and binutils!
Thanks.
DarylD

Re:Ld & Ar errors

Post by DarylD »

That is how I do it, should work perfectly...

Dont think djgpp will output elf, but you could use cygwin and compile the elf versions under that.

Daryl.
Slasher

Re:Ld & Ar errors

Post by Slasher »

i compiled the C files as follows
gcc -c -Wall -ffree-standing -fwritable-stings etc
but not with the -fPIC.
do you use -fPIC and what does it do?
also can you type how you compile your files?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Ld & Ar errors

Post by Pype.Clicker »

-fPIC produces position-independent code.Tis means the compiler will add a lot of complexity like the Global Offset Table or the Procedure Linking Table and lock a register to point to the GOT at any time ... It also privilegies relative calls/jumps whenever possible ...

I doubt it's a wise option to use -fPIC within a kernel (mostly because of that register-locking which may be troublesome for asm interfacing ...). At least, you shouldn't enable it before you go down deep in the ELF specifications and find out what it is really about ...
DarylD

Re:Ld & Ar errors

Post by DarylD »

I wouldn't recommend using -fpic for the kernel itself, but its safe enough to use for modules/applications, although the benefits are a bit dubious. Also, GOT/PLT based code will run a smidge slower due to all the indirection and it will bloat the code size slightly too.

I have a (pretty much) complete elf loader in my code which handles the GOT/PLT, but to be honest I don't really need it yet. Its possible to get away with using relocatable code instead which just involves fixing up relocation links at load time.

Daryl.
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Ld & Ar errors

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:51 pm, edited 1 time in total.
whyme_t

Re:Ld & Ar errors

Post by whyme_t »

Code Slasher wrote: ld -T klink.ld -o kmain.bin kmain.o kernel.lib
I had problems when linking the c++ support lib with my kernel. To solve that problem I had to link the lib between my stub and main object file. Don't know if this will help, as you don't have a stub.

Code: Select all

ld -T klink.ld -o kmain.bin kstub.o kernel.lib kmain.o
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Ld & Ar errors

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:52 pm, edited 1 time in total.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Ld & Ar errors

Post by Pype.Clicker »

a stub is a small bunch of code (usually in ASSembly) that will interface 2 different calling convention (for instance, the interrupt handler stub which will pusha ; call C-code ; popa ; iret , the booter stub which will push ebp;mov ebp,esp;call C_init;cli;hlt, etc.)
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Ld & Ar errors

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:52 pm, edited 1 time in total.
whyme_t

Re:Ld & Ar errors

Post by whyme_t »

Perica, What made you think I was answering you? I have no knowledge of using ar and there was no mention of it in my post. I was responding to Code Slasher, you know... the one who originally asked the question ::)
Slasher

Re:Ld & Ar errors

Post by Slasher »

I do not understand why i need a stub! what i'm trying to do is, instead of having a command line with many files (Right now i can't add more files cause i have passed the 255 character limit of dos/win command line) i want to create a library of my kernel code by joining all the *.o files into a single *.o or *.lib file!
I'm not using any c++, don't need it.

How do you guy do it? that's all i'm asking for (please type complete command line options for gcc and ar, cause i'm really getting annoyed with DJGPP.I can remeber how simple this was to achieve with BORLAND!!!).
I link the files as follows

gcc -c -Wall -fnostdlib -fwriteable-strings -ffreestanding -fno-builtin *.c
and the use
ar rsc kernel.lib *.o
to create kernel.lib
i then use
ld -T klink.ld -o kmain.bin kmain.o kernel.lib

but this doesn't work, as i stated above.
(question: do i need to put -l before kernel.lib? ie
ld -T klink.ld -o kmain.bin kmain.o -l kernel.lib)

also, when i tried adding -fPIC i got the following error message
as.exe: bfd assertion fail /djgpp/gnu/binutl-2.112/bfd/coff-i386.c:529
C:\djgpp/tmp/cceucqjl.s: Assembler Message: 50 : Error: cannot represent relocation type BFD_RELOC_386_PLT32

Anyone know what that means?
I'm begining to feel that my version of DJGPP/BINUTL is flawed. I'm i wrong?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Ld & Ar errors

Post by Pype.Clicker »

Position Independent Code is not possible with COFF object file. This is an ELF-only feature ...

Also, you should check your kernel entry point (kinit, start, whatever) is at the offset assumed by your bootloader ... (may objdump be with you :)
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Ld & Ar errors

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:51 pm, edited 1 time in total.
Slasher

Re:Ld & Ar errors

Post by Slasher »

Ok,
now i got the latest Djgpp files from the main website and reinstalled it.

But now i getting an out of memory error from ld.
any ideas?
also how can i set Djgpp to output ELF?
thanks
Post Reply