void obj_som_init_stab_section (segT seg) { segT saved_seg = now_seg; segT space; subsegT saved_subseg = now_subseg; char *p, *file; unsigned int stroff; /* Make the space which will contain the debug subspaces. */ space = bfd_make_section_old_way (stdoutput, "$GDB_DEBUG$"); /* Set SOM specific attributes for the space. In particular we set the space "defined", "private", "sort_key", and "spnum" values. Due to a bug in pxdb (called by hpux linker), the sort keys of the various stabs spaces/subspaces need to be "small". We reserve range 72/73 which appear to work well. */ obj_set_section_attributes (space, 1, 1, 72, 2); bfd_set_section_alignment (stdoutput, space, 2); /* Set the containing space for both stab sections to be $GDB_DEBUG$ (just created above). Also set some attributes which BFD does not understand. In particular, access bits, sort keys, and load quadrant. */ obj_set_subsection_attributes (seg, space, 0x1f, 73, 0, 0, 0, 0); bfd_set_section_alignment (stdoutput, seg, 2); /* Make some space for the first special stab entry and zero the memory. It contains information about the length of this file's stab string and the like. Using it avoids the need to relocate the stab strings. The $GDB_STRINGS$ space will be created as a side effect of the call to get_stab_string_offset. */ p = frag_more (12); memset (p, 0, 12); as_where (&file, (unsigned int *) NULL); stroff = get_stab_string_offset (file, "$GDB_STRINGS$"); know (stroff == 1); md_number_to_chars (p, stroff, 4); seg_info (seg)->stabu.p = p; /* Set the containing space for both stab sections to be $GDB_DEBUG$ (just created above). Also set some attributes which BFD does not understand. In particular, access bits, sort keys, and load quadrant. */ seg = bfd_get_section_by_name (stdoutput, "$GDB_STRINGS$"); obj_set_subsection_attributes (seg, space, 0x1f, 72, 0, 0, 0, 0); bfd_set_section_alignment (stdoutput, seg, 2); subseg_set (saved_seg, saved_subseg); }
static bfd_boolean s390_elf_create_ifunc_sections (bfd *abfd, struct bfd_link_info *info) { flagword flags; asection *s; const struct elf_backend_data *bed = get_elf_backend_data (abfd); struct elf_link_hash_table *htab = elf_hash_table (info); if (htab->iplt != NULL) return TRUE; flags = bed->dynamic_sec_flags; if (bfd_link_pic (info)) { s = bfd_make_section_with_flags (abfd, ".rela.ifunc", flags | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) return FALSE; htab->irelifunc = s; } /* Create .iplt, .rel[a].iplt, and .igot.plt. */ s = bfd_make_section_with_flags (abfd, ".iplt", flags | SEC_CODE | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) return FALSE; htab->iplt = s; s = bfd_make_section_with_flags (abfd, ".rela.iplt", flags | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) return FALSE; htab->irelplt = s; s = bfd_make_section_with_flags (abfd, ".igot.plt", flags); if (s == NULL || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) return FALSE; htab->igotplt = s; return TRUE; }
static void write_gcore_file_1 (bfd *obfd) { struct cleanup *cleanup; void *note_data = NULL; int note_size = 0; asection *note_sec = NULL; /* An external target method must build the notes section. */ /* FIXME: uweigand/2011-10-06: All architectures that support core file generation should be converted to gdbarch_make_corefile_notes; at that point, the target vector method can be removed. */ if (!gdbarch_make_corefile_notes_p (target_gdbarch ())) note_data = target_make_corefile_notes (obfd, ¬e_size); else note_data = gdbarch_make_corefile_notes (target_gdbarch (), obfd, ¬e_size); cleanup = make_cleanup (xfree, note_data); if (note_data == NULL || note_size == 0) error (_("Target does not support core file generation.")); /* Create the note section. */ note_sec = bfd_make_section_anyway_with_flags (obfd, "note0", SEC_HAS_CONTENTS | SEC_READONLY | SEC_ALLOC); if (note_sec == NULL) error (_("Failed to create 'note' section for corefile: %s"), bfd_errmsg (bfd_get_error ())); bfd_set_section_vma (obfd, note_sec, 0); bfd_set_section_alignment (obfd, note_sec, 0); bfd_set_section_size (obfd, note_sec, note_size); /* Now create the memory/load sections. */ if (gcore_memory_sections (obfd) == 0) error (_("gcore: failed to get corefile memory sections from target.")); /* Write out the contents of the note section. */ if (!bfd_set_section_contents (obfd, note_sec, note_data, 0, note_size)) warning (_("writing note section (%s)"), bfd_errmsg (bfd_get_error ())); do_cleanups (cleanup); }
/* FIXME: add comment: */ static void dump_bfd_file(const char *filename, const char *mode, const char *target, CORE_ADDR vaddr, const bfd_byte *buf, int len) { bfd *obfd; asection *osection; obfd = bfd_openw_with_cleanup(filename, target, mode); osection = bfd_make_section_anyway(obfd, ".newsec"); bfd_set_section_size(obfd, osection, len); if (bfd_set_section_vma(obfd, osection, vaddr)) { ; } if (bfd_set_section_alignment(obfd, osection, 0)) { ; } bfd_set_section_flags(obfd, osection, (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD)); osection->entsize = 0; bfd_set_section_contents(obfd, osection, buf, 0, len); }
bfd_boolean _bfd_elf_convert_gnu_properties (bfd *ibfd, asection *isec, bfd *obfd, bfd_byte **ptr, bfd_size_type *ptr_size) { unsigned int size; bfd_byte *contents; unsigned int align_shift; const struct elf_backend_data *bed; elf_property_list *list = elf_properties (ibfd); bed = get_elf_backend_data (obfd); align_shift = bed->s->elfclass == ELFCLASS64 ? 3 : 2; /* Get the output .note.gnu.property section size. */ size = bfd_get_section_size (isec->output_section); /* Update the output .note.gnu.property section alignment. */ bfd_set_section_alignment (obfd, isec->output_section, align_shift); if (size > bfd_get_section_size (isec)) { contents = (bfd_byte *) bfd_malloc (size); free (*ptr); *ptr = contents; } else contents = *ptr; *ptr_size = size; /* Generate the output .note.gnu.property section. */ elf_write_gnu_properties (ibfd, contents, list, size, 1 << align_shift); return TRUE; }
bfd_boolean _bfd_cgc_create_ifunc_sections (bfd *abfd, struct bfd_link_info *info) { flagword flags, pltflags; asection *s; const struct cgc_backend_data *bed = get_cgc_backend_data (abfd); struct cgc_link_hash_table *htab = cgc_hash_table (info); if (htab->irelifunc != NULL || htab->iplt != NULL) return TRUE; flags = bed->dynamic_sec_flags; pltflags = flags; if (bed->plt_not_loaded) /* We do not clear SEC_ALLOC here because we still want the OS to allocate space for the section; it's just that there's nothing to read in from the object file. */ pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS); else pltflags |= SEC_ALLOC | SEC_CODE | SEC_LOAD; if (bed->plt_readonly) pltflags |= SEC_READONLY; if (info->shared) { /* We need to create .rel[a].ifunc for shared objects. */ const char *rel_sec = (bed->rela_plts_and_copies_p ? ".rela.ifunc" : ".rel.ifunc"); s = bfd_make_section_with_flags (abfd, rel_sec, flags | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) return FALSE; htab->irelifunc = s; } else { /* We need to create .iplt, .rel[a].iplt, .igot and .igot.plt for static executables. */ s = bfd_make_section_with_flags (abfd, ".iplt", pltflags); if (s == NULL || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) return FALSE; htab->iplt = s; s = bfd_make_section_with_flags (abfd, (bed->rela_plts_and_copies_p ? ".rela.iplt" : ".rel.iplt"), flags | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) return FALSE; htab->irelplt = s; /* We don't need the .igot section if we have the .igot.plt section. */ if (bed->want_got_plt) s = bfd_make_section_with_flags (abfd, ".igot.plt", flags); else s = bfd_make_section_with_flags (abfd, ".igot", flags); if (s == NULL || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) return FALSE; htab->igotplt = s; } return TRUE; }
static void mips_elf32_after_open() { /* Call the standard elf routine. */ gldelf32ltsmip_after_open (); #ifdef SUPPORT_EMBEDDED_RELOCS if (command_line.embedded_relocs && (! link_info.relocateable)) { bfd *abfd; /* In the embedded relocs mode we create a .rel.sdata section for each input file with a .sdata section which has has relocations. The BFD backend will fill in these sections with magic numbers which can be used to relocate the data section at run time. */ for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) { asection *datasec; /* As first-order business, make sure that each input BFD is ELF. We need to call a special BFD backend function to generate the embedded relocs, and we have that function only for ELF */ if (bfd_get_flavour (abfd) != bfd_target_elf_flavour) einfo ("%F%B: all input objects must be ELF for --embedded-relocs\n"); if (bfd_get_arch_size (abfd) != 32) einfo ("%F%B: all input objects must be 32-bit ELF for --embedded-relocs\n"); datasec = bfd_get_section_by_name (abfd, ".sdata"); /* Note that we assume that the reloc_count field has already been set up. We could call bfd_get_reloc_upper_bound, but that returns the size of a memory buffer rather than a reloc count. We do not want to call bfd_canonicalize_reloc, because although it would always work it would force us to read in the relocs into BFD canonical form, which would waste a significant amount of time and memory. */ if (datasec != NULL && datasec->reloc_count > 0) { asection *relsec; relsec = bfd_make_section (abfd, ".rel.sdata"); if (relsec == NULL || ! bfd_set_section_flags (abfd, relsec, (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY)) || ! bfd_set_section_alignment (abfd, relsec, (32 == 32) ? 2 : 3) || ! bfd_set_section_size (abfd, relsec, datasec->reloc_count * ((32 / 8) + 8))) einfo ("%F%B: cannot create .rel.sdata section: %E\n"); } /* Double check that all other data sections have no relocs, as is required for embedded PIC code. */ bfd_map_over_sections (abfd, mips_elf32_check_sections, (PTR) datasec); } } #endif /* SUPPORT_EMBEDDED_RELOCS */ }
static void gcore_command (char *args, int from_tty) { struct cleanup *old_chain; char *corefilename, corefilename_buffer[40]; asection *note_sec = NULL; bfd *obfd; void *note_data = NULL; int note_size = 0; /* No use generating a corefile without a target process. */ if (!target_has_execution) noprocess (); if (args && *args) corefilename = args; else { /* Default corefile name is "core.PID". */ sprintf (corefilename_buffer, "core.%d", PIDGET (inferior_ptid)); corefilename = corefilename_buffer; } if (info_verbose) fprintf_filtered (gdb_stdout, "Opening corefile '%s' for output.\n", corefilename); /* Open the output file. */ obfd = bfd_openw (corefilename, default_gcore_target ()); if (!obfd) error (_("Failed to open '%s' for output."), corefilename); /* Need a cleanup that will close the file (FIXME: delete it?). */ old_chain = make_cleanup_bfd_close (obfd); bfd_set_format (obfd, bfd_core); bfd_set_arch_mach (obfd, default_gcore_arch (), default_gcore_mach ()); /* An external target method must build the notes section. */ note_data = target_make_corefile_notes (obfd, ¬e_size); /* Create the note section. */ if (note_data != NULL && note_size != 0) { note_sec = bfd_make_section_anyway_with_flags (obfd, "note0", SEC_HAS_CONTENTS | SEC_READONLY | SEC_ALLOC); if (note_sec == NULL) error (_("Failed to create 'note' section for corefile: %s"), bfd_errmsg (bfd_get_error ())); bfd_set_section_vma (obfd, note_sec, 0); bfd_set_section_alignment (obfd, note_sec, 0); bfd_set_section_size (obfd, note_sec, note_size); } /* Now create the memory/load sections. */ if (gcore_memory_sections (obfd) == 0) error (_("gcore: failed to get corefile memory sections from target.")); /* Write out the contents of the note section. */ if (note_data != NULL && note_size != 0) { if (!bfd_set_section_contents (obfd, note_sec, note_data, 0, note_size)) warning (_("writing note section (%s)"), bfd_errmsg (bfd_get_error ())); } /* Succeeded. */ fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename); /* Clean-ups will close the output file and free malloc memory. */ do_cleanups (old_chain); return; }
static void setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg) { bfd *obfd = obfdarg; struct section_list *p; sec_ptr osection; bfd_size_type size; bfd_vma vma; bfd_vma lma; const char *err; const char * name; name = bfd_section_name (ibfd, isection); osection = bfd_make_section_anyway (obfd, name); if (osection == NULL) { perror("setup_section: making"); } size = bfd_section_size (ibfd, isection); if (! bfd_set_section_size (obfd, osection, size)) { perror("setup_section: size"); } vma = bfd_section_vma (ibfd, isection); if (! bfd_set_section_vma (obfd, osection, vma)) { perror("setup_section: vma"); } lma = isection->lma; osection->lma = lma; /* FIXME: This is probably not enough. If we change the LMA we may have to recompute the header for the file as well. */ if (!bfd_set_section_alignment (obfd, osection, bfd_section_alignment (ibfd, isection))) { perror("setup_section: alignment"); } if (!bfd_set_section_flags (obfd, osection, bfd_get_section_flags(ibfd, isection))) { perror("setup_section: flags"); } /* Copy merge entity size. */ osection->entsize = isection->entsize; /* This used to be mangle_section; we do here to avoid using bfd_get_section_by_name since some formats allow multiple sections with the same name. */ isection->output_section = osection; isection->output_offset = 0; /* Allow the BFD backend to copy any private data it understands from the input section to the output section. */ if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection)) { perror("setup_section: private data"); } /* All went well. */ return; perror("setup_section: %s: section `%s': error in %s: %s"), bfd_get_filename (ibfd), bfd_section_name (ibfd, isection), err, bfd_errmsg (bfd_get_error ()); }