+ /* See if this region of memory lies inside a known file on disk.
+ If so, we can avoid copying its contents by clearing SEC_LOAD. */
+ struct objfile *objfile;
+ struct obj_section *objsec;
+
+ ALL_OBJSECTIONS (objfile, objsec)
+ {
+ bfd *abfd = objfile->obfd;
+ asection *asec = objsec->the_bfd_section;
+ bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
+ asec);
+ bfd_vma start = objsec->addr & -align;
+ bfd_vma end = (objsec->endaddr + align - 1) & -align;
+ /* Match if either the entire memory region lies inside the
+ section (i.e. a mapping covering some pages of a large
+ segment) or the entire section lies inside the memory region
+ (i.e. a mapping covering multiple small sections).
+
+ This BFD was synthesized from reading target memory,
+ we don't want to omit that. */
+ if (((vaddr >= start && vaddr + size <= end)
+ || (start >= vaddr && end <= vaddr + size))
+ && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
+ {
+ flags &= ~SEC_LOAD;
+ flags |= SEC_NEVER_LOAD;
+ goto keep; /* break out of two nested for loops */
+ }
+ }
+
+ keep: