Page 1 of 1

elf troubles..

Posted: Thu May 24, 2007 4:15 am
by os64dev
I am trying to build a kernel in the elf format but the file seems to become huge > 1MiB. I've searched the wiki and such but it still gives problems.

here is my linker script:

Code: Select all

SECTIONS
{
    . = 0xFFFFFFFFC0000000;
    /***************************************************************************
    * This block contains the executable code, its information is used by the  *
    * program loader to allocate and setup executable read-only pages.         *
    ***************************************************************************/

    code_base = .;

    .text :
    {   *(.text*);
    }

    code_end = .;


    . = ALIGN (0x1000);                              /* align on a 4 KiB page */
    /***************************************************************************
    * This block contains the non-changeable data, its information is used by  *
    * the program loader to allocate and setup non-executable read-only pages. *
    ***************************************************************************/

    rodata_base = .;

    .rodata :
    {   *(.rdata*);
        *(.rodata*);

        ctors_base = ALIGN (0x08);
            *(.ctors*);
        ctors_end = ALIGN (0x08); 

        dtors_base = ALIGN (0x08);
            *(.dtors*);
        dtors_end = ALIGN (0x08); 
    }

    rodata_end = .;


    . = ALIGN (0x1000);                              /* align on a 4 KiB page */
    /***************************************************************************
    * This block contains the initialised data, its information is used by the *
    * program loader to allocate and setup non-executable read-write pages.    *
    ***************************************************************************/

    rwinit_base = .;

    .rwinit :
    {   *(.data*);
        *(.rwdata*);
    }

    rwinit_end = .;

    /***************************************************************************
    * This block contains the non-initialised data, its information is used by *
    * the program loader to allocate and setup non-executable read-write pages.*
    ***************************************************************************/

    rwdata_base = .;

    .rwdata :
    {   bss_base = ALIGN (0x08);
        *(.bss*);
        bss_end = ALIGN (0x08); 
        *(COMMON*);
    }

    rwdata_end = ALIGN (0x10);         /* align on a realmode segment boundry */

    /DISCARD/ : { *(.comment .note .eh_frame) }
}
it seems that it produces some info after 1 MiB in the output file.
Oh yeah it all gcc++ based .

Posted: Thu May 24, 2007 4:21 am
by AndrewAPrice

Code: Select all

    . = 0xFFFFFFFFC0000000; 
I'm not a linker expert, but is this aligning your code to this position? Or creating a pointer to it? If it's aligning it, then it could be filling blank data up to this point.

Posted: Thu May 24, 2007 5:58 am
by bluecode
Use

Code: Select all

    . = 0xFFFFFFFFC0000000 + SIZEOF_HEADERS; 
Dump ld will align your code to 1 MiB (within the elf file) for some stupid reason.

Posted: Thu May 24, 2007 6:40 am
by os64dev
thanx for the replies. I found out that i did not call ld with the -nostartfiles commandline option. After changing this it worked fine. @Bluecode it seems that your option would also have worked because SIZEOF_HEADERS is linked to the startfiles.