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

Not compatible with Alpine Linux (musl-based distro) #13

Open
dsheets opened this issue Mar 12, 2016 · 0 comments
Open

Not compatible with Alpine Linux (musl-based distro) #13

dsheets opened this issue Mar 12, 2016 · 0 comments
Labels

Comments

@dsheets
Copy link
Contributor

dsheets commented Mar 12, 2016

Execution fails on Alpine Linux 3.3 with:

? ldd "/home/opam/.opam/system/bin/fs_test_posix"
    /lib/ld-musl-x86_64.so.1 (0x55c8cceac000)
    libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x55c8cceac000)
< `ldd /home/opam/.opam/system/bin/fs_test_posix | sed -ne "/libc.so/s/.*=> \\([^ ]*\\).*/\\1/p"`| head -1
fs_test: internal error, uncaught exception:
         Failure("hd")

This is due to fragile libc version extraction code at

let exec = "ldd" in
let args = [|bin|] in
let sed_script = "/libc.so/s/.*=> \\([^ ]*\\).*/\\1/p" in
if exit_command exec args true (function 1 -> Some false | _ -> None)
then (* ldd can understand the ELF binary *)
Libc.System, List.hd (
read_command
("`ldd "^bin
^" | sed -ne "^(sprintf "%S" sed_script)
^"`"
^"| head -1"
)
)
else (* ldd can't understand the ELF binary;
we probably have a different libc... *)
let musl_ldd = "/lib/x86_64-linux-musl/libc.so" in
if Sys.file_exists musl_ldd
then begin
let musl_args = Array.append [|exec|] args in
let env = [||] in
let p = create_process_exec_args musl_ldd musl_args env in
match waitpid [] p.pid with
| (_, Unix.WEXITED 0) ->
let b = Buffer.create 1024 in
ignore (drain_into_buf p.stdout b);
eprintf "%s\n%!" (Buffer.contents b);
let sed = create_process "sed" [|"-ne"; sed_script|] env in
let sed_oc = Unix.out_channel_of_descr sed.stdin in
Buffer.output_buffer sed_oc b;
flush sed_oc;
Unix.close sed.stdin;
(match waitpid [] sed.pid with
| (_, Unix.WEXITED 0) ->
let cmd = input_line (Unix.in_channel_of_descr sed.stdout) in
(* TODO: should this check that we did, in fact, extract a
musl so? *)
Libc.Musl, List.hd (read_command (cmd^" 2>&1 | head -2 | tail -1"))
| (_, Unix.WEXITED _) -> failwith "Error: sed exec failed."
| (_,_) -> failwith "Error: sed exec failed unexpectedly."
)
| (_, Unix.WEXITED _) -> failwith "Error: musl libc exec failed."
| (_, _) -> failwith "Error: musl libc exec failed unexpectedly."
end
else failwith "Error: libc detection failure. Submit a report."
.

@dsheets dsheets added the bug label Mar 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant