Page 1 of 1

Link script question

Posted: Thu Mar 14, 2013 6:08 am
by lordio
In Beginner Mistakes, it's mentioned that the .rodata section is supposed to be located within the .text section. My linker script places it in its own section, like so:

Code: Select all

OUTPUT_FORMAT(elf64-x86-64)
ENTRY(kmain)
SECTIONS
{
	. = 0x30000;
	.text : { *(.text) }
	.rodata : { *(.rodata) }
	.data : { *(.data) }
	.bss : { *(.bss) }
}
Is there any reason .rodata must/should be in .text?

Everything compiles and runs, I'm just wondering why the page is so specific.

EDIT: I reread the page, and it mentions some problems, but it's not clear if they occur if .rodata is not included in the link script, or if it's not in the .text section.

Re: Link script question

Posted: Thu Mar 14, 2013 9:37 am
by Combuster
.rodata contains any strings you might be using, so your linker script must add it to the output binary.

Typical for output binaries is to have a division between read-only data and read-write data. Both code and string constants qualifies for the first, and reducing the total amount of section correspondingly reduces memory overhead.

Re: Link script question

Posted: Thu Mar 14, 2013 10:55 am
by lordio
So, it's less that it must be there, more that it's just a good idea, as it keeps the size of the kernel binary to a minimum.