valueT md_section_align (segT segment, valueT size) { int align = bfd_get_section_alignment (stdoutput, segment); return ((size + (1 << align) - 1) & -(1 << align)); }
static int gcore_create_callback (CORE_ADDR vaddr, unsigned long size, int read, int write, int exec, void *data) { bfd *obfd = data; asection *osec; flagword flags = SEC_ALLOC | SEC_HAS_CONTENTS | SEC_LOAD; /* If the memory segment has no permissions set, ignore it, otherwise when we later try to access it for read/write, we'll get an error or jam the kernel. */ if (read == 0 && write == 0 && exec == 0) { if (info_verbose) { fprintf_filtered (gdb_stdout, "Ignore segment, %s bytes at 0x%s\n", paddr_d (size), paddr_nz (vaddr)); } return 0; } if (write == 0) { /* 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: flags |= SEC_READONLY; }
static void setup_sections (bfd *abfd, asection *sect, void *data_voidp) { struct setup_sections_data *data = data_voidp; CORE_ADDR alignment; unsigned prot; if (sect != NULL) { /* It is required by later bfd_get_relocated_section_contents. */ if (sect->output_section == NULL) sect->output_section = sect; if ((bfd_get_section_flags (abfd, sect) & SEC_ALLOC) == 0) return; /* Make the memory always readable. */ prot = GDB_MMAP_PROT_READ; if ((bfd_get_section_flags (abfd, sect) & SEC_READONLY) == 0) prot |= GDB_MMAP_PROT_WRITE; if ((bfd_get_section_flags (abfd, sect) & SEC_CODE) != 0) prot |= GDB_MMAP_PROT_EXEC; if (compile_debug) fprintf_unfiltered (gdb_stdlog, "module \"%s\" section \"%s\" size %s prot %u\n", bfd_get_filename (abfd), bfd_get_section_name (abfd, sect), paddress (target_gdbarch (), bfd_get_section_size (sect)), prot); } else prot = -1; if (sect == NULL || (data->last_prot != prot && bfd_get_section_size (sect) != 0)) { CORE_ADDR addr; asection *sect_iter; if (data->last_size != 0) { addr = gdbarch_infcall_mmap (target_gdbarch (), data->last_size, data->last_prot); munmap_list_add (data->munmap_list_headp, addr, data->last_size); if (compile_debug) fprintf_unfiltered (gdb_stdlog, "allocated %s bytes at %s prot %u\n", paddress (target_gdbarch (), data->last_size), paddress (target_gdbarch (), addr), data->last_prot); } else addr = 0; if ((addr & (data->last_max_alignment - 1)) != 0) error (_("Inferior compiled module address %s " "is not aligned to BFD required %s."), paddress (target_gdbarch (), addr), paddress (target_gdbarch (), data->last_max_alignment)); for (sect_iter = data->last_section_first; sect_iter != sect; sect_iter = sect_iter->next) if ((bfd_get_section_flags (abfd, sect_iter) & SEC_ALLOC) != 0) bfd_set_section_vma (abfd, sect_iter, addr + bfd_get_section_vma (abfd, sect_iter)); data->last_size = 0; data->last_section_first = sect; data->last_prot = prot; data->last_max_alignment = 1; } if (sect == NULL) return; alignment = ((CORE_ADDR) 1) << bfd_get_section_alignment (abfd, sect); data->last_max_alignment = max (data->last_max_alignment, alignment); data->last_size = (data->last_size + alignment - 1) & -alignment; bfd_set_section_vma (abfd, sect, data->last_size); data->last_size += bfd_get_section_size (sect); data->last_size = (data->last_size + alignment - 1) & -alignment; }