Skip to content

options/rtld: Implement relocations in text sections (DT/DF_TEXTREL)#1448

Open
oberrow wants to merge 6 commits intomanagarm:masterfrom
oberrow:master
Open

options/rtld: Implement relocations in text sections (DT/DF_TEXTREL)#1448
oberrow wants to merge 6 commits intomanagarm:masterfrom
oberrow:master

Conversation

@oberrow
Copy link
Contributor

@oberrow oberrow commented Sep 8, 2025

No description provided.

Copy link
Member

@Dennisbonke Dennisbonke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small issues I spotted in 2 seconds, an in depth review is required before this can be merged.

@oberrow oberrow requested a review from Dennisbonke September 8, 2025 21:37
@avdgrinten
Copy link
Member

Why is this needed? On which architecture / target do you need .text relocations?

@oberrow
Copy link
Contributor Author

oberrow commented Sep 16, 2025

Why is this needed? On which architecture / target do you need .text relocations?


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.

size_t phdrEntrySize = 0;
size_t phdrCount = 0;

frg::vector<void*, MemoryAllocator> exec_phdrs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never map as RWX. Instead, map as RW first and then change that to RX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants