[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug ld/32240] warning: relocation against `_Z5test2v' in read-only sect
From: |
nickc at redhat dot com |
Subject: |
[Bug ld/32240] warning: relocation against `_Z5test2v' in read-only section |
Date: |
Fri, 18 Oct 2024 14:01:15 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=32240
Nick Clifton <nickc at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nickc at redhat dot com
--- Comment #3 from Nick Clifton <nickc at redhat dot com> ---
Hi Frederico,
What is your target architecture ?
I suspect that this matters since the built-in linker script varies for
different target architectures, and when I tried running your test on my
machine everything worked. (My machine is an x86_64 and admittedly I was using
g++ 13.3.1 rather than 14.2, but I suspect that is the architecture and not the
g++ version that is making the difference).
The warning is an issue in that it means that an executable is being
generated where the loader is expected to modify a read-only section.
Something that normally should not happen at load time. Of course it is only a
warning and you are free to ignore it.
You may find that adding -Wl,-z,notext to the command line will silence the
warning.
Also, just to be clear, your linker script fragment:
SECTIONS
{
.rodata (READONLY) : {
KEEP(*(.rodata))
[...]
}
INSERT AFTER .rodata;
is going to end up creating *two* .rodata sections in the output. The first
one will contain all the .rodata.* sections (eg .rodata.str1.1 from your test
program) and the second one will contain all the .rodata sections (eg from
crtbegin.o).
And finally :-)
> Note that if I leave (READONLY) out, I get following warning
> /usr/bin/ld: warning: a.out has a LOAD segment with RWX permissions
> (out of curiosity, is it possible to remove only the X permission?
> I believe `READONLY` removes both W and X)
This happens because the tests section is being placed after the .text
section. The tests section has Read and Write permission whilst the .text
section has Read and Execute permission so the resulting segment to contain
both of them has Read, Write and Execute permissions. To solve this, try
placing the tests section after the .data section instead of the .text section.
Cheers
Nick
--
You are receiving this mail because:
You are on the CC list for the bug.