@@ -697,7 +697,7 @@ let needed imported defined resolve_alias resolve_alternate obj =
697
697
StrSet. empty
698
698
obj.symbols
699
699
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 =
701
701
let main_pgm = link_exe <> `DLL in
702
702
703
703
(* fully resolve filenames, eliminate duplicates *)
@@ -979,6 +979,53 @@ let build_dll link_exe output_file files exts extra_args =
979
979
link_obj (Printf. sprintf " %s(%s)" libname objname) obj)
980
980
in
981
981
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 %!" libname objname
1023
+ entrypoint;
1024
+ link_libobj o
1025
+ with Not_found ->
1026
+ if ! explain then
1027
+ Printf. printf " Entrypoint %s not found\n %!" entrypoint
1028
+ in
982
1029
let redirect = Hashtbl. create 16 in
983
1030
List. iter
984
1031
(fun (fn , obj ) ->
@@ -1113,21 +1160,21 @@ let build_dll link_exe output_file files exts extra_args =
1113
1160
being an empty file. *)
1114
1161
let c = open_out implib in output_string c " x" ; close_out c;
1115
1162
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
1119
1166
in
1120
1167
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
1123
1170
in
1124
1171
1125
- let extra_args =
1172
+ let extra_args_string =
1126
1173
(* FlexDLL doesn't process .voltbl sections correctly, so don't allow the linker
1127
1174
to process them. *)
1128
1175
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
1131
1178
in
1132
1179
1133
1180
(* 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 =
1154
1201
(Filename. quote output_file)
1155
1202
! subsystem
1156
1203
files descr
1157
- extra_args
1204
+ extra_args_string
1158
1205
| `CYGWIN64 ->
1159
1206
let def_file =
1160
1207
if main_pgm then " "
@@ -1175,7 +1222,7 @@ let build_dll link_exe output_file files exts extra_args =
1175
1222
descr
1176
1223
files
1177
1224
def_file
1178
- extra_args
1225
+ extra_args_string
1179
1226
| `MINGW | `MINGW64 | `GNAT | `GNAT64 ->
1180
1227
let def_file =
1181
1228
if main_pgm then " "
@@ -1198,7 +1245,7 @@ let build_dll link_exe output_file files exts extra_args =
1198
1245
files
1199
1246
def_file
1200
1247
(if ! implib then " -Wl,--out-implib=" ^ Filename. quote (Filename. chop_extension output_file ^ " .a" ) else " " )
1201
- extra_args
1248
+ extra_args_string
1202
1249
| `LIGHTLD ->
1203
1250
no_merge_manifest := true ;
1204
1251
Printf. sprintf
@@ -1209,7 +1256,7 @@ let build_dll link_exe output_file files exts extra_args =
1209
1256
descr
1210
1257
files
1211
1258
(if ! implib then " --out-implib " ^ Filename. quote (Filename. chop_extension output_file ^ " .a" ) else " " )
1212
- extra_args
1259
+ extra_args_string
1213
1260
in
1214
1261
debug ~dry_mode 1 " + %s" cmd;
1215
1262
if not ! dry_mode then begin
0 commit comments