Deleted Added
full compact
peicode.h (84865) peicode.h (94536)
1/* Support for the generic parts of PE/PEI, for BFD.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Cygnus Solutions.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify

--- 125 unchanged lines hidden (view full) ---

134}
135pe_ILF_vars;
136
137static asection_ptr pe_ILF_make_a_section PARAMS ((pe_ILF_vars *, const char *, unsigned int, flagword));
138static void pe_ILF_make_a_reloc PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, asection_ptr));
139static void pe_ILF_make_a_symbol PARAMS ((pe_ILF_vars *, const char *, const char *, asection_ptr, flagword));
140static void pe_ILF_save_relocs PARAMS ((pe_ILF_vars *, asection_ptr));
141static void pe_ILF_make_a_symbol_reloc PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, struct symbol_cache_entry **, unsigned int));
1/* Support for the generic parts of PE/PEI, for BFD.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Cygnus Solutions.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify

--- 125 unchanged lines hidden (view full) ---

134}
135pe_ILF_vars;
136
137static asection_ptr pe_ILF_make_a_section PARAMS ((pe_ILF_vars *, const char *, unsigned int, flagword));
138static void pe_ILF_make_a_reloc PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, asection_ptr));
139static void pe_ILF_make_a_symbol PARAMS ((pe_ILF_vars *, const char *, const char *, asection_ptr, flagword));
140static void pe_ILF_save_relocs PARAMS ((pe_ILF_vars *, asection_ptr));
141static void pe_ILF_make_a_symbol_reloc PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, struct symbol_cache_entry **, unsigned int));
142static boolean pe_ILF_build_a_bfd PARAMS ((bfd *, unsigned short, bfd_byte *, bfd_byte *, unsigned int, unsigned int));
142static boolean pe_ILF_build_a_bfd PARAMS ((bfd *, unsigned int, bfd_byte *, bfd_byte *, unsigned int, unsigned int));
143static const bfd_target * pe_ILF_object_p PARAMS ((bfd *));
144static const bfd_target * pe_bfd_object_p PARAMS ((bfd *));
145#endif /* COFF_IMAGE_WITH_PE */
146
147/**********************************************************************/
148
149#ifndef NO_COFF_RELOCS
150static void
151coff_swap_reloc_in (abfd, src, dst)
152 bfd *abfd;
153 PTR src;
154 PTR dst;
155{
156 RELOC *reloc_src = (RELOC *) src;
157 struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
158
143static const bfd_target * pe_ILF_object_p PARAMS ((bfd *));
144static const bfd_target * pe_bfd_object_p PARAMS ((bfd *));
145#endif /* COFF_IMAGE_WITH_PE */
146
147/**********************************************************************/
148
149#ifndef NO_COFF_RELOCS
150static void
151coff_swap_reloc_in (abfd, src, dst)
152 bfd *abfd;
153 PTR src;
154 PTR dst;
155{
156 RELOC *reloc_src = (RELOC *) src;
157 struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
158
159 reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
160 reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
159 reloc_dst->r_vaddr = H_GET_32 (abfd, reloc_src->r_vaddr);
160 reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
161
161
162 reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
162 reloc_dst->r_type = H_GET_16 (abfd, reloc_src->r_type);
163
164#ifdef SWAP_IN_RELOC_OFFSET
163
164#ifdef SWAP_IN_RELOC_OFFSET
165 reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
166 (bfd_byte *) reloc_src->r_offset);
165 reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
167#endif
168}
169
170static unsigned int
171coff_swap_reloc_out (abfd, src, dst)
172 bfd *abfd;
173 PTR src;
174 PTR dst;
175{
176 struct internal_reloc *reloc_src = (struct internal_reloc *)src;
177 struct external_reloc *reloc_dst = (struct external_reloc *)dst;
166#endif
167}
168
169static unsigned int
170coff_swap_reloc_out (abfd, src, dst)
171 bfd *abfd;
172 PTR src;
173 PTR dst;
174{
175 struct internal_reloc *reloc_src = (struct internal_reloc *)src;
176 struct external_reloc *reloc_dst = (struct external_reloc *)dst;
178 bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
179 bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
177 H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
178 H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
180
179
181 bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
182 reloc_dst->r_type);
180 H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
183
184#ifdef SWAP_OUT_RELOC_OFFSET
181
182#ifdef SWAP_OUT_RELOC_OFFSET
185 SWAP_OUT_RELOC_OFFSET(abfd,
186 reloc_src->r_offset,
187 (bfd_byte *) reloc_dst->r_offset);
183 SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
188#endif
189#ifdef SWAP_OUT_RELOC_EXTRA
184#endif
185#ifdef SWAP_OUT_RELOC_EXTRA
190 SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
186 SWAP_OUT_RELOC_EXTRA(abfd, reloc_src, reloc_dst);
191#endif
192 return RELSZ;
193}
194#endif /* not NO_COFF_RELOCS */
195
196static void
197coff_swap_filehdr_in (abfd, src, dst)
198 bfd *abfd;
199 PTR src;
200 PTR dst;
201{
202 FILHDR *filehdr_src = (FILHDR *) src;
203 struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
187#endif
188 return RELSZ;
189}
190#endif /* not NO_COFF_RELOCS */
191
192static void
193coff_swap_filehdr_in (abfd, src, dst)
194 bfd *abfd;
195 PTR src;
196 PTR dst;
197{
198 FILHDR *filehdr_src = (FILHDR *) src;
199 struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
204 filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
205 filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
206 filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
200 filehdr_dst->f_magic = H_GET_16 (abfd, filehdr_src->f_magic);
201 filehdr_dst->f_nscns = H_GET_16 (abfd, filehdr_src-> f_nscns);
202 filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src-> f_timdat);
207
203
208 filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
209 filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
210 filehdr_dst->f_symptr = bfd_h_get_32 (abfd, (bfd_byte *) filehdr_src->f_symptr);
204 filehdr_dst->f_nsyms = H_GET_32 (abfd, filehdr_src-> f_nsyms);
205 filehdr_dst->f_flags = H_GET_16 (abfd, filehdr_src-> f_flags);
206 filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
211
212 /* Other people's tools sometimes generate headers with an nsyms but
213 a zero symptr. */
214 if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
215 {
216 filehdr_dst->f_nsyms = 0;
217 filehdr_dst->f_flags |= F_LSYMS;
218 }
219
207
208 /* Other people's tools sometimes generate headers with an nsyms but
209 a zero symptr. */
210 if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
211 {
212 filehdr_dst->f_nsyms = 0;
213 filehdr_dst->f_flags |= F_LSYMS;
214 }
215
220 filehdr_dst->f_opthdr = bfd_h_get_16(abfd,
221 (bfd_byte *)filehdr_src-> f_opthdr);
216 filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
222}
223
224#ifdef COFF_IMAGE_WITH_PE
225# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
226#else
227# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
228#endif
229
230static void
231coff_swap_scnhdr_in (abfd, ext, in)
232 bfd *abfd;
233 PTR ext;
234 PTR in;
235{
236 SCNHDR *scnhdr_ext = (SCNHDR *) ext;
237 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
238
239 memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217}
218
219#ifdef COFF_IMAGE_WITH_PE
220# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
221#else
222# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
223#endif
224
225static void
226coff_swap_scnhdr_in (abfd, ext, in)
227 bfd *abfd;
228 PTR ext;
229 PTR in;
230{
231 SCNHDR *scnhdr_ext = (SCNHDR *) ext;
232 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
233
234 memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
240 scnhdr_int->s_vaddr =
241 GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
242 scnhdr_int->s_paddr =
243 GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
244 scnhdr_int->s_size =
245 GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
246 scnhdr_int->s_scnptr =
247 GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
248 scnhdr_int->s_relptr =
249 GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
250 scnhdr_int->s_lnnoptr =
251 GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
252 scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
235 scnhdr_int->s_vaddr = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
236 scnhdr_int->s_paddr = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
237 scnhdr_int->s_size = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
238 scnhdr_int->s_scnptr = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
239 scnhdr_int->s_relptr = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
240 scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
241 scnhdr_int->s_flags = H_GET_32 (abfd, scnhdr_ext->s_flags);
253
254 /* MS handles overflow of line numbers by carrying into the reloc
255 field (it appears). Since it's supposed to be zero for PE
256 *IMAGE* format, that's safe. This is still a bit iffy. */
257#ifdef COFF_IMAGE_WITH_PE
242
243 /* MS handles overflow of line numbers by carrying into the reloc
244 field (it appears). Since it's supposed to be zero for PE
245 *IMAGE* format, that's safe. This is still a bit iffy. */
246#ifdef COFF_IMAGE_WITH_PE
258 scnhdr_int->s_nlnno =
259 (bfd_h_get_16 (abfd, (bfd_byte *) scnhdr_ext->s_nlnno)
260 + (bfd_h_get_16 (abfd, (bfd_byte *) scnhdr_ext->s_nreloc) << 16));
247 scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
248 + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
261 scnhdr_int->s_nreloc = 0;
262#else
249 scnhdr_int->s_nreloc = 0;
250#else
263 scnhdr_int->s_nreloc = bfd_h_get_16 (abfd,
264 (bfd_byte *) scnhdr_ext->s_nreloc);
265 scnhdr_int->s_nlnno = bfd_h_get_16 (abfd,
266 (bfd_byte *) scnhdr_ext->s_nlnno);
251 scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
252 scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
267#endif
268
269 if (scnhdr_int->s_vaddr != 0)
270 {
271 scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
272 scnhdr_int->s_vaddr &= 0xffffffff;
273 }
274

--- 12 unchanged lines hidden (view full) ---

287#endif
288}
289
290static boolean
291pe_mkobject (abfd)
292 bfd * abfd;
293{
294 pe_data_type *pe;
253#endif
254
255 if (scnhdr_int->s_vaddr != 0)
256 {
257 scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
258 scnhdr_int->s_vaddr &= 0xffffffff;
259 }
260

--- 12 unchanged lines hidden (view full) ---

273#endif
274}
275
276static boolean
277pe_mkobject (abfd)
278 bfd * abfd;
279{
280 pe_data_type *pe;
295 abfd->tdata.pe_obj_data =
296 (struct pe_tdata *) bfd_zalloc (abfd, sizeof (pe_data_type));
281 bfd_size_type amt = sizeof (pe_data_type);
297
282
283 abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
284
298 if (abfd->tdata.pe_obj_data == 0)
299 return false;
300
301 pe = pe_data (abfd);
302
303 pe->coff.pe = 1;
304
305 /* in_reloc_p is architecture dependent. */

--- 230 unchanged lines hidden (view full) ---

536 sec->relocation = vars->reltab;
537 sec->reloc_count = vars->relcount;
538 sec->flags |= SEC_RELOC;
539
540 vars->reltab += vars->relcount;
541 vars->int_reltab += vars->relcount;
542 vars->relcount = 0;
543
285 if (abfd->tdata.pe_obj_data == 0)
286 return false;
287
288 pe = pe_data (abfd);
289
290 pe->coff.pe = 1;
291
292 /* in_reloc_p is architecture dependent. */

--- 230 unchanged lines hidden (view full) ---

523 sec->relocation = vars->reltab;
524 sec->reloc_count = vars->relcount;
525 sec->flags |= SEC_RELOC;
526
527 vars->reltab += vars->relcount;
528 vars->int_reltab += vars->relcount;
529 vars->relcount = 0;
530
544 BFD_ASSERT ((bfd_byte *)vars->int_reltab < (bfd_byte *)vars->string_table);
531 BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
545}
546
547/* Create a global symbol and add it to the relevant tables. */
548static void
549pe_ILF_make_a_symbol (pe_ILF_vars * vars,
550 const char * prefix,
551 const char * symbol_name,
552 asection_ptr section,

--- 29 unchanged lines hidden (view full) ---

582
583 /* Copy the symbol's name into the string table. */
584 sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
585
586 if (section == NULL)
587 section = (asection_ptr) & bfd_und_section;
588
589 /* Initialise the external symbol. */
532}
533
534/* Create a global symbol and add it to the relevant tables. */
535static void
536pe_ILF_make_a_symbol (pe_ILF_vars * vars,
537 const char * prefix,
538 const char * symbol_name,
539 asection_ptr section,

--- 29 unchanged lines hidden (view full) ---

569
570 /* Copy the symbol's name into the string table. */
571 sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
572
573 if (section == NULL)
574 section = (asection_ptr) & bfd_und_section;
575
576 /* Initialise the external symbol. */
590 bfd_h_put_32 (vars->abfd, vars->string_ptr - vars->string_table, (bfd_byte *) esym->e.e.e_offset);
591 bfd_h_put_16 (vars->abfd, section->target_index, (bfd_byte *) esym->e_scnum);
577 H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
578 esym->e.e.e_offset);
579 H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
592 esym->e_sclass[0] = sclass;
593
594 /* The following initialisations are unnecessary - the memory is
595 zero initialised. They are just kept here as reminders. */
596#if 0
597 esym->e.e.e_zeroes = 0;
598 esym->e_value = 0;
599 esym->e_type = T_NULL;

--- 61 unchanged lines hidden (view full) ---

661
662 bfd_set_section_alignment (vars->abfd, sec, 2);
663
664 /* Check that we will not run out of space. */
665 BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
666
667 /* Set the section size and contents. The actual
668 contents are filled in by our parent. */
580 esym->e_sclass[0] = sclass;
581
582 /* The following initialisations are unnecessary - the memory is
583 zero initialised. They are just kept here as reminders. */
584#if 0
585 esym->e.e.e_zeroes = 0;
586 esym->e_value = 0;
587 esym->e_type = T_NULL;

--- 61 unchanged lines hidden (view full) ---

649
650 bfd_set_section_alignment (vars->abfd, sec, 2);
651
652 /* Check that we will not run out of space. */
653 BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
654
655 /* Set the section size and contents. The actual
656 contents are filled in by our parent. */
669 bfd_set_section_size (vars->abfd, sec, size);
657 bfd_set_section_size (vars->abfd, sec, (bfd_size_type) size);
670 sec->contents = vars->data;
671 sec->target_index = vars->sec_index ++;
672
673 /* Advance data pointer in the vars structure. */
674 vars->data += size;
675
676 /* Skip the padding byte if it was not needed.
677 The logic here is that if the string length is odd,

--- 84 unchanged lines hidden (view full) ---

762
763#ifndef NUM_ENTRIES
764#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
765#endif
766
767/* Build a full BFD from the information supplied in a ILF object. */
768static boolean
769pe_ILF_build_a_bfd (bfd * abfd,
658 sec->contents = vars->data;
659 sec->target_index = vars->sec_index ++;
660
661 /* Advance data pointer in the vars structure. */
662 vars->data += size;
663
664 /* Skip the padding byte if it was not needed.
665 The logic here is that if the string length is odd,

--- 84 unchanged lines hidden (view full) ---

750
751#ifndef NUM_ENTRIES
752#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
753#endif
754
755/* Build a full BFD from the information supplied in a ILF object. */
756static boolean
757pe_ILF_build_a_bfd (bfd * abfd,
770 unsigned short magic,
758 unsigned int magic,
771 bfd_byte * symbol_name,
772 bfd_byte * source_dll,
773 unsigned int ordinal,
774 unsigned int types)
775{
776 bfd_byte * ptr;
777 pe_ILF_vars vars;
778 struct internal_filehdr internal_f;

--- 11 unchanged lines hidden (view full) ---

790 {
791 case IMPORT_CODE:
792 case IMPORT_DATA:
793 break;
794
795 case IMPORT_CONST:
796 /* XXX code yet to be written. */
797 _bfd_error_handler (_("%s: Unhandled import type; %x"),
759 bfd_byte * symbol_name,
760 bfd_byte * source_dll,
761 unsigned int ordinal,
762 unsigned int types)
763{
764 bfd_byte * ptr;
765 pe_ILF_vars vars;
766 struct internal_filehdr internal_f;

--- 11 unchanged lines hidden (view full) ---

778 {
779 case IMPORT_CODE:
780 case IMPORT_DATA:
781 break;
782
783 case IMPORT_CONST:
784 /* XXX code yet to be written. */
785 _bfd_error_handler (_("%s: Unhandled import type; %x"),
798 bfd_get_filename (abfd), import_type);
786 bfd_archive_filename (abfd), import_type);
799 return false;
800
801 default:
802 _bfd_error_handler (_("%s: Unrecognised import type; %x"),
787 return false;
788
789 default:
790 _bfd_error_handler (_("%s: Unrecognised import type; %x"),
803 bfd_get_filename (abfd), import_type);
791 bfd_archive_filename (abfd), import_type);
804 return false;
805 }
806
807 switch (import_name_type)
808 {
809 case IMPORT_ORDINAL:
810 case IMPORT_NAME:
811 case IMPORT_NAME_NOPREFIX:
812 case IMPORT_NAME_UNDECORATE:
813 break;
814
815 default:
816 _bfd_error_handler (_("%s: Unrecognised import name type; %x"),
792 return false;
793 }
794
795 switch (import_name_type)
796 {
797 case IMPORT_ORDINAL:
798 case IMPORT_NAME:
799 case IMPORT_NAME_NOPREFIX:
800 case IMPORT_NAME_UNDECORATE:
801 break;
802
803 default:
804 _bfd_error_handler (_("%s: Unrecognised import name type; %x"),
817 bfd_get_filename (abfd), import_name_type);
805 bfd_archive_filename (abfd), import_name_type);
818 return false;
819 }
820
821 /* Initialise local variables.
822
823 Note these are kept in a structure rather than being
824 declared as statics since bfd frowns on global variables.
825
826 We are going to construct the contents of the BFD in memory,
827 so allocate all the space that we will need right now. */
806 return false;
807 }
808
809 /* Initialise local variables.
810
811 Note these are kept in a structure rather than being
812 declared as statics since bfd frowns on global variables.
813
814 We are going to construct the contents of the BFD in memory,
815 so allocate all the space that we will need right now. */
828 ptr = bfd_zalloc (abfd, ILF_DATA_SIZE);
816 ptr = bfd_zalloc (abfd, (bfd_size_type) ILF_DATA_SIZE);
829 if (ptr == NULL)
830 return false;
831
832 /* Create a bfd_in_memory structure. */
833 vars.bim = (struct bfd_in_memory *) ptr;
834 vars.bim->buffer = ptr;
835 vars.bim->size = ILF_DATA_SIZE;
836 ptr += sizeof (* vars.bim);

--- 91 unchanged lines hidden (view full) ---

928 id6->contents[0] = ordinal & 0xff;
929 id6->contents[1] = ordinal >> 8;
930
931 strcpy (id6->contents + 2, symbol);
932 }
933
934 if (import_name_type != IMPORT_ORDINAL)
935 {
817 if (ptr == NULL)
818 return false;
819
820 /* Create a bfd_in_memory structure. */
821 vars.bim = (struct bfd_in_memory *) ptr;
822 vars.bim->buffer = ptr;
823 vars.bim->size = ILF_DATA_SIZE;
824 ptr += sizeof (* vars.bim);

--- 91 unchanged lines hidden (view full) ---

916 id6->contents[0] = ordinal & 0xff;
917 id6->contents[1] = ordinal >> 8;
918
919 strcpy (id6->contents + 2, symbol);
920 }
921
922 if (import_name_type != IMPORT_ORDINAL)
923 {
936 pe_ILF_make_a_reloc (& vars, 0, BFD_RELOC_RVA, id6);
937 pe_ILF_save_relocs (& vars, id4);
924 pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
925 pe_ILF_save_relocs (&vars, id4);
938
926
939 pe_ILF_make_a_reloc (& vars, 0, BFD_RELOC_RVA, id6);
940 pe_ILF_save_relocs (& vars, id5);
927 pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
928 pe_ILF_save_relocs (&vars, id5);
941 }
942
943 /* Create extra sections depending upon the type of import we are dealing with. */
944 switch (import_type)
945 {
946 int i;
947
948 case IMPORT_CODE:

--- 22 unchanged lines hidden (view full) ---

971 pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
972 imp_sym = vars.sym_ptr_ptr - 1;
973 imp_index = vars.sym_index - 1;
974
975 /* Create a reloc for the data in the text section. */
976#ifdef MIPS_ARCH_MAGIC_WINCE
977 if (magic == MIPS_ARCH_MAGIC_WINCE)
978 {
929 }
930
931 /* Create extra sections depending upon the type of import we are dealing with. */
932 switch (import_type)
933 {
934 int i;
935
936 case IMPORT_CODE:

--- 22 unchanged lines hidden (view full) ---

959 pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
960 imp_sym = vars.sym_ptr_ptr - 1;
961 imp_index = vars.sym_index - 1;
962
963 /* Create a reloc for the data in the text section. */
964#ifdef MIPS_ARCH_MAGIC_WINCE
965 if (magic == MIPS_ARCH_MAGIC_WINCE)
966 {
979 pe_ILF_make_a_symbol_reloc (& vars, 0, BFD_RELOC_HI16_S,
980 (struct symbol_cache_entry **) imp_sym, imp_index);
981 pe_ILF_make_a_reloc (& vars, 0, BFD_RELOC_LO16, text);
982 pe_ILF_make_a_symbol_reloc (& vars, 4, BFD_RELOC_LO16,
983 (struct symbol_cache_entry **) imp_sym, imp_index);
967 pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
968 (struct symbol_cache_entry **) imp_sym,
969 imp_index);
970 pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
971 pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
972 (struct symbol_cache_entry **) imp_sym,
973 imp_index);
984 }
985 else
986#endif
974 }
975 else
976#endif
987 pe_ILF_make_a_symbol_reloc (& vars, jtab[i].offset, BFD_RELOC_32,
988 (asymbol **) imp_sym, imp_index);
977 pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
978 BFD_RELOC_32, (asymbol **) imp_sym,
979 imp_index);
989
990 pe_ILF_save_relocs (& vars, text);
991 break;
992
993 case IMPORT_DATA:
994 break;
995
996 default:

--- 4 unchanged lines hidden (view full) ---

1001 /* Initialise the bfd. */
1002 memset (& internal_f, 0, sizeof (internal_f));
1003
1004 internal_f.f_magic = magic;
1005 internal_f.f_symptr = 0;
1006 internal_f.f_nsyms = 0;
1007 internal_f.f_flags = F_AR32WR | F_LNNO; /* XXX is this correct ? */
1008
980
981 pe_ILF_save_relocs (& vars, text);
982 break;
983
984 case IMPORT_DATA:
985 break;
986
987 default:

--- 4 unchanged lines hidden (view full) ---

992 /* Initialise the bfd. */
993 memset (& internal_f, 0, sizeof (internal_f));
994
995 internal_f.f_magic = magic;
996 internal_f.f_symptr = 0;
997 internal_f.f_nsyms = 0;
998 internal_f.f_flags = F_AR32WR | F_LNNO; /* XXX is this correct ? */
999
1009 if ( ! bfd_set_start_address (abfd, 0)
1000 if ( ! bfd_set_start_address (abfd, (bfd_vma) 0)
1010 || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1011 return false;
1012
1013 if (bfd_coff_mkobject_hook (abfd, (PTR) & internal_f, NULL) == NULL)
1014 return false;
1015
1016 coff_data (abfd)->pe = 1;
1017#ifdef THUMBPEMAGIC

--- 8 unchanged lines hidden (view full) ---

1026 abfd->iostream = (PTR) vars.bim;
1027 abfd->flags |= BFD_IN_MEMORY /* | HAS_LOCALS */;
1028 abfd->where = 0;
1029 obj_sym_filepos (abfd) = 0;
1030
1031 /* Now create a symbol describing the imported value. */
1032 switch (import_type)
1033 {
1001 || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1002 return false;
1003
1004 if (bfd_coff_mkobject_hook (abfd, (PTR) & internal_f, NULL) == NULL)
1005 return false;
1006
1007 coff_data (abfd)->pe = 1;
1008#ifdef THUMBPEMAGIC

--- 8 unchanged lines hidden (view full) ---

1017 abfd->iostream = (PTR) vars.bim;
1018 abfd->flags |= BFD_IN_MEMORY /* | HAS_LOCALS */;
1019 abfd->where = 0;
1020 obj_sym_filepos (abfd) = 0;
1021
1022 /* Now create a symbol describing the imported value. */
1023 switch (import_type)
1024 {
1034 bfd_byte * ptr;
1035
1036 case IMPORT_CODE:
1037 pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1038 BSF_NOT_AT_END | BSF_FUNCTION);
1039
1040 /* Create an import symbol for the DLL, without the
1041 .dll suffix. */
1042 ptr = strrchr (source_dll, '.');
1043 if (ptr)

--- 38 unchanged lines hidden (view full) ---

1082static const bfd_target *
1083pe_ILF_object_p (bfd * abfd)
1084{
1085 bfd_byte buffer[16];
1086 bfd_byte * ptr;
1087 bfd_byte * symbol_name;
1088 bfd_byte * source_dll;
1089 unsigned int machine;
1025 case IMPORT_CODE:
1026 pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1027 BSF_NOT_AT_END | BSF_FUNCTION);
1028
1029 /* Create an import symbol for the DLL, without the
1030 .dll suffix. */
1031 ptr = strrchr (source_dll, '.');
1032 if (ptr)

--- 38 unchanged lines hidden (view full) ---

1071static const bfd_target *
1072pe_ILF_object_p (bfd * abfd)
1073{
1074 bfd_byte buffer[16];
1075 bfd_byte * ptr;
1076 bfd_byte * symbol_name;
1077 bfd_byte * source_dll;
1078 unsigned int machine;
1090 unsigned long size;
1079 bfd_size_type size;
1091 unsigned int ordinal;
1092 unsigned int types;
1080 unsigned int ordinal;
1081 unsigned int types;
1093 unsigned short magic;
1082 unsigned int magic;
1094
1095 /* Upon entry the first four buyes of the ILF header have
1096 already been read. Now read the rest of the header. */
1083
1084 /* Upon entry the first four buyes of the ILF header have
1085 already been read. Now read the rest of the header. */
1097 if (bfd_read (buffer, 1, 16, abfd) != 16)
1086 if (bfd_bread (buffer, (bfd_size_type) 16, abfd) != 16)
1098 return NULL;
1099
1100 ptr = buffer;
1101
1102 /* We do not bother to check the version number.
1087 return NULL;
1088
1089 ptr = buffer;
1090
1091 /* We do not bother to check the version number.
1103 version = bfd_h_get_16 (abfd, ptr); */
1092 version = H_GET_16 (abfd, ptr); */
1104 ptr += 2;
1105
1093 ptr += 2;
1094
1106 machine = bfd_h_get_16 (abfd, ptr);
1095 machine = H_GET_16 (abfd, ptr);
1107 ptr += 2;
1108
1109 /* Check that the machine type is recognised. */
1110 magic = 0;
1111
1112 switch (machine)
1113 {
1114 case IMAGE_FILE_MACHINE_UNKNOWN:

--- 51 unchanged lines hidden (view full) ---

1166 break;
1167
1168 case IMAGE_FILE_MACHINE_POWERPC:
1169 /* We no longer support PowerPC. */
1170 default:
1171 _bfd_error_handler
1172 (
1173_("%s: Unrecognised machine type (0x%x) in Import Library Format archive"),
1096 ptr += 2;
1097
1098 /* Check that the machine type is recognised. */
1099 magic = 0;
1100
1101 switch (machine)
1102 {
1103 case IMAGE_FILE_MACHINE_UNKNOWN:

--- 51 unchanged lines hidden (view full) ---

1155 break;
1156
1157 case IMAGE_FILE_MACHINE_POWERPC:
1158 /* We no longer support PowerPC. */
1159 default:
1160 _bfd_error_handler
1161 (
1162_("%s: Unrecognised machine type (0x%x) in Import Library Format archive"),
1174 bfd_get_filename (abfd), machine);
1163 bfd_archive_filename (abfd), machine);
1175 bfd_set_error (bfd_error_malformed_archive);
1176
1177 return NULL;
1178 break;
1179 }
1180
1181 if (magic == 0)
1182 {
1183 _bfd_error_handler
1184 (
1185_("%s: Recognised but unhandled machine type (0x%x) in Import Library Format archive"),
1164 bfd_set_error (bfd_error_malformed_archive);
1165
1166 return NULL;
1167 break;
1168 }
1169
1170 if (magic == 0)
1171 {
1172 _bfd_error_handler
1173 (
1174_("%s: Recognised but unhandled machine type (0x%x) in Import Library Format archive"),
1186 bfd_get_filename (abfd), machine);
1175 bfd_archive_filename (abfd), machine);
1187 bfd_set_error (bfd_error_wrong_format);
1188
1189 return NULL;
1190 }
1191
1192 /* We do not bother to check the date.
1176 bfd_set_error (bfd_error_wrong_format);
1177
1178 return NULL;
1179 }
1180
1181 /* We do not bother to check the date.
1193 date = bfd_h_get_32 (abfd, ptr); */
1182 date = H_GET_32 (abfd, ptr); */
1194 ptr += 4;
1195
1183 ptr += 4;
1184
1196 size = bfd_h_get_32 (abfd, ptr);
1185 size = H_GET_32 (abfd, ptr);
1197 ptr += 4;
1198
1199 if (size == 0)
1200 {
1201 _bfd_error_handler
1202 (_("%s: size field is zero in Import Library Format header"),
1186 ptr += 4;
1187
1188 if (size == 0)
1189 {
1190 _bfd_error_handler
1191 (_("%s: size field is zero in Import Library Format header"),
1203 bfd_get_filename (abfd));
1192 bfd_archive_filename (abfd));
1204 bfd_set_error (bfd_error_malformed_archive);
1205
1206 return NULL;
1207 }
1208
1193 bfd_set_error (bfd_error_malformed_archive);
1194
1195 return NULL;
1196 }
1197
1209 ordinal = bfd_h_get_16 (abfd, ptr);
1198 ordinal = H_GET_16 (abfd, ptr);
1210 ptr += 2;
1211
1199 ptr += 2;
1200
1212 types = bfd_h_get_16 (abfd, ptr);
1201 types = H_GET_16 (abfd, ptr);
1213 /* ptr += 2; */
1214
1215 /* Now read in the two strings that follow. */
1216 ptr = bfd_alloc (abfd, size);
1217 if (ptr == NULL)
1218 return NULL;
1219
1202 /* ptr += 2; */
1203
1204 /* Now read in the two strings that follow. */
1205 ptr = bfd_alloc (abfd, size);
1206 if (ptr == NULL)
1207 return NULL;
1208
1220 if (bfd_read (ptr, 1, size, abfd) != size)
1209 if (bfd_bread (ptr, size, abfd) != size)
1221 return NULL;
1222
1223 symbol_name = ptr;
1224 source_dll = ptr + strlen (ptr) + 1;
1225
1226 /* Verify that the strings are null terminated. */
1227 if (ptr[size - 1] != 0 || ((unsigned long) (source_dll - ptr) >= size))
1228 {
1229 _bfd_error_handler
1230 (_("%s: string not null terminated in ILF object file."),
1210 return NULL;
1211
1212 symbol_name = ptr;
1213 source_dll = ptr + strlen (ptr) + 1;
1214
1215 /* Verify that the strings are null terminated. */
1216 if (ptr[size - 1] != 0 || ((unsigned long) (source_dll - ptr) >= size))
1217 {
1218 _bfd_error_handler
1219 (_("%s: string not null terminated in ILF object file."),
1231 bfd_get_filename (abfd));
1220 bfd_archive_filename (abfd));
1232 bfd_set_error (bfd_error_malformed_archive);
1233
1234 return NULL;
1235 }
1236
1237 /* Now construct the bfd. */
1238 if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1239 source_dll, ordinal, types))

--- 6 unchanged lines hidden (view full) ---

1246pe_bfd_object_p (bfd * abfd)
1247{
1248 bfd_byte buffer[4];
1249 struct external_PEI_DOS_hdr dos_hdr;
1250 struct external_PEI_IMAGE_hdr image_hdr;
1251 file_ptr offset;
1252
1253 /* Detect if this a Microsoft Import Library Format element. */
1221 bfd_set_error (bfd_error_malformed_archive);
1222
1223 return NULL;
1224 }
1225
1226 /* Now construct the bfd. */
1227 if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1228 source_dll, ordinal, types))

--- 6 unchanged lines hidden (view full) ---

1235pe_bfd_object_p (bfd * abfd)
1236{
1237 bfd_byte buffer[4];
1238 struct external_PEI_DOS_hdr dos_hdr;
1239 struct external_PEI_IMAGE_hdr image_hdr;
1240 file_ptr offset;
1241
1242 /* Detect if this a Microsoft Import Library Format element. */
1254 if (bfd_seek (abfd, 0x00, SEEK_SET) != 0
1255 || bfd_read (buffer, 1, 4, abfd) != 4)
1243 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1244 || bfd_bread (buffer, (bfd_size_type) 4, abfd) != 4)
1256 {
1257 if (bfd_get_error () != bfd_error_system_call)
1258 bfd_set_error (bfd_error_wrong_format);
1259 return NULL;
1260 }
1261
1245 {
1246 if (bfd_get_error () != bfd_error_system_call)
1247 bfd_set_error (bfd_error_wrong_format);
1248 return NULL;
1249 }
1250
1262 if (bfd_h_get_32 (abfd, buffer) == 0xffff0000)
1251 if (H_GET_32 (abfd, buffer) == 0xffff0000)
1263 return pe_ILF_object_p (abfd);
1264
1252 return pe_ILF_object_p (abfd);
1253
1265 if (bfd_seek (abfd, 0x00, SEEK_SET) != 0
1266 || bfd_read (&dos_hdr, 1, sizeof (dos_hdr), abfd)
1254 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1255 || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1267 != sizeof (dos_hdr))
1268 {
1269 if (bfd_get_error () != bfd_error_system_call)
1270 bfd_set_error (bfd_error_wrong_format);
1271 return NULL;
1272 }
1273
1274 /* There are really two magic numbers involved; the magic number
1275 that says this is a NT executable (PEI) and the magic number that
1276 determines the architecture. The former is DOSMAGIC, stored in
1277 the e_magic field. The latter is stored in the f_magic field.
1278 If the NT magic number isn't valid, the architecture magic number
1279 could be mimicked by some other field (specifically, the number
1280 of relocs in section 3). Since this routine can only be called
1281 correctly for a PEI file, check the e_magic number here, and, if
1282 it doesn't match, clobber the f_magic number so that we don't get
1283 a false match. */
1256 != sizeof (dos_hdr))
1257 {
1258 if (bfd_get_error () != bfd_error_system_call)
1259 bfd_set_error (bfd_error_wrong_format);
1260 return NULL;
1261 }
1262
1263 /* There are really two magic numbers involved; the magic number
1264 that says this is a NT executable (PEI) and the magic number that
1265 determines the architecture. The former is DOSMAGIC, stored in
1266 the e_magic field. The latter is stored in the f_magic field.
1267 If the NT magic number isn't valid, the architecture magic number
1268 could be mimicked by some other field (specifically, the number
1269 of relocs in section 3). Since this routine can only be called
1270 correctly for a PEI file, check the e_magic number here, and, if
1271 it doesn't match, clobber the f_magic number so that we don't get
1272 a false match. */
1284 if (bfd_h_get_16 (abfd, (bfd_byte *) dos_hdr.e_magic) != DOSMAGIC)
1273 if (H_GET_16 (abfd, dos_hdr.e_magic) != DOSMAGIC)
1285 {
1286 bfd_set_error (bfd_error_wrong_format);
1287 return NULL;
1288 }
1289
1274 {
1275 bfd_set_error (bfd_error_wrong_format);
1276 return NULL;
1277 }
1278
1290 offset = bfd_h_get_32 (abfd, (bfd_byte *) dos_hdr.e_lfanew);
1291 if (bfd_seek (abfd, (file_ptr) offset, SEEK_SET) != 0
1292 || bfd_read (&image_hdr, 1, sizeof (image_hdr), abfd)
1293 != sizeof (image_hdr))
1279 offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1280 if (bfd_seek (abfd, offset, SEEK_SET) != 0
1281 || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1282 != sizeof (image_hdr)))
1294 {
1295 if (bfd_get_error () != bfd_error_system_call)
1296 bfd_set_error (bfd_error_wrong_format);
1297 return NULL;
1298 }
1299
1283 {
1284 if (bfd_get_error () != bfd_error_system_call)
1285 bfd_set_error (bfd_error_wrong_format);
1286 return NULL;
1287 }
1288
1300 if (bfd_h_get_32 (abfd, (bfd_byte *) image_hdr.nt_signature)
1301 != 0x4550)
1289 if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1302 {
1303 bfd_set_error (bfd_error_wrong_format);
1304 return NULL;
1305 }
1306
1307 /* Here is the hack. coff_object_p wants to read filhsz bytes to
1308 pick up the COFF header for PE, see "struct external_PEI_filehdr"
1309 in include/coff/pe.h. We adjust so that that will work. */
1290 {
1291 bfd_set_error (bfd_error_wrong_format);
1292 return NULL;
1293 }
1294
1295 /* Here is the hack. coff_object_p wants to read filhsz bytes to
1296 pick up the COFF header for PE, see "struct external_PEI_filehdr"
1297 in include/coff/pe.h. We adjust so that that will work. */
1310 if (bfd_seek (abfd,
1311 (file_ptr) (offset - sizeof (dos_hdr)),
1312 SEEK_SET)
1313 != 0)
1298 if (bfd_seek (abfd, (file_ptr) (offset - sizeof (dos_hdr)), SEEK_SET) != 0)
1314 {
1315 if (bfd_get_error () != bfd_error_system_call)
1316 bfd_set_error (bfd_error_wrong_format);
1317 return NULL;
1318 }
1319
1320 return coff_object_p (abfd);
1321}
1322
1323#define coff_object_p pe_bfd_object_p
1324#endif /* COFF_IMAGE_WITH_PE */
1299 {
1300 if (bfd_get_error () != bfd_error_system_call)
1301 bfd_set_error (bfd_error_wrong_format);
1302 return NULL;
1303 }
1304
1305 return coff_object_p (abfd);
1306}
1307
1308#define coff_object_p pe_bfd_object_p
1309#endif /* COFF_IMAGE_WITH_PE */