Search code examples
gccassemblylinkerlinker-errorslinker-scripts

Syntax error in linker script


I have a syntax error on line 8
I have read the GNU docs concerning the syntax and managed to solve the syntax error but got incompatibility issues
Here's my script:

ENTRY (loader)
OUTPUT ("kernel.bin")

addr = 0x100000;
SECTIONS
{
        .text addr: 
        ALIGN(0x1000)
        {
            *(.text*);
            *(.rodata*);
        }

        .data:
        ALIGN(0x1000)
        {
            *(.data*);
        }

        .bss:
        ALIGN(0x1000)
        {
            *(.bss*);
        }
}

Please excuse me as I'm just trying to startup with OSDeving with a Hello World sample


Solution

  • Here is what my linker script looked like before I moved my kernel to the higher half:

    OUTPUT_FORMAT("elf32-i386","elf32-i386","elf32-i386")
    OUTPUT_ARCH(i386)
    
    ENTRY(entry)
    SECTIONS
    {
        . = 0x00100000;
        start = .;
        .text : 
        {
            *(.text)
            . = ALIGN(4096);
        }
    
        .data :
        {
            *(.data)
            *(.rodata)
            . = ALIGN(4096);
        }
    
        .bss :
        {
            *(.bss)
            *(stack_bottom)
            *(stack_top)
            . = ALIGN(4096);
        }
        end = .;
        kernel_end = .;
    }
    

    I believe the issue is lack of space between ".text" and the colon. I had ld give me errors like that for a different project. If you want to designate where each section should be located, do it like this:

    .text : AT(ADDR(.text) - 0xC0000000)
        {
            *(.text)
            . = ALIGN(4096);
        }