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