From e83f3040315030236d9161d3215f8144f1df47e1 Mon Sep 17 00:00:00 2001 From: Fred Fish Date: Wed, 18 Dec 1991 03:51:33 +0000 Subject: [PATCH] Enclose corename and execname inside a HAVE_PROCFS ifdef, since they are unused when it is not defined. --- bfd/ChangeLog | 14 +++++++++ bfd/elf.c | 84 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 69 insertions(+), 29 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index fecaf07b5b1..2a45534e90d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,17 @@ +Tue Dec 17 19:48:59 1991 Fred Fish (fnf at cygnus.com) + + * elf.c (elf_core_file_matches_executable_p): Enclose corename + and execname inside HAVE_PROCFS ifdef since they are unused + when it is not defined. + +Mon Dec 16 12:00:10 1991 Fred Fish (fnf at cygnus.com) + + * elf.c: Flag all sections as either code or data. We can't + be sure what they are anyway, since ELF doesn't fit the + traditional model of text+data+bss very well. Add new local + function elf_read() to simplify code. Record entry point in + the bfd structure. + Thu Dec 12 21:01:22 1991 John Gilmore (gnu at cygnus.com) * hosts/h-*.h: Configure fopen using ../include/fopen-*.h diff --git a/bfd/elf.c b/bfd/elf.c index e276ad54a83..aa3e2fbe502 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -141,8 +141,8 @@ DEFUN(elf_swap_symbol_in,(abfd, src, dst), } -/* Translate an ELF header in external format into an ELF header in internal - format. */ +/* Translate an ELF file header in external format into an ELF file header in + internal format. */ static void DEFUN(elf_swap_ehdr_in,(abfd, src, dst), @@ -245,6 +245,10 @@ DEFUN(bfd_section_from_shdr, (abfd, hdr, shstrtab), { newsect -> flags |= SEC_CODE; /* FIXME: may only contain SOME code */ } + else + { + newsect -> flags |= SEC_DATA; + } if (hdr -> sh_type == SHT_SYMTAB) { abfd -> flags |= HAS_SYMS; @@ -460,8 +464,10 @@ DEFUN(elf_core_file_matches_executable_p, (core_bfd, exec_bfd), bfd *core_bfd AND bfd *exec_bfd) { +#if HAVE_PROCFS char *corename; char *execname; +#endif /* First, xvecs must match since both are ELF files for the same target. */ @@ -544,7 +550,7 @@ DEFUN(elf_corefile_note, (abfd, hdr), asection *newsect; if (hdr -> p_filesz > 0 - && (buf = malloc (hdr -> p_filesz)) != NULL + && (buf = (char *)malloc(hdr -> p_filesz)) != NULL && bfd_seek (abfd, hdr -> p_offset, SEEK_SET) != -1L && bfd_read ((PTR) buf, hdr -> p_filesz, 1, abfd) == hdr -> p_filesz) { @@ -594,9 +600,41 @@ DEFUN(elf_corefile_note, (abfd, hdr), { free (buf); } + return true; + } +/* Read a specified number of bytes at a specified offset in an ELF + file, into a newly allocated buffer, and return a pointer to the + buffer. */ + +static char * +DEFUN(elf_read, (abfd, offset, size), + bfd *abfd AND + long offset AND + int size) +{ + char *buf; + + if ((buf = bfd_alloc (abfd, size)) == NULL) + { + bfd_error = no_memory; + return (NULL); + } + if (bfd_seek (abfd, offset, SEEK_SET) == -1) + { + bfd_error = system_call_error; + return (NULL); + } + if (bfd_read ((PTR) buf, size, 1, abfd) != size) + { + bfd_error = system_call_error; + return (NULL); + } + return (buf); +} + /* Begin processing a given object. First we validate the file by reading in the ELF header and checking @@ -614,6 +652,7 @@ DEFUN (elf_object_p, (abfd), bfd *abfd) int shindex; char *shstrtab; /* Internal copy of section header stringtab */ int shstrtabsize; /* Size of section header string table */ + Elf_Off offset; /* Temp place to stash file offsets */ /* Read in the ELF header in external format. */ @@ -726,22 +765,12 @@ wrong: will need the base pointer to this table later. */ shstrtabsize = i_shdr[i_ehdr.e_shstrndx].sh_size; - if ((shstrtab = bfd_alloc (abfd, shstrtabsize)) == NULL) + offset = i_shdr[i_ehdr.e_shstrndx].sh_offset; + if ((shstrtab = elf_read (abfd, offset, shstrtabsize)) == NULL) { - bfd_error = no_memory; - return (NULL); - } - if (bfd_seek (abfd, i_shdr[i_ehdr.e_shstrndx].sh_offset, SEEK_SET) == -1) - { - bfd_error = system_call_error; - return (NULL); - } - if (bfd_read ((PTR) shstrtab, shstrtabsize, 1, abfd) != shstrtabsize) - { - bfd_error = system_call_error; return (NULL); } - + /* Once all of the section headers have been read and converted, we can start processing them. Note that the first section header is a dummy placeholder entry, so we ignore it. @@ -763,6 +792,10 @@ wrong: } } + /* Remember the entry point specified in the ELF file header. */ + + bfd_get_start_address (abfd) = i_ehdr.e_entry; + return (abfd->xvec); } @@ -903,6 +936,10 @@ wrong: } } + /* Remember the entry point specified in the ELF file header. */ + + bfd_get_start_address (abfd) = i_ehdr.e_entry; + return (abfd->xvec); } @@ -965,20 +1002,9 @@ DEFUN (elf_slurp_symbol_table, (abfd), bfd *abfd) long as the bfd is in use, since we will end up setting up pointers into it for the names of all the symbols. */ - if (bfd_seek (abfd, elf_strtab_filepos (abfd), SEEK_SET) == -1) - { - bfd_error = system_call_error; - return (false); - } - if ((strtab = bfd_alloc (abfd, elf_strtab_filesz (abfd))) == NULL) - { - bfd_error = system_call_error; - return (false); - } - if (bfd_read ((PTR) strtab, elf_strtab_filesz (abfd), 1, abfd) != - elf_strtab_filesz (abfd)) + strtab = elf_read (abfd, elf_strtab_filepos(abfd), elf_strtab_filesz(abfd)); + if (strtab == NULL) { - bfd_error = system_call_error; return (false); } -- 2.30.2