@@ -697,7 +697,7 @@ let needed imported defined resolve_alias resolve_alternate obj =
697697    StrSet. empty
698698    obj.symbols
699699
700- let  build_dll  link_exe  output_file  files  exts  extra_args  = 
700+ let  build_dll  link_exe  output_file  files  exts  extra_args_string  = 
701701  let  main_pgm =  link_exe <>  `DLL  in 
702702
703703  (*  fully resolve filenames, eliminate duplicates *) 
@@ -979,6 +979,53 @@ let build_dll link_exe output_file files exts extra_args =
979979          link_obj (Printf. sprintf " %s(%s)" 
980980  in 
981981
982+   let  entrypoint = 
983+     if  not  main_pgm then 
984+       None 
985+     else 
986+       match  ! toolchain with 
987+       |  `CYGWIN64  ->
988+           Some  " main" 
989+       |  `MINGW  |  `MINGW64  -> begin 
990+           let  entry_point  s  = 
991+             String. length s >  7  &&  String. sub s 0  7  =  " -Wl,-e," 
992+           in 
993+           try 
994+             let  s =  List. find entry_point ! extra_args in 
995+             Some  (String. sub s 7  (String. length s -  7 ))
996+           with  Not_found  -> 
997+             Some  " mainCRTStartup" 
998+         end 
999+       |  `MSVC  |  `MSVC64  -> begin 
1000+           let  entry_point  s  = 
1001+             String. length s >  7  &&  String. lowercase_ascii (String. sub s 0  7 ) =  " /entry:" 
1002+           in 
1003+           try 
1004+             let  s =  List. find entry_point ! extra_args in 
1005+             Some  (String. sub s 7  (String. length s -  7 ))
1006+           with  Not_found  -> 
1007+             if  ! subsystem =  " windows" then 
1008+               Some  " WinMainCRTStartup" 
1009+             else 
1010+               Some  " mainCRTStartup" 
1011+         end 
1012+       |  `LIGHTLD  |  `GNAT  |  `GNAT64  ->
1013+           None 
1014+   in 
1015+   let  ()  = 
1016+     match  entrypoint with 
1017+     |  None  -> () 
1018+     |  Some  entrypoint  ->
1019+         try 
1020+           let  (libname, objname, _)  as  o  =  defined_in entrypoint in 
1021+           if  ! explain then 
1022+             Printf. printf " %s(%s) because of entrypoint %s\n %!" 
1023+                                                                 entrypoint;
1024+           link_libobj o
1025+         with  Not_found  -> 
1026+           if  ! explain then 
1027+             Printf. printf " Entrypoint %s not found\n %!" 
1028+   in 
9821029  let  redirect =  Hashtbl. create 16  in 
9831030  List. iter
9841031    (fun  (fn , obj ) ->
@@ -1113,21 +1160,21 @@ let build_dll link_exe output_file files exts extra_args =
11131160           being an empty file. *)  
11141161        let  c =  open_out implib in  output_string c " x" 
11151162        let  _impexp =  add_temp (Filename. chop_suffix implib " .lib" ^  " .exp" in 
1116-         let  extra_args  = 
1117-           if  ! custom_crt then  " /nodefaultlib:LIBCMT /nodefaultlib:MSVCRT " ^  extra_args 
1118-           else  " msvcrt.lib " ^  extra_args 
1163+         let  extra_args_string  = 
1164+           if  ! custom_crt then  " /nodefaultlib:LIBCMT /nodefaultlib:MSVCRT " ^  extra_args_string 
1165+           else  " msvcrt.lib " ^  extra_args_string 
11191166        in 
11201167
1121-         let  extra_args  = 
1122-           if  ! machine =  `x64  then  (Printf. sprintf " /base:%s " ! base_addr) ^  extra_args  else  extra_args 
1168+         let  extra_args_string  = 
1169+           if  ! machine =  `x64  then  (Printf. sprintf " /base:%s " ! base_addr) ^  extra_args_string  else  extra_args_string 
11231170        in 
11241171
1125-         let  extra_args  = 
1172+         let  extra_args_string  = 
11261173          (*  FlexDLL doesn't process .voltbl sections correctly, so don't allow the linker
11271174             to process them. *)  
11281175          if  Sys. command " link | findstr EMITVOLATILEMETADATA > nul" =  0  then 
1129-             " /EMITVOLATILEMETADATA:NO " ^  extra_args 
1130-           else  extra_args 
1176+             " /EMITVOLATILEMETADATA:NO " ^  extra_args_string 
1177+           else  extra_args_string 
11311178        in 
11321179
11331180        (*  Flexdll requires that all images (main programs and all the DLLs) are
@@ -1154,7 +1201,7 @@ let build_dll link_exe output_file files exts extra_args =
11541201          (Filename. quote output_file)
11551202          ! subsystem
11561203          files descr
1157-           extra_args 
1204+           extra_args_string 
11581205    |  `CYGWIN64  ->
11591206        let  def_file = 
11601207          if  main_pgm then  " " 
@@ -1175,7 +1222,7 @@ let build_dll link_exe output_file files exts extra_args =
11751222          descr
11761223          files
11771224          def_file
1178-           extra_args 
1225+           extra_args_string 
11791226    |  `MINGW  |  `MINGW64  |  `GNAT  |  `GNAT64  ->
11801227        let  def_file = 
11811228          if  main_pgm then  " " 
@@ -1198,7 +1245,7 @@ let build_dll link_exe output_file files exts extra_args =
11981245          files
11991246          def_file
12001247          (if  ! implib then  " -Wl,--out-implib=" ^  Filename. quote (Filename. chop_extension output_file ^  " .a" else  " " 
1201-           extra_args 
1248+           extra_args_string 
12021249    |  `LIGHTLD  ->
12031250        no_merge_manifest :=  true ;
12041251        Printf. sprintf
@@ -1209,7 +1256,7 @@ let build_dll link_exe output_file files exts extra_args =
12091256          descr
12101257          files
12111258          (if  ! implib then  " --out-implib " ^  Filename. quote (Filename. chop_extension output_file ^  " .a" else  " " 
1212-           extra_args 
1259+           extra_args_string 
12131260  in 
12141261  debug ~dry_mode  1  " + %s" 
12151262  if  not  ! dry_mode then  begin 
0 commit comments