Section names in GCC

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
pini

Section names in GCC

Post by pini »

I was wondering why I had problems with writing strings with my printf functions. At last, I found out why.

When I'm using the following syntax :

Code: Select all

printf("my test string")
then the read-only data "my test string" goes in the read-only data section.
In my linker script, I set up a section called .rodata, which I thought was a common name for the read-only data section.
But I found out that gcc (version 3.2.2) was putting my read-only strings in as section called .rodata.str1.1
So when I boot up my kernel, it was saying that the .rodata section was empty, and it really was !

I would like to know if it is possible to force gcc to use my own section names ?
Tim

Re:Section names in GCC

Post by Tim »

No need. In your linker script:

Code: Select all

.rodata
{
    (.rodata*)
}
This will insert all sections whose names begin with .rodata into the .rodata section.

Edit: The numbered suffixes are a deliberate attempt by the compiler to put data in order. To enforce this order, try:

Code: Select all

.rodata
{
    *(SORT(.rodata$*))
}
Windows linkers rely on this behaviour (sorting of numbered sections) to generate import tables.
pini

Re:Section names in GCC

Post by pini »

This is exactly what I needed
Post Reply