From a4dcd9a06a1b6ef3350fc0308ecbfb1fdea3a53c Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 14 Oct 2017 20:57:15 -0400 Subject: binutils-2.24.51: added mdso integration support. --- binutils-2.24.51.midipix.patch | 349 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 326 insertions(+), 23 deletions(-) (limited to 'binutils-2.24.51.midipix.patch') diff --git a/binutils-2.24.51.midipix.patch b/binutils-2.24.51.midipix.patch index ae08861..68e6ec9 100644 --- a/binutils-2.24.51.midipix.patch +++ b/binutils-2.24.51.midipix.patch @@ -40,7 +40,7 @@ diff -ru --new-file a/bfd/midipix.h b/bfd/midipix.h +esac diff -ru --new-file a/ld/emultempl/pe.em b/ld/emultempl/pe.em --- a/ld/emultempl/pe.em 2014-07-03 01:37:48.000000000 -0400 -+++ b/ld/emultempl/pe.em 2015-11-25 09:02:09.729144140 -0500 ++++ b/ld/emultempl/pe.em 2017-10-14 20:05:15.268012525 -0400 @@ -35,6 +35,18 @@ only determine if the subsystem is console or windows in order to select the correct entry point by default. */ @@ -60,7 +60,7 @@ diff -ru --new-file a/ld/emultempl/pe.em b/ld/emultempl/pe.em #define TARGET_IS_${EMULATION_NAME} /* Do this before including bfd.h, so we prototype the right functions. */ -@@ -132,7 +144,7 @@ +@@ -132,13 +144,15 @@ static char * thumb_entry_symbol = NULL; static lang_assignment_statement_type *image_base_statement = 0; static unsigned short pe_dll_characteristics = 0; @@ -69,7 +69,35 @@ diff -ru --new-file a/ld/emultempl/pe.em b/ld/emultempl/pe.em static const char *emit_build_id; #ifdef DLL_SUPPORT -@@ -471,8 +483,8 @@ + static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable. */ + static char *pe_out_def_filename = NULL; + static char *pe_implib_filename = NULL; ++static char * pe_dsolib_filename = NULL; ++static char * pe_dsolib_loader_path = NULL; + static int pe_enable_auto_image_base = 0; + static unsigned long pe_auto_image_base = 0x61500000; + static char *pe_dll_search_prefix = NULL; +@@ -229,7 +243,9 @@ + #define OPTION_ENABLE_STDCALL_FIXUP (OPTION_STDCALL_ALIASES + 1) + #define OPTION_DISABLE_STDCALL_FIXUP (OPTION_ENABLE_STDCALL_FIXUP + 1) + #define OPTION_IMPLIB_FILENAME (OPTION_DISABLE_STDCALL_FIXUP + 1) +-#define OPTION_THUMB_ENTRY (OPTION_IMPLIB_FILENAME + 1) ++#define OPTION_DSOLIB_FILENAME (OPTION_IMPLIB_FILENAME + 1) ++#define OPTION_DSOLIB_LOADER_PATH (OPTION_DSOLIB_FILENAME + 1) ++#define OPTION_THUMB_ENTRY (OPTION_DSOLIB_LOADER_PATH + 1) + #define OPTION_WARN_DUPLICATE_EXPORTS (OPTION_THUMB_ENTRY + 1) + #define OPTION_IMP_COMPAT (OPTION_WARN_DUPLICATE_EXPORTS + 1) + #define OPTION_ENABLE_AUTO_IMAGE_BASE (OPTION_IMP_COMPAT + 1) +@@ -324,6 +340,8 @@ + {"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-dsolib", required_argument, NULL, OPTION_DSOLIB_FILENAME}, ++ {"dsolib-loader-path", required_argument, NULL, OPTION_DSOLIB_LOADER_PATH}, + {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS}, + /* getopt() allows abbreviations, so we do this to stop it from + treating -c as an abbreviation for these --compat-implib. */ +@@ -471,8 +489,8 @@ specifically set with --image-base\n")); fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n")); fprintf (file, _(" --dll-search-prefix= When linking dynamically to a dll without\n\ @@ -80,7 +108,20 @@ diff -ru --new-file a/ld/emultempl/pe.em b/ld/emultempl/pe.em fprintf (file, _(" --enable-auto-import Do sophisticated linking of _sym to\n\ __imp_sym for DATA references\n")); fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n")); -@@ -1698,7 +1710,7 @@ +@@ -808,6 +826,12 @@ + case OPTION_IMPLIB_FILENAME: + pe_implib_filename = xstrdup (optarg); + break; ++ case OPTION_DSOLIB_FILENAME: ++ pe_dsolib_filename = xstrdup (optarg); ++ break; ++ case OPTION_DSOLIB_LOADER_PATH: ++ pe_dsolib_loader_path = xstrdup (optarg); ++ break; + case OPTION_WARN_DUPLICATE_EXPORTS: + pe_dll_warn_dup_exports = 1; + break; +@@ -1698,7 +1722,7 @@ extension, and use that for the remainder of the comparisons. */ pnt = strrchr (is3->the_bfd->filename, '.'); @@ -89,7 +130,7 @@ diff -ru --new-file a/ld/emultempl/pe.em b/ld/emultempl/pe.em break; } -@@ -1733,7 +1745,7 @@ +@@ -1733,7 +1757,7 @@ then leave the filename alone. */ pnt = strrchr (is->the_bfd->filename, '.'); @@ -98,7 +139,22 @@ diff -ru --new-file a/ld/emultempl/pe.em b/ld/emultempl/pe.em { int idata2 = 0, reloc_count=0; asection *sec; -@@ -2298,10 +2310,14 @@ +@@ -2063,8 +2087,14 @@ + ) + { + pe_dll_fill_sections (link_info.output_bfd, &link_info); ++ ++ /* generate legacy implib? */ + if (pe_implib_filename) + pe_dll_generate_implib (pe_def_file, pe_implib_filename, &link_info); ++ ++ /* generate mdso implib? */ ++ if (pe_dsolib_filename) ++ pe_dll_generate_dsolib (pe_def_file, pe_dsolib_filename, pe_dsolib_loader_path, 32); + } + #if defined(TARGET_IS_shpe) + /* ARM doesn't need relocs. */ +@@ -2298,10 +2328,14 @@ } libname_fmt [] = { @@ -115,7 +171,7 @@ diff -ru --new-file a/ld/emultempl/pe.em b/ld/emultempl/pe.em /* "libfoo.a" could be either an import lib or a static lib. For backwards compatibility, libfoo.a needs to precede libfoo.dll and foo.dll in the search. */ -@@ -2310,10 +2326,10 @@ +@@ -2310,10 +2344,10 @@ { "%s.lib", FALSE }, #ifdef DLL_SUPPORT /* Try "foo.dll" (preferred dll name, if specified). */ @@ -130,7 +186,7 @@ diff -ru --new-file a/ld/emultempl/pe.em b/ld/emultempl/pe.em /* Note: If adding more formats to this table, make sure to check to diff -ru --new-file a/ld/emultempl/pep.em b/ld/emultempl/pep.em --- a/ld/emultempl/pep.em 2014-07-03 01:37:48.000000000 -0400 -+++ b/ld/emultempl/pep.em 2015-11-25 09:02:21.153143987 -0500 ++++ b/ld/emultempl/pep.em 2017-10-14 19:17:10.840545945 -0400 @@ -42,6 +42,18 @@ /* For WINDOWS_XP64 and higher */ /* Based on pe.em, but modified for 64 bit support. */ @@ -150,7 +206,7 @@ diff -ru --new-file a/ld/emultempl/pep.em b/ld/emultempl/pep.em #define TARGET_IS_${EMULATION_NAME} #define COFF_IMAGE_WITH_PE -@@ -147,7 +159,7 @@ +@@ -147,13 +159,15 @@ static int support_old_code = 0; static lang_assignment_statement_type *image_base_statement = 0; static unsigned short pe_dll_characteristics = 0; @@ -159,7 +215,33 @@ diff -ru --new-file a/ld/emultempl/pep.em b/ld/emultempl/pep.em static const char *emit_build_id; #ifdef DLL_SUPPORT -@@ -434,8 +446,8 @@ + static int pep_enable_stdcall_fixup = 1; /* 0=disable 1=enable (default). */ + static char * pep_out_def_filename = NULL; + static char * pep_implib_filename = NULL; ++static char * pep_dsolib_filename = NULL; ++static char * pep_dsolib_loader_path = NULL; + static int pep_enable_auto_image_base = 0; + static char * pep_dll_search_prefix = NULL; + #endif +@@ -218,6 +232,8 @@ + OPTION_ENABLE_STDCALL_FIXUP, + OPTION_DISABLE_STDCALL_FIXUP, + OPTION_IMPLIB_FILENAME, ++ OPTION_DSOLIB_FILENAME, ++ OPTION_DSOLIB_LOADER_PATH, + OPTION_WARN_DUPLICATE_EXPORTS, + OPTION_IMP_COMPAT, + OPTION_ENABLE_AUTO_IMAGE_BASE, +@@ -296,6 +312,8 @@ + {"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-dsolib", required_argument, NULL, OPTION_DSOLIB_FILENAME}, ++ {"dsolib-loader-path", required_argument, NULL, OPTION_DSOLIB_LOADER_PATH}, + {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS}, + /* getopt() allows abbreviations, so we do this to stop it from + treating -c as an abbreviation for these --compat-implib. */ +@@ -434,8 +452,8 @@ unless user specifies one\n")); fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n")); fprintf (file, _(" --dll-search-prefix= When linking dynamically to a dll without\n\ @@ -170,7 +252,20 @@ diff -ru --new-file a/ld/emultempl/pep.em b/ld/emultempl/pep.em fprintf (file, _(" --enable-auto-import Do sophisticated linking of _sym to\n\ __imp_sym for DATA references\n")); fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n")); -@@ -1635,7 +1647,7 @@ +@@ -760,6 +778,12 @@ + case OPTION_IMPLIB_FILENAME: + pep_implib_filename = xstrdup (optarg); + break; ++ case OPTION_DSOLIB_FILENAME: ++ pep_dsolib_filename = xstrdup (optarg); ++ break; ++ case OPTION_DSOLIB_LOADER_PATH: ++ pep_dsolib_loader_path = xstrdup (optarg); ++ break; + case OPTION_WARN_DUPLICATE_EXPORTS: + pep_dll_warn_dup_exports = 1; + break; +@@ -1635,7 +1659,7 @@ extension, and use that for the remainder of the comparisons. */ pnt = strrchr (is3->the_bfd->filename, '.'); @@ -179,7 +274,7 @@ diff -ru --new-file a/ld/emultempl/pep.em b/ld/emultempl/pep.em break; } -@@ -1670,7 +1682,7 @@ +@@ -1670,7 +1694,7 @@ then leave the filename alone. */ pnt = strrchr (is->the_bfd->filename, '.'); @@ -188,7 +283,22 @@ diff -ru --new-file a/ld/emultempl/pep.em b/ld/emultempl/pep.em { int idata2 = 0, reloc_count=0; asection *sec; -@@ -2062,10 +2074,14 @@ +@@ -1834,8 +1858,14 @@ + || (!link_info.relocatable && pep_def_file->num_exports != 0)) + { + pep_dll_fill_sections (link_info.output_bfd, &link_info); ++ ++ /* generate legacy implib? */ + if (pep_implib_filename) + pep_dll_generate_implib (pep_def_file, pep_implib_filename, &link_info); ++ ++ /* generate mdso implib? */ ++ if (pep_dsolib_filename) ++ pep_dll_generate_dsolib (pep_def_file, pep_dsolib_filename, pep_dsolib_loader_path, 64); + } + + if (pep_out_def_filename) +@@ -2062,10 +2092,14 @@ } libname_fmt [] = { @@ -205,7 +315,7 @@ diff -ru --new-file a/ld/emultempl/pep.em b/ld/emultempl/pep.em /* "libfoo.a" could be either an import lib or a static lib. For backwards compatibility, libfoo.a needs to precede libfoo.dll and foo.dll in the search. */ -@@ -2074,10 +2090,10 @@ +@@ -2074,10 +2108,10 @@ { "%s.lib", FALSE }, #ifdef DLL_SUPPORT /* Try "foo.dll" (preferred dll name, if specified). */ @@ -401,8 +511,16 @@ diff -ru --new-file a/binutils/winduni.c b/binutils/winduni.c { 737, "MS-GREEK" }, diff -ru a/ld/pe-dll.c b/ld/pe-dll.c --- a/ld/pe-dll.c 2014-07-03 01:37:48.000000000 -0400 -+++ b/ld/pe-dll.c 2015-06-13 20:08:00.160401506 -0400 -@@ -40,6 +40,7 @@ ++++ b/ld/pe-dll.c 2017-10-14 19:49:19.492911435 -0400 +@@ -27,6 +27,7 @@ + #include "safe-ctype.h" + + #include ++#include + + #include "ld.h" + #include "ldexp.h" +@@ -40,6 +41,7 @@ #include "coff/internal.h" #include "../bfd/libcoff.h" #include "deffile.h" @@ -410,7 +528,7 @@ diff -ru a/ld/pe-dll.c b/ld/pe-dll.c #ifdef pe_use_x86_64 -@@ -234,7 +235,11 @@ +@@ -234,7 +236,11 @@ { STRING_COMMA_LEN ("impure_ptr") }, { STRING_COMMA_LEN ("_impure_ptr") }, { STRING_COMMA_LEN ("_fmode") }, @@ -422,7 +540,7 @@ diff -ru a/ld/pe-dll.c b/ld/pe-dll.c { NULL, 0 } }; -@@ -644,10 +649,13 @@ +@@ -644,10 +650,13 @@ { int i, j; struct bfd_link_hash_entry *blhe; @@ -436,7 +554,7 @@ diff -ru a/ld/pe-dll.c b/ld/pe-dll.c if (!pe_def_file) pe_def_file = def_file_empty (); -@@ -737,6 +745,16 @@ +@@ -737,6 +746,16 @@ if (is_import (sn)) continue; @@ -453,7 +571,7 @@ diff -ru a/ld/pe-dll.c b/ld/pe-dll.c name = xmalloc (strlen ("__imp_") + strlen (sn) + 1); sprintf (name, "%s%s", "__imp_", sn); -@@ -745,7 +763,8 @@ +@@ -745,7 +764,8 @@ free (name); if (blhe && blhe->type == bfd_link_hash_defined) @@ -463,7 +581,7 @@ diff -ru a/ld/pe-dll.c b/ld/pe-dll.c } if (pe_details->underscored && *sn == '_') -@@ -761,7 +780,20 @@ +@@ -761,7 +781,20 @@ /* Fill data flag properly, from dlltool.c. */ if (!is_dup) p->flag_data = !(symbols[j]->flags & BSF_FUNCTION); @@ -484,7 +602,7 @@ diff -ru a/ld/pe-dll.c b/ld/pe-dll.c } } } -@@ -910,6 +942,7 @@ +@@ -910,6 +943,7 @@ if (blhe && (blhe->type == bfd_link_hash_defined @@ -492,7 +610,7 @@ diff -ru a/ld/pe-dll.c b/ld/pe-dll.c || (blhe->type == bfd_link_hash_common))) { count_exported++; -@@ -919,7 +952,7 @@ +@@ -919,7 +953,7 @@ /* Only fill in the sections. The actual offsets are computed in fill_exported_offsets() after common symbols are laid out. */ @@ -501,6 +619,191 @@ diff -ru a/ld/pe-dll.c b/ld/pe-dll.c exported_symbol_sections[i] = blhe->u.def.section; else exported_symbol_sections[i] = blhe->u.c.p->section; +@@ -2688,6 +2722,150 @@ + } + + ++ ++ ++void ++pe_dll_generate_dsolib( ++ def_file * def, ++ const char * dsolib_file_name, ++ const char * loader_path, ++ unsigned char bits) ++{ ++ char * mdso_exe_path; ++ char * slash; ++ char * mark; ++ FILE * fout; ++ char * argv[10]; ++ int fd[2]; ++ int pid; ++ int rpid; ++ int ecode; ++ int i; ++ ++ /* sigh; even though pe_dll_generate_implib() might fail, */ ++ /* ld's _finish() code path assumes no errors could occur */ ++ /* and accordingly does not perform any checks upon return. */ ++ /* handle errors here and invoke xexit() as needed. */ ++ ++ /* bits */ ++ if ((bits != 32) && (bits != 64)) { ++ fprintf(stderr,"%s: internal error (bits == %d.\n",program_name,bits); ++ xexit(EXIT_FAILURE); ++ } ++ ++ /* mdso_exe_path buffer alloc */ ++ if (!(mdso_exe_path = calloc(1,strlen(program_name) + strlen("mdso") + 1))) { ++ fprintf(stderr,"%s: cannot allocate mdso_exe_path buffer.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++ ++ /* mdso_exe_path init */ ++ strcpy(mdso_exe_path,program_name); ++ ++ if ((slash = strrchr(mdso_exe_path,'/'))) ++ slash++; ++ else ++ slash = mdso_exe_path; ++ ++ if ((mark = strrchr(slash,'-'))) ++ mark++; ++ else ++ mark = slash; ++ ++ sprintf(mark,"%s","mdso"); ++ ++ /* pipe */ ++ if (pipe(fd)) { ++ fprintf(stderr,"%s: cannot create a pipe.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++ ++ /* fout init */ ++ if (!(fout = fdopen(fd[1],"a"))) { ++ fprintf(stderr,"%s: pipe fdopen failed.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++ ++ /* fork */ ++ if ((pid = fork()) < 0) { ++ fprintf(stderr,"%s: fork failed.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++ ++ /* child: execvp */ ++ if (pid == 0) { ++ argv[0] = mdso_exe_path; ++ argv[1] = (bits == 64) ? "-m64" : "-m32"; ++ argv[2] = "--implib"; ++ argv[3] = (char *)dsolib_file_name; ++ argv[4] = "--libname"; ++ argv[5] = (def->name) ? def->name : (char *)dll_name; ++ ++ if (loader_path) { ++ argv[6] = "--libpath"; ++ argv[7] = (char *)loader_path; ++ argv[8] = "-"; ++ argv[9] = 0; ++ } else { ++ argv[6] = "-"; ++ argv[7] = 0; ++ } ++ ++ fclose(fout); ++ close(fd[1]); ++ close(0); ++ ++ if (dup(fd[0]) == 0) ++ execvp(mdso_exe_path,argv); ++ ++ exit(EXIT_FAILURE); ++ } ++ ++ /* be good */ ++ free(mdso_exe_path); ++ ++ /* parent: expsyms --> pipe */ ++ for (i=0; i < def->num_exports; i++) { ++ if (!(pe_def_file->exports[i].flag_private)) { ++ if (fprintf(fout,"%s\n",def->exports[i].name) < 0) { ++ fprintf(stderr,"%s: pipe write operation failed.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++ } ++ } ++ ++ if (fflush(fout) < 0) { ++ fprintf(stderr,"%s: pipe fflush operation failed.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++ ++ fclose(fout); ++ close(fd[0]); ++ ++ /* obtain child exit status */ ++ if ((rpid = waitpid(pid,&ecode,0)) < 0) { ++ fprintf(stderr,"%s: waitpid operation failed.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++ ++ if (rpid != pid) { ++ fprintf(stderr,"%s: waitpid returned an unexpected pid.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++ ++ if (!(WIFEXITED(ecode))) { ++ fprintf(stderr,"%s: waitpid reported abnormal child process termination.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++ ++ if (WEXITSTATUS(ecode)) { ++ fprintf(stderr,"%s: the child process returned an error.\n",program_name); ++ xexit(EXIT_FAILURE); ++ } ++} ++ ++ ++ + void + pe_dll_generate_implib (def_file *def, const char *impfilename, struct bfd_link_info *info) + { +diff -ru a/ld/pe-dll.h b/ld/pe-dll.h +--- a/ld/pe-dll.h 2014-07-03 01:37:48.000000000 -0400 ++++ b/ld/pe-dll.h 2017-10-14 20:01:45.817295022 -0400 +@@ -49,6 +49,8 @@ + (const char *); + extern void pe_dll_generate_implib + (def_file *, const char *, struct bfd_link_info *); ++extern void pe_dll_generate_dsolib ++ (def_file *, const char *, const char *, unsigned char); + extern void pe_process_import_defs + (bfd *, struct bfd_link_info *); + extern bfd_boolean pe_implied_import_dll +diff -ru a/ld/pep-dll.c b/ld/pep-dll.c +--- a/ld/pep-dll.c 2014-07-03 01:37:48.000000000 -0400 ++++ b/ld/pep-dll.c 2017-10-14 10:14:35.490521636 -0400 +@@ -54,6 +54,7 @@ + #define pe_dll_fill_sections pep_dll_fill_sections + #define pe_exe_fill_sections pep_exe_fill_sections + #define pe_dll_generate_implib pep_dll_generate_implib ++#define pe_dll_generate_dsolib pep_dll_generate_dsolib + #define pe_dll_add_excludes pep_dll_add_excludes + #define pe_walk_relocs_of_symbol pep_walk_relocs_of_symbol + #define pe_bfd_is_dll pep_bfd_is_dll +diff -ru a/ld/pep-dll.h b/ld/pep-dll.h +--- a/ld/pep-dll.h 2014-07-03 01:37:48.000000000 -0400 ++++ b/ld/pep-dll.h 2017-10-14 19:17:26.885792850 -0400 +@@ -46,6 +46,7 @@ + extern void pep_dll_add_excludes (const char *, const exclude_type); + extern void pep_dll_generate_def_file (const char *); + extern void pep_dll_generate_implib (def_file *, const char *, struct bfd_link_info *); ++extern void pep_dll_generate_dsolib (def_file *, const char *, const char *, unsigned char); + extern void pep_process_import_defs (bfd *, struct bfd_link_info *); + extern bfd_boolean pep_implied_import_dll (const char *); + extern void pep_dll_build_sections (bfd *, struct bfd_link_info *); diff -ru --new-file a/bfd/config.bfd b/bfd/config.bfd --- a/bfd/config.bfd 2014-07-03 01:37:20.000000000 -0400 +++ b/bfd/config.bfd 2015-02-14 11:27:08.199179775 -0500 -- cgit v1.2.3