When I compile
__attribute__((section(".text"))) const int x = 42;
int main(){ return x; }
with gcc (works with tinycc and clang), I get
Warning: ignoring changed section attributes for .text
.
What is the cause of the warning and how can it be eliminated while still keeping the (always readonly) data in .text
?
Apparently:
__attribute__((section(".text#"))) const int x = 42;
Ref: https://gcc.gnu.org/ml/gcc-help/2010-09/msg00088.html where the answerer explains:
__attribute__ ((section(".text")))
will make gcc emits,"aw",@progbits
after the.text
to alter the section attributes. If you use:__attribute__ ((section(".text#")))
(notice the extra'#'
) this suffix will be commented in the assembly and the warning will disappear
In that case the variable concerned was not const
, so it was especially ill-advised (as stated by another responder) to the same question. In your case it is a const
, so the access is "a"
rather than "aw"
- still probably ill-advised however.
Apparently gcc emits a .section .text,"a",@progbits
directive instead of just .section .text
. I don't see any way to avoid it. However the default linker script usually merges all sections named .text.*
so you can do something like __attribute__((section(".text.consts")))
and in the final binary it will be in the .text
section.
@Clifford found a hackish workaround which involves putting a #
after the section name so that the assembler considers the rest of the line a comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With