-
Notifications
You must be signed in to change notification settings - Fork 109
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
build_scripts/layout.ld: add a relro section #526
Conversation
I want to make sure I'm understanding this correctly. When you build |
mbetls creates the following sections (and some more of the same type), this is from one of the mbedtls libraries:
When linking the static library to our libtock-rs app (without the changes in this PR), I see the following in the elf output :
This is built for the nrf52840, so With the changes in the PR we see the following in the elf:
and we can compile and run the app without the issue from the prior case. So my thinking was that adding a |
Okay, sounds reasonable to me. |
This accomadates situations for example: where global variables are initialized to a value that requires relocation. Things like globally stored function pointers, or storing the address of another global variable. Such items require runtime initialization in the form of dynamic relocation, and cannot be placed in a RO segment. However, as it is declared to be a constant (not modified by the program), the dynamic linker can mark it as RO after the dynamic relocation as been applied [1]. When GCC sees a variable which is constant but requires dynamic relocation, it puts it into a section named `.data.rel.ro`, further, a variable that requires dynamic relocation against a local symbol is put into a `.data.rel.ro.local` section, this helps group such variables together so that the dynamic linker may apply the relocations, which will always be RELATIVE locations [1]. [1] https://www.airs.com/blog/archives/189 Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
483ea13
to
c6abe2a
Compare
Context: I encountered this issue when linking
mbedtls
to a libtock-rs app.This accommodates situations for example: where global variables are initialized to a value that requires relocation. Things like globally stored function pointers, or storing the address of another global variable. Such items require runtime initialization in the form of dynamic relocation, and cannot be placed in a RO segment. However, as it is declared to be a constant (not modified by the program), the dynamic linker can mark it as RO after the dynamic relocation as been applied [1].
When GCC sees a variable which is constant but requires dynamic relocation, it puts it into a section named
.data.rel.ro
, further, a variable that requires dynamic relocation against a local symbol is put into a.data.rel.ro.local
section, this helps group such variables together so that the dynamic linker may apply the relocations, which will always be RELATIVE locations [1].[1] https://www.airs.com/blog/archives/189