This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Fwd: Compiling with -fdata-sections doesn't put the constant in the section expected
- From: ClÃment PÃron <peron dot clem at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 1 Oct 2014 11:30:44 +0200
- Subject: Fwd: Compiling with -fdata-sections doesn't put the constant in the section expected
- Authentication-results: sourceware.org; auth=none
- References: <CAJiuCcfJHXCRAnj4v7fhoAcwWAyWLN2z_9+Seygqx05iJUQCtw at mail dot gmail dot com> <CAJiuCceKWtpiJdySnft_K_9FkxXvBKiXt9U2EYmSnWZHr26nyA at mail dot gmail dot com>
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
}