Compute this while parsing the program headers in parse_rtld_phdr().
Obtained from: CheriBSD
Sponsored by: AFRL, DARPA
Differential D52033
rtld: Compute obj->maxsize for obj_rtld jhb on Aug 19 2025, 9:09 PM. Authored by Tags None Referenced Files
Details
Compute this while parsing the program headers in parse_rtld_phdr(). Obtained from: CheriBSD
Diff Detail
Event TimelineComment Actions It is slightly weird because you do assume that linker orders the PT_LOAD segments by vaddr, but you use it only for vaddrbase. For mapsize you use MAX() instead. Comment Actions Hmm, it is true that for obj_main we do assume they are sorted, but in map_object we don't assume sorting: obj_main: case PT_LOAD: if (nsegs == 0) { /* First load segment */ obj->vaddrbase = rtld_trunc_page(ph->p_vaddr); obj->mapbase = obj->vaddrbase + obj->relocbase; } else { /* Last load segment */ obj->mapsize = rtld_round_page( ph->p_vaddr + ph->p_memsz) - obj->vaddrbase; } nsegs++; break; map_object: case PT_LOAD: segs[++nsegs] = phdr; if ((segs[nsegs]->p_align & (page_size - 1)) != 0) { _rtld_error( "%s: PT_LOAD segment %d not page-aligned", path, nsegs); goto error; } if ((segs[nsegs]->p_flags & PF_X) == PF_X) { text_end = MAX(text_end, rtld_round_page(segs[nsegs]->p_vaddr + segs[nsegs]->p_memsz)); } break; Though I guess we do kind of assume sorting in map_object as well: base_vaddr = rtld_trunc_page(segs[0]->p_vaddr); base_vlimit = rtld_round_page(segs[nsegs]->p_vaddr + segs[nsegs]->p_memsz); I wonder if we could remove the MAX from the PF_X check in map_object then. I'm fine with removing the sorting to match obj_main if you prefer that. Comment Actions The PF_X and text_end bit of code would also be easier to read if we just used phdr directly instead of segs[nsegs]. Comment Actions I think it is best to remove the MAX() from both places. We might add a check that segments are ordered. If you prefer not to touch map_object, I can do this after your commit, and also will add the check. |