Clément Péron
2014-10-01 09:30:44 UTC
Hi,
In the manual, it says that : -fdata-sections
-ffunction-sections-fdata-sections Place each function or data item
into its own section in the output file if the target supports
arbitrary sections
I try to use it but the result is not the one as expected.
gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
And i compile with these arguments :
gcc -c -o hello.o -ffunction-sections -fdata-sections hello.c
I can see with objdump that .text sections are good.
I have different .text.__function__
But i have only one .rodata instead of different .rodata.__function__
Thanks for your help,
Clement
/*------------ hello.c ---------------*/
#include <stdio.h>
#include <stdlib.h>
void used_function();
int main(){
printf("On-the fly string"); //goto .rodata
used_function();
return 0;
}
void unused_function(){
const char var9[] = "String const";
char var3[] = "String not const"; //goto .text.unused_function and
is removed by the linker
printf("I would like to optimize this string !"); //goto
.rodata.str1.8 and isn't removed by the linker
printf("%s %s", var9, var3);
}
void used_function(){
printf("A string used here with the same size 2"); //goto .rodata.str1.8
}
In the manual, it says that : -fdata-sections
-ffunction-sections-fdata-sections Place each function or data item
into its own section in the output file if the target supports
arbitrary sections
I try to use it but the result is not the one as expected.
gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
And i compile with these arguments :
gcc -c -o hello.o -ffunction-sections -fdata-sections hello.c
I can see with objdump that .text sections are good.
I have different .text.__function__
But i have only one .rodata instead of different .rodata.__function__
Thanks for your help,
Clement
/*------------ hello.c ---------------*/
#include <stdio.h>
#include <stdlib.h>
void used_function();
int main(){
printf("On-the fly string"); //goto .rodata
used_function();
return 0;
}
void unused_function(){
const char var9[] = "String const";
char var3[] = "String not const"; //goto .text.unused_function and
is removed by the linker
printf("I would like to optimize this string !"); //goto
.rodata.str1.8 and isn't removed by the linker
printf("%s %s", var9, var3);
}
void used_function(){
printf("A string used here with the same size 2"); //goto .rodata.str1.8
}