Skip to content

Commit 2885c51

Browse files
NuriAmarifacebook-github-bot
authored andcommitted
Add option to use thin archives and --start-lib --end-lib style linker invocations (attempt 2)
Summary: When linking an executable, each apple_library depended upon is usually packaged as a static archive. While we want archive linking semantics, we often don't want the archive itself. We may instead pass the archive members to the linker between --start-lib and --end-lib flags without ever creating the archive. The hope is that by avoiding building the archive at all, we may speed up builds and save on RE resources. For the time being, this change excludes distributed thin-LTO, but that will come as a follow up. This change was reverted a couple times, but only because changes to the linker invocation crafting logic this depends upon caused issues. This is a non functional change on its own. Reviewed By: rmaz Differential Revision: D69948536 fbshipit-source-id: 41a41dfd482ec316bc7baad7db09375cf9db9295
1 parent aa18ad8 commit 2885c51

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

prelude/cxx/cxx_library.bzl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,8 +1609,15 @@ def _static_library(
16091609
# object files instead of the originating objects.
16101610
object_external_debug_info = []
16111611
if linker_type == LinkerType("darwin"):
1612-
object_external_debug_info.append(archive.artifact)
1613-
object_external_debug_info.extend(archive.external_objects)
1612+
if archive.external_objects:
1613+
# On Darwin, when using virtual archives, object files are passed
1614+
# to the linker directly between --start-lib --end-lib flags to
1615+
# achieve archive semantics without creating the archive. Providing
1616+
# the archive artifact as an input here is unnecessary.
1617+
object_external_debug_info.extend(archive.external_objects)
1618+
else:
1619+
# For normal archives, we just need to provide the archive artifact
1620+
object_external_debug_info.append(archive.artifact)
16141621
elif objects_have_external_debug_info:
16151622
object_external_debug_info.extend(objects)
16161623

prelude/linking/link_info.bzl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,16 @@ def _is_linkable_comprised_of_object_files_or_a_lazy_archive(linkable: LinkableT
247247
# Adds appropriate args representing `linkable` to `args`
248248
def append_linkable_args(args: cmd_args, linkable: LinkableTypes):
249249
if isinstance(linkable, ArchiveLinkable):
250-
if linkable.link_whole:
250+
if linkable.linker_type == LinkerType("darwin") and linkable.archive.external_objects:
251+
if not linkable.link_whole:
252+
args.add("-Wl,--start-lib")
253+
254+
for object in linkable.archive.external_objects:
255+
args.add(object)
256+
257+
if not linkable.link_whole:
258+
args.add("-Wl,--end-lib")
259+
elif linkable.link_whole:
251260
args.add(get_link_whole_args(linkable.linker_type, [linkable.archive.artifact]))
252261
else:
253262
args.add(linkable.archive.artifact)

0 commit comments

Comments
 (0)