Skip to content

Commit

Permalink
Linkstatic support for use_lto_native_object_directory
Browse files Browse the repository at this point in the history
Adds support for use_lto_native_object_directory when using linkstatic, which allows us to use linkstatic and actions that generate tree artifacts simultaneously.

When use_lto_native_object_directory is enabled, lto artifacts that are not handled by lto indexing are stored in shared.nonlto-obj, instead of shared.nonlto.

LibrariesToLinkCollector currently assumes that they are stored in shared.nonlto, resulting in an error when using linkstatic.

We check if use_lto_native_object_directory is enabled, and if it is, we check if obj files are stored in shared.nonlto-obj instead of shared.nonlto.

PiperOrigin-RevId: 568542260
Change-Id: I53c336ac9fccee2276f28aa46c585d21f478c31b
  • Loading branch information
Googler authored and Copybara-Service committed Sep 26, 2023
1 parent 92e16da commit 480c8c8
Showing 1 changed file with 12 additions and 5 deletions.
Expand Up @@ -646,6 +646,12 @@ private void addStaticInputLinkOptions(
boolean inputIsWholeArchive =
!input.disableWholeArchive() && (isAlwaysLinkStaticLibrary || needWholeArchive);

PathFragment sharedNonLtoObjRootPrefix =
featureConfiguration.isEnabled(CppRuleClasses.USE_LTO_NATIVE_OBJECT_DIRECTORY)
? CppHelper.getThinLtoNativeObjectDirectoryFromLtoOutputRoot(
CppHelper.SHARED_NONLTO_BACKEND_ROOT_PREFIX)
: CppHelper.SHARED_NONLTO_BACKEND_ROOT_PREFIX;

// If we had any LTO artifacts, ltoMap whould be non-null. In that case,
// we should have created a thinltoParamFile which the LTO indexing
// step will populate with the exec paths that correspond to the LTO
Expand All @@ -667,7 +673,7 @@ private void addStaticInputLinkOptions(
if (ltoMap != null && (a = ltoMap.remove(member)) != null) {
// When ltoMap is non-null the backend artifact may be missing due to libraries that
// list .o files explicitly, or generate .o files from assembler.
if (handledByLtoIndexing(a, allowLtoIndexing)) {
if (handledByLtoIndexing(a, allowLtoIndexing, sharedNonLtoObjRootPrefix)) {
// The LTO artifacts that should be included in the final link
// are listed in the thinltoParamFile, generated by the LTO indexing.

Expand Down Expand Up @@ -724,7 +730,7 @@ private void addStaticInputLinkOptions(
Artifact inputArtifact = input.getArtifact();
Artifact a;
if (ltoMap != null && (a = ltoMap.remove(inputArtifact)) != null) {
if (handledByLtoIndexing(a, allowLtoIndexing)) {
if (handledByLtoIndexing(a, allowLtoIndexing, sharedNonLtoObjRootPrefix)) {
// The LTO artifacts that should be included in the final link
// are listed in the thinltoParamFile, generated by the LTO indexing.

Expand Down Expand Up @@ -772,13 +778,14 @@ private void addStaticInputLinkOptions(
*
* @param a is an artifact produced by an LTO backend.
* @param allowLtoIndexing
* @param sharedNonLtoObjRootPrefix the root prefix of where the shared non lto obj are stored
*/
private static boolean handledByLtoIndexing(Artifact a, boolean allowLtoIndexing) {
private static boolean handledByLtoIndexing(
Artifact a, boolean allowLtoIndexing, PathFragment sharedNonLtoObjRootPrefix) {
// If no LTO indexing is allowed for this link, then none are handled by LTO indexing.
// Otherwise, this may be from a linkstatic library that we decided not to include in
// LTO indexing because we are linking a test, to improve scalability when linking many tests.
return allowLtoIndexing
&& !a.getRootRelativePath().startsWith(CppHelper.SHARED_NONLTO_BACKEND_ROOT_PREFIX);
return allowLtoIndexing && !a.getRootRelativePath().startsWith(sharedNonLtoObjRootPrefix);
}

@Nullable
Expand Down

0 comments on commit 480c8c8

Please sign in to comment.