This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Problem for using __attribute__((section(".text")))
- From: Ian Lance Taylor <iant at google dot com>
- To: Heyu Zhu <zhu dot heyu at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 10 Sep 2010 08:34:30 -0700
- Subject: Re: Problem for using __attribute__((section(".text")))
- References: <AANLkTin+nJ37czksx-2qitdoZw0xtOyyiSVqJpz4+sOJ@mail.gmail.com>
Heyu Zhu <zhu.heyu@gmail.com> writes:
> File boot.c is like below:
>
> int val[] __attribute__ ((section(".text"))) = {1, 2, 3, 4, 5 ,6};
> int getval(int i) {
> return val[i];
> }
>
> Then i compile it use gcc-4.2.4 and binutils2.20
>
> arm-elf-gcc boot.c -c -o boot.o
>
> It gives a warning:
>
> /tmp/ccIlHjum.s: Assembler message:
> /tmp/ccIlHjum.s:4: Warning: ignoring changed section attributes for .text
>
> What's wrong? What should i do to remove the warning?
You are putting a writable variable in .text, so gcc is trying to make
.text be writable. That fails, because .text was already implicitly
declared as read-only.
When using __attribute__ ((section)) you should normally stick to your
own sections, rather than trying to use existing ones.
You will in any case get a similar effect if you write
const int val[] = ...
Ian