Incremental links for created non-source linker inputs

17 views
Skip to first unread message

Nico Weber

unread,
May 20, 2021, 10:41:46 AM5/20/21
to gn-dev
Hi,

the LLVM build has ".export" files that lists a bunch of symbols. They're converted to a platform-specific file in a build step (for example a .def file on Windows or version script on Linux), and then the path to that generated file is passed to the linker (for example using /DEF:$file on Windows, or -Wl,--version-script,$file on Linux).

In the GN build, I'm modeling this with a template that has an action() to do the conversion, and a config() that adds the right ldflags, and the config() is a public_config on the action. That way, clients only have to use the template to create a target, add a dep on that in a shared_library() target, and things work. (Details: https://reviews.llvm.org/D102843)

However, if the .export file is touched and nothing else changes, then the build will correctly re-create the platform-specific linker input, but it won't actually re-run the link: The shared_library() target considers the dep on the action creating the linker input as an order-only dep. Is there some way to make this work?

(I tried adding `inputs = get_target_outputs(":exports")` to the shared_library target. With that, the target does re-link when the .exports file is touched. But all of the target's sources also get recompiled, and it means using the template requires adding both the dep and that line. So that approach isn't ideal.)

Looking around a bit I found:

These suggest that there's no good way for doing that. Is that still correct? I like the idea in the second bug that suggests having the linker write a depfile. That would address this nicely.

Thanks,
Nico

Andrew Grieve

unread,
May 20, 2021, 10:58:50 AM5/20/21
to Nico Weber, gn-dev
I just skimmed, but config() can have inputs now if that's enough. We do it for afdo profiles:

Nico Weber

unread,
May 20, 2021, 11:01:43 AM5/20/21
to Andrew Grieve, gn-dev
Ah I forgot to mention that I tried this too. GN then complains that the input is generated but that here's no dep on the action generating it -- but configs can't have reps.

Petr Hosek

unread,
May 20, 2021, 1:43:40 PM5/20/21
to Nico Weber, Andrew Grieve, gn-dev
We've implemented support for depfiles in LLD, but only in the ELF backend. It's enabled by the --dependency-file= option, see its use in our build: https://cs.opensource.google/fuchsia/fuchsia/+/main:build/toolchain/clang_toolchain.gni;l=478

--
To unsubscribe from this group and stop receiving emails from it, send an email to gn-dev+un...@chromium.org.

Petr Hosek

unread,
May 20, 2021, 1:47:02 PM5/20/21
to Nico Weber, Andrew Grieve, gn-dev
I forgot to mention, we also implemented that feature in BFD ld and gold, but it only landed a year ago so you need relatively recent versions.
Reply all
Reply to author
Forward
0 new messages