options/rtld: Implement relocations in text sections (DT/DF_TEXTREL)#1448
Open
oberrow wants to merge 6 commits intomanagarm:masterfrom
Open
options/rtld: Implement relocations in text sections (DT/DF_TEXTREL)#1448oberrow wants to merge 6 commits intomanagarm:masterfrom
oberrow wants to merge 6 commits intomanagarm:masterfrom
Conversation
Dennisbonke
requested changes
Sep 8, 2025
Member
Dennisbonke
left a comment
There was a problem hiding this comment.
Some small issues I spotted in 2 seconds, an in depth review is required before this can be merged.
Member
|
Why is this needed? On which architecture / target do you need |
Contributor
Author
I have found that my m68k toolchain generates text relocations for PIE executables and for shared libraries, which was a problem for my m68k port. |
avdgrinten
reviewed
Sep 16, 2025
| size_t phdrEntrySize = 0; | ||
| size_t phdrCount = 0; | ||
|
|
||
| frg::vector<void*, MemoryAllocator> exec_phdrs; |
Member
There was a problem hiding this comment.
We already have phdrPointer etc. which can be used to iterate over the PHDRs.
Comment on lines
+905
to
+915
| if(object->haveTextRel) { | ||
| for(auto &phdr_ptr : object->exec_phdrs) { | ||
| elf_phdr* phdr = (elf_phdr *)phdr_ptr; | ||
| void* addr = (void *)(phdr->p_vaddr + (uintptr_t)object->baseAddress); | ||
| int prot = PROT_WRITE | PROT_READ | PROT_EXEC; | ||
| if (mlibc::sys_vm_protect) | ||
| mlibc::sys_vm_protect(addr, phdr->p_memsz, prot); | ||
| else | ||
| __ensure(!"sys_vm_protect required when DF_TEXTREL/DT_TEXTREL is present"); | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
This could be done in linkObjects() to be symmetrical with the code path that removes PROT_WRITE again.
| for(auto &phdr_ptr : object->exec_phdrs) { | ||
| elf_phdr* phdr = (elf_phdr *)phdr_ptr; | ||
| void* addr = (void *)(phdr->p_vaddr + (uintptr_t)object->baseAddress); | ||
| int prot = PROT_WRITE | PROT_READ | PROT_EXEC; |
Member
There was a problem hiding this comment.
We should never map as RWX. Instead, map as RW first and then change that to RX.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.