-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
read_only
define not working as intended with Clang
#369
Comments
There is simpler alternative that does not rely on compiler custom attributes or inline assembly tricks.
const globals will be placed in read-only section automatically. So:
|
I had assumed that
There are also certain constructs where one may want something to be read-only without being If the usage of |
Right, it does not guarantee it. But all compilers raddbg targets does support that by default. My assumption is that read_only was like that only because originally code was C++, and in C++ |
Thought I had tested |
The define here:
raddebugger/src/base/base_core.h
Line 27 in edfbcb9
Does not work as intended. It currently poisons the
.rodata
section and makes it both readable and writable. I tested this with Clang 18.1.3 both by running a simple test of writing to aread_only
variable without segfaulting and by checking the section attributes withobjdump -h
.The behavior between GCC and Clang seem to be the same in terms of the generated assembly. They both insert a
.section section_name, "aw", @progbits
directive before the memory initialization. It's just that GCC warns you that this is modifying the.rodata
section attributes while Clang issues no such error.Unfortunately, I don't believe there's any way to define a variable as part of a read-only section with Clang, as
__attribute__((section("section_name")))
will always give the section"aw"
attributes, which will always make the section in the final ELF image writable.There's a hack-y workaround for this with GCC, described in this StackOverflow answer. To get this to work with modern GCC you do:
Which uses the correct attributes and comment delimiter. This works in GCC because it doesn't sanitize the section name, so we can inject our own section attributes and then comment out the
"aw", @progbits
that it usually inserts. Clang, however, does sanitize the section name, so there's no way to comment out the unwanted section attributes.I can think of two ways to fix this:
__attribute__((section("section_name")))
attribute and add a post-compilation script or program that reads the ELF header and patches the section to read-only.There may be a better way that I've missed. Only fiddled with this for a little while.
The text was updated successfully, but these errors were encountered: