Linking..

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
AvengerX

Linking..

Post by AvengerX »

Ok, i have a shell script to link a C and ASM file together, that's all wel, but it links/compiles incorrectly, either way, my script is like so:

---
#!/bin/csh
nasm -f elf $1.s -o obj/$1_a.o
if ( $? != 0 ) then
echo NASM: Error!
exit 1
endif
gcc -ffreestanding -static -c $1.c -o obj/$1_c.o
if ( $? != 0 ) then
echo GCC: Error!
exit 1
endif

ld -o obj/$1 -static -Ttext 0x600-e 0x0 obj/$1_a.o obj/$1_c.o
if ( $? != 0 ) then
echo LD: Error!
exit 1
endif
trimbin obj/$1 obj/$1.sect #trim elf out of binary
sectbin obj/$1.sect $2 #make binary confom to sectors, 512, 1024..
exit 0

---

now.. i linked a file with it (a variation on it without the ASM parts), and it reports a 4 kb file size (and the precompiled binary was like 72 bytes...) what the heck!? thanks in advance, if i get any help
AvengerX

Re:Linking..

Post by AvengerX »

-bump-
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:Linking..

Post by Pype.Clicker »

this "4K incrementation" might be due to some default padding in your binary fileformat ... (very common with ELF, for instance)
AvengerX

Re:Linking..

Post by AvengerX »

it['s not so much elf, because i have the trimbin script to make it a flat-binary... come to think of it, NOTHING 9i have made with that script has worked, (like character prin6ting) but dos debug gave me correct assembly..
AvengerX

Re:Linking..

Post by AvengerX »

oh yeah, and how would i get it to boot with GRUB?
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:Linking..

Post by Pype.Clicker »

imho, grub REQUIRE elf format ... and i see nothing in your script that enforces a flat binary .. try to use objdump -x to see where your bytes come from: it could be a relocation table, a padding header, debug symbols, whatever ...
AvengerX

Re:Linking..

Post by AvengerX »

I tried an ELF binary with grub (it didnt work), and the trimbin line enforces the binary (it contains the objcopy command, but i reference it for like... instead of having to alter all the files to make a change (at least to the objcopy line))
Post Reply