LD makes output huge!

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
mr. x2

LD makes output huge!

Post by mr. x2 »

I'm trying to compile my OS under Linux, in Windows the kernel.bin will be ~40 kb, but in Linux, it will be ~1mb! All the object files are correct, but the output of ld is huge.
This is how I link:
ld -T kernel.ld
This is my linker script:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start_stub)
OUTPUT("kernel.bin")

INPUT(kinit.o)
INPUT(kints.o)
INPUT(ints.o)
INPUT(driver_keyboard.o)
INPUT(driver_floppy.o)
INPUT(kernel.o)
INPUT(app_console.o)
INPUT(io.o)
INPUT(pic.o)
INPUT(idt.o)
INPUT(panic.o)
INPUT(doprintf.o)
INPUT(queue.o)
INPUT(string.o)
INPUT(memory.o)
INPUT(math.o)
INPUT(dma.o)
INPUT(driver_pefs.o)
INPUT(timer.o)
INPUT(mem_manager.o)
INPUT(driver_layers.o)
INPUT(sched.o)
INPUT(driver_FAT.o)
INPUT(driver_fs.o)
INPUT(driver_dev.o)
INPUT(config_parser.o)


SECTIONS  {
  .text 0x100000: {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :  {
    *(.bss)
  }

  kernel_end = .;
}
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:LD makes output huge!

Post by Candy »

mr. x2 wrote: I'm trying to compile my OS under Linux, in Windows the kernel.bin will be ~40 kb, but in Linux, it will be ~1mb! All the object files are correct, but the output of ld is huge.
You probably include a huge section of zeroes. Can you post the first 10 lines of a "hexdump -C filename" of the output file?
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 makes output huge!

Post by Pype.Clicker »

that suggests something wrong in your linker script that made it write 1MB of zeroes rather than setting the virtual address to 1MB ...

Do you have . = 0x00100000 somewhere ?
mr. x2

Re:LD makes output huge!

Post by mr. x2 »

Pype.Clicker wrote: that suggests something wrong in your linker script that made it write 1MB of zeroes rather than setting the virtual address to 1MB ...

Do you have . = 0x00100000 somewhere ?
Nope
mr. x2

Re:LD makes output huge!

Post by mr. x2 »

Candy wrote:
mr. x2 wrote: I'm trying to compile my OS under Linux, in Windows the kernel.bin will be ~40 kb, but in Linux, it will be ~1mb! All the object files are correct, but the output of ld is huge.
You probably include a huge section of zeroes. Can you post the first 10 lines of a "hexdump -C filename" of the output file?
If I understood hexdump right, there should be alot of zeroes right at 0x00000100 to 0x000f4240...
Someone

Re:LD makes output huge!

Post by Someone »

I suggest you to use this linker script:

SECTIONS {
.text 0x100000: {
*(.text) *(.rodata)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}

kernel_end = .;
}

i hope it works :D
virusx

Re:LD makes output huge!

Post by virusx »

hi,

I hope this will fixyour problem.
ld -Ttext 0x100000 -Txyz.ld ...

regards
NoNaMe

Re:LD makes output huge!

Post by NoNaMe »

Hi,

I had the same problem when I declared an Array or a Pointer. This was because the following was not in my link script:

*(.rodata)

So the following link script should work fine:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start_stub)
OUTPUT("kernel.bin")

INPUT(kinit.o)
INPUT(kints.o)
INPUT(ints.o)
INPUT(driver_keyboard.o)
INPUT(driver_floppy.o)
INPUT(kernel.o)
INPUT(app_console.o)
INPUT(io.o)
INPUT(pic.o)
INPUT(idt.o)
INPUT(panic.o)
INPUT(doprintf.o)
INPUT(queue.o)
INPUT(string.o)
INPUT(memory.o)
INPUT(math.o)
INPUT(dma.o)
INPUT(driver_pefs.o)
INPUT(timer.o)
INPUT(mem_manager.o)
INPUT(driver_layers.o)
INPUT(sched.o)
INPUT(driver_FAT.o)
INPUT(driver_fs.o)
INPUT(driver_dev.o)
INPUT(config_parser.o)

SECTIONS
{
   .text 0x100000:
   {
      code = .; _code = .; __code = .;
      *(.text) *(.rodata)
      . = ALIGN(4096);
   }
   .data :
   {
      data = .; _data = .; __data = .;
      *(.data)
      . = ALIGN(4096);
   }
   .bss :
   {
      bss = .; _bss = .; __bss = .;
      *(.bss)
      . = ALIGN(4096);
   }
   end = .; _end = .; __end = .;
}
Thanks to Someone to post his link script. It was there I saw the solution.

Regards
Post Reply