Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Next version
(Nicolás Ojeda Bär, review by David Allsopp)
- GRP#169: Drop the .llvm_addrsig section from rewritten objects.
(Antonin Décimo, review by David Allsopp)
- New `clang64` chain for C compilers with a Unix-style command line targeting
the MSVC ABI and runtime, such as `clang --target=x86_64-pc-windows-msvc` and
`zig cc -target x86_64-windows-msvc`. By default the link is driven through
the C compiler with an lld-link-style linker (lld), and `-Wl,/option`-style
arguments are now recognized and forwarded. A linker with a GNU-style command
line given with `-use-linker` (e.g. `-use-linker "ld.lld -m i386pep"`) is
instead invoked directly with GNU option spellings. Note that GNU binutils ld
is currently unable to link the MSVC CRT (it selects the wrong members from
msvcrt.lib).
(Antonin Décimo)

Version 0.44
- GPR#127: Recognise hyphens in option names in the COFF .drectve section.
Expand Down
40 changes: 37 additions & 3 deletions Compat.ml.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@

407:module Stdlib = Pervasives

404:module String = struct
404: include String
405:module String = struct
405: include String
402:
402: let init n f =
402: let s = create n in
Expand All @@ -131,7 +131,13 @@
404: end
404: done;
404: sub s 0 !j :: !r
404:end
405:
405: let rec index_rec_opt s lim i c =
405: if i >= lim then None else
405: if unsafe_get s i = c then Some i else index_rec_opt s lim (i + 1) c
405:
405: let index_opt s c = index_rec_opt s (length s) 0 c
405:end

401:module Sys = struct
401: include Sys
Expand All @@ -141,6 +147,34 @@
401: let unix = (Sys.os_type = "Unix")
401:end

404:module Filename = struct
404: include Filename
404:
404: let is_dir_sep s i =
404: if Sys.unix then s.[i] = '/'
404: else if Sys.win32 || Sys.cygwin then
404: let c = s.[i] in
404: c = '/' || c = '\\' || c = ':' && i = 1
404: else false
404:
404: let extension_len name =
404: let rec check i0 i =
404: if i < 0 || is_dir_sep name i then 0
404: else if name.[i] = '.' then check i0 (i - 1)
404: else String.length name - i0
404: in
404: let rec search_dot i =
404: if i < 0 || is_dir_sep name i then 0
404: else if name.[i] = '.' then check i (i - 1)
404: else search_dot (i - 1)
404: in
404: search_dot (String.length name - 1)
404:
404: let remove_extension name =
404: let l = extension_len name in
404: if l = 0 then name else String.sub name 0 (String.length name - l)
404:end

402:type bytes = string
402:let output_bytes = output_string

Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ MIN64CC = $(MINGW64_PREFIX)gcc
CYGWIN64_PREFIX = x86_64-pc-cygwin-
CYG64CC = $(CYGWIN64_PREFIX)gcc

# A C compiler with a Unix-style CLI targeting the MSVC ABI/CRT
# (e.g. clang --target=x86_64-pc-windows-msvc, zig cc)
CLANG64CC = clang --target=x86_64-pc-windows-msvc

version.ml: Makefile flexdll.opam
echo 'let version = "$(VERSION)"' > $@
echo 'let mingw_prefix = "$(MINGW_PREFIX)"' >> $@
Expand All @@ -47,6 +51,7 @@ version.ml: Makefile flexdll.opam
echo 'let mingw = "$(notdir $(MINCC))"' >> $@
echo 'let mingw64 = "$(notdir $(MIN64CC))"' >> $@
echo 'let gnat = "gcc"' >> $@
echo 'let clang64 = "$(CLANG64CC)"' >> $@

# Supported tool-chains

Expand Down Expand Up @@ -151,6 +156,7 @@ support: $(addprefix build_, $(CHAINS))
build_gnat: flexdll_gnat.o flexdll_initer_gnat.o
build_msvc: flexdll_msvc.obj flexdll_initer_msvc.obj
build_msvc64: flexdll_msvc64.obj flexdll_initer_msvc64.obj
build_clang64: flexdll_clang64.o flexdll_initer_clang64.o
build_cygwin64: flexdll_cygwin64.o flexdll_initer_cygwin64.o
build_mingw: flexdll_mingw.o flexdll_initer_mingw.o
build_mingw64: flexdll_mingw64.o flexdll_initer_mingw64.o
Expand Down Expand Up @@ -215,6 +221,13 @@ flexdll_msvc.obj: flexdll.c flexdll.h
flexdll_msvc64.obj: flexdll.c flexdll.h
$(MSVC64_PREFIX) $(MSVCC64) $(MSVC_FLAGS) /DMSVC /DMSVC64 -c /Fo"$@" $<

# -fms-runtime-lib=dll matches the /MD of MSVC_FLAGS (the objects must not
# carry a -defaultlib:libcmt directive)
CLANG64_FLAGS = $(GCC_FLAGS) -fms-runtime-lib=dll -D_CRT_SECURE_NO_DEPRECATE

flexdll_clang64.o: flexdll.c flexdll.h
$(CLANG64CC) $(CLANG64_FLAGS) -DMSVC -DMSVC64 -c -o $@ $<

flexdll_cygwin64.o: flexdll.c flexdll.h
$(CYG64CC) $(GCC_FLAGS) -DCYGWIN -c -o $@ $<

Expand All @@ -233,6 +246,9 @@ flexdll_initer_msvc.obj: flexdll_initer.c
flexdll_initer_msvc64.obj: flexdll_initer.c
$(MSVC64_PREFIX) $(MSVCC64) $(MSVC_FLAGS) -c /Fo"$@" $<

flexdll_initer_clang64.o: flexdll_initer.c
$(CLANG64CC) $(CLANG64_FLAGS) -c -o $@ $<

flexdll_initer_cygwin64.o: flexdll_initer.c
$(CYG64CC) $(GCC_FLAGS) -c -o $@ $<

Expand Down Expand Up @@ -263,6 +279,9 @@ demo_mingw64: flexlink.exe flexdll_mingw64.o flexdll_initer_mingw64.o
demo_msvc64: flexlink.exe flexdll_msvc64.obj flexdll_initer_msvc64.obj
$(MSVC64_PREFIX) $(MAKE) -C test clean demo CHAIN=msvc64 CC="$(MSVCC64)" CFLAGS="$(MSVC_FLAGS)" PLUG2_CFLAGS="/bigobj" O=obj

demo_clang64: flexlink.exe flexdll_clang64.o flexdll_initer_clang64.o
$(MAKE) -C test clean demo CHAIN=clang64 CC="$(CLANG64CC)" CFLAGS="$(CLANG64_FLAGS)" O=o

distclean: clean
rm -f Makefile.winsdk

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ MSVC: the 32-bit C compiler from Microsoft.

MSVC64: the 64-bit C compiler from Microsoft.

CLANG64: a 64-bit C compiler with a Unix-style command line targeting the
MSVC ABI and runtime (e.g. `clang --target=x86_64-pc-windows-msvc` or
`zig cc -target x86_64-windows-msvc`). By default the link is driven
through the C compiler with an lld-link-style linker; a linker with a
GNU-style command line passed with `-use-linker` (e.g.
`-use-linker "ld.lld -m i386pep"`) is invoked directly instead.

CYGWIN64: the 64-bit gcc compiler shipped with Cygwin.

MINGW: the 32-bit gcc compiler from the MinGW-w64 project, packaged in
Expand Down
13 changes: 9 additions & 4 deletions cmdline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let use_default_libs = ref true
let subsystem = ref "console"
let explain = ref false
let builtin_linker = ref false
let toolchain : [ `MSVC | `MSVC64 | `MINGW | `MINGW64 | `GNAT | `GNAT64 | `CYGWIN64 | `LIGHTLD ] ref = ref `MSVC
let toolchain : [ `MSVC | `MSVC64 | `CLANG64 | `MINGW | `MINGW64 | `GNAT | `GNAT64 | `CYGWIN64 | `LIGHTLD ] ref = ref `MSVC
let use_linker = ref None
let use_mt = ref None
let save_temps = ref false
Expand Down Expand Up @@ -103,12 +103,13 @@ let specs = [
"-l", Arg.String (fun s -> files := ("-l" ^ s) :: !files),
"<lib> Library file";

"-chain", Arg.Symbol (["msvc";"msvc64";"cygwin64";"mingw";"mingw64";"gnat";"gnat64";"ld"],
"-chain", Arg.Symbol (["msvc";"msvc64";"clang64";"cygwin64";"mingw";"mingw64";"gnat";"gnat64";"ld"],
(fun s ->
machine := `x86; underscore := true;
toolchain := match s with
| "msvc" -> `MSVC
| "msvc64" -> machine := `x64; underscore := false; `MSVC64
| "clang64" -> machine := `x64; underscore := false; `CLANG64
| "cygwin64" -> machine := `x64; underscore := false; `CYGWIN64
| "mingw" -> `MINGW
| "gnat" -> `GNAT
Expand Down Expand Up @@ -277,8 +278,12 @@ let parse_cmdline () =
String.sub s 0 2 :: String.sub s 2 (String.length s - 2) :: tr rest
| s :: rest when String.length s >= 5 && String.sub s 0 5 = "/link" ->
"-link" :: String.sub s 5 (String.length s - 5) :: tr rest
(* Convert gcc linker option prefix -Wl, to flexlink linker prefix -link *)
| s :: rest when String.length s >= 6 && String.sub s 0 5 = "-Wl,-" ->
(* Convert gcc linker option prefix -Wl, to flexlink linker prefix -link.
Also accept MSVC-style option spellings after -Wl, (e.g. -Wl,/entry:Sym,
as used with the clang64 chain) which would otherwise be mangled by the
-opt:value splitting below. *)
| s :: rest when String.length s >= 5 && String.sub s 0 4 = "-Wl,"
&& (s.[4] = '-' || s.[4] = '/') ->
let args =
String.split_on_char ',' (String.sub s 4 (String.length s - 4))
in
Expand Down
Loading