gcc / ld problem

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
cmp

gcc / ld problem

Post by cmp »

hi, i used tcc to compile, so far, but the compiler's support of c is unsufficent, so i wanted to settle to gcc, but when i link i get file sizes above 4k, for a hang kernel
the files:
asmsystem.asm

Code: Select all

; PROG.ASM
bits 16

EXTERN _kernel_main

SEGMENT START

      mov ax, cs
            mov ds, ax
         mov es, ax         
      
      call _kernel_main

hang:
               jmp hang
system.c

Code: Select all

void kernel_main (void) {
}
compile.bat

Code: Select all

@echo off
echo.

echo nasm:
bin\nasmw -f elf -o system.o asmsystem.asm
echo done
echo.

echo gcc:
bin\gcc -c -m32 -o system2.o system.c
echo done
echo.

echo ld:
bin\ld -o kernel -Ttext 0x0 -e 0x0 system.o system2.o
echo done
echo.

echo objcopy:
bin\objcopy -R .note -R .comment -S -O binary kernel system.sys
echo done
echo.

echo disasemble kernel:
bin\objdump --disassemble-all kernel >disasm.txt
echo done
echo.

pause
cu, thanks beforehand
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:gcc / ld problem

Post by Pype.Clicker »

try objdump -x kernel to see what section takes place.
Possible problems include
- the ELF headers themselves take alot of space
- the text section has been padded to 4K (one page) by the linker to make on-demand loading faster (can be disabled with -n option iirc)
- some other section (.note, .symtab, .strtab ... ) you do not wish is added by default. Use the power of objcopy to remove it .
cmp

Re:gcc / ld problem

Post by cmp »

ok, thanks, i'll try it soon

[edit:]
i just tried it, but the file ist still almost 4 k (3.8 k)

compile.bat

Code: Select all

@echo off
echo.

echo nasm:
bin\nasmw -f elf -o system.o asmsystem.asm
echo done
echo.

echo gcc:
bin\gcc -c -m32 -o system2.o system.c
echo done
echo.

echo ld:
bin\ld -n -o kernel -Ttext 0x0 -e 0x0 system.o system2.o
echo done
echo.

echo objcopy:
bin\objcopy -R start: -R .idata -R .etext -R .note -R .comment -S -O binary kernel system.sys
echo done
echo.

echo disasemble kernel:
bin\objdump --disassemble-all kernel >disasm.txt
echo done
echo.

pause
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:gcc / ld problem

Post by Pype.Clicker »

note that the "-x" (all-headers) will be more instructive than -d (disassemble)
Post Reply