LInker kernel start address output is wrong.

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
Sourcer
Member
Member
Posts: 58
Joined: Fri Jun 17, 2016 11:29 pm
Libera.chat IRC: WalterPinkman

LInker kernel start address output is wrong.

Post 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.
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: LInker kernel start address output is wrong.

Post 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
Sourcer
Member
Member
Posts: 58
Joined: Fri Jun 17, 2016 11:29 pm
Libera.chat IRC: WalterPinkman

Re: LInker kernel start address output is wrong.

Post 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.
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: LInker kernel start address output is wrong.

Post by mariuszp »

It's not stupid, it makes perfect sense.

The linker assigns addresses to symbols. It doesn't assign value to variables.
User avatar
Neroku
Posts: 24
Joined: Tue Dec 01, 2015 4:53 am

Re: LInker kernel start address output is wrong.

Post 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[];
currently working on kboot86, the Genesis of my kernel
Post Reply