lld rounds up p_memsz(PT_GNU_RELRO) to satisfy common-page-size. If the page
size is smaller than common-page-size, rounding up relro_size may incorrectly
make some RW pages read-only.
Details
- Reviewers
markj emaste fbsd-phab_maskray.me - Commits
- rGc9f833abf1d7: rtld: Round down relro_size
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
I do not understand this patch.
If linker specified that the end of relro is in the middle of some page, this means that there are relocations targeting that page. If we truncate relro_size, then relocation processing would operate on ro mapping and get SIGBUS/SIGSEGV.
Linker should not set relro_size that way. BTW, does bfd ld or gold produce something similar?
For PT_GNU_RELRO, [p_vaddr,p_vaddr+p_memsz) specifies the address range which can be read-only. ld.so can shrink the range (rounddown), but not extend the range (roundup).
Extending the range can actually potentially cause SIGSEGV.
Linker should not set relro_size that way. BTW, does bfd ld or gold produce something similar?
GNU ld, gold, and ld.lld ensures p_vaddr+p_memsz is a multiple of common-page-size.
While max-page-size >= system the page size, common-page-size can be smaller than the system page size.
ld.lld uses a different (IMO better) layout (https://reviews.llvm.org/D58892) but the difference does not matter for this patch.
@fbsd-phab_maskray.me Could you post the error message somewhere? In general, cross-builds from linux+macOS should work, and I try to fix them after any breaking change.
The new behavior matches Linux glibc/musl.
I don't have a error message. If you want to test a breaking case for the old behavior, perhaps use -z common-page=1024 and then set the system page size larger than common-page-size.
I believe mprotect will have an incorrect length.
Sorry, I meant the error from your attempt at building FreeBSD on non-FreeBSD. I didn't mean anything related to this patch.