--- pe-dll.c.orig Fri Apr 26 17:23:34 2002 +++ pe-dll.c Fri Apr 26 21:55:42 2002 @@ -120,6 +120,8 @@ See also: ld/emultempl/pe.em. */ +extern int pe_implib_ordinal; + static void add_bfd_to_link PARAMS ((bfd *, const char *, struct bfd_link_info *)); @@ -1895,6 +1897,8 @@ make_one (exp, parent) return abfd; } +extern long pe_data_import_ordinal; + static bfd * make_singleton_name_thunk (import, parent) const char *import; @@ -1927,6 +1931,14 @@ make_singleton_name_thunk (import, paren d4 = (unsigned char *) xmalloc (4); id4->contents = d4; memset (d4, 0, 8); + + /* handle ordinal linking */ + if (pe_data_import_ordinal) { + d4[0]= pe_data_import_ordinal; + d4[1]= pe_data_import_ordinal>>8; + d4[3]= 0x80; + } + else quick_reloc (abfd, 0, BFD_RELOC_RVA, 2); save_relocs (id4); @@ -2121,6 +2133,10 @@ pe_dll_generate_implib (def, impfilename bfd *n; def->exports[i].internal_name = def->exports[i].name; + + if (pe_implib_ordinal) { + def->exports[i].flag_noname = 1; + } n = make_one (def->exports + i, outarch); n->next = head; head = n; --- emultempl/pe.em.orig Tue Apr 23 13:47:55 2002 +++ emultempl/pe.em Fri Apr 26 22:20:13 2002 @@ -153,6 +153,7 @@ static char *pe_out_def_filename = NULL; static char *pe_implib_filename = NULL; static int pe_enable_auto_image_base = 0; static char *pe_dll_search_prefix = NULL; +int pe_implib_ordinal = 0; #endif extern const char *output_filename; @@ -221,6 +222,7 @@ gld_${EMULATION_NAME}_before_parse() #define OPTION_DLL_ENABLE_AUTO_IMPORT (OPTION_NO_DEFAULT_EXCLUDES + 1) #define OPTION_DLL_DISABLE_AUTO_IMPORT (OPTION_DLL_ENABLE_AUTO_IMPORT + 1) #define OPTION_ENABLE_EXTRA_PE_DEBUG (OPTION_DLL_DISABLE_AUTO_IMPORT + 1) +#define OPTION_IMPLIB_ORDINAL (OPTION_ENABLE_EXTRA_PE_DEBUG + 1) static struct option longopts[] = { /* PE options */ @@ -252,6 +254,7 @@ static struct option longopts[] = { {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP}, {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP}, {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME}, + {"out-implib-ordinal", required_argument, NULL, OPTION_IMPLIB_ORDINAL}, {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS}, {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT}, {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE}, @@ -336,6 +339,8 @@ gld_${EMULATION_NAME}_list_options (file fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n")); fprintf (file, _(" --kill-at Remove @nn from exported symbols\n")); fprintf (file, _(" --out-implib Generate import library\n")); + fprintf (file, _(" --out-implib-ordinal Generate import library using ordinals \n")); + fprintf (file, _(" instead of names\n")); fprintf (file, _(" --output-def Generate a .DEF file for the built DLL\n")); fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n")); fprintf (file, _(" --compat-implib Create backward compatible import libs;\n")); @@ -630,6 +635,10 @@ gld_${EMULATION_NAME}_parse_args(argc, a case OPTION_ENABLE_EXTRA_PE_DEBUG: pe_dll_extra_pe_debug = 1; break; + case OPTION_IMPLIB_ORDINAL: + pe_implib_filename = xstrdup (optarg); + pe_implib_ordinal = 1; + break; #endif } return 1; @@ -885,6 +894,57 @@ make_import_fixup (rel, s) return 1; } +void get_data_import_ordinal(bfd *b) +{ + struct sec *s = bfd_get_section_by_name (b, ".idata$5"); + if (s) + { + int size = bfd_get_section_size_before_reloc (s); + char *buf = xmalloc (size); + + bfd_get_section_contents (b, s, buf, 0, size); + pe_data_import_ordinal = *(unsigned short *)buf; + if (pe_dll_extra_pe_debug) + printf("#%04x\n",pe_data_import_ordinal); + free (buf); + } + else + pe_data_import_ordinal = 0; +} + + +/* ordinal linking + +ordinal import library object file + +d001500.o: file format pe-i386 + +Contents of section .idata$7: + 0000 00000000 .... +Contents of section .idata$5: + 0000 dc050080 .... + ^^^^^ + This value is used + +Contents of section .idata$4: + 0000 dc050080 .... + + +regular import library object file + +d001500.o: file format pe-i386 + +Contents of section .idata$7: + 0000 00000000 .... +Contents of section .idata$5: + 0000 00000000 .... +Contents of section .idata$4: + 0000 00000000 .... +Contents of section .idata$6: + 0000 db057661 72303439 39000000 ..var0499... + ^^^^ + This value seems also be usable (not implemented yet) +*/ static void pe_find_data_imports () @@ -916,6 +976,8 @@ pe_find_data_imports () symbols = (asymbol **) xmalloc (symsize); nsyms = bfd_canonicalize_symtab (b, symbols); + get_data_import_ordinal(b); + for (i = 0; i < nsyms; i++) { if (memcmp(symbols[i]->name, "__head_",