"end" symbol from my linker script is zero?

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
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

"end" symbol from my linker script is zero?

Post by Caleb1994 »

Hey, I was having an odd error when trying to clone a page directory. It was saying that my frame allocator was returning zero. This made no sense, because I explicitly tell the allocator to reserve the first frame as it holds important system stuff. So, I opened up GDB, connected, and began examining variables. I noticed that the pointer to my frame bitmap was NULL. As I stepped through the program (from the beginning) I realized it had always been NULL from the beginning, but for some reason it hadn't caused errors (it should have though... that is the IDT...). I set this pointer to the value of "end" which is exported from my linker script, and should point directly after my kernel, and upon examining "end" in gdb, I realized end was null also! Can you guys think of any reason that the linker would report "end" to be zero? Here is my linker script:

Code: Select all

OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
Thanks, Caleb.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: "end" symbol from my linker script is zero?

Post by gerryg400 »

Remember that 'end' is not a variable. It does not have a value. You must take its address with &end to get the pointer you are looking for.

[EDIT:] Berkus is fast.
If a trainstation is where trains stop, what is a workstation ?
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

Re: "end" symbol from my linker script is zero?

Post by Caleb1994 »

Wow... You guys are fast... You nailed it... I had read online that the symbols in a linker script were accessable in C, but not that an address had to be referenced like that! I thought it was a little weird that when I ran:

gdb>whatis end

out of curiosity, I got "int" which, if it was an address, should have been an "unsigned int". Thanks!
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: "end" symbol from my linker script is zero?

Post by gerryg400 »

For portability between 32 and 64 bit address spaces, it's better to be

Code: Select all

extern const void end;
That makes &end a void *.
If a trainstation is where trains stop, what is a workstation ?
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

Re: "end" symbol from my linker script is zero?

Post by Caleb1994 »

Well I was just doing this:

extern end;

because I wasn't sure what type that the linker gave it.

Although, it seems I can't rely on this value now... sigh... Apperantly grub places important things like boot modules right after the kernel so... I have to account for that lol

EDIT:


Oh... wow... I wasn't thinking. In C, when there is no type, "int" is assumed. Bahahahaha I forgot. xD
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

Re: "end" symbol from my linker script is zero?

Post by Caleb1994 »

Yeah, it isn't a problem. It's just that now that I figured out what was wrong with "end", I realized I didn't need it anymore xP
Post Reply