diff options
author | Ian Lance Taylor <ian@airs.com> | 1994-05-20 16:04:59 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 1994-05-20 16:04:59 +0000 |
commit | 497c543457bbdabe61c03733d2a44167bf354dae (patch) | |
tree | 4c2207e298b66fa12ea3ecd088a3e5b2c6d6b640 /bfd/elf.c | |
parent | 09985c960d737684e85d60dcc5796e2f1e8b6b45 (diff) | |
download | gdb-497c543457bbdabe61c03733d2a44167bf354dae.zip gdb-497c543457bbdabe61c03733d2a44167bf354dae.tar.gz gdb-497c543457bbdabe61c03733d2a44167bf354dae.tar.bz2 |
* elf.c (_bfd_elf_make_section_from_shdr): New function, based on
code repeated three times in bfd_section_from_shdr in elfcode.h.
* libelf.h (_bfd_elf_make_section_from_shdr): Declare.
* elfcode.h (bfd_section_from_shdr): Use new function
_bfd_elf_make_section_from_shdr to create BFD sections. If a
reloc section does not use the main symbol table, or it is part of
the process image, treat it as a normal section, not relocs.
* elf32-mips.c (mips_elf_section_from_shdr): Use new function
_bfd_elf_make_section_from_shdr.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -154,6 +154,68 @@ elf_string_from_elf_section (abfd, shindex, strindex) return ((char *) hdr->rawdata) + strindex; } +/* Make a BFD section from an ELF section. We store a pointer to the + BFD section in the rawdata field of the header. */ + +boolean +_bfd_elf_make_section_from_shdr (abfd, hdr, name) + bfd *abfd; + Elf_Internal_Shdr *hdr; + const char *name; +{ + asection *newsect; + flagword flags; + + if (hdr->rawdata != NULL) + { + BFD_ASSERT (strcmp (name, ((asection *) hdr->rawdata)->name) == 0); + return true; + } + + newsect = bfd_make_section_anyway (abfd, name); + if (newsect == NULL) + return false; + + newsect->filepos = hdr->sh_offset; + + if (! bfd_set_section_vma (abfd, newsect, hdr->sh_addr) + || ! bfd_set_section_size (abfd, newsect, hdr->sh_size) + || ! bfd_set_section_alignment (abfd, newsect, + bfd_log2 (hdr->sh_addralign))) + return false; + + flags = SEC_NO_FLAGS; + if (hdr->sh_type != SHT_NOBITS) + flags |= SEC_HAS_CONTENTS; + if ((hdr->sh_flags & SHF_ALLOC) != 0) + { + flags |= SEC_ALLOC; + if (hdr->sh_type != SHT_NOBITS) + flags |= SEC_LOAD; + } + if ((hdr->sh_flags & SHF_WRITE) == 0) + flags |= SEC_READONLY; + if ((hdr->sh_flags & SHF_EXECINSTR) != 0) + flags |= SEC_CODE; + else if ((flags & SEC_ALLOC) != 0) + flags |= SEC_DATA; + + /* The debugging sections appear to be recognized only by name, not + any sort of flag. */ + if (strncmp (name, ".debug", sizeof ".debug" - 1) == 0 + || strncmp (name, ".line", sizeof ".line" - 1) == 0 + || strncmp (name, ".stab", sizeof ".stab" - 1) == 0) + flags |= SEC_DEBUGGING; + + if (! bfd_set_section_flags (abfd, newsect, flags)) + return false; + + hdr->rawdata = (PTR) newsect; + elf_section_data (newsect)->this_hdr = *hdr; + + return true; +} + /* INTERNAL_FUNCTION bfd_elf_find_section |