Index: pe-dll.c =================================================================== RCS file: /cvs/uberbaum/ld/pe-dll.c,v retrieving revision 1.41 diff -u -p -2 -r1.41 pe-dll.c --- pe-dll.c 25 May 2002 20:39:25 -0000 1.41 +++ pe-dll.c 28 Jun 2002 09:11:56 -0000 @@ -302,4 +302,6 @@ static char *make_import_fixup_mark PARA static bfd *make_import_fixup_entry PARAMS ((const char *, const char *, const char *, bfd *)); +static bfd *make_cygreloc_fixup_entry + PARAMS ((const char *, const char *, int, bfd *)); static unsigned int pe_get16 PARAMS ((bfd *, int)); static unsigned int pe_get32 PARAMS ((bfd *, int)); @@ -2068,7 +2070,58 @@ make_import_fixup_entry (name, fixup_nam } +/* .section .data_cygwin_reloc + .long addend + .rva __fuNN_SYM (pointer to reference (address) in text) */ + +static bfd * +make_cygreloc_fixup_entry (name, fixup_name, addend, parent) + const char *name ATTRIBUTE_UNUSED; + const char *fixup_name; + int addend; + bfd *parent; +{ + asection *cygrel; + unsigned char *cygrel_d; + char *oname; + bfd *abfd; + + oname = (char *) xmalloc (20); + sprintf (oname, "cr%06d.o", tmp_seq); + tmp_seq++; + + abfd = bfd_create (oname, parent); + bfd_find_target (pe_details->object_target, abfd); + bfd_make_writable (abfd); + + bfd_set_format (abfd, bfd_object); + bfd_set_arch_mach (abfd, pe_details->bfd_arch, 0); + + symptr = 0; + symtab = (asymbol **) xmalloc (2 * sizeof (asymbol *)); + cygrel = quick_section (abfd, ".data_cygwin_reloc", SEC_HAS_CONTENTS, 2); + + quick_symbol (abfd, "", fixup_name, "", UNDSEC, BSF_GLOBAL, 0); + + bfd_set_section_size (abfd, cygrel, 8); + cygrel_d = (unsigned char *) xmalloc (8); + cygrel->contents = cygrel_d; + memset (cygrel_d, 0, 8); + bfd_put_32 (abfd, addend, cygrel_d); + + quick_reloc (abfd, 4, BFD_RELOC_RVA, 1); + save_relocs (cygrel); + + bfd_set_symtab (abfd, symtab, symptr); + + bfd_set_section_contents (abfd, cygrel, cygrel_d, 0, 8); + + bfd_make_readable (abfd); + return abfd; +} + void -pe_create_import_fixup (rel) +pe_create_import_fixup (rel, addend) arelent *rel; + int addend; { char buf[300]; @@ -2077,4 +2130,5 @@ pe_create_import_fixup (rel) const char *name = sym->name; char *fixup_name = make_import_fixup_mark (rel); + bfd *b; sprintf (buf, U ("_nm_thnk_%s"), name); @@ -2095,8 +2149,16 @@ pe_create_import_fixup (rel) char * dll_symname = pe_data_import_dll ? pe_data_import_dll : "unknown"; - bfd *b = make_import_fixup_entry (name, fixup_name, dll_symname, - output_bfd); + b = make_import_fixup_entry (name, fixup_name, dll_symname, output_bfd); add_bfd_to_link (b, b->filename, &link_info); } + + if (addend != 0) + { + if (pe_dll_extra_pe_debug) + printf ("creating cygreloc entry for %s (addend=%d)\n", + fixup_name, addend); + b = make_cygreloc_fixup_entry (name, fixup_name, addend, output_bfd); + add_bfd_to_link (b, b->filename, &link_info); + } } Index: pe-dll.h =================================================================== RCS file: /cvs/uberbaum/ld/pe-dll.h,v retrieving revision 1.8 diff -u -p -2 -r1.8 pe-dll.h --- pe-dll.h 8 Jun 2002 07:39:45 -0000 1.8 +++ pe-dll.h 28 Jun 2002 09:11:56 -0000 @@ -51,4 +51,4 @@ extern void pe_walk_relocs_of_symbol PAR int (*cb) (arelent *, asection *))); -extern void pe_create_import_fixup PARAMS ((arelent * rel)); +extern void pe_create_import_fixup PARAMS ((arelent * rel, int addend)); #endif /* PE_DLL_H */ Index: emultempl/pe.em =================================================================== RCS file: /cvs/uberbaum/ld/emultempl/pe.em,v retrieving revision 1.64 diff -u -p -2 -r1.64 pe.em --- emultempl/pe.em 7 Jun 2002 14:56:00 -0000 1.64 +++ emultempl/pe.em 28 Jun 2002 09:11:56 -0000 @@ -881,12 +881,5 @@ make_import_fixup (rel, s) } - if (addend == 0) - pe_create_import_fixup (rel); - else - { - einfo (_("%C: variable '%T' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.\n"), - s->owner, s, rel->address, sym->name); - einfo ("%X"); - } + pe_create_import_fixup (rel, addend); } Index: scripttempl/pe.sc =================================================================== RCS file: /cvs/uberbaum/ld/scripttempl/pe.sc,v retrieving revision 1.5 diff -u -p -2 -r1.5 pe.sc --- scripttempl/pe.sc 16 Jan 2002 01:48:43 -0000 1.5 +++ scripttempl/pe.sc 28 Jun 2002 09:11:57 -0000 @@ -76,4 +76,7 @@ SECTIONS *(.data) *(.data2) + ___CYGWIN_RELOC_LIST__ = .; __CYGWIN_RELOC_LIST__ = . ; + *(.data_cygwin_reloc) + ___CYGWIN_RELOC_LIST_END__ = .; __CYGWIN_RELOC_LIST_END__ = . ; ${R_DATA} ${RELOCATING+__data_end__ = . ;}