https://sourceware.org/bugzilla/show_bug.cgi?id=32240
Bug ID: 32240
Summary: warning: relocation against `_Z5test2v' in read-only
section
Product: binutils
Version: 2.43.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: federico.kircheis at gmail dot com
Target Milestone: ---
Hello, I'm curently getting the warning
~~~~
warning: relocation against `_Z5test2v' in read-only section
~~~~
but I find no way how to discard it (I believe it is a non-issue) or fix it (in
case it is an issue).
My code looks like
cpp
~~~~
#include <cstdio>
#include <cstdint>
#include <span>
using test_signature = void();
#define CONCAT_IMPL(x, y) x##y
#define CONCAT(x, y) CONCAT_IMPL(x, y)
#define TEST(name) \
void name();\
[[gnu::used]] constexpr auto CONCAT(helper, __LINE__)
[[gnu::section(".tmptests")]] = &name; \
void name()
TEST(test1){std::puts("test1");}
TEST(test2){std::puts("test2");}
std::span<test_signature*> get_tests() noexcept {
extern const test_signature* tests_begin[];
extern const test_signature* tests_end[];
const auto tests_size = ((uintptr_t)(tests_end) -
(uintptr_t)(tests_begin))/sizeof(test_signature*);
test_signature** begin = tests_begin;
asm("":"+r"(begin));
return std::span<test_signature*>(begin, begin + tests_size);
}
int main(){
auto funcs = get_tests();
for(const auto& v : funcs){
v();
}
}
~~~~
the linker script I'm using looks like
~~~~
linkerscript.ld
SECTIONS
{
.rodata (READONLY) : {
KEEP(*(.rodata))
PROVIDE(tests_begin = .);
KEEP(*(.tmptests))
PROVIDE(tests_end = .);
}
}
INSERT AFTER .rodata;
~~~~
And the command line using for compiling
~~~~
> g++ --std=c++23 -Wl,-Tlinkerscript.ld -O3 main.cpp
/usr/bin/ld: /tmp/cc1SVaUI.o: warning: relocation against `_Z5test2v' in
read-only section `.tmptests'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
~~~~
A variation I've tried (with no difference, same warning)
~~~~
SECTIONS
{
tests (READONLY) : {
PROVIDE(tests_begin = .);
KEEP(*(.tmptests))
PROVIDE(tests_end = .);
}
}
INSERT AFTER .text;
~~~~
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)
--
You are receiving this mail because:
You are on the CC list for the bug.