+ for (i = 0; i < ARRAY_SIZE (temp_file_to_remove); i++)
+ {
+ if (temp_file_to_remove[i])
+ {
+ unlink (temp_file_to_remove[i]);
+ temp_file_to_remove[i] = NULL;
+ }
+ }
+}
+
+static void
+gen_exp_file (void)
+{
+ FILE *f;
+ int i;
+ export_type *exp;
+ dlist_type *dl;
+
+ /* xgettext:c-format */
+ inform (_("Generating export file: %s"), exp_name);
+
+ f = fopen (TMP_ASM, FOPEN_WT);
+ if (!f)
+ /* xgettext:c-format */
+ fatal (_("Unable to open temporary assembler file: %s"), TMP_ASM);
+
+ temp_file_to_remove[TEMP_EXPORT_FILE] = TMP_ASM;
+
+ /* xgettext:c-format */
+ inform (_("Opened temporary file: %s"), TMP_ASM);
+
+ dump_def_info (f);
+
+ if (d_exports)
+ {
+ fprintf (f, "\t.section .edata\n\n");
+ fprintf (f, "\t%s 0 %s Allways 0\n", ASM_LONG, ASM_C);
+ fprintf (f, "\t%s 0x%lx %s Time and date\n", ASM_LONG,
+ (unsigned long) time(0), ASM_C);
+ fprintf (f, "\t%s 0 %s Major and Minor version\n", ASM_LONG, ASM_C);
+ fprintf (f, "\t%sname%s %s Ptr to name of dll\n", ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
+ fprintf (f, "\t%s %d %s Starting ordinal of exports\n", ASM_LONG, d_low_ord, ASM_C);
+
+
+ fprintf (f, "\t%s %d %s Number of functions\n", ASM_LONG, d_high_ord - d_low_ord + 1, ASM_C);
+ fprintf(f,"\t%s named funcs %d, low ord %d, high ord %d\n",
+ ASM_C,
+ d_named_nfuncs, d_low_ord, d_high_ord);
+ fprintf (f, "\t%s %d %s Number of names\n", ASM_LONG,
+ show_allnames ? d_high_ord - d_low_ord + 1 : d_named_nfuncs, ASM_C);
+ fprintf (f, "\t%safuncs%s %s Address of functions\n", ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
+
+ fprintf (f, "\t%sanames%s %s Address of Name Pointer Table\n",
+ ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
+
+ fprintf (f, "\t%sanords%s %s Address of ordinals\n", ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
+
+ fprintf (f, "name: %s \"%s\"\n", ASM_TEXT, dll_name);
+
+
+ fprintf(f,"%s Export address Table\n", ASM_C);
+ fprintf(f,"\t%s\n", ASM_ALIGN_LONG);
+ fprintf (f, "afuncs:\n");
+ i = d_low_ord;
+
+ for (exp = d_exports; exp; exp = exp->next)
+ {
+ if (exp->ordinal != i)
+ {
+ while (i < exp->ordinal)
+ {
+ fprintf(f,"\t%s\t0\n", ASM_LONG);
+ i++;
+ }
+ }
+
+ if (exp->forward == 0)
+ {
+ if (exp->internal_name[0] == '@')
+ fprintf (f, "\t%s%s%s\t%s %d\n", ASM_RVA_BEFORE,
+ exp->internal_name, ASM_RVA_AFTER, ASM_C, exp->ordinal);
+ else
+ fprintf (f, "\t%s%s%s%s\t%s %d\n", ASM_RVA_BEFORE,
+ ASM_PREFIX (exp->internal_name),
+ exp->internal_name, ASM_RVA_AFTER, ASM_C, exp->ordinal);
+ }
+ else
+ fprintf (f, "\t%sf%d%s\t%s %d\n", ASM_RVA_BEFORE,
+ exp->forward, ASM_RVA_AFTER, ASM_C, exp->ordinal);
+ i++;
+ }
+
+ fprintf (f,"%s Export Name Pointer Table\n", ASM_C);
+ fprintf (f, "anames:\n");
+
+ for (i = 0; (exp = d_exports_lexically[i]); i++)
+ {
+ if (!exp->noname || show_allnames)
+ fprintf (f, "\t%sn%d%s\n",
+ ASM_RVA_BEFORE, exp->ordinal, ASM_RVA_AFTER);
+ }
+
+ fprintf (f,"%s Export Ordinal Table\n", ASM_C);
+ fprintf (f, "anords:\n");
+ for (i = 0; (exp = d_exports_lexically[i]); i++)
+ {
+ if (!exp->noname || show_allnames)
+ fprintf (f, "\t%s %d\n", ASM_SHORT, exp->ordinal - d_low_ord);
+ }
+
+ fprintf(f,"%s Export Name Table\n", ASM_C);
+ for (i = 0; (exp = d_exports_lexically[i]); i++)
+ {
+ if (!exp->noname || show_allnames)
+ fprintf (f, "n%d: %s \"%s\"\n",
+ exp->ordinal, ASM_TEXT,
+ (exp->its_name ? exp->its_name : xlate (exp->name)));
+ if (exp->forward != 0)
+ fprintf (f, "f%d: %s \"%s\"\n",
+ exp->forward, ASM_TEXT, exp->internal_name);
+ }
+
+ if (a_list)
+ {
+ fprintf (f, "\t.section %s\n", DRECTVE_SECTION_NAME);
+ for (dl = a_list; dl; dl = dl->next)
+ {
+ fprintf (f, "\t%s\t\"%s\"\n", ASM_TEXT, dl->text);
+ }
+ }
+
+ if (d_list)
+ {
+ fprintf (f, "\t.section .rdata\n");
+ for (dl = d_list; dl; dl = dl->next)
+ {
+ char *p;
+ int l;
+
+ /* We don't output as ascii because there can
+ be quote characters in the string. */
+ l = 0;
+ for (p = dl->text; *p; p++)
+ {
+ if (l == 0)
+ fprintf (f, "\t%s\t", ASM_BYTE);
+ else
+ fprintf (f, ",");
+ fprintf (f, "%d", *p);
+ if (p[1] == 0)
+ {
+ fprintf (f, ",0\n");
+ break;
+ }
+ if (++l == 10)
+ {
+ fprintf (f, "\n");
+ l = 0;
+ }
+ }
+ }
+ }
+ }
+
+ /* Add to the output file a way of getting to the exported names
+ without using the import library. */
+ if (add_indirect)
+ {
+ fprintf (f, "\t.section\t.rdata\n");
+ for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
+ if (!exp->noname || show_allnames)
+ {
+ /* We use a single underscore for MS compatibility, and a
+ double underscore for backward compatibility with old
+ cygwin releases. */
+ if (create_compat_implib)
+ fprintf (f, "\t%s\t__imp_%s\n", ASM_GLOBAL, exp->name);
+ fprintf (f, "\t%s\t_imp_%s%s\n", ASM_GLOBAL,
+ (!leading_underscore ? "" : "_"), exp->name);
+ if (create_compat_implib)
+ fprintf (f, "__imp_%s:\n", exp->name);
+ fprintf (f, "_imp_%s%s:\n", (!leading_underscore ? "" : "_"), exp->name);
+ fprintf (f, "\t%s\t%s\n", ASM_LONG, exp->name);
+ }
+ }
+
+ /* Dump the reloc section if a base file is provided. */
+ if (base_file)
+ {
+ bfd_vma addr;
+ bfd_vma need[COFF_PAGE_SIZE];
+ bfd_vma page_addr;
+ bfd_size_type numbytes;
+ int num_entries;
+ bfd_vma *copy;
+ int j;
+ int on_page;
+ fprintf (f, "\t.section\t.init\n");
+ fprintf (f, "lab:\n");
+
+ fseek (base_file, 0, SEEK_END);
+ numbytes = ftell (base_file);
+ fseek (base_file, 0, SEEK_SET);
+ copy = xmalloc (numbytes);
+ if (fread (copy, 1, numbytes, base_file) < numbytes)
+ fatal (_("failed to read the number of entries from base file"));
+ num_entries = numbytes / sizeof (bfd_vma);
+
+
+ fprintf (f, "\t.section\t.reloc\n");
+ if (num_entries)
+ {
+ int src;
+ int dst = 0;
+ bfd_vma last = (bfd_vma) -1;
+ qsort (copy, num_entries, sizeof (bfd_vma), sfunc);
+ /* Delete duplicates */
+ for (src = 0; src < num_entries; src++)
+ {
+ if (last != copy[src])
+ last = copy[dst++] = copy[src];
+ }
+ num_entries = dst;
+ addr = copy[0];
+ page_addr = addr & PAGE_MASK; /* work out the page addr */
+ on_page = 0;
+ for (j = 0; j < num_entries; j++)
+ {
+ addr = copy[j];
+ if ((addr & PAGE_MASK) != page_addr)
+ {
+ flush_page (f, need, page_addr, on_page);
+ on_page = 0;
+ page_addr = addr & PAGE_MASK;
+ }
+ need[on_page++] = addr;
+ }
+ flush_page (f, need, page_addr, on_page);
+
+/* fprintf (f, "\t%s\t0,0\t%s End\n", ASM_LONG, ASM_C);*/
+ }
+ }
+
+ generate_idata_ofile (f);
+
+ fclose (f);
+
+ /* Assemble the file. */
+ assemble_file (TMP_ASM, exp_name);
+
+ if (dontdeltemps == 0)
+ {
+ temp_file_to_remove[TEMP_EXPORT_FILE] = NULL;
+ unlink (TMP_ASM);
+ }
+
+ inform (_("Generated exports file"));
+}
+
+static const char *
+xlate (const char *name)
+{
+ int lead_at = (*name == '@');
+ int is_stdcall = (!lead_at && strchr (name, '@') != NULL);
+
+ if (!lead_at && (add_underscore
+ || (add_stdcall_underscore && is_stdcall)))
+ {
+ char *copy = xmalloc (strlen (name) + 2);
+
+ copy[0] = '_';
+ strcpy (copy + 1, name);
+ name = copy;
+ }
+
+ if (killat)
+ {
+ char *p;
+
+ name += lead_at;
+ /* PR 9766: Look for the last @ sign in the name. */
+ p = strrchr (name, '@');
+ if (p && ISDIGIT (p[1]))
+ *p = 0;
+ }
+ return name;
+}
+
+typedef struct
+{
+ int id;
+ const char *name;
+ int flags;
+ int align;
+ asection *sec;
+ asymbol *sym;
+ asymbol **sympp;
+ int size;
+ unsigned char *data;
+} sinfo;
+
+#define INIT_SEC_DATA(id, name, flags, align) \
+ { id, name, flags, align, NULL, NULL, NULL, 0, NULL }
+
+#ifndef DLLTOOL_PPC
+
+#define TEXT 0
+#define DATA 1
+#define BSS 2
+#define IDATA7 3
+#define IDATA5 4
+#define IDATA4 5
+#define IDATA6 6
+
+#define NSECS 7
+
+#define TEXT_SEC_FLAGS \
+ (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS)
+#define DATA_SEC_FLAGS (SEC_ALLOC | SEC_LOAD | SEC_DATA)
+#define BSS_SEC_FLAGS SEC_ALLOC
+
+static sinfo secdata[NSECS] =
+{
+ INIT_SEC_DATA (TEXT, ".text", TEXT_SEC_FLAGS, 2),
+ INIT_SEC_DATA (DATA, ".data", DATA_SEC_FLAGS, 2),
+ INIT_SEC_DATA (BSS, ".bss", BSS_SEC_FLAGS, 2),
+ INIT_SEC_DATA (IDATA7, ".idata$7", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (IDATA5, ".idata$5", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (IDATA4, ".idata$4", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (IDATA6, ".idata$6", SEC_HAS_CONTENTS, 1)
+};
+
+#else
+
+/* Sections numbered to make the order the same as other PowerPC NT
+ compilers. This also keeps funny alignment thingies from happening. */
+#define TEXT 0
+#define PDATA 1
+#define RDATA 2
+#define IDATA5 3
+#define IDATA4 4
+#define IDATA6 5
+#define IDATA7 6
+#define DATA 7
+#define BSS 8
+
+#define NSECS 9
+
+static sinfo secdata[NSECS] =
+{
+ INIT_SEC_DATA (TEXT, ".text", SEC_CODE | SEC_HAS_CONTENTS, 3),
+ INIT_SEC_DATA (PDATA, ".pdata", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (RDATA, ".reldata", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (IDATA5, ".idata$5", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (IDATA4, ".idata$4", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (IDATA6, ".idata$6", SEC_HAS_CONTENTS, 1),
+ INIT_SEC_DATA (IDATA7, ".idata$7", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (DATA, ".data", SEC_DATA, 2),
+ INIT_SEC_DATA (BSS, ".bss", 0, 2)
+};
+
+#endif
+
+/* This is what we're trying to make. We generate the imp symbols with
+ both single and double underscores, for compatibility.
+
+ .text
+ .global _GetFileVersionInfoSizeW@8
+ .global __imp_GetFileVersionInfoSizeW@8
+_GetFileVersionInfoSizeW@8:
+ jmp * __imp_GetFileVersionInfoSizeW@8
+ .section .idata$7 # To force loading of head
+ .long __version_a_head
+# Import Address Table
+ .section .idata$5
+__imp_GetFileVersionInfoSizeW@8:
+ .rva ID2
+
+# Import Lookup Table
+ .section .idata$4
+ .rva ID2
+# Hint/Name table
+ .section .idata$6
+ID2: .short 2
+ .asciz "GetFileVersionInfoSizeW"
+
+
+ For the PowerPC, here's the variation on the above scheme:
+
+# Rather than a simple "jmp *", the code to get to the dll function
+# looks like:
+ .text
+ lwz r11,[tocv]__imp_function_name(r2)
+# RELOC: 00000000 TOCREL16,TOCDEFN __imp_function_name
+ lwz r12,0(r11)
+ stw r2,4(r1)
+ mtctr r12
+ lwz r2,4(r11)
+ bctr */
+
+static char *
+make_label (const char *prefix, const char *name)
+{
+ int len = strlen (ASM_PREFIX (name)) + strlen (prefix) + strlen (name);
+ char *copy = xmalloc (len + 1);
+
+ strcpy (copy, ASM_PREFIX (name));
+ strcat (copy, prefix);
+ strcat (copy, name);
+ return copy;
+}
+
+static char *
+make_imp_label (const char *prefix, const char *name)
+{
+ int len;
+ char *copy;
+
+ if (name[0] == '@')
+ {
+ len = strlen (prefix) + strlen (name);
+ copy = xmalloc (len + 1);
+ strcpy (copy, prefix);
+ strcat (copy, name);
+ }
+ else
+ {
+ len = strlen (ASM_PREFIX (name)) + strlen (prefix) + strlen (name);
+ copy = xmalloc (len + 1);
+ strcpy (copy, prefix);
+ strcat (copy, ASM_PREFIX (name));
+ strcat (copy, name);
+ }
+ return copy;
+}
+
+static bfd *
+make_one_lib_file (export_type *exp, int i, int delay)
+{
+ bfd * abfd;
+ asymbol * exp_label;
+ asymbol * iname = 0;
+ asymbol * iname2;
+ asymbol * iname_lab;
+ asymbol ** iname_lab_pp;
+ asymbol ** iname_pp;
+#ifdef DLLTOOL_PPC
+ asymbol ** fn_pp;
+ asymbol ** toc_pp;
+#define EXTRA 2
+#endif
+#ifndef EXTRA
+#define EXTRA 0
+#endif
+ asymbol * ptrs[NSECS + 4 + EXTRA + 1];
+ flagword applicable;
+ char * outname = xmalloc (strlen (TMP_STUB) + 10);
+ int oidx = 0;
+
+
+ sprintf (outname, "%s%05d.o", TMP_STUB, i);
+
+ abfd = bfd_openw (outname, HOW_BFD_WRITE_TARGET);
+
+ if (!abfd)
+ /* xgettext:c-format */
+ fatal (_("bfd_open failed open stub file: %s: %s"),
+ outname, bfd_get_errmsg ());
+
+ /* xgettext:c-format */
+ inform (_("Creating stub file: %s"), outname);
+
+ bfd_set_format (abfd, bfd_object);
+ bfd_set_arch_mach (abfd, HOW_BFD_ARCH, 0);
+
+#ifdef DLLTOOL_ARM
+ if (machine == MARM_INTERWORK || machine == MTHUMB)
+ bfd_set_private_flags (abfd, F_INTERWORK);
+#endif
+
+ applicable = bfd_applicable_section_flags (abfd);
+
+ /* First make symbols for the sections. */
+ for (i = 0; i < NSECS; i++)
+ {
+ sinfo *si = secdata + i;
+
+ if (si->id != i)
+ abort ();
+ si->sec = bfd_make_section_old_way (abfd, si->name);
+ bfd_set_section_flags (si->sec, si->flags & applicable);
+
+ bfd_set_section_alignment (si->sec, si->align);
+ si->sec->output_section = si->sec;
+ si->sym = bfd_make_empty_symbol(abfd);
+ si->sym->name = si->sec->name;
+ si->sym->section = si->sec;
+ si->sym->flags = BSF_LOCAL;
+ si->sym->value = 0;
+ ptrs[oidx] = si->sym;
+ si->sympp = ptrs + oidx;
+ si->size = 0;
+ si->data = NULL;
+
+ oidx++;
+ }
+
+ if (! exp->data)
+ {
+ exp_label = bfd_make_empty_symbol (abfd);
+ exp_label->name = make_imp_label ("", exp->name);
+
+ /* On PowerPC, the function name points to a descriptor in
+ the rdata section, the first element of which is a
+ pointer to the code (..function_name), and the second
+ points to the .toc. */
+#ifdef DLLTOOL_PPC
+ if (machine == MPPC)
+ exp_label->section = secdata[RDATA].sec;
+ else
+#endif
+ exp_label->section = secdata[TEXT].sec;
+
+ exp_label->flags = BSF_GLOBAL;
+ exp_label->value = 0;
+
+#ifdef DLLTOOL_ARM
+ if (machine == MTHUMB)
+ bfd_coff_set_symbol_class (abfd, exp_label, C_THUMBEXTFUNC);
+#endif
+ ptrs[oidx++] = exp_label;
+ }
+
+ /* Generate imp symbols with one underscore for Microsoft
+ compatibility, and with two underscores for backward
+ compatibility with old versions of cygwin. */
+ if (create_compat_implib)
+ {
+ iname = bfd_make_empty_symbol (abfd);
+ iname->name = make_imp_label ("___imp", exp->name);
+ iname->section = secdata[IDATA5].sec;
+ iname->flags = BSF_GLOBAL;
+ iname->value = 0;
+ }
+
+ iname2 = bfd_make_empty_symbol (abfd);
+ iname2->name = make_imp_label ("__imp_", exp->name);
+ iname2->section = secdata[IDATA5].sec;
+ iname2->flags = BSF_GLOBAL;
+ iname2->value = 0;
+
+ iname_lab = bfd_make_empty_symbol (abfd);
+
+ iname_lab->name = head_label;
+ iname_lab->section = bfd_und_section_ptr;
+ iname_lab->flags = 0;
+ iname_lab->value = 0;
+
+ iname_pp = ptrs + oidx;
+ if (create_compat_implib)
+ ptrs[oidx++] = iname;
+ ptrs[oidx++] = iname2;
+
+ iname_lab_pp = ptrs + oidx;
+ ptrs[oidx++] = iname_lab;
+
+#ifdef DLLTOOL_PPC
+ /* The symbol referring to the code (.text). */
+ {
+ asymbol *function_name;
+
+ function_name = bfd_make_empty_symbol(abfd);
+ function_name->name = make_label ("..", exp->name);
+ function_name->section = secdata[TEXT].sec;
+ function_name->flags = BSF_GLOBAL;
+ function_name->value = 0;
+
+ fn_pp = ptrs + oidx;
+ ptrs[oidx++] = function_name;
+ }
+
+ /* The .toc symbol. */
+ {
+ asymbol *toc_symbol;
+
+ toc_symbol = bfd_make_empty_symbol (abfd);
+ toc_symbol->name = make_label (".", "toc");
+ toc_symbol->section = bfd_und_section_ptr;
+ toc_symbol->flags = BSF_GLOBAL;
+ toc_symbol->value = 0;
+
+ toc_pp = ptrs + oidx;
+ ptrs[oidx++] = toc_symbol;
+ }
+#endif
+
+ ptrs[oidx] = 0;
+
+ for (i = 0; i < NSECS; i++)
+ {
+ sinfo *si = secdata + i;
+ asection *sec = si->sec;
+ arelent *rel, *rel2 = 0, *rel3 = 0;
+ arelent **rpp;
+
+ switch (i)
+ {
+ case TEXT:
+ if (! exp->data)
+ {
+ si->size = HOW_JTAB_SIZE;
+ si->data = xmalloc (HOW_JTAB_SIZE);
+ memcpy (si->data, HOW_JTAB, HOW_JTAB_SIZE);
+
+ /* Add the reloc into idata$5. */
+ rel = xmalloc (sizeof (arelent));
+
+ rpp = xmalloc (sizeof (arelent *) * (delay ? 4 : 2));
+ rpp[0] = rel;
+ rpp[1] = 0;
+
+ rel->address = HOW_JTAB_ROFF;
+ rel->addend = 0;
+
+ if (delay)
+ {
+ rel2 = xmalloc (sizeof (arelent));
+ rpp[1] = rel2;
+ rel2->address = HOW_JTAB_ROFF2;
+ rel2->addend = 0;
+ rel3 = xmalloc (sizeof (arelent));
+ rpp[2] = rel3;
+ rel3->address = HOW_JTAB_ROFF3;
+ rel3->addend = 0;
+ rpp[3] = 0;
+ }
+
+ if (machine == MPPC)
+ {
+ rel->howto = bfd_reloc_type_lookup (abfd,
+ BFD_RELOC_16_GOTOFF);
+ rel->sym_ptr_ptr = iname_pp;
+ }
+ else if (machine == MX86)
+ {
+ rel->howto = bfd_reloc_type_lookup (abfd,
+ BFD_RELOC_32_PCREL);
+ rel->sym_ptr_ptr = iname_pp;
+ }
+ else
+ {
+ rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+ rel->sym_ptr_ptr = secdata[IDATA5].sympp;
+ }
+
+ if (delay)
+ {
+ if (machine == MX86)
+ rel2->howto = bfd_reloc_type_lookup (abfd,
+ BFD_RELOC_32_PCREL);
+ else
+ rel2->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+ rel2->sym_ptr_ptr = rel->sym_ptr_ptr;
+ rel3->howto = bfd_reloc_type_lookup (abfd,
+ BFD_RELOC_32_PCREL);
+ rel3->sym_ptr_ptr = iname_lab_pp;
+ }
+
+ sec->orelocation = rpp;
+ sec->reloc_count = delay ? 3 : 1;
+ }
+ break;
+
+ case IDATA5:
+ if (delay)
+ {
+ si->size = create_for_pep ? 8 : 4;
+ si->data = xmalloc (si->size);
+ sec->reloc_count = 1;
+ memset (si->data, 0, si->size);
+ /* Point after jmp [__imp_...] instruction. */
+ si->data[0] = 6;
+ rel = xmalloc (sizeof (arelent));
+ rpp = xmalloc (sizeof (arelent *) * 2);
+ rpp[0] = rel;
+ rpp[1] = 0;
+ rel->address = 0;
+ rel->addend = 0;
+ if (create_for_pep)
+ rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_64);
+ else
+ rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+ rel->sym_ptr_ptr = secdata[TEXT].sympp;
+ sec->orelocation = rpp;
+ break;
+ }
+ /* Fall through. */
+
+ case IDATA4:
+ /* An idata$4 or idata$5 is one word long, and has an
+ rva to idata$6. */
+
+ if (create_for_pep)
+ {
+ si->data = xmalloc (8);
+ si->size = 8;
+ if (exp->noname)
+ {
+ si->data[0] = exp->ordinal ;
+ si->data[1] = exp->ordinal >> 8;
+ si->data[2] = exp->ordinal >> 16;
+ si->data[3] = exp->ordinal >> 24;
+ si->data[4] = 0;
+ si->data[5] = 0;
+ si->data[6] = 0;
+ si->data[7] = 0x80;
+ }
+ else
+ {
+ sec->reloc_count = 1;
+ memset (si->data, 0, si->size);
+ rel = xmalloc (sizeof (arelent));
+ rpp = xmalloc (sizeof (arelent *) * 2);
+ rpp[0] = rel;
+ rpp[1] = 0;
+ rel->address = 0;
+ rel->addend = 0;
+ rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_RVA);
+ rel->sym_ptr_ptr = secdata[IDATA6].sympp;
+ sec->orelocation = rpp;
+ }
+ }
+ else
+ {
+ si->data = xmalloc (4);
+ si->size = 4;
+
+ if (exp->noname)
+ {
+ si->data[0] = exp->ordinal ;
+ si->data[1] = exp->ordinal >> 8;
+ si->data[2] = exp->ordinal >> 16;
+ si->data[3] = 0x80;
+ }
+ else
+ {
+ sec->reloc_count = 1;
+ memset (si->data, 0, si->size);
+ rel = xmalloc (sizeof (arelent));
+ rpp = xmalloc (sizeof (arelent *) * 2);
+ rpp[0] = rel;
+ rpp[1] = 0;
+ rel->address = 0;
+ rel->addend = 0;
+ rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_RVA);
+ rel->sym_ptr_ptr = secdata[IDATA6].sympp;
+ sec->orelocation = rpp;
+ }
+ }
+ break;
+
+ case IDATA6:
+ if (!exp->noname)
+ {
+ int idx = exp->ordinal;
+
+ if (exp->its_name)
+ si->size = strlen (exp->its_name) + 3;
+ else
+ si->size = strlen (xlate (exp->import_name)) + 3;
+ si->data = xmalloc (si->size);
+ memset (si->data, 0, si->size);
+ si->data[0] = idx & 0xff;
+ si->data[1] = idx >> 8;
+ if (exp->its_name)
+ strcpy ((char *) si->data + 2, exp->its_name);
+ else
+ strcpy ((char *) si->data + 2, xlate (exp->import_name));
+ }
+ break;
+ case IDATA7:
+ if (delay)
+ break;
+ si->size = 4;
+ si->data = xmalloc (4);
+ memset (si->data, 0, si->size);
+ rel = xmalloc (sizeof (arelent));
+ rpp = xmalloc (sizeof (arelent *) * 2);
+ rpp[0] = rel;
+ rel->address = 0;
+ rel->addend = 0;
+ rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_RVA);
+ rel->sym_ptr_ptr = iname_lab_pp;
+ sec->orelocation = rpp;
+ sec->reloc_count = 1;
+ break;
+
+#ifdef DLLTOOL_PPC
+ case PDATA:
+ {
+ /* The .pdata section is 5 words long.
+ Think of it as:
+ struct
+ {
+ bfd_vma BeginAddress, [0x00]
+ EndAddress, [0x04]
+ ExceptionHandler, [0x08]
+ HandlerData, [0x0c]
+ PrologEndAddress; [0x10]
+ }; */
+
+ /* So this pdata section setups up this as a glue linkage to
+ a dll routine. There are a number of house keeping things
+ we need to do:
+
+ 1. In the name of glue trickery, the ADDR32 relocs for 0,
+ 4, and 0x10 are set to point to the same place:
+ "..function_name".
+ 2. There is one more reloc needed in the pdata section.
+ The actual glue instruction to restore the toc on
+ return is saved as the offset in an IMGLUE reloc.
+ So we need a total of four relocs for this section.
+
+ 3. Lastly, the HandlerData field is set to 0x03, to indicate
+ that this is a glue routine. */
+ arelent *imglue, *ba_rel, *ea_rel, *pea_rel;
+
+ /* Alignment must be set to 2**2 or you get extra stuff. */
+ bfd_set_section_alignment (sec, 2);
+
+ si->size = 4 * 5;
+ si->data = xmalloc (si->size);
+ memset (si->data, 0, si->size);
+ rpp = xmalloc (sizeof (arelent *) * 5);
+ rpp[0] = imglue = xmalloc (sizeof (arelent));
+ rpp[1] = ba_rel = xmalloc (sizeof (arelent));
+ rpp[2] = ea_rel = xmalloc (sizeof (arelent));
+ rpp[3] = pea_rel = xmalloc (sizeof (arelent));
+ rpp[4] = 0;
+
+ /* Stick the toc reload instruction in the glue reloc. */
+ bfd_put_32(abfd, ppc_glue_insn, (char *) &imglue->address);
+
+ imglue->addend = 0;
+ imglue->howto = bfd_reloc_type_lookup (abfd,
+ BFD_RELOC_32_GOTOFF);
+ imglue->sym_ptr_ptr = fn_pp;
+
+ ba_rel->address = 0;
+ ba_rel->addend = 0;
+ ba_rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+ ba_rel->sym_ptr_ptr = fn_pp;
+
+ bfd_put_32 (abfd, 0x18, si->data + 0x04);
+ ea_rel->address = 4;
+ ea_rel->addend = 0;
+ ea_rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+ ea_rel->sym_ptr_ptr = fn_pp;
+
+ /* Mark it as glue. */
+ bfd_put_32 (abfd, 0x03, si->data + 0x0c);
+
+ /* Mark the prolog end address. */
+ bfd_put_32 (abfd, 0x0D, si->data + 0x10);
+ pea_rel->address = 0x10;
+ pea_rel->addend = 0;
+ pea_rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+ pea_rel->sym_ptr_ptr = fn_pp;
+
+ sec->orelocation = rpp;
+ sec->reloc_count = 4;
+ break;
+ }
+ case RDATA:
+ /* Each external function in a PowerPC PE file has a two word
+ descriptor consisting of:
+ 1. The address of the code.
+ 2. The address of the appropriate .toc
+ We use relocs to build this. */
+ si->size = 8;
+ si->data = xmalloc (8);
+ memset (si->data, 0, si->size);
+
+ rpp = xmalloc (sizeof (arelent *) * 3);
+ rpp[0] = rel = xmalloc (sizeof (arelent));
+ rpp[1] = xmalloc (sizeof (arelent));
+ rpp[2] = 0;
+
+ rel->address = 0;
+ rel->addend = 0;
+ rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+ rel->sym_ptr_ptr = fn_pp;
+
+ rel = rpp[1];
+
+ rel->address = 4;
+ rel->addend = 0;
+ rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+ rel->sym_ptr_ptr = toc_pp;
+
+ sec->orelocation = rpp;
+ sec->reloc_count = 2;
+ break;
+#endif /* DLLTOOL_PPC */
+ }
+ }
+
+ {
+ bfd_vma vma = 0;
+ /* Size up all the sections. */
+ for (i = 0; i < NSECS; i++)
+ {
+ sinfo *si = secdata + i;
+
+ bfd_set_section_size (si->sec, si->size);
+ bfd_set_section_vma (si->sec, vma);
+ }
+ }
+ /* Write them out. */
+ for (i = 0; i < NSECS; i++)
+ {
+ sinfo *si = secdata + i;