@@ -725,7 +725,7 @@ let needed imported defined resolve_alias resolve_alternate obj =
725
725
StrSet. empty
726
726
obj.symbols
727
727
728
- let build_dll link_exe output_file files exts extra_args =
728
+ let build_dll link_exe output_file files exts extra_args_string =
729
729
let main_pgm = link_exe <> `DLL in
730
730
731
731
(* fully resolve filenames, eliminate duplicates *)
@@ -1007,6 +1007,53 @@ let build_dll link_exe output_file files exts extra_args =
1007
1007
link_obj (Printf. sprintf " %s(%s)" libname objname) obj)
1008
1008
in
1009
1009
1010
+ let entrypoint =
1011
+ if not main_pgm then
1012
+ None
1013
+ else
1014
+ match ! toolchain with
1015
+ | `CYGWIN64 ->
1016
+ Some " main"
1017
+ | `MINGW | `MINGW64 -> begin
1018
+ let entry_point s =
1019
+ String. length s > 7 && String. sub s 0 7 = " -Wl,-e,"
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
+ Some " mainCRTStartup"
1026
+ end
1027
+ | `MSVC | `MSVC64 -> begin
1028
+ let entry_point s =
1029
+ String. length s > 7 && String. lowercase_ascii (String. sub s 0 7 ) = " /entry:"
1030
+ in
1031
+ try
1032
+ let s = List. find entry_point ! extra_args in
1033
+ Some (String. sub s 7 (String. length s - 7 ))
1034
+ with Not_found ->
1035
+ if ! subsystem = " windows" then
1036
+ Some " WinMainCRTStartup"
1037
+ else
1038
+ Some " mainCRTStartup"
1039
+ end
1040
+ | `LIGHTLD | `GNAT | `GNAT64 ->
1041
+ None
1042
+ in
1043
+ let () =
1044
+ match entrypoint with
1045
+ | None -> ()
1046
+ | Some entrypoint ->
1047
+ try
1048
+ let (libname, objname, _) as o = defined_in entrypoint in
1049
+ if ! explain then
1050
+ Printf. printf " %s(%s) because of entrypoint %s\n %!" libname objname
1051
+ entrypoint;
1052
+ link_libobj o
1053
+ with Not_found ->
1054
+ if ! explain then
1055
+ Printf. printf " Entrypoint %s not found\n %!" entrypoint
1056
+ in
1010
1057
let redirect = Hashtbl. create 16 in
1011
1058
List. iter
1012
1059
(fun (fn , obj ) ->
@@ -1142,24 +1189,24 @@ let build_dll link_exe output_file files exts extra_args =
1142
1189
being an empty file. *)
1143
1190
let c = open_out implib in output_string c " x" ; close_out c;
1144
1191
let _impexp = add_temp (Filename. chop_suffix implib " .lib" ^ " .exp" ) in
1145
- let extra_args =
1146
- if ! custom_crt then " /nodefaultlib:LIBCMT /nodefaultlib:MSVCRT " ^ extra_args
1147
- else " msvcrt.lib " ^ extra_args
1192
+ let extra_args_string =
1193
+ if ! custom_crt then " /nodefaultlib:LIBCMT /nodefaultlib:MSVCRT " ^ extra_args_string
1194
+ else " msvcrt.lib " ^ extra_args_string
1148
1195
in
1149
1196
1150
- let extra_args =
1151
- if ! machine = `x64 then (Printf. sprintf " /base:%s " ! base_addr) ^ extra_args else extra_args
1197
+ let extra_args_string =
1198
+ if ! machine = `x64 then (Printf. sprintf " /base:%s " ! base_addr) ^ extra_args_string else extra_args_string
1152
1199
in
1153
1200
1154
- let extra_args =
1201
+ let extra_args_string =
1155
1202
(* FlexDLL doesn't process .voltbl sections correctly, so don't allow the linker
1156
1203
to process them. *)
1157
1204
let command =
1158
1205
if Sys. win32 then link ^ " /nologo /? | findstr EMITVOLATILEMETADATA > NUL"
1159
1206
else link ^ " /nologo '/?' | grep -iq emitvolatilemetadata >/dev/null" in
1160
1207
if Sys. command command = 0 then
1161
- " /EMITVOLATILEMETADATA:NO " ^ extra_args
1162
- else extra_args
1208
+ " /EMITVOLATILEMETADATA:NO " ^ extra_args_string
1209
+ else extra_args_string
1163
1210
in
1164
1211
1165
1212
(* Flexdll requires that all images (main programs and all the DLLs) are
@@ -1187,7 +1234,7 @@ let build_dll link_exe output_file files exts extra_args =
1187
1234
(Filename. quote output_file)
1188
1235
! subsystem
1189
1236
files descr
1190
- extra_args
1237
+ extra_args_string
1191
1238
| `CYGWIN64 ->
1192
1239
let def_file =
1193
1240
if main_pgm then " "
@@ -1209,7 +1256,7 @@ let build_dll link_exe output_file files exts extra_args =
1209
1256
descr
1210
1257
files
1211
1258
def_file
1212
- extra_args
1259
+ extra_args_string
1213
1260
| `MINGW | `MINGW64 | `GNAT | `GNAT64 ->
1214
1261
let def_file =
1215
1262
if main_pgm then " "
@@ -1233,7 +1280,7 @@ let build_dll link_exe output_file files exts extra_args =
1233
1280
files
1234
1281
def_file
1235
1282
(if ! implib then " -Wl,--out-implib=" ^ Filename. quote (Filename. chop_extension output_file ^ " .a" ) else " " )
1236
- extra_args
1283
+ extra_args_string
1237
1284
| `LIGHTLD ->
1238
1285
no_merge_manifest := true ;
1239
1286
let ld = Option. value ! Cmdline. use_linker ~default: " ld" in
@@ -1246,7 +1293,7 @@ let build_dll link_exe output_file files exts extra_args =
1246
1293
descr
1247
1294
files
1248
1295
(if ! implib then " --out-implib " ^ Filename. quote (Filename. chop_extension output_file ^ " .a" ) else " " )
1249
- extra_args
1296
+ extra_args_string
1250
1297
in
1251
1298
debug ~dry_mode 1 " + %s" cmd;
1252
1299
if not ! dry_mode then begin
0 commit comments