I would like to grant full permissions (read, write, and execute) to all memory pages in an ELF binary. Ideally, I'd like to be able to do this as a transformation on a binary or object file, in the same way that symbols can be changed with objcopy. I have not yet found a good way to do this. I would also be okay with a solution that involves running code at startup that calls mprotect on every page with the flags PROT_READ | PROT_WRITE | PROT_EXEC. I've tried this briefly, but I haven't found a good way to know which pages are mapped, and therefore which pages need to be mprotected.
It isn't required that dynamically allocated pages have all permissions, only the pages mapped at program startup.
                        
The following script implements Employed Russian's answer in code:
p_typeof theRELROsegment toPT_NULLFlagsonLOADsegments toPF_X|PF_W|PF_R.It depends on
pyelftoolsforpython3, which can be installed withpip3 install pyelftools.