Page 1 of 1

gcc / ld problem

Posted: Fri Jan 31, 2003 12:20 pm
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

Re:gcc / ld problem

Posted: Fri Jan 31, 2003 1:57 pm
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 .

Re:gcc / ld problem

Posted: Sat Feb 01, 2003 8:38 am
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

Re:gcc / ld problem

Posted: Sun Feb 02, 2003 1:58 pm
by Pype.Clicker
note that the "-x" (all-headers) will be more instructive than -d (disassemble)