ld, mold work. lld, gold don't

For discussion of ports to POSIX based systems, especially using GNUStep.

Moderators: another_commander, winston, Getafix

Post Reply
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 775
Joined: Sun Jun 20, 2010 6:00 pm

ld, mold work. lld, gold don't

Post by mcarans »

I have tested various linkers. The Flatpak runtime default linker is gold - it doesn't link with the Oolite deployment build.

lld 20 and 21 both cause a segmentation fault when the game starts. I have created an issue with the LLVM Project and with libobjc2 in case the problem somehow is there which seems unlikely.

ld (bfd) the standard linker works in all cases including flatpak. I also tested mold and it works on Ubuntu and flatpak.
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 775
Joined: Sun Jun 20, 2010 6:00 pm

Re: ld, mold work. lld, gold don't

Post by mcarans »

I learnt something new. You can make a reproducible tar to recreate problems with linkers.

To do this in GNUmakefile set:

Code: Select all

    ADDITIONAL_LDFLAGS           = -fuse-ld=lld  
    ADDITIONAL_LDFLAGS           += -Wl,--reproduce=/tmp/rep.tar
Comment these link time optimisation lines in that file:

Code: Select all

    ifeq ($(lto),yes)
        ADDITIONAL_CFLAGS        += -flto
        ADDITIONAL_OBJCFLAGS     += -flto
        ADDITIONAL_CCFLAGS       += -flto
        ADDITIONAL_LDFLAGS       += -flto
    endif
Run make -f Makefile release-deployment then unpack the /tmp/rep.tar file produced.

Copy the Resources folder from an existing oolite.app to the unpacked rep.tar folder.

Then you can do ld.lld @response.txt to produce the oolite executable.

You can test different linkers eg. mold @response.txt or ld.bfd @response.txt for the gcc linker.

I've created a reproduce tar for the issue I raised with LLVM project: https://github.com/llvm/llvm-project/is ... 3695092366
User avatar
Lone_Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 829
Joined: Wed Aug 08, 2007 10:59 pm
Location: Netherlands

Re: ld, mold work. lld, gold don't

Post by Lone_Wolf »

binutils 2.44 release notes wrote:
Perhaps the most significant change is the absence of the "gold" linker, which is deprecated and about to disappear entirely. Gold appeared in 2008 with some fanfare as a faster linker, but it has suffered from a lack of maintenance in recent years.
see https://lwn.net/Articles/1007541/

Don't bother with gold linker.
OS : Arch Linux 64-bit - rolling release

From: The Netherlands, Europe

OXPs : My user page (needs updating)

Retired, occasionally active
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 775
Joined: Sun Jun 20, 2010 6:00 pm

Re: ld, mold work. lld, gold don't

Post by mcarans »

Lone_Wolf wrote: Mon Dec 29, 2025 2:02 pm
binutils 2.44 release notes wrote:
Perhaps the most significant change is the absence of the "gold" linker, which is deprecated and about to disappear entirely. Gold appeared in 2008 with some fanfare as a faster linker, but it has suffered from a lack of maintenance in recent years.
see https://lwn.net/Articles/1007541/

Don't bother with gold linker.
I wouldn't have bothered with gold, but surprisingly, it is still the standard linker in the flatpak runtime which prompted this investigation.
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 775
Joined: Sun Jun 20, 2010 6:00 pm

Re: ld, mold work. lld, gold don't

Post by mcarans »

I found that rebuilding libjs_static.a rather than using the one in the repo which is really old fixes it for the lld linker. As with oolite_splash, I will need to use zig to target older glibc or build on older ubuntu rather than using the .a I built locally with gcc.
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 775
Joined: Sun Jun 20, 2010 6:00 pm

Re: ld, mold work. lld, gold don't

Post by mcarans »

I have made a repo for building spidermonkey from source on Linux: https://github.com/mcarans/spidermonkey-linux

I've used it to build on Ubuntu 22.04 a libjs_static.a file to update the one we currently use: https://github.com/OoliteProject/oolite ... ies/pull/4
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 775
Joined: Sun Jun 20, 2010 6:00 pm

Re: ld, mold work. lld, gold don't

Post by mcarans »

With AI assistance, I was able to debug the lld linking problem with old SpiderMonkey and provide a summary to the LLVM devs - basically that lld seems to omit relative relocations:

https://github.com/llvm/llvm-project/is ... 4131570768

Turns out this was an intentional change in lld in 2021: https://maskray.me/blog/2021-11-07-init ... transition

The main thing is it's not a bug and that the solution is simple and already checked in: rebuild libjs_static.a with gcc on Ubuntu 22.
Post Reply