summaryrefslogtreecommitdiff
path: root/patches/binutils/binutils-2.24.51.midipix.patch
blob: 33114e1628bb530018adcfea1ef918d68acf98df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
diff --ru --new-file a/ld/ldfile.c b/ld/ldfile.c
--- a/ld/ldfile.c	2014-07-03 01:37:48.000000000 -0400
+++ b/ld/ldfile.c	2019-08-17 11:38:31.062209027 -0400
@@ -122,6 +122,16 @@ bfd_boolean
 ldfile_try_open_bfd (const char *attempt,
 		     lang_input_statement_type *entry)
 {
+
+#ifdef PE_TARGET_MDSO
+  if (!entry->flags.dynamic) {
+    (void)0;
+  } else  if (!(attempt = pe_mdso_input_name(attempt))) {
+    fprintf(stderr,"%s: pe_mdso_input_name() returned an error.\n",program_name);
+    xexit(EXIT_FAILURE);
+  }
+#endif
+
   entry->the_bfd = bfd_openr (attempt, entry->target);
 
   if (verbose)
diff -ru --new-file a/ld/configure b/ld/configure
--- a/ld/configure	2014-07-03 01:37:48.000000000 -0400
+++ b/ld/configure	2015-03-11 20:01:08.888756786 -0400
@@ -19773,3 +19773,31 @@
 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
 fi
 
+sed -i -e 's/@pe_executable_name@/'"$PE_EXECUTABLE_NAME"'/g' Makefile
+sed -i -e 's/@pe_framework_libs@/'"$PE_FRAMEWORK_LIBS"'/g' Makefile
+sed -i -e 's/@pe_crt_section@/'"$PE_CRT_SECTION"'/g' Makefile
+sed -i -e 's/@pe_cygwin_fork_support@/'"$PE_CYGWIN_FORK_SUPPORT"'/g' Makefile
+
+#PE custom import library support
+if [ -f peimplib.h ]; then
+	echo 'build directory is not clean (peimplib.h already exists)'
+	exit 2
+fi
+
+touch peimplib.h || exit 2
+
+case $target_os in
+	*midipix*)
+		cat >> peimplib.h << EOF
+/* PE target-specific bits, generated by ld/configure */
+#ifndef PE_TARGET_MIDIPIX
+#define PE_TARGET_MIDIPIX
+#endif
+
+#ifndef PE_TARGET_MDSO
+#define PE_TARGET_MDSO 1
+#endif
+
+#include "pe-mdso.h"
+EOF
+esac
diff --ru --new-file a/ld/sysdep.h b/ld/sysdep.h
--- a/ld/sysdep.h	2014-07-03 01:37:48.000000000 -0400
+++ b/ld/sysdep.h	2019-08-16 03:08:47.771929753 -0400
@@ -26,6 +26,7 @@
 #endif
 
 #include "config.h"
+#include "peimplib.h"
 
 #include <stdio.h>
 #include <sys/types.h>
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	2019-08-17 11:38:31.062209027 -0400
@@ -69,6 +69,14 @@ fragment <<EOF
 #include "ldbuildid.h"
 #include "coff/internal.h"
 
+#ifndef PE_IMPLIB_SUFFIX
+#define PE_IMPLIB_SUFFIX	".dll.a"
+#endif
+
+#ifndef PE_DSO_SUFFIX
+#define PE_DSO_SUFFIX		".dll"
+#endif
+
 /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
    header in generic PE code.  */
 #include "coff/i386.h"
@@ -132,13 +140,15 @@ static int support_old_code = 0;
 static char * thumb_entry_symbol = NULL;
 static lang_assignment_statement_type *image_base_statement = 0;
 static unsigned short pe_dll_characteristics = 0;
-static bfd_boolean insert_timestamp = TRUE;
+static bfd_boolean insert_timestamp = 0;
 static const char *emit_build_id;
 
 #ifdef DLL_SUPPORT
 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 +239,9 @@ fragment <<EOF
 #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 +336,8 @@ gld${EMULATION_NAME}_add_options
     {"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 +485,8 @@ gld_${EMULATION_NAME}_list_options (FILE *file)
                                        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=<string>       When linking dynamically to a dll without\n\
-                                       an importlib, use <string><basename>.dll\n\
-                                       in preference to lib<basename>.dll \n"));
+                                       an importlib, use <string><basename>"PE_DSO_SUFFIX"\n\
+                                       in preference to lib<basename>"PE_DSO_SUFFIX" \n"));
   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"));
@@ -808,6 +822,12 @@ gld${EMULATION_NAME}_handle_option (int optc)
     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 +1718,7 @@ gld_${EMULATION_NAME}_after_open (void)
 		       extension, and use that for the remainder of the
 		       comparisons.  */
 		    pnt = strrchr (is3->the_bfd->filename, '.');
-		    if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
+		    if (pnt != NULL && filename_cmp (pnt, PE_DSO_SUFFIX) == 0)
 		      break;
 		  }
 
@@ -1733,7 +1753,7 @@ gld_${EMULATION_NAME}_after_open (void)
 	       then leave the filename alone.  */
 	    pnt = strrchr (is->the_bfd->filename, '.');
 
-	    if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
+	    if (is_ms_arch && (filename_cmp (pnt, PE_DSO_SUFFIX) == 0))
 	      {
 		int idata2 = 0, reloc_count=0;
 		asection *sec;
@@ -2063,8 +2083,14 @@ gld_${EMULATION_NAME}_finish (void)
     )
     {
       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, 0, pe_dsolib_filename, pe_dsolib_loader_path, 32);
     }
 #if defined(TARGET_IS_shpe)
   /* ARM doesn't need relocs.  */
@@ -2298,16 +2324,25 @@ gld_${EMULATION_NAME}_open_dynamic_archive
     }
   libname_fmt [] =
     {
+      /* optionally support ldso-specific import libraries */
+      #ifdef PE_TARGET_MDSO
+      { "lib%s"PE_DSOLIB_SUFFIX, FALSE },
+      #endif
       /* Preferred explicit import library for dll's.  */
-      { "lib%s.dll.a", FALSE },
+      { "lib%s"PE_IMPLIB_SUFFIX, FALSE },
       /* Alternate explicit import library for dll's.  */
-      { "%s.dll.a", FALSE },
+      { "%s"PE_IMPLIB_SUFFIX, FALSE },
+#ifdef PE_TARGET_MDSO
+      /* libfoo.so precedes libfoo.a, generate mdso implib as needed */
+      {	"lib%s"PE_DSO_SUFFIX, FALSE },
+#endif
       /* "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.  */
       { "lib%s.a", FALSE },
       /* The 'native' spelling of an import lib name is "foo.lib".  */
       { "%s.lib", FALSE },
+#ifndef PE_TARGET_MDSO
 #ifdef DLL_SUPPORT
       /* Try "<prefix>foo.dll" (preferred dll name, if specified).  */
       {	"%s%s.dll", TRUE },
@@ -2316,6 +2351,7 @@ gld_${EMULATION_NAME}_open_dynamic_archive
       {	"lib%s.dll", FALSE },
       /* Finally try 'native' dll name "foo.dll".  */
       {  "%s.dll", FALSE },
+#endif
       /* Note: If adding more formats to this table, make sure to check to
 	 see if their length is longer than libname_fmt[0].format, and if
 	 so, update the call to xmalloc() below.  */
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	2019-08-17 11:38:31.062209027 -0400
@@ -67,6 +67,14 @@ fragment <<EOF
 #include "ldbuildid.h"
 #include "coff/internal.h"
 
+#ifndef PE_IMPLIB_SUFFIX
+#define PE_IMPLIB_SUFFIX	".dll.a"
+#endif
+
+#ifndef PE_DSO_SUFFIX
+#define PE_DSO_SUFFIX		".dll"
+#endif
+
 /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
    header in generic PE code.  */
 #include "coff/x86_64.h"
@@ -147,13 +155,15 @@ static flagword real_flags = IMAGE_FILE_LARGE_ADDRESS_AWARE;
 static int support_old_code = 0;
 static lang_assignment_statement_type *image_base_statement = 0;
 static unsigned short pe_dll_characteristics = 0;
-static bfd_boolean insert_timestamp = TRUE;
+static bfd_boolean insert_timestamp = 0;
 static const char *emit_build_id;
 
 #ifdef DLL_SUPPORT
 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 +228,8 @@ enum options
   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 +308,8 @@ gld${EMULATION_NAME}_add_options
     {"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 +448,8 @@ gld_${EMULATION_NAME}_list_options (FILE *file)
                                        unless user specifies one\n"));
   fprintf (file, _("  --disable-auto-image-base          Do not auto-choose image base. (default)\n"));
   fprintf (file, _("  --dll-search-prefix=<string>       When linking dynamically to a dll without\n\
-                                       an importlib, use <string><basename>.dll\n\
-                                       in preference to lib<basename>.dll \n"));
+                                       an importlib, use <string><basename>"PE_DSO_SUFFIX"\n\
+                                       in preference to lib<basename>"PE_DSO_SUFFIX" \n"));
   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"));
@@ -760,6 +774,12 @@ gld${EMULATION_NAME}_handle_option (int optc)
     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 +1655,7 @@ gld_${EMULATION_NAME}_after_open (void)
 		       extension, and use that for the remainder of the
 		       comparisons.  */
 		    pnt = strrchr (is3->the_bfd->filename, '.');
-		    if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
+		    if (pnt != NULL && filename_cmp (pnt, PE_DSO_SUFFIX) == 0)
 		      break;
 		  }
 
@@ -1670,7 +1690,7 @@ gld_${EMULATION_NAME}_after_open (void)
 	       then leave the filename alone.  */
 	    pnt = strrchr (is->the_bfd->filename, '.');
 
-	    if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
+	    if (is_ms_arch && (filename_cmp (pnt, PE_DSO_SUFFIX) == 0))
 	      {
 		int idata2 = 0, reloc_count=0;
 		asection *sec;
@@ -1834,8 +1854,14 @@ gld_${EMULATION_NAME}_finish (void)
       || (!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, 0, pep_dsolib_filename, pep_dsolib_loader_path, 64);
     }
 
   if (pep_out_def_filename)
@@ -2062,16 +2088,25 @@ gld_${EMULATION_NAME}_open_dynamic_archive
     }
   libname_fmt [] =
     {
+      /* optionally support ldso-specific import libraries */
+#ifdef PE_TARGET_MDSO
+      { "lib%s"PE_DSOLIB_SUFFIX, FALSE },
+#endif
       /* Preferred explicit import library for dll's.  */
-      { "lib%s.dll.a", FALSE },
+      { "lib%s"PE_IMPLIB_SUFFIX, FALSE },
       /* Alternate explicit import library for dll's.  */
-      { "%s.dll.a", FALSE },
+      { "%s"PE_IMPLIB_SUFFIX, FALSE },
+#ifdef PE_TARGET_MDSO
+      /* libfoo.so precedes libfoo.a, generate mdso implib as needed */
+      {	"lib%s"PE_DSO_SUFFIX, FALSE },
+#endif
       /* "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.  */
       { "lib%s.a", FALSE },
       /* The 'native' spelling of an import lib name is "foo.lib".  */
       { "%s.lib", FALSE },
+#ifndef PE_TARGET_MDSO
 #ifdef DLL_SUPPORT
       /* Try "<prefix>foo.dll" (preferred dll name, if specified).  */
       {	"%s%s.dll", TRUE },
@@ -2080,6 +2115,7 @@ gld_${EMULATION_NAME}_open_dynamic_archive
       {	"lib%s.dll", FALSE },
       /* Finally try 'native' dll name "foo.dll".  */
       {  "%s.dll", FALSE },
+#endif
       /* Note: If adding more formats to this table, make sure to check to
 	 see if their length is longer than libname_fmt[0].format, and if
 	 so, update the call to xmalloc() below.  */
diff -ru --new-file a/ld/configure.tgt b/ld/configure.tgt
--- a/ld/configure.tgt	2014-07-03 01:37:48.000000000 -0400
+++ b/ld/configure.tgt	2019-08-15 06:52:04.192983142 -0400
@@ -319,6 +319,12 @@
 			test "$targ" != "$host" && LIB_PATH='${tooldir}/lib/w32api' ;;
 i[3-7]86-*-mingw32*)	targ_emul=i386pe ;
 			targ_extra_ofiles="deffilep.o pe-dll.o" ;;
+i[3-7]86-*-midipix*)	targ_emul=i386pe ;
+			targ_extra_ofiles="deffilep.o pe-dll.o pe-mdso.o" ;
+			PE_FRAMEWORK_LIBS="-lperk -lmdso" ;
+			PE_EXECUTABLE_NAME=a.out ;
+			PE_CRT_SECTION=no ;
+			PE_CYGWIN_FORK_SUPPORT=no ;;
 x86_64-*-pe | x86_64-*-pep) targ_emul=i386pep ;
 			targ_extra_emuls=i386pe ;
 			targ_extra_ofiles="deffilep.o pep-dll.o pe-dll.o" ;;
@@ -329,7 +335,14 @@
 x86_64-*-mingw*)	targ_emul=i386pep ;
 			targ_extra_emuls=i386pe
 			targ_extra_ofiles="deffilep.o pep-dll.o pe-dll.o" ;;
-i[3-7]86-*-interix*)	targ_emul=i386pe_posix;
+x86_64-*-midipix*)	targ_emul=i386pep ;
+			targ_extra_emuls=i386pe ;
+			targ_extra_ofiles="deffilep.o pep-dll.o pe-dll.o pe-mdso.o" ;
+			PE_FRAMEWORK_LIBS="-lperk -lmdso" ;
+			PE_EXECUTABLE_NAME=a.out ;
+			PE_CRT_SECTION=no ;
+			PE_CYGWIN_FORK_SUPPORT=no ;;
+i[3-7]86-*-interix*)	targ_emul=i386pe_posix ;
  			targ_extra_ofiles="deffilep.o pe-dll.o" ;;
 i[3-7]86-*-beospe*)	targ_emul=i386beos ;;
 i[3-7]86-*-beos*)	targ_emul=elf_i386_be ;;
@@ -825,6 +838,10 @@
 *-*-linux*)
   ;;
 
+*-*-midipix*)
+  NATIVE_LIB_DIRS=
+  ;;
+
 *-*-netbsd*)
   ;;
 
diff -ru --new-file a/ld/Makefile.in b/ld/Makefile.in
--- a/ld/Makefile.in	2014-07-03 01:37:48.000000000 -0400
+++ b/ld/Makefile.in	2019-08-15 05:53:23.807970635 -0400
@@ -54,6 +54,10 @@
 host_triplet = @host@
 target_triplet = @target@
 bin_PROGRAMS = ld-new$(EXEEXT)
+PE_EXECUTABLE_NAME = @pe_executable_name@
+PE_FRAMEWORK_LIBS = @pe_framework_libs@
+PE_CRT_SECTION = @pe_crt_section@
+PE_CYGWIN_FORK_SUPPORT = @pe_cygwin_fork_support@
 
 # Automake 1.9 will only build info files in the objdir if they are
 # mentioned in DISTCLEANFILES.  It doesn't have to be unconditional,
@@ -831,7 +835,7 @@
 POTFILES = $(CFILES) $(HFILES) $(EMULATION_FILES)
 
 # These all start with e so 'make clean' can find them.
-GENSCRIPTS = LIB_PATH='${LIB_PATH}' $(SHELL) $(srcdir)/genscripts.sh "${srcdir}" "${libdir}" "${prefix}" "${exec_prefix}" @host@ @target@ @target_alias@ "@EMULATION_LIBPATH@" "@NATIVE_LIB_DIRS@" @use_sysroot@ @enable_initfini_array@
+GENSCRIPTS = EXECUTABLE_NAME='${PE_EXECUTABLE_NAME}' PE_FRAMEWORK_LIBS='${PE_FRAMEWORK_LIBS}' PE_CRT_SECTION='${PE_CRT_SECTION}' PE_CYGWIN_FORK_SUPPORT='${PE_CYGWIN_FORK_SUPPORT}' LIB_PATH='${LIB_PATH}' $(SHELL) $(srcdir)/genscripts.sh "${srcdir}" "${libdir}" "${prefix}" "${exec_prefix}" @host@ @target@ @target_alias@ "@EMULATION_LIBPATH@" "@NATIVE_LIB_DIRS@" @use_sysroot@ @enable_initfini_array@
 GEN_DEPENDS = $(srcdir)/genscripts.sh stringify.sed
 ELF_DEPS = $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/elf-generic.em $(srcdir)/scripttempl/DWARF.sc
 ELF_GEN_DEPS = $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em $(srcdir)/emultempl/genelf.em $(srcdir)/scripttempl/DWARF.sc
@@ -1032,7 +1036,7 @@
 	else :; fi
 ld-new$(EXEEXT): $(ld_new_OBJECTS) $(ld_new_DEPENDENCIES) 
 	@rm -f ld-new$(EXEEXT)
-	$(LINK) $(ld_new_OBJECTS) $(ld_new_LDADD) $(LIBS)
+	$(LINK) $(ld_new_OBJECTS) $(ld_new_LDADD) $(LIBS) $(PE_FRAMEWORK_LIBS)
 
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
@@ -3411,16 +3415,16 @@
 ld-partial.@OBJEXT@: ld-new$(EXEEXT)
 	./ld-new$(EXEEXT) $(HOSTING_EMU) -o ld-partial.@OBJEXT@ -r $(OFILES)
 ld1$(EXEEXT): ld-partial.@OBJEXT@
-	./ld-new$(EXEEXT) $(HOSTING_EMU) -o ld1$(EXEEXT) $(HOSTING_CRT0) ld-partial.@OBJEXT@ $(TESTBFDLIB) $(LIBIBERTY) $(HOSTING_LIBS) $(LIBS)
+	./ld-new$(EXEEXT) $(HOSTING_EMU) -o ld1$(EXEEXT) $(HOSTING_CRT0) ld-partial.@OBJEXT@ $(TESTBFDLIB) $(LIBIBERTY) $(HOSTING_LIBS) $(LIBS) $(PE_FRAMEWORK_LIBS)
 
 ld1-full$(EXEEXT): ld-new
-	./ld-new$(EXEEXT) $(HOSTING_EMU) -o ld1-full$(EXEEXT) $(HOSTING_CRT0) $(OFILES) $(TESTBFDLIB) $(LIBIBERTY) $(HOSTING_LIBS) $(LIBS)
+	./ld-new$(EXEEXT) $(HOSTING_EMU) -o ld1-full$(EXEEXT) $(HOSTING_CRT0) $(OFILES) $(TESTBFDLIB) $(LIBIBERTY) $(HOSTING_LIBS) $(LIBS) $(PE_FRAMEWORK_LIBS)
 
 ld2$(EXEEXT): ld1$(EXEEXT)
-	./ld1$(EXEEXT) $(HOSTING_EMU) -o ld2$(EXEEXT) $(HOSTING_CRT0) $(OFILES) $(TESTBFDLIB) $(LIBIBERTY) $(HOSTING_LIBS) $(LIBS)
+	./ld1$(EXEEXT) $(HOSTING_EMU) -o ld2$(EXEEXT) $(HOSTING_CRT0) $(OFILES) $(TESTBFDLIB) $(LIBIBERTY) $(HOSTING_LIBS) $(LIBS) $(PE_FRAMEWORK_LIBS)
 
 ld3$(EXEEXT): ld2$(EXEEXT)
-	./ld2$(EXEEXT) $(HOSTING_EMU) -o ld3$(EXEEXT) $(HOSTING_CRT0) $(OFILES) $(TESTBFDLIB) $(LIBIBERTY) $(HOSTING_LIBS) $(LIBS)
+	./ld2$(EXEEXT) $(HOSTING_EMU) -o ld3$(EXEEXT) $(HOSTING_CRT0) $(OFILES) $(TESTBFDLIB) $(LIBIBERTY) $(HOSTING_LIBS) $(LIBS) $(PE_FRAMEWORK_LIBS)
 
 bootstrap: ld3$(EXEEXT)
 	cmp ld2$(EXEEXT) ld3$(EXEEXT)
diff -ru --new-file a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc
--- a/ld/scripttempl/pep.sc	2014-07-03 01:37:48.000000000 -0400
+++ b/ld/scripttempl/pep.sc	2015-03-11 20:10:05.324773952 -0400
@@ -92,12 +92,17 @@
     ${RELOCATING+ *(.gcc_except_table)}
   }
 
+EOF
+if [ x"$PE_CYGWIN_FORK_SUPPORT" != xno ]; then cat << EOF
   /* The Cygwin32 library uses a section to avoid copying certain data
      on fork.  This used to be named ".data$nocopy".  The linker used
      to include this between __data_start__ and __data_end__, but that
      breaks building the cygwin32 dll.  Instead, we name the section
      ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
 
+EOF
+fi
+cat << EOF
   .data ${RELOCATING+BLOCK(__section_alignment__)} :
   {
     ${RELOCATING+__data_start__ = . ;}
@@ -106,7 +111,12 @@
     ${R_DATA}
     *(.jcr)
     ${RELOCATING+__data_end__ = . ;}
+EOF
+if [ x"$PE_CYGWIN_FORK_SUPPORT" != xno ]; then cat << EOF
     ${RELOCATING+*(.data_cygwin_nocopy)}
+EOF
+fi
+cat << EOF
   }
 
   .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
@@ -170,6 +180,8 @@
     ${RELOCATING+__IAT_end__ = .;}
     ${R_IDATA67}
   }
+EOF
+if [ x"$PE_CRT_SECTION" != xno ]; then cat << EOF
   .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
   { 					
     ${RELOCATING+___crt_xc_start__ = . ;}
@@ -188,6 +200,9 @@
     ${R_CRT_XT}
     ${RELOCATING+___crt_xt_end__ = . ;}
   }
+EOF
+fi
+cat << EOF
 
   /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
      at the end of the .tls section.  This is important because _tls_start MUST
diff -ru --new-file a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc
--- a/ld/scripttempl/pe.sc	2014-07-03 01:37:48.000000000 -0400
+++ b/ld/scripttempl/pe.sc	2015-03-11 20:10:10.036774102 -0400
@@ -92,12 +92,17 @@
     ${RELOCATING+ *(.gcc_except_table)}
   }
 
+EOF
+if [ x"$PE_CYGWIN_FORK_SUPPORT" != xno ]; then cat << EOF
   /* The Cygwin32 library uses a section to avoid copying certain data
      on fork.  This used to be named ".data$nocopy".  The linker used
      to include this between __data_start__ and __data_end__, but that
      breaks building the cygwin32 dll.  Instead, we name the section
      ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
 
+EOF
+fi
+cat << EOF
   .data ${RELOCATING+BLOCK(__section_alignment__)} :
   {
     ${RELOCATING+__data_start__ = . ;}
@@ -106,7 +111,12 @@
     ${R_DATA}
     *(.jcr)
     ${RELOCATING+__data_end__ = . ;}
+EOF
+if [ x"$PE_CYGWIN_FORK_SUPPORT" != xno ]; then cat << EOF
     ${RELOCATING+*(.data_cygwin_nocopy)}
+EOF
+fi
+cat << EOF
   }
 
   .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
@@ -165,6 +175,8 @@
     ${RELOCATING+__IAT_end__ = .;}
     ${R_IDATA67}
   }
+EOF
+if [ x"$PE_CRT_SECTION" != xno ]; then cat << EOF
   .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
   { 					
     ${RELOCATING+___crt_xc_start__ = . ;}
@@ -183,6 +195,9 @@
     ${R_CRT_XT}
     ${RELOCATING+___crt_xt_end__ = . ;}
   }
+EOF
+fi
+cat << EOF
 
   /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
      at the end of section.  This is important because _tls_start MUST
diff -ru --new-file a/binutils/winduni.c b/binutils/winduni.c
--- a/binutils/winduni.c	2014-07-03 01:37:23.000000000 -0400
+++ b/binutils/winduni.c	2015-02-14 11:18:32.987163288 -0500
@@ -57,7 +57,7 @@
 /* Codepages mapped.  */
 static local_iconv_map codepages[] =
 {
-  { 0, "MS-ANSI" },
+  { 0, "cp1252" },
   { 1, "WINDOWS-1252" },
   { 437, "MS-ANSI" },
   { 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	2019-06-30 22:22:22.643202346 -0400
@@ -27,6 +27,7 @@
 #include "safe-ctype.h"
 
 #include <time.h>
+#include <sys/wait.h>
 
 #include "ld.h"
 #include "ldexp.h"
@@ -40,6 +41,7 @@
 #include "coff/internal.h"
 #include "../bfd/libcoff.h"
 #include "deffile.h"
+#include "peimplib.h"
 
 #ifdef pe_use_x86_64
 
@@ -234,7 +236,11 @@
   { STRING_COMMA_LEN ("impure_ptr") },
   { STRING_COMMA_LEN ("_impure_ptr") },
   { STRING_COMMA_LEN ("_fmode") },
+  #ifdef PE_TARGET_MIDIPIX
+  /* (default) excluded symbols are defined by the caller (specs, etc.) */
+  #else
   { STRING_COMMA_LEN ("environ") },
+  #endif
   { NULL, 0 }
 };
 
@@ -644,10 +650,13 @@
 {
   int i, j;
   struct bfd_link_hash_entry *blhe;
+  struct bfd_link_hash_entry *blhew;
   bfd *b;
   struct bfd_section *s;
   def_file_export *e = 0;
   bfd_boolean resort_needed;
+  char *weaksym;
+  char *objsym;
 
   if (!pe_def_file)
     pe_def_file = def_file_empty ();
@@ -737,6 +746,16 @@
 		    if (is_import (sn))
 			  continue;
 
+		    if (!strncmp (sn, ".weak.", 6) && strchr (sn + 6, '.'))
+		      {
+		        objsym = strdup (sn);
+		        weaksym = strdup (sn + 6);
+		        *(strchr (weaksym, '.')) = '\0';
+		        sn = weaksym;
+		      }
+		    else
+		      weaksym = 0;
+
 		    name = xmalloc (strlen ("__imp_") + strlen (sn) + 1);
 		    sprintf (name, "%s%s", "__imp_", sn);
 
@@ -745,7 +764,9 @@
 		    free (name);
 
 		    if (blhe && blhe->type == bfd_link_hash_defined)
-		      continue;
+		      if (strncmp (blhe->u.def.section->name, ".got$", 5))
+		        if (strncmp (blhe->u.def.section->name, ".dsosyms$", 9))
+			  continue;
 		  }
 
 		  if (pe_details->underscored && *sn == '_')
@@ -756,12 +777,30 @@
 		      int is_dup = 0;
 		      def_file_export *p;
 
-		      p = def_file_add_export (pe_def_file, sn, 0, -1,
-					       NULL, &is_dup);
-		      /* Fill data flag properly, from dlltool.c.  */
-		      if (!is_dup)
-		        p->flag_data = !(symbols[j]->flags & BSF_FUNCTION);
-		    }
+                      if (weaksym) {
+                        blhew = bfd_link_hash_lookup (info->hash, weaksym,
+                                                      FALSE, FALSE, FALSE);
+                      }
+
+                      if (!weaksym || blhew) {
+                        p = def_file_add_export (pe_def_file, sn, 0, -1,
+                                                 NULL, &is_dup);
+
+                        /* Fill data flag properly, from dlltool.c.  */
+                        if (!is_dup)
+                          p->flag_data = !(symbols[j]->flags & BSF_FUNCTION);
+
+                        if (weaksym) {
+                          if (blhew->type != bfd_link_hash_defined) {
+                            free (p->internal_name);
+                            p->internal_name = objsym;
+                          }
+                        }
+
+                        if (weaksym)
+                          free (weaksym);
+                      }
+                    }
 		}
 	    }
 	}
@@ -910,6 +949,7 @@
 
       if (blhe
 	  && (blhe->type == bfd_link_hash_defined
+	      || (blhe->type == bfd_link_hash_defweak)
 	      || (blhe->type == bfd_link_hash_common)))
 	{
 	  count_exported++;
@@ -919,7 +959,7 @@
 	  /* Only fill in the sections. The actual offsets are computed
 	     in fill_exported_offsets() after common symbols are laid
 	     out.  */
-	  if (blhe->type == bfd_link_hash_defined)
+	  if ((blhe->type == bfd_link_hash_defined) || (blhe->type == bfd_link_hash_defweak))
 	    exported_symbol_sections[i] = blhe->u.def.section;
 	  else
 	    exported_symbol_sections[i] = blhe->u.c.p->section;
@@ -2688,6 +2728,160 @@
 }
 
 
+
+
+void
+pe_dll_generate_dsolib(
+	def_file *    def,
+	const char ** expsyms,
+	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 */
+	if (expsyms) {
+		for (; *expsyms; ) {
+			if (fprintf(fout,"%s\n",*expsyms++) < 0) {
+				fprintf(stderr,"%s: pipe write operation failed.\n",program_name);
+				xexit(EXIT_FAILURE);
+			}
+		}
+	} else {
+		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 *, 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 *, 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
@@ -679,7 +679,7 @@
     targ_archs="$targ_archs bfd_arm_arch"
     want64=true
     ;;
-  x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin)
+  x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin | x86_64-*-midipix*)
     targ_defvec=x86_64_pe_vec
     targ_selvecs="x86_64_pe_vec x86_64_pei_vec x86_64_pe_be_vec x86_64_elf64_vec l1om_elf64_vec k1om_elf64_vec i386_pe_vec i386_pei_vec i386_elf32_vec"
     want64=true
@@ -731,7 +731,7 @@
     targ_defvec=i386_elf32_vec
     targ_selvecs=i386_coff_vec
     ;;
-  i[3-7]86-*-mingw32* | i[3-7]86-*-cygwin* | i[3-7]86-*-winnt | i[3-7]86-*-pe)
+  i[3-7]86-*-mingw32* | i[3-7]86-*-cygwin* | i[3-7]86-*-winnt | i[3-7]86-*-pe | i[3-7]86-*-midipix*)
     targ_defvec=i386_pe_vec
     targ_selvecs="i386_pe_vec i386_pei_vec i386_elf32_vec"
     targ_underscore=yes
diff -ru --new-file a/binutils/configure b/binutils/configure
--- a/binutils/configure	2014-07-03 01:37:22.000000000 -0400
+++ b/binutils/configure	2015-09-13 21:35:09.738957435 -0400
@@ -14015,7 +14015,7 @@
 	  BUILD_WINDRES='$(WINDRES_PROG)$(EXEEXT)'
 	  BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)'
 	  ;;
-	x86_64-*-mingw* | x86_64-*-cygwin*)
+	x86_64-*-mingw* | x86_64-*-midipix* | x86_64-*-cygwin*)
   	  BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)'
 	  if test -z "$DLLTOOL_DEFAULT"; then
 	    DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_MX86_64"
@@ -14025,7 +14025,7 @@
 	  BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)'
 	  BUILD_DLLWRAP='$(DLLWRAP_PROG)$(EXEEXT)'
 	  ;;
-	i[3-7]86-*-pe* | i[3-7]86-*-cygwin* | i[3-7]86-*-mingw32** | i[3-7]86-*-netbsdpe*)
+	i[3-7]86-*-pe* | i[3-7]86-*-cygwin* | i[3-7]86-*-midipix* | i[3-7]86-*-mingw32** | i[3-7]86-*-netbsdpe*)
   	  BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)'
 	  if test -z "$DLLTOOL_DEFAULT"; then
 	    DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_I386"
diff -ru --new-file a/configure b/configure
--- a/configure	2014-07-03 01:37:23.000000000 -0400
+++ b/configure	2015-03-11 17:07:15.820422926 -0400
@@ -3428,6 +3428,9 @@
   x86_64-*-mingw*)
     noconfigdirs="$noconfigdirs ${libgcj}"
     ;;
+  *-midipix*)
+    noconfigdirs="$noconfigdirs ${libgcj}"
+    ;;
   mmix-*-*)
     noconfigdirs="$noconfigdirs target-libffi target-boehm-gc"
     ;;
@@ -3549,6 +3552,9 @@
   *-*-mingw*)
     noconfigdirs="$noconfigdirs target-newlib target-libgloss"
     ;;
+  *-*-midipix*)
+    noconfigdirs="$noconfigdirs target-newlib target-libgloss"
+    ;;
   *-*-netbsd*)
     noconfigdirs="$noconfigdirs target-newlib target-libgloss"
     ;;
@@ -6257,7 +6263,7 @@
 
 target_elf=no
 case $target in
-  *-darwin* | *-aix* | *-cygwin* | *-mingw* | *-aout* | *-*coff* | \
+  *-darwin* | *-aix* | *-cygwin* | *-mingw* | *-midipix* | *-aout* | *-*coff* | \
   *-msdosdjgpp* | *-vms* | *-wince* | *-*-pe* | \
   alpha*-dec-osf* | *-interix* | hppa[12]*-*-hpux*)
     target_elf=no
diff -ru --new-file a/gas/configure.tgt b/gas/configure.tgt
--- a/gas/configure.tgt	2014-07-03 01:37:25.000000000 -0400
+++ b/gas/configure.tgt	2015-02-14 11:27:08.223179776 -0500
@@ -262,7 +262,7 @@
      i*)				fmt=coff em=pe ;;
    esac ;;
   i386-*-interix*)			fmt=coff em=interix ;;
-  i386-*-mingw*)
+  i386-*-mingw* | i386-*-midipix*)
     case ${cpu} in
       x86_64*)				fmt=coff em=pep ;;
       i*)				fmt=coff em=pe ;;
diff -ru a/bfd/cofflink.c b/bfd/cofflink.c
--- a/bfd/cofflink.c	2014-07-03 01:37:20.000000000 -0400
+++ b/bfd/cofflink.c	2015-06-13 20:22:46.000389638 -0400
@@ -202,6 +202,7 @@
   bfd_size_type symesz;
   bfd_byte *esym;
   bfd_byte *esym_end;
+  char *weaksym;
 
   *pneeded = FALSE;
 
@@ -236,6 +237,16 @@
 	      && CONST_STRNEQ (name, "__imp_"))
 	    h = bfd_link_hash_lookup (info->hash, name + 6, FALSE, FALSE, TRUE);
 
+	  if (!h && !strncmp (name, ".weak.", 6) && strchr (name + 6, '.'))
+	    {
+	      weaksym = strdup (name + 6);
+	      *(strchr (weaksym, '.')) = '\0';
+	      h = bfd_link_hash_lookup (info->hash, weaksym, FALSE, FALSE, TRUE);
+	      name = weaksym;
+	    }
+	  else
+	    weaksym = 0;
+
 	  /* We are only interested in symbols that are currently
 	     undefined.  If a symbol is currently known to be common,
 	     COFF linkers do not bring in an object file which defines
@@ -249,6 +260,9 @@
 	      *pneeded = TRUE;
 	      return TRUE;
 	    }
+
+	  if (weaksym)
+	    free (weaksym);
 	}
 
       esym += (sym.n_numaux + 1) * symesz;
@@ -320,6 +334,7 @@
   bfd_byte *esym;
   bfd_byte *esym_end;
   bfd_size_type amt;
+  char *weaksym;
 
   symcount = obj_raw_syment_count (abfd);
 
@@ -476,6 +491,20 @@
 		addit = FALSE;
 	    }
 
+	  if (!strncmp (name, ".weak.", 6) && strchr (name + 6, '.'))
+	    {
+	      if (! (bfd_coff_link_add_one_symbol
+		     (info, abfd, name, flags, section, value,
+		      (const char *) NULL, copy, FALSE,
+		      (struct bfd_link_hash_entry **) sym_hash)))
+		goto error_return;
+
+	      weaksym = strdup (name + 6);
+	      *(strchr(weaksym, '.')) = 0;
+	      name = weaksym;
+	      flags |= BSF_WEAK;
+	    }
+
 	  if (addit)
 	    {
 	      if (! (bfd_coff_link_add_one_symbol
diff -ru a/bfd/linker.c b/bfd/linker.c
--- a/bfd/linker.c	2014-07-03 01:37:21.000000000 -0400
+++ b/bfd/linker.c	2015-06-06 17:51:24.148275212 -0400
@@ -1050,6 +1050,7 @@
   struct archive_hash_table arsym_hash;
   unsigned int indx;
   struct bfd_link_hash_entry **pundef;
+  char *weaksym;
 
   if (! bfd_has_map (abfd))
     {
@@ -1073,6 +1074,13 @@
       struct archive_hash_entry *arh;
       struct archive_list *l, **pp;
 
+      if (!strncmp (arsym->name, ".weak.", 6) && strchr (arsym->name + 6, '.'))
+	{
+	  weaksym = strdup (arsym->name + 6);
+	  *(strchr (weaksym, '.')) = '\0';
+	  arsym->name = weaksym;
+	}
+
       arh = archive_hash_lookup (&arsym_hash, arsym->name, TRUE, FALSE);
       if (arh == NULL)
 	goto error_return;
diff -ru a/gas/config/tc-i386.c b/gas/config/tc-i386.c
--- a/gas/config/tc-i386.c	2014-07-03 01:37:25.000000000 -0400
+++ b/gas/config/tc-i386.c	2015-06-12 22:40:37.100250091 -0400
@@ -9148,25 +9148,6 @@
 	value += md_pcrel_from (fixP);
 #endif
     }
-#if defined (OBJ_COFF) && defined (TE_PE)
-  if (fixP->fx_addsy != NULL
-      && S_IS_WEAK (fixP->fx_addsy)
-      /* PR 16858: Do not modify weak function references.  */
-      && ! fixP->fx_pcrel)
-    {
-#if !defined (TE_PEP)
-      /* For x86 PE weak function symbols are neither PC-relative
-	 nor do they set S_IS_FUNCTION.  So the only reliable way
-	 to detect them is to check the flags of their containing
-	 section.  */
-      if (S_GET_SEGMENT (fixP->fx_addsy) != NULL
-	  && S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_CODE)
-	;
-      else
-#endif
-      value -= S_GET_VALUE (fixP->fx_addsy);
-    }
-#endif
 
   /* Fix a few things - the dynamic linker expects certain values here,
      and we must not disappoint it.  */
@@ -9237,8 +9218,11 @@
       fixP->fx_done = 0;
       /* Remember value for tc_gen_reloc.  */
       fixP->fx_addnumber = value;
-      /* Clear out the frag for now.  */
-      value = 0;
+      /* for data symbols, cancel the effect of the relocation */
+      if (!((S_GET_SEGMENT (fixP->fx_addsy)->flags) & SEC_CODE))
+        value = -S_GET_VALUE (fixP->fx_addsy);
+      else
+        value = 0;
     }
 #endif
   else if (use_rela_relocations)

--- a/binutils/rename.c	2014-07-03 01:37:22.000000000 -0400
+++ b/binutils/rename.c	2015-11-25 23:13:38.086948592 -0500
@@ -167,7 +167,10 @@
 	  && s.st_nlink == 1)
       )
     {
-      ret = rename (from, to);
+      if ((ret = rename (from, to)))
+	if (!(ret = simple_copy (from, to)))
+	  unlink (from);
+
       if (ret == 0)
 	{
 	  if (exists)