zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.71k stars 6.54k forks source link

Using mold for faster linking #57844

Open arbrauns opened 1 year ago

arbrauns commented 1 year ago

Is your enhancement proposal related to a problem? Please describe. A significant part of the total build time for a zephyr project can be taken up by the linking of up to three ELF binaries, especially for incremental builds. The mold linker is specifically designed as a significantly faster, modern alternative to existing linkers.

Unfortunately, it is currently targeted mostly at (linux) OS packaging rather than embedded use. As such, there are at least a few outstanding issues that make it unsuitable for the time being, among them:

Describe the solution you'd like The build system automatically uses mold if available, for faster builds without user action.

Describe alternatives you've considered The user can opt-in to using mold using a CMake directive.

Additional context I'm mostly posting this here since I haven't found any previous discussion on this, and so other people don't have to try and fail at setting it up themselves.

nashif commented 1 year ago

@tejlmand @stephanosio FYI

stephanosio commented 1 year ago

I cannot possibly think of a way we can use this linker when it does not have a proper support for the linker scripts; moreover, its author does not seem to be very keen on supporting one either.

I would suggest closing this for now and re-opening it after mold becomes a proper linker that supports linker scripts.

arbrauns commented 1 year ago

Sure, I wasn't suggesting supporting it in its current state, just wanted to post a "tracking issue" to be referred to in the future.

nordicjm commented 1 year ago

A significant part of the total build time for a zephyr project can be taken up by the linking of up to three ELF binaries, especially for incremental builds.

I mean, really? Are you running on windows? And how slow is slow? Because I've certainly not noticed linking to be slow on ESXi VMs, desktops or laptops on linux.

arbrauns commented 1 year ago

I mean, really? Are you running on windows? And how slow is slow? Because I've certainly not noticed linking to be slow on ESXi VMs, desktops or laptops on linux.

In one of my current projects, touching a single source file causes a subsequent west build to take 28 seconds. Actually recompiling the C file only takes a fraction of a second, of course, the rest is linking zephyr_pre0.elf, zephyr_pre1.elf and zephyr.elf.

Linux, i7-11700, project directory on an NVMe SSD.

zephyrbot commented 8 months ago

Hi @tejlmand, @evgeniy-paltsev, @nashif, @tejlmand, @abrodkin,

This issue, marked as an Enhancement, was opened a while ago and did not get any traction. It was just assigned to you based on the labels. If you don't consider yourself the right person to address this issue, please re-assing it to the right person.

Please take a moment to review if the issue is still relevant to the project. If it is, please provide feedback and direction on how to move forward. If it is not, has already been addressed, is a duplicate, or is no longer relevant, please close it with a short comment explaining the reason.

@arbrauns you are also encouraged to help moving this issue forward by providing additional information and confirming this request/issue is still relevant to you.

Thanks!

arbrauns commented 8 months ago

I don't think there's anything actionable here yet, this is waiting on improvements in upstream mold.