Link script question

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
lordio
Posts: 7
Joined: Tue Jan 22, 2013 6:37 pm

Link script question

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Link script question

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
lordio
Posts: 7
Joined: Tue Jan 22, 2013 6:37 pm

Re: Link script question

Post 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.
Post Reply