Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple arguments with -Wl, #85

Merged
merged 3 commits into from
Sep 30, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Next version
- GPR#103: Delete objects from C files compiled by flexlink (David Allsopp, report by Xavier Leroy)
- GPR#85: Split multiple arguments passed with a single -Wl (David Allsopp)

Version 0.41
- GPR#98: Eliminate Warning 6 compiling coff.ml (David Allsopp)
Expand Down
133 changes: 133 additions & 0 deletions Compat.ml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
(************************************************************************)
(* FlexDLL *)
(* Alain Frisch *)
(* *)
(* Copyright 2007 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(************************************************************************)

(* Compatibility shims. Each line is prefixed with the compiler at which the
line ceases to be necessary. A function introduced in OCaml 4.01, therefore,
is prefixed with "401:" *)

405:module Arg = struct
405: include Arg
405:
405: let trim_cr s =
405: let len = String.length s in
405: if len > 0 && String.get s (len - 1) = '\r' then
405: String.sub s 0 (len - 1)
405: else
405: s
405:
405: let read_aux trim sep file =
405: let ic = open_in_bin file in
405: let buf = Buffer.create 200 in
405: let words = ref [] in
405: let stash () =
405: let word = Buffer.contents buf in
405: let word = if trim then trim_cr word else word in
405: words := word :: !words;
405: Buffer.clear buf
405: in
405: begin
405: try while true do
405: let c = input_char ic in
405: if c = sep then stash () else Buffer.add_char buf c
405: done
405: with End_of_file -> ()
405: end;
405: if Buffer.length buf > 0 then stash ();
405: close_in ic;
405: Array.of_list (List.rev !words)
405:
405: let read_arg = read_aux true '\n'
405:
405: let read_arg0 = read_aux false '\x00'
405:
405:end

403:module Uchar = struct
403: let unsafe_of_int c = c
403:
403: let to_int c = c
403:end

406:module Buffer = struct
406: include Buffer
406:
402: let to_bytes = contents
402:
406: let add_utf_16le_uchar b u = match Uchar.to_int u with
406: | u when u < 0 -> assert false
406: | u when u <= 0xFFFF ->
406: add_char b (Char.unsafe_chr (u land 0xFF));
406: add_char b (Char.unsafe_chr (u lsr 8))
406: | u when u <= 0x10FFFF ->
406: let u' = u - 0x10000 in
406: let hi = 0xD800 lor (u' lsr 10) in
406: let lo = 0xDC00 lor (u' land 0x3FF) in
406: add_char b (Char.unsafe_chr (hi land 0xFF));
406: add_char b (Char.unsafe_chr (hi lsr 8));
406: add_char b (Char.unsafe_chr (lo land 0xFF));
406: add_char b (Char.unsafe_chr (lo lsr 8))
406: | _ -> assert false
406:end

402:module Bytes = struct
402: include String
402:
402: let blit_string = blit
402: let sub_string = sub
402: let of_string x = x
402: let to_string x = x
402: let cat = (^)
402:end

403:module Char = struct
403: include Char
403:
403: let lowercase_ascii c =
403: if (c >= 'A' && c <= 'Z')
403: then unsafe_chr(code c + 32)
403: else c
403:
403: let uppercase_ascii c =
403: if (c >= 'a' && c <= 'z')
403: then unsafe_chr(code c - 32)
403: else c
403:end

407:module Stdlib = Pervasives

404:module String = struct
404: include String
402:
402: let init n f =
402: let s = create n in
402: for i = 0 to n - 1 do
402: unsafe_set s i (f i)
402: done;
402: s
403:
403: let lowercase_ascii s =
403: init (length s) (fun i -> Char.lowercase_ascii (unsafe_get s i))
403: let uppercase_ascii s =
403: init (length s) (fun i -> Char.uppercase_ascii (unsafe_get s i))
404:
404: let split_on_char sep s =
404: let r = ref [] in
404: let j = ref (length s) in
404: for i = length s - 1 downto 0 do
404: if unsafe_get s i = sep then begin
404: r := sub s (i + 1) (!j - i - 1) :: !r;
404: j := i
404: end
404: done;
404: sub s 0 !j :: !r
404:end

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

401:let ( |> ) x f = f x
10 changes: 0 additions & 10 deletions Compat401.ml

This file was deleted.

20 changes: 0 additions & 20 deletions Compat402.ml

This file was deleted.

45 changes: 0 additions & 45 deletions Compat403.ml

This file was deleted.

45 changes: 0 additions & 45 deletions Compat405.ml

This file was deleted.

30 changes: 0 additions & 30 deletions Compat406.ml

This file was deleted.

9 changes: 0 additions & 9 deletions Compat407.ml

This file was deleted.

21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,19 @@ COMPILER-$(COMPAT_VERSION):
rm -f COMPILER-*
touch COMPILER-$(COMPAT_VERSION)

test_ver = $(shell if [ $(COMPAT_VERSION) -lt $(1) ] ; then echo lt ; fi)
test_ver = $(shell if [ $(COMPAT_VERSION) -ge $(1) ] ; then echo ge ; fi)

# This list must be in order
COMPAT_MODULES := $(if $(call test_ver,40100),Compat401) \
$(if $(call test_ver,40200),Compat402) \
$(if $(call test_ver,40300),Compat403) \
$(if $(call test_ver,40500),Compat405) \
$(if $(call test_ver,40600),Compat406) \
$(if $(call test_ver,40700),Compat407)

Compat.ml: COMPILER-$(COMPAT_VERSION) $(addsuffix .ml, $(COMPAT_MODULES))
cat $^ > $@
COMPAT_LEVEL := \
$(strip $(if $(call test_ver,40100),401) \
$(if $(call test_ver,40200),402) \
$(if $(call test_ver,40300),403) \
$(if $(call test_ver,40500),405) \
$(if $(call test_ver,40600),406) \
$(if $(call test_ver,40700),407))

Compat.ml: Compat.ml.in COMPILER-$(COMPAT_VERSION)
sed -e '$(if $(COMPAT_LEVEL),/^$(subst $(SPACE),:\|^,$(COMPAT_LEVEL)):/d;)s/^[0-9]*://' $< > $@

flexlink.exe: $(OBJS) $(RES)
@echo Building flexlink.exe with TOOLCHAIN=$(TOOLCHAIN) for OCaml $(OCAML_VERSION)
Expand Down
5 changes: 4 additions & 1 deletion cmdline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ let parse_cmdline () =
"-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,-" ->
"-link" :: String.sub s 4 (String.length s - 4) :: tr rest
let args =
String.split_on_char ',' (String.sub s 4 (String.length s - 4))
in
List.fold_right (fun arg args -> "-link" :: arg :: args) args (tr rest)
| "-arg" :: x :: rest ->
tr (Array.to_list (Arg.read_arg x)) @ rest
| "-arg0" :: x :: rest ->
Expand Down