Page 1 of 1

Linux MUSL

Posted: Sat Sep 03, 2022 1:13 am
by swoboderz
So i have been experimenting with a MUSL libc and heres some problems i have run into.

Code: Select all

dots@gentpad ~ $ factorio
Error relocating /home/dots/Games/factorio/bin/x64/factorio: setcontext: symbol not found
Error relocating /home/dots/Games/factorio/bin/x64/factorio: makecontext: symbol not found
Error relocating /home/dots/Games/factorio/bin/x64/factorio: __res_nquery: symbol not found
Error relocating /home/dots/Games/factorio/bin/x64/factorio: __dn_expand: symbol not found
After installing libucontext from official repository:

Code: Select all

dots@gentpad ~ $ factorio
Error relocating /home/dots/Games/factorio/bin/x64/factorio: __res_nquery: symbol not found
Error relocating /home/dots/Games/factorio/bin/x64/factorio: __dn_expand: symbol not found
I do know the functions just above come from a libresolv but it seems the MUSL libc does not contain it. i tried doing a quick hack of designing the function signatures by creating a gcompat patch (glibc compat layer) myself with various combos of returning -1, 0, or x > 0 but it segfaults.

I can confirm it wasnt the libucontext but instead the patch, which changes the ld-linux (ld-musl) binary from the following:

Code: Select all

(lldb) run
Process 5712 launched: '/home/dots/Games/factorio/bin/x64/factorio' (x86_64)
Process 5712 stopped
* thread #1, name = 'ld-musl-x86_64.', stop reason = exec
    frame #0: 0x00007ffff7fc3027 libc.so`_dlstart
libc.so`_dlstart:
->  0x7ffff7fc3027 <+0>:  xorq   %rbp, %rbp
    0x7ffff7fc302a <+3>:  movq   %rsp, %rdi
    0x7ffff7fc302d <+6>:  leaq   0x37df4(%rip), %rsi
    0x7ffff7fc3034 <+13>: andq   $-0x10, %rsp
(lldb) continue
Process 5712 resuming
Process 5712 stopped
* thread #1, name = 'ld-musl-x86_64.', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
    frame #0: 0x000000000172b8e5
->  0x172b8e5: andw   (%rax,%r12,2), %dx
    0x172b8ea: jne    0x172b848
    0x172b8f0: andl   $0x1, %r15d
    0x172b8f4: je     0x172b910
(lldb)
I am wondering what it would actually take to get MUSL support. or any ideas on how to get around the unfound symbols (i had previously assumed the Mod menu would be broken before i found it segfaulting with my cheap imitation)
Thanks! :D

Re: Linux MUSL

Posted: Sat Sep 03, 2022 2:53 pm
by Rseding91
But why?

Re: Linux MUSL

Posted: Sat Sep 03, 2022 4:38 pm
by swoboderz
Rseding91 wrote: Sat Sep 03, 2022 2:53 pmBut why?
What do you mean?

Re: Linux MUSL

Posted: Sat Sep 03, 2022 5:04 pm
by Rseding91
Why try to get a 3rd party library working with the game when you could just *play* the game as is?

Re: Linux MUSL

Posted: Sat Sep 03, 2022 7:04 pm
by swoboderz
Rseding91 wrote: Sat Sep 03, 2022 5:04 pm Why try to get a 3rd party library working with the game when you could just *play* the game as is?
there are differences between the MUSL libc ABI and the GLIBC ABI. MUSL is trying to become a full replacement, however there remains a package "gcompat" for more non-posix standards that glibc happenned to create to add support outside the MUSL libc. if you are unaware, a LibC maps C standard functions to a program. On my current operating system, factorio simply will not run because its not using the GNU Libc. Everything if installed up until the point of factorio was source compiled. so there was no issue.

Re: Linux MUSL

Posted: Sun Sep 04, 2022 12:12 am
by mrvn
You should check your code. You obviously implemented the missing functions wrong.

res_nquery() is used to find the factorio server to check for updates, to download mods and for multiplayer. While you can probably play offline (which would allow a return -1 for the function) that would limit the game. Returning 0 seems kind of odd and returning x > 0 will definetly not work if you don't actually fill in the answer buffer.

You should write a dummy libresolv linked against musl.

Re: Linux MUSL

Posted: Sun Sep 04, 2022 4:29 pm
by ptx0
Rseding91 wrote: Sat Sep 03, 2022 5:04 pm Why try to get a 3rd party library working with the game when you could just *play* the game as is?
well, Alpine Linux is based on musl instead of libc.

Re: Linux MUSL

Posted: Mon Sep 05, 2022 12:21 am
by swoboderz
mrvn wrote: Sun Sep 04, 2022 12:12 am You should check your code. You obviously implemented the missing functions wrong.

res_nquery() is used to find the factorio server to check for updates, to download mods and for multiplayer. While you can probably play offline (which would allow a return -1 for the function) that would limit the game. Returning 0 seems kind of odd and returning x > 0 will definetly not work if you don't actually fill in the answer buffer.

You should write a dummy libresolv linked against musl.
I actually tried returning -1 and it proceeded to segfault anyway

Re: Linux MUSL

Posted: Mon Sep 05, 2022 12:28 am
by mrvn
swoboderz wrote: Mon Sep 05, 2022 12:21 am
mrvn wrote: Sun Sep 04, 2022 12:12 am You should check your code. You obviously implemented the missing functions wrong.

res_nquery() is used to find the factorio server to check for updates, to download mods and for multiplayer. While you can probably play offline (which would allow a return -1 for the function) that would limit the game. Returning 0 seems kind of odd and returning x > 0 will definetly not work if you don't actually fill in the answer buffer.

You should write a dummy libresolv linked against musl.
I actually tried returning -1 and it proceeded to segfault anyway
Did you set h_errno? Returning an error of SUCCESS (or whatever value is in h_errno currently) might be confusing the code.

Re: Linux MUSL

Posted: Mon Sep 05, 2022 12:52 pm
by vinzenz
swoboderz wrote: Mon Sep 05, 2022 12:21 am I actually tried returning -1 and it proceeded to segfault anyway

you can try stubbing res_ninit to return -1, so Factorio doesn't even try to engage with libresolv