Page 1 of 1

Section names in GCC

Posted: Sun Aug 03, 2003 2:50 pm
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 ?

Re:Section names in GCC

Posted: Sun Aug 03, 2003 3:58 pm
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.

Re:Section names in GCC

Posted: Mon Aug 04, 2003 2:52 am
by pini
This is exactly what I needed