Skip to content

Improve flexlink support on Unix (for cross-compiling contexts) - #157

Merged
dra27 merged 3 commits into
ocaml:masterfrom
MisterDA:run-on-unix
Apr 2, 2025
Merged

dra27 merged 3 commits into
ocaml:masterfrom
MisterDA:run-on-unix

Conversation

@MisterDA

Copy link
Copy Markdown
Contributor

When flexlink runs on Unix in cross-compiling contexts, it shouldn't use cmd.exe or batch syntax, or response files.

@dra27 dra27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that flexlink runs on both Sys.cygwin and Sys.win32 already, I'd possibly change the guards to be written in terms of Sys.unix instead (but that's probably just paranoia).

I'm not following the need for the exec bit yet (and therefore as to whether it should be guarded if Sys.unix then instead?)

Comment thread reloc.ml Outdated
(* note: for Cygwin, using bash allow to follow symlinks to find
gcc... *)
if !toolchain = `CYGWIN64 ||
if not Sys.win32 || !toolchain = `CYGWIN64 ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters, but given that this works if flexlink is on either native Windows or Cygwin, why not instead have if Sys.unix ||?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to find a counter-example, so your idea must work.

Comment thread reloc.ml Outdated
String.concat " "
(List.map (fun f -> if f = "" then f else Filename.quote f) lst) in
if String.length s >= 1024 && cmdline.may_use_response_file then Filename.quote (build_diversion lst)
if (Sys.win32 || Sys.cygwin) && String.length s >= 1024 && cmdline.may_use_response_file then Filename.quote (build_diversion lst)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Sys.win32 || Sys.cygwin) && String.length s >= 1024 && cmdline.may_use_response_file then Filename.quote (build_diversion lst)
if not Sys.unix && String.length s >= 1024 && cmdline.may_use_response_file then Filename.quote (build_diversion lst)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied, thanks

Comment thread reloc.ml Outdated
else
begin
let (cfn, oc) = open_temp_file "longcmd" ".sh" in
output_string oc "exec ";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this definitely correct? The command before was going to go via Sys.command (i.e. "sh -c"-like), which this in theory breaks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command goes into a bash file that's executed as bash longcmdxxxxxx.sh below. As it's always a single invocation (no pipes, no command chains) and sometimes redirections, I think it's exactly the use-case for exec. Am I mistaken?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you mean. The whole thing boils down to sh -c 'bash longcmdxxxxxx.sh'. Better be safe than sorry, I'll revert this bit.

@MisterDA
MisterDA marked this pull request as draft March 29, 2025 10:51
@MisterDA
MisterDA marked this pull request as ready for review March 31, 2025 17:06

@dra27 dra27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a rebase, but otherwise good to go, thank you!

MisterDA added 3 commits April 2, 2025 13:51
Use link.exe/lld-link.exe /? option to avoid lld-link complaining
about no input files. Pass /nologo just in case, to avoid Microsoft's
copyright prompt.
@dra27
dra27 enabled auto-merge April 2, 2025 16:07
@dra27
dra27 merged commit a280d9a into ocaml:master Apr 2, 2025
@MisterDA
MisterDA deleted the run-on-unix branch April 2, 2025 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants