@@ -715,7 +715,7 @@ let needed imported defined resolve_alias resolve_alternate obj =
715
715
StrSet. empty
716
716
obj.symbols
717
717
718
- let build_dll link_exe output_file files exts extra_args =
718
+ let build_dll link_exe output_file files exts extra_args_string =
719
719
let main_pgm = link_exe <> `DLL in
720
720
721
721
(* fully resolve filenames, eliminate duplicates *)
@@ -997,6 +997,53 @@ let build_dll link_exe output_file files exts extra_args =
997
997
link_obj (Printf. sprintf " %s(%s)" libname objname) obj)
998
998
in
999
999
1000
+ let entrypoint =
1001
+ if not main_pgm then
1002
+ None
1003
+ else
1004
+ match ! toolchain with
1005
+ | `CYGWIN64 ->
1006
+ Some " main"
1007
+ | `MINGW | `MINGW64 -> begin
1008
+ let entry_point s =
1009
+ String. length s > 7 && String. sub s 0 7 = " -Wl,-e,"
1010
+ in
1011
+ try
1012
+ let s = List. find entry_point ! extra_args in
1013
+ Some (String. sub s 7 (String. length s - 7 ))
1014
+ with Not_found ->
1015
+ Some " mainCRTStartup"
1016
+ end
1017
+ | `MSVC | `MSVC64 -> begin
1018
+ let entry_point s =
1019
+ String. length s > 7 && String. lowercase_ascii (String. sub s 0 7 ) = " /entry:"
1020
+ in
1021
+ try
1022
+ let s = List. find entry_point ! extra_args in
1023
+ Some (String. sub s 7 (String. length s - 7 ))
1024
+ with Not_found ->
1025
+ if ! subsystem = " windows" then
1026
+ Some " WinMainCRTStartup"
1027
+ else
1028
+ Some " mainCRTStartup"
1029
+ end
1030
+ | `LIGHTLD | `GNAT | `GNAT64 ->
1031
+ None
1032
+ in
1033
+ let () =
1034
+ match entrypoint with
1035
+ | None -> ()
1036
+ | Some entrypoint ->
1037
+ try
1038
+ let (libname, objname, _) as o = defined_in entrypoint in
1039
+ if ! explain then
1040
+ Printf. printf " %s(%s) because of entrypoint %s\n %!" libname objname
1041
+ entrypoint;
1042
+ link_libobj o
1043
+ with Not_found ->
1044
+ if ! explain then
1045
+ Printf. printf " Entrypoint %s not found\n %!" entrypoint
1046
+ in
1000
1047
let redirect = Hashtbl. create 16 in
1001
1048
List. iter
1002
1049
(fun (fn , obj ) ->
@@ -1132,22 +1179,22 @@ let build_dll link_exe output_file files exts extra_args =
1132
1179
being an empty file. *)
1133
1180
let c = open_out implib in output_string c " x" ; close_out c;
1134
1181
let _impexp = add_temp (Filename. chop_suffix implib " .lib" ^ " .exp" ) in
1135
- let extra_args =
1136
- if ! custom_crt then " /nodefaultlib:LIBCMT /nodefaultlib:MSVCRT " ^ extra_args
1137
- else " msvcrt.lib " ^ extra_args
1182
+ let extra_args_string =
1183
+ if ! custom_crt then " /nodefaultlib:LIBCMT /nodefaultlib:MSVCRT " ^ extra_args_string
1184
+ else " msvcrt.lib " ^ extra_args_string
1138
1185
in
1139
1186
1140
- let extra_args =
1141
- if ! machine = `x64 then (Printf. sprintf " /base:%s " ! base_addr) ^ extra_args else extra_args
1187
+ let extra_args_string =
1188
+ if ! machine = `x64 then (Printf. sprintf " /base:%s " ! base_addr) ^ extra_args_string else extra_args_string
1142
1189
in
1143
1190
1144
- let extra_args =
1191
+ let extra_args_string =
1145
1192
(* FlexDLL doesn't process .voltbl sections correctly, so don't allow the linker
1146
1193
to process them. *)
1147
1194
let command = link ^ " | findstr EMITVOLATILEMETADATA > NUL" in
1148
1195
if Sys. command command = 0 then
1149
- " /EMITVOLATILEMETADATA:NO " ^ extra_args
1150
- else extra_args
1196
+ " /EMITVOLATILEMETADATA:NO " ^ extra_args_string
1197
+ else extra_args_string
1151
1198
in
1152
1199
1153
1200
(* Flexdll requires that all images (main programs and all the DLLs) are
@@ -1175,7 +1222,7 @@ let build_dll link_exe output_file files exts extra_args =
1175
1222
(Filename. quote output_file)
1176
1223
! subsystem
1177
1224
files descr
1178
- extra_args
1225
+ extra_args_string
1179
1226
| `CYGWIN64 ->
1180
1227
let def_file =
1181
1228
if main_pgm then " "
@@ -1197,7 +1244,7 @@ let build_dll link_exe output_file files exts extra_args =
1197
1244
descr
1198
1245
files
1199
1246
def_file
1200
- extra_args
1247
+ extra_args_string
1201
1248
| `MINGW | `MINGW64 | `GNAT | `GNAT64 ->
1202
1249
let def_file =
1203
1250
if main_pgm then " "
@@ -1221,7 +1268,7 @@ let build_dll link_exe output_file files exts extra_args =
1221
1268
files
1222
1269
def_file
1223
1270
(if ! implib then " -Wl,--out-implib=" ^ Filename. quote (Filename. chop_extension output_file ^ " .a" ) else " " )
1224
- extra_args
1271
+ extra_args_string
1225
1272
| `LIGHTLD ->
1226
1273
no_merge_manifest := true ;
1227
1274
let ld = Option. value ! Cmdline. use_linker ~default: " ld" in
@@ -1234,7 +1281,7 @@ let build_dll link_exe output_file files exts extra_args =
1234
1281
descr
1235
1282
files
1236
1283
(if ! implib then " --out-implib " ^ Filename. quote (Filename. chop_extension output_file ^ " .a" ) else " " )
1237
- extra_args
1284
+ extra_args_string
1238
1285
in
1239
1286
debug ~dry_mode 1 " + %s" cmd;
1240
1287
if not ! dry_mode then begin
0 commit comments