Page 1 of 1

LInker kernel start address output is wrong.

Posted: Fri Jun 24, 2016 11:38 am
by Sourcer
I'm trying to print the kernel's start address,

Using this linker script:

Code: Select all

OUTPUT_FORMAT(elf32-i386)
ENTRY(start)

SECTIONS
{
    . = 1M;
    kernel_start = .;
   .multiboot : ALIGN(4K)  { *(.multiboot) }
   .text : ALIGN(4K) { *(.text) }
   .data : ALIGN(4K) { *(.data) }
   .bss  : ALIGN(4K) { *(.bss)  }
    kernel_end = .;
}
And these symbols in my code:

Code: Select all

extern unsigned long kernel_start, kernel_end;
When printing kernel_start the value is:
0x1badb002

kernel_end:
0x0

I tried to play with the values alittle bit, and when

Code: Select all

kernel_start = 0x0
in my linker script, the output is even more weird:
0xf000ff53

I'm missing something here, maybe because i'm tired.. beats me.

Re: LInker kernel start address output is wrong.

Posted: Fri Jun 24, 2016 12:28 pm
by glauxosdever
Hi,


Try using the address of the symbol, instead of the symbol itself.

Code: Select all

extern unsigned char kernel_start;
extern unsigned char kernel_end;

int function_name (int a)
{
    /* Some code goes here. */

    /* Get the addresses of the kernel start and end. */
    kernel_start_addr = &kernel_start;
    kernel_end_addr = &kernel_end;

    /* Use the addresses in a way you want. */

    /* Some other code goes here */
}
Hope this helps. :)


Regards,
glauxosdever

Re: LInker kernel start address output is wrong.

Posted: Fri Jun 24, 2016 1:06 pm
by Sourcer
glauxosdever wrote:Hi,


Try using the address of the symbol, instead of the symbol itself.

Code: Select all

extern unsigned char kernel_start;
extern unsigned char kernel_end;

int function_name (int a)
{
    /* Some code goes here. */

    /* Get the addresses of the kernel start and end. */
    kernel_start_addr = &kernel_start;
    kernel_end_addr = &kernel_end;

    /* Use the addresses in a way you want. */

    /* Some other code goes here */
}
Hope this helps. :)


Regards,
glauxosdever
So let me get this straight, when:

Code: Select all

symbol = value;
in the linker script,

Code: Select all

&symbol == value
?

This is kinda stupid, but ok hehe. thanks.

Re: LInker kernel start address output is wrong.

Posted: Thu Jul 07, 2016 11:11 am
by mariuszp
It's not stupid, it makes perfect sense.

The linker assigns addresses to symbols. It doesn't assign value to variables.

Re: LInker kernel start address output is wrong.

Posted: Thu Jul 07, 2016 3:02 pm
by Neroku
glauxosdever wrote:

Code: Select all

extern unsigned char kernel_start;
extern unsigned char kernel_end;

int function_name (int a)
{
    /* Some code goes here. */

    /* Get the addresses of the kernel start and end. */
    kernel_start_addr = &kernel_start;
    kernel_end_addr = &kernel_end;

    /* Use the addresses in a way you want. */

    /* Some other code goes here */
}
I would suggest to redefine both kernel_start and kernel_end as empty arrays. This way they directly represent these addresses you are looking for:

Code: Select all

extern unsigned char kernel_start[];
extern unsigned char kernel_end[];