InBetweenNames / gentooLTO

A Gentoo Portage configuration for building with -O3, Graphite, and LTO optimizations
GNU General Public License v2.0
570 stars 96 forks source link

Add Support for Mold (linker) #820

Open OpenSourceAnarchist opened 2 years ago

OpenSourceAnarchist commented 2 years ago

Mold is an alternative linker that recently became stable, and it provides numerous benefits over lld, gold, and bfd. Benchmarks are provided on the project's GitHub page (see https://github.com/rui314/mold).

Mold is available in Gentoo's default repositories (sys-devel/mold) and more info is available on the Gentoo Wiki page (https://wiki.gentoo.org/wiki/Mold).

It seems to be a drop-in replacement, though currently GCC 11.x requires a patch (listed on the Wiki page — this one) to use it at the moment. GCC 12.1.0 and onward has official support. See https://github.com/rui314/mold#how-to-use for more details about how to set it up with Clang, GCC, Rust, etc.

There is a Gentoo bug page for tracking packages with link failures using mold, though it is currently empty. According to the Wiki page, "mold does not support linker scripts; it cannot be used to link the kernel", so we should add a file with a fallback LDFLAGS definition for such packages, though very few exceptions should be needed. According to the project's GitHub page, users are encouraged "to file a bug if you find mold is not faster than other linkers", so there should be no downside to moving to mold as it will always try to be the fastest linker.

wolfwood commented 2 years ago

sadly i have a number of packages that depend on an older version of tbb and are thus blocking installation of mold. definitely excited to see this tested tho.

wolfwood commented 2 years ago

I can't get the patch to apply.

also, this is a list of gentoo packages that fail from the mold author https://docs.google.com/spreadsheets/u/1/d/1LnyrUw79oY5DxBNfXGmlxr2-0n4V0AA06BzbO2cdhZg/htmlview#gid=0

OpenSourceAnarchist commented 2 years ago

@wolfwood Thank you for that list, that's really helpful if this eventually gets accepted. I didn't try the patch (currently am on Arch Linux with the ALHP custom repos but might switch to gentooLTO...)—what version of gcc are you running?

Unfortunately, mold also doesn't currently support LTO. Perhaps once rui314/mold#181 is fixed/implemented then gentooLTO can consider making the official switch. Seems like a blocking issue as of right now.

wolfwood commented 2 years ago

I'm running the version the patch is for 11.2.1_p20211127.

glad to see the gcc LTO folks are enthusiastic about mold support!

On Thu, Jan 6, 2022, 10:31 OpenSourceAnarchist @.***> wrote:

@wolfwood https://github.com/wolfwood Thank you for that list, that's really helpful if this eventually gets accepted. I didn't try the patch (currently am on Arch Linux with the ALHP custom repos https://git.harting.dev/ALHP/ALHP.GO but might switch to gentooLTO...)—what version of gcc are you running?

Unfortunately, mold also doesn't currently support LTO. Perhaps once rui314/mold#181 https://github.com/rui314/mold/issues/181 is fixed/implemented then gentooLTO can consider making the official switch. Seems like a blocking issue as of right now.

— Reply to this email directly, view it on GitHub https://github.com/InBetweenNames/gentooLTO/issues/820#issuecomment-1006819428, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAHXYWSLC5FI6OW2K3BLG3UUXNXBANCNFSM5LFI4IWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Jannik2099 commented 2 years ago

Right now mold is not a drop-in, it's a drop-through - linkers have grown WAY more features than just rudimentarily stitching together object files, and many packages make use of these features. Mold simply doesn't provide most of that functionality yet, and it will lead to silent corruption in some specific shared library configurations. It is far away from ready for system-wide, and I don't see why lto-overlay should hop on so soon.

Besides, is this the right place for a linker that can't do LTO? :P

ptr1337 commented 2 years ago

@OpenSourceAnarchist I got some gcc packages with the mold patch. Currently does mold a fallback to the other linker, if lto is detected. Here you can find the packages and also the pkgbuild and their patches in.

https://cloud.ptr1337.dev/s/zN4jQ7MAENd663P

Also compiling right now a gcc 11.2.1 (latest commit) and the gentoo gcc patches included. Also the lto gcc support patch (if it works) is included, which you find here:

https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=76f10e938b79e87c2890e16ffcc350af0ec5e1b9

ghost commented 2 years ago

Latest version of gcc, gcc-11.2.1_p20220115, contains the changes required to use mold officially

mid-kid commented 2 years ago

Apparently mold supports LTO since version 1.1!