1 /* Routines to help build PEI-format DLLs (Win32 etc)
2 Copyright (C) 1998 Free Software Foundation, Inc.
3 Written by DJ Delorie <dj@cygnus.com>
5 This file is part of GLD, the Gnu Linker.
7 GLD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GLD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GLD; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "libiberty.h"
34 #include "coff/internal.h"
35 #include "../bfd/libcoff.h"
38 /************************************************************************
40 This file turns a regular Windows PE image into a DLL. Because of
41 the complexity of this operation, it has been broken down into a
42 number of separate modules which are all called by the main function
43 at the end of this file. This function is not re-entrant and is
44 normally only called once, so static variables are used to reduce
45 the number of parameters and return values required.
47 See also: ld/emultempl/pe.em
49 ************************************************************************/
51 /* from emultempl/pe.em */
53 extern def_file
*pe_def_file
;
54 extern int pe_dll_export_everything
;
55 extern int pe_dll_do_default_excludes
;
56 extern int pe_dll_kill_ats
;
57 extern int pe_dll_stdcall_aliases
;
59 /************************************************************************
61 static variables and types
63 ************************************************************************/
65 static bfd_vma image_base
;
67 static bfd
*filler_bfd
;
68 static struct sec
*edata_s
, *reloc_s
;
69 static unsigned char *edata_d
, *reloc_d
;
70 static int edata_sz
, reloc_sz
;
72 /************************************************************************
74 Helper functions for qsort. Relocs must be sorted so that we can write
77 ************************************************************************/
83 unsigned long a
= *(unsigned long *) va
;
84 unsigned long b
= *(unsigned long *) vb
;
89 pe_export_sort (va
, vb
)
92 def_file_export
*a
= (def_file_export
*) va
;
93 def_file_export
*b
= (def_file_export
*) vb
;
94 return strcmp (a
->name
, b
->name
);
97 /************************************************************************
99 Read and process the .DEF file
101 ************************************************************************/
103 /* These correspond to the entries in pe_def_file->exports[]. I use
104 exported_symbol_sections[i] to tag whether or not the symbol was
105 defined, since we can't export symbols we don't have. */
107 static bfd_vma
*exported_symbol_offsets
;
108 static struct sec
**exported_symbol_sections
;
110 static int export_table_size
;
111 static int count_exported
;
112 static int count_exported_byname
;
113 static int count_with_ordinals
;
114 static const char *dll_name
;
115 static int min_ordinal
, max_ordinal
;
116 static int *exported_symbols
;
118 typedef struct exclude_list_struct
121 struct exclude_list_struct
*next
;
124 static struct exclude_list_struct
*excludes
= 0;
127 pe_dll_add_excludes (new_excludes
)
128 const char *new_excludes
;
131 char *exclude_string
;
133 local_copy
= xstrdup (new_excludes
);
135 exclude_string
= strtok (local_copy
, ",:");
136 for (; exclude_string
; exclude_string
= strtok (NULL
, ",:"))
138 struct exclude_list_struct
*new_exclude
;
140 new_exclude
= ((struct exclude_list_struct
*)
141 xmalloc (sizeof (struct exclude_list_struct
)));
142 new_exclude
->string
= (char *) xmalloc (strlen (exclude_string
) + 1);
143 strcpy (new_exclude
->string
, exclude_string
);
144 new_exclude
->next
= excludes
;
145 excludes
= new_exclude
;
157 struct exclude_list_struct
*ex
;
158 for (i
= 0; i
< d
->num_exports
; i
++)
159 if (strcmp (d
->exports
[i
].name
, n
) == 0)
161 if (pe_dll_do_default_excludes
)
163 if (strcmp (n
, "DllMain@12") == 0)
165 if (strcmp (n
, "DllEntryPoint@0") == 0)
167 if (strcmp (n
, "impure_ptr") == 0)
170 for (ex
= excludes
; ex
; ex
= ex
->next
)
171 if (strcmp (n
, ex
->string
) == 0)
177 process_def_file (abfd
, info
)
179 struct bfd_link_info
*info
;
182 struct bfd_link_hash_entry
*blhe
;
188 pe_def_file
= def_file_empty ();
190 /* First, run around to all the objects looking for the .drectve
191 sections, and push those into the def file too */
193 for (b
= info
->input_bfds
; b
; b
= b
->link_next
)
195 s
= bfd_get_section_by_name (b
, ".drectve");
198 int size
= bfd_get_section_size_before_reloc (s
);
199 char *buf
= xmalloc (size
);
200 bfd_get_section_contents (b
, s
, buf
, 0, size
);
201 def_file_add_directive (pe_def_file
, buf
, size
);
206 /* Now, maybe export everything else the default way */
208 if (pe_dll_export_everything
|| pe_def_file
->num_exports
== 0)
210 for (b
= info
->input_bfds
; b
; b
= b
->link_next
)
215 symsize
= bfd_get_symtab_upper_bound (b
);
216 symbols
= (asymbol
**) xmalloc (symsize
);
217 nsyms
= bfd_canonicalize_symtab (b
, symbols
);
219 for (j
= 0; j
< nsyms
; j
++)
221 if ((symbols
[j
]->flags
& (BSF_FUNCTION
| BSF_GLOBAL
))
222 == (BSF_FUNCTION
| BSF_GLOBAL
))
224 const char *sn
= symbols
[j
]->name
;
227 if (auto_export (pe_def_file
, sn
))
228 def_file_add_export (pe_def_file
, sn
, 0, -1);
235 #define NE pe_def_file->num_exports
236 e
= pe_def_file
->exports
; /* convenience */
238 /* Canonicalize the export list */
242 for (i
= 0; i
< NE
; i
++)
244 if (strchr (e
[i
].name
, '@'))
246 /* This will preserve internal_name, which may have been pointing
247 to the same memory as name, or might not have */
248 char *tmp
= xstrdup (e
[i
].name
);
249 *(strchr (tmp
, '@')) = 0;
255 if (pe_dll_stdcall_aliases
)
257 for (i
= 0; i
< NE
; i
++)
259 if (strchr (e
[i
].name
, '@'))
261 char *tmp
= xstrdup (e
[i
].name
);
262 *(strchr (tmp
, '@')) = 0;
263 if (auto_export (pe_def_file
, tmp
))
264 def_file_add_export (pe_def_file
, tmp
, e
[i
].internal_name
, -1);
271 exported_symbol_offsets
= (bfd_vma
*) xmalloc (NE
* sizeof (bfd_vma
));
272 exported_symbol_sections
= (struct sec
**) xmalloc (NE
* sizeof (struct sec
*));
274 memset (exported_symbol_sections
, 0, NE
* sizeof (struct sec
*));
278 count_exported_byname
= 0;
279 count_with_ordinals
= 0;
281 qsort (pe_def_file
->exports
, NE
, sizeof (pe_def_file
->exports
[0]), pe_export_sort
);
282 for (i
= 0, j
= 0; i
< NE
; i
++)
284 if (i
> 0 && strcmp (e
[i
].name
, e
[i
- 1].name
) == 0)
286 /* This is a duplicate */
287 if (e
[j
- 1].ordinal
!= -1
288 && e
[i
].ordinal
!= -1
289 && e
[j
- 1].ordinal
!= e
[i
].ordinal
)
291 /* xgettext:c-format */
292 einfo (_("%XError, duplicate EXPORT with oridinals: %s (%d vs %d)\n"),
293 e
[j
- 1].name
, e
[j
- 1].ordinal
, e
[i
].ordinal
);
297 /* xgettext:c-format */
298 einfo (_("Warning, duplicate EXPORT: %s\n"),
302 e
[j
- 1].ordinal
= e
[i
].ordinal
;
303 e
[j
- 1].flag_private
|= e
[i
].flag_private
;
304 e
[j
- 1].flag_constant
|= e
[i
].flag_constant
;
305 e
[j
- 1].flag_noname
|= e
[i
].flag_noname
;
306 e
[j
- 1].flag_data
|= e
[i
].flag_data
;
315 pe_def_file
->num_exports
= j
; /* == NE */
317 for (i
= 0; i
< NE
; i
++)
319 char *name
= (char *) xmalloc (strlen (pe_def_file
->exports
[i
].internal_name
) + 2);
321 strcpy (name
+ 1, pe_def_file
->exports
[i
].internal_name
);
323 blhe
= bfd_link_hash_lookup (info
->hash
,
327 if (blhe
&& (blhe
->type
== bfd_link_hash_defined
))
330 if (!pe_def_file
->exports
[i
].flag_noname
)
331 count_exported_byname
++;
332 exported_symbol_offsets
[i
] = blhe
->u
.def
.value
;
333 exported_symbol_sections
[i
] = blhe
->u
.def
.section
;
334 if (pe_def_file
->exports
[i
].ordinal
!= -1)
336 if (max_ordinal
< pe_def_file
->exports
[i
].ordinal
)
337 max_ordinal
= pe_def_file
->exports
[i
].ordinal
;
338 if (min_ordinal
> pe_def_file
->exports
[i
].ordinal
)
339 min_ordinal
= pe_def_file
->exports
[i
].ordinal
;
340 count_with_ordinals
++;
345 /* xgettext:c-format */
346 einfo (_("%XCannot export %s: symbol wrong type\n"),
347 pe_def_file
->exports
[i
].internal_name
);
351 /* xgettext:c-format */
352 einfo (_("%XCannot export %s: symbol not found\n"),
353 pe_def_file
->exports
[i
].internal_name
);
359 /* For now, just export all global functions. Read DEF files later */
360 for (i
= 0; i
< num_input_bfds
; i
++)
362 for (j
= 0; j
< symtab
[i
].nsyms
; j
++)
364 if ((symtab
[i
].symbols
[j
]->flags
& (BSF_FUNCTION
| BSF_GLOBAL
))
365 == (BSF_FUNCTION
| BSF_GLOBAL
))
366 symtab
[i
].exported
[j
] = 1;
372 /************************************************************************
374 Build the bfd that will contain .edata and .reloc sections
376 ************************************************************************/
381 static lang_input_statement_type
*filler_file
;
382 filler_file
= lang_add_input_file ("dll stuff",
383 lang_input_file_is_fake_enum
,
385 filler_file
->the_bfd
= filler_bfd
= bfd_create ("dll stuff", output_bfd
);
386 if (filler_bfd
== NULL
387 || !bfd_set_arch_mach (filler_bfd
,
388 bfd_get_arch (output_bfd
),
389 bfd_get_mach (output_bfd
)))
391 einfo ("%X%P: can not create BFD %E\n");
395 edata_s
= bfd_make_section_old_way (filler_bfd
, ".edata");
397 || !bfd_set_section_flags (filler_bfd
, edata_s
,
404 einfo ("%X%P: can not create .edata section: %E\n");
407 bfd_set_section_size (filler_bfd
, edata_s
, edata_sz
);
409 reloc_s
= bfd_make_section_old_way (filler_bfd
, ".reloc");
411 || !bfd_set_section_flags (filler_bfd
, reloc_s
,
418 einfo ("%X%P: can not create .reloc section: %E\n");
421 bfd_set_section_size (filler_bfd
, reloc_s
, 0);
423 ldlang_add_file (filler_file
);
426 /************************************************************************
428 Gather all the exported symbols and build the .edata section
430 ************************************************************************/
433 generate_edata (abfd
, info
)
435 struct bfd_link_info
*info
;
437 int i
, j
, next_ordinal
;
438 int name_table_size
= 0;
441 /* First, we need to know how many exported symbols there are,
442 and what the range of ordinals is. */
444 if (pe_def_file
->name
)
446 dll_name
= pe_def_file
->name
;
450 dll_name
= abfd
->filename
;
451 for (dlnp
= dll_name
; *dlnp
; dlnp
++)
453 if (*dlnp
== '\\' || *dlnp
== '/' || *dlnp
== ':')
458 if (count_with_ordinals
&& max_ordinal
> count_exported
)
460 if (min_ordinal
> max_ordinal
- count_exported
+ 1)
461 min_ordinal
= max_ordinal
- count_exported
+ 1;
466 max_ordinal
= count_exported
;
468 export_table_size
= max_ordinal
- min_ordinal
+ 1;
470 exported_symbols
= (int *) xmalloc (export_table_size
* sizeof (int));
471 for (i
= 0; i
< export_table_size
; i
++)
472 exported_symbols
[i
] = -1;
474 /* Now we need to assign ordinals to those that don't have them */
475 for (i
= 0; i
< NE
; i
++)
477 if (exported_symbol_sections
[i
])
479 if (pe_def_file
->exports
[i
].ordinal
!= -1)
481 int ei
= pe_def_file
->exports
[i
].ordinal
- min_ordinal
;
482 int pi
= exported_symbols
[ei
];
485 /* xgettext:c-format */
486 einfo (_("%XError, oridinal used twice: %d (%s vs %s)\n"),
487 pe_def_file
->exports
[i
].ordinal
,
488 pe_def_file
->exports
[i
].name
,
489 pe_def_file
->exports
[pi
].name
);
491 exported_symbols
[ei
] = i
;
493 name_table_size
+= strlen (pe_def_file
->exports
[i
].name
) + 1;
497 next_ordinal
= min_ordinal
;
498 for (i
= 0; i
< NE
; i
++)
499 if (exported_symbol_sections
[i
])
500 if (pe_def_file
->exports
[i
].ordinal
== -1)
502 while (exported_symbols
[next_ordinal
- min_ordinal
] != -1)
504 exported_symbols
[next_ordinal
- min_ordinal
] = i
;
505 pe_def_file
->exports
[i
].ordinal
= next_ordinal
;
508 /* OK, now we can allocate some memory */
510 edata_sz
= (40 /* directory */
511 + 4 * export_table_size
/* addresses */
512 + 4 * count_exported_byname
/* name ptrs */
513 + 2 * count_exported_byname
/* ordinals */
514 + name_table_size
+ strlen (dll_name
) + 1);
518 fill_edata (abfd
, info
)
520 struct bfd_link_info
*info
;
523 unsigned char *edirectory
;
524 unsigned long *eaddresses
;
525 unsigned long *enameptrs
;
526 unsigned short *eordinals
;
527 unsigned char *enamestr
;
529 edata_d
= (unsigned char *) xmalloc (edata_sz
);
531 /* Note use of array pointer math here */
532 edirectory
= edata_d
;
533 eaddresses
= (unsigned long *) (edata_d
+ 40);
534 enameptrs
= eaddresses
+ export_table_size
;
535 eordinals
= (unsigned short *) (enameptrs
+ count_exported_byname
);
536 enamestr
= (char *) (eordinals
+ count_exported_byname
);
538 #define ERVA(ptr) (((unsigned char *)(ptr) - edata_d) + edata_s->output_section->vma - image_base)
540 memset (edata_d
, 0, 40);
541 if (pe_def_file
->version_major
!= -1)
543 bfd_put_16 (abfd
, pe_def_file
->version_major
, edata_d
+ 8);
544 bfd_put_16 (abfd
, pe_def_file
->version_minor
, edata_d
+ 10);
546 bfd_put_32 (abfd
, ERVA (enamestr
), edata_d
+ 12);
547 strcpy (enamestr
, dll_name
);
548 enamestr
+= strlen (enamestr
) + 1;
549 bfd_put_32 (abfd
, min_ordinal
, edata_d
+ 16);
550 bfd_put_32 (abfd
, export_table_size
, edata_d
+ 20);
551 bfd_put_32 (abfd
, count_exported_byname
, edata_d
+ 24);
552 bfd_put_32 (abfd
, ERVA (eaddresses
), edata_d
+ 28);
553 bfd_put_32 (abfd
, ERVA (enameptrs
), edata_d
+ 32);
554 bfd_put_32 (abfd
, ERVA (eordinals
), edata_d
+ 36);
556 /* Ok, now for the filling in part */
557 for (i
= 0; i
< export_table_size
; i
++)
559 int s
= exported_symbols
[i
];
562 struct sec
*ssec
= exported_symbol_sections
[s
];
563 unsigned long srva
= (exported_symbol_offsets
[s
]
564 + ssec
->output_section
->vma
565 + ssec
->output_offset
);
567 bfd_put_32 (abfd
, srva
- image_base
, (void *) (eaddresses
+ i
));
568 if (!pe_def_file
->exports
[s
].flag_noname
)
570 char *ename
= pe_def_file
->exports
[s
].name
;
571 bfd_put_32 (abfd
, ERVA (enamestr
), (void *) enameptrs
);
572 strcpy (enamestr
, ename
[0] == '_' ? ename
+ 1 : ename
);
573 enamestr
+= strlen (enamestr
) + 1;
574 bfd_put_16 (abfd
, i
, (void *) eordinals
);
582 /************************************************************************
584 Gather all the relocations and build the .reloc section
586 ************************************************************************/
589 generate_reloc (abfd
, info
)
591 struct bfd_link_info
*info
;
594 /* for .reloc stuff */
595 bfd_vma
*reloc_addresses
;
596 int total_relocs
= 0;
598 unsigned long sec_page
= (unsigned long) (-1);
599 unsigned long page_ptr
, page_count
;
605 for (b
= info
->input_bfds
; b
; b
= b
->link_next
)
606 for (s
= b
->sections
; s
; s
= s
->next
)
607 total_relocs
+= s
->reloc_count
;
609 reloc_addresses
= (unsigned long *) xmalloc (total_relocs
* sizeof (unsigned long));
613 for (bi
= 0, b
= info
->input_bfds
; b
; bi
++, b
= b
->link_next
)
616 int relsize
, nrelocs
, i
;
618 for (s
= b
->sections
; s
; s
= s
->next
)
620 unsigned long sec_vma
= s
->output_section
->vma
+ s
->output_offset
;
624 symsize
= bfd_get_symtab_upper_bound (b
);
625 symbols
= (asymbol
**) xmalloc (symsize
);
626 nsyms
= bfd_canonicalize_symtab (b
, symbols
);
628 relsize
= bfd_get_reloc_upper_bound (b
, s
);
629 relocs
= (arelent
**) xmalloc ((size_t) relsize
);
630 nrelocs
= bfd_canonicalize_reloc (b
, s
, relocs
, symbols
);
632 for (i
= 0; i
< nrelocs
; i
++)
634 if (!relocs
[i
]->howto
->pc_relative
)
636 switch (relocs
[i
]->howto
->bitsize
)
639 reloc_addresses
[total_relocs
++] = sec_vma
+ relocs
[i
]->address
;
642 /* xgettext:c-format */
643 einfo (_("%XError: %d-bit reloc in dll\n"),
644 relocs
[i
]->howto
->bitsize
);
650 /* Warning: the allocated symbols are remembered in BFD and reused
651 later, so don't free them! */
656 /* At this point, we have total_relocs relocation addresses in
657 reloc_addresses, which are all suitable for the .reloc section.
658 We must now create the new sections. */
660 qsort (reloc_addresses
, total_relocs
, sizeof (unsigned long), reloc_sort
);
662 for (i
= 0; i
< total_relocs
; i
++)
664 unsigned long this_page
= (reloc_addresses
[i
] >> 12);
665 if (this_page
!= sec_page
)
667 reloc_sz
= (reloc_sz
+ 3) & ~3; /* 4-byte align */
669 sec_page
= this_page
;
673 reloc_sz
= (reloc_sz
+ 3) & ~3; /* 4-byte align */
675 reloc_d
= (unsigned char *) xmalloc (reloc_sz
);
677 sec_page
= (unsigned long) (-1);
679 page_ptr
= (unsigned long) (-1);
681 for (i
= 0; i
< total_relocs
; i
++)
683 unsigned long rva
= reloc_addresses
[i
] - image_base
;
684 unsigned long this_page
= (rva
& ~0xfff);
685 if (this_page
!= sec_page
)
688 reloc_d
[reloc_sz
++] = 0;
689 if (page_ptr
!= (unsigned long) (-1))
690 bfd_put_32 (abfd
, reloc_sz
- page_ptr
, reloc_d
+ page_ptr
+ 4);
691 bfd_put_32 (abfd
, this_page
, reloc_d
+ reloc_sz
);
694 sec_page
= this_page
;
697 bfd_put_16 (abfd
, (rva
& 0xfff) + 0x3000, reloc_d
+ reloc_sz
);
702 reloc_d
[reloc_sz
++] = 0;
703 if (page_ptr
!= (unsigned long) (-1))
704 bfd_put_32 (abfd
, reloc_sz
- page_ptr
, reloc_d
+ page_ptr
+ 4);
705 while (reloc_sz
< reloc_s
->_raw_size
)
706 reloc_d
[reloc_sz
++] = 0;
709 /************************************************************************
711 Given the exiting def_file structure, print out a .DEF file that
714 ************************************************************************/
717 quoteput (s
, f
, needs_quotes
)
723 for (cp
= s
; *cp
; cp
++)
724 if (*cp
== '\'' || *cp
== '"' || *cp
== '\\' || isspace (*cp
) || *cp
== ','
732 if (*s
== '"' || *s
== '\\')
744 pe_dll_generate_def_file (pe_out_def_filename
)
745 char *pe_out_def_filename
;
748 FILE *out
= fopen (pe_out_def_filename
, "w");
751 /* xgettext:c-format */
752 einfo (_("%s: Can't open output def file %s\n"),
753 program_name
, pe_out_def_filename
);
756 if (pe_def_file
->name
)
758 if (pe_def_file
->is_dll
)
759 fprintf (out
, "LIBRARY ");
761 fprintf (out
, "NAME ");
762 quoteput (pe_def_file
->name
, out
, 1);
763 if (pe_def_file
->base_address
!= (bfd_vma
) (-1))
764 fprintf (out
, " BASE=0x%x", pe_def_file
->base_address
);
768 if (pe_def_file
->description
)
770 fprintf (out
, "DESCRIPTION ");
771 quoteput (pe_def_file
->description
, out
, 1);
775 if (pe_def_file
->version_minor
)
776 fprintf (out
, "VERSION %d.%d\n", pe_def_file
->version_major
,
777 pe_def_file
->version_minor
);
779 fprintf (out
, "VERSION %d\n", pe_def_file
->version_major
);
781 if (pe_def_file
->stack_reserve
!= -1 || pe_def_file
->heap_reserve
!= -1)
784 if (pe_def_file
->stack_commit
!= -1)
785 fprintf (out
, "STACKSIZE 0x%x,0x%x\n",
786 pe_def_file
->stack_reserve
, pe_def_file
->stack_commit
);
787 else if (pe_def_file
->stack_reserve
!= -1)
788 fprintf (out
, "STACKSIZE 0x%x\n", pe_def_file
->stack_reserve
);
789 if (pe_def_file
->heap_commit
!= -1)
790 fprintf (out
, "HEAPSIZE 0x%x,0x%x\n",
791 pe_def_file
->heap_reserve
, pe_def_file
->heap_commit
);
792 else if (pe_def_file
->heap_reserve
!= -1)
793 fprintf (out
, "HEAPSIZE 0x%x\n", pe_def_file
->heap_reserve
);
795 if (pe_def_file
->num_section_defs
> 0)
797 fprintf (out
, "\nSECTIONS\n\n");
798 for (i
= 0; i
< pe_def_file
->num_section_defs
; i
++)
801 quoteput (pe_def_file
->section_defs
[i
].name
, out
, 0);
802 if (pe_def_file
->section_defs
[i
].class)
804 fprintf (out
, " CLASS ");
805 quoteput (pe_def_file
->section_defs
[i
].class, out
, 0);
807 if (pe_def_file
->section_defs
[i
].flag_read
)
808 fprintf (out
, " READ");
809 if (pe_def_file
->section_defs
[i
].flag_write
)
810 fprintf (out
, " WRITE");
811 if (pe_def_file
->section_defs
[i
].flag_execute
)
812 fprintf (out
, " EXECUTE");
813 if (pe_def_file
->section_defs
[i
].flag_shared
)
814 fprintf (out
, " SHARED");
819 if (pe_def_file
->num_exports
> 0)
821 fprintf (out
, "\nEXPORTS\n\n");
822 for (i
= 0; i
< pe_def_file
->num_exports
; i
++)
824 def_file_export
*e
= pe_def_file
->exports
+ i
;
826 quoteput (e
->name
, out
, 0);
827 if (e
->internal_name
&& strcmp (e
->internal_name
, e
->name
))
829 fprintf (out
, " = ");
830 quoteput (e
->internal_name
, out
, 0);
832 if (e
->ordinal
!= -1)
833 fprintf (out
, " @%d", e
->ordinal
);
835 fprintf (out
, " PRIVATE");
836 if (e
->flag_constant
)
837 fprintf (out
, " CONSTANT");
839 fprintf (out
, " NONAME");
841 fprintf (out
, " DATA");
847 if (pe_def_file
->num_imports
> 0)
849 fprintf (out
, "\nIMPORTS\n\n");
850 for (i
= 0; i
< pe_def_file
->num_imports
; i
++)
852 def_file_import
*im
= pe_def_file
->imports
+ i
;
854 if (im
->internal_name
855 && (!im
->name
|| strcmp (im
->internal_name
, im
->name
)))
857 quoteput (im
->internal_name
, out
, 0);
858 fprintf (out
, " = ");
860 quoteput (im
->module
, out
, 0);
863 quoteput (im
->name
, out
, 0);
865 fprintf (out
, "%d", im
->ordinal
);
870 if (fclose (out
) == EOF
)
872 /* xgettext:c-format */
873 einfo (_("%P: Error closing file `%s'\n"), pe_out_def_filename
);
877 /************************************************************************
879 These are the main functions, called from the emulation. The first
880 is called after the bfds are read, so we can guess at how much space
881 we need. The second is called after everything is placed, so we
882 can put the right values in place.
884 ************************************************************************/
887 pe_dll_build_sections (abfd
, info
)
889 struct bfd_link_info
*info
;
891 process_def_file (abfd
, info
);
893 generate_edata (abfd
, info
);
898 pe_dll_fill_sections (abfd
, info
)
900 struct bfd_link_info
*info
;
902 image_base
= pe_data (abfd
)->pe_opthdr
.ImageBase
;
904 generate_reloc (abfd
, info
);
907 bfd_set_section_size (filler_bfd
, reloc_s
, reloc_sz
);
909 /* Resize the sections. */
910 lang_size_sections (stat_ptr
->head
, abs_output_section
,
911 &stat_ptr
->head
, 0, (bfd_vma
) 0, false);
913 /* Redo special stuff. */
914 ldemul_after_allocation ();
916 /* Do the assignments again. */
917 lang_do_assignments (stat_ptr
->head
,
919 (fill_type
) 0, (bfd_vma
) 0);
922 fill_edata (abfd
, info
);
924 pe_data (abfd
)->dll
= 1;
926 edata_s
->contents
= edata_d
;
927 reloc_s
->contents
= reloc_d
;