aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2016-10-06 10:55:54 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-10-06 10:58:43 +0000
commitffdc05d2278d7f9c6e299c923019f689cde5fe76 (patch)
tree3f927eca381f68465fc0b142c9c499b18d503f62 /src/main/java/com/google/devtools/build/lib/rules/cpp
parent27085f44a168b502542cda6216863601e64da833 (diff)
Add action_config and feature for linking on Windows
Also implemented whole archive feature on Windows 1. Pulled action_configs and features from CppLinkActionConfigs.java 2. Deleted many features not working on Windows. (AFAIK) including: symbol_counts output_execpath_flags_executable global_whole_archive_open runtime_root_flags global_whole_archive_close force_pic_flags 3. Added c++-link-interface-dynamic-library action config Not sure there is such thing on Windows, but it's currently in MANDATORY_LINK_TARGET_TYPES 4. Added build variable "whole_archive_object_files_params" 5. Automatically detect if linker supports /WHOLEARCHIVE and use the corresponding build variable -- Change-Id: I232798a0eb1a3291f972b313a81e678b0121d58c Reviewed-on: https://bazel-review.googlesource.com/#/c/6414 MOS_MIGRATED_REVID=135342093
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java54
1 files changed, 47 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
index f0ca362f9a..178d0688fb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
@@ -86,6 +86,14 @@ public class CppLinkActionBuilder {
public static final String WHOLE_ARCHIVE_LINKER_INPUT_PARAMS_VARIABLE =
"whole_archive_linker_params";
+ /**
+ * A build variable for flags providing object files from libraries that were supposed to go in a
+ * -whole_archive block. Old MSVC linker doesn't support /WHOLEARCHIVE:[LIB] option, so we link
+ * object files directly as a workaround.
+ */
+ public static final String WHOLE_ARCHIVE_OBJECT_FILES_PARAMS_VARIABLE =
+ "whole_archive_object_files_params";
+
/** A build variable whose presence indicates that whole archive flags should be applied. */
public static final String GLOBAL_WHOLE_ARCHIVE_VARIABLE = "global_whole_archive";
@@ -1120,6 +1128,7 @@ public class CppLinkActionBuilder {
Set<String> libopts;
List<String> linkerInputParams;
List<String> wholeArchiveLinkerInputParams;
+ List<String> wholeArchiveObjectFilesParams;
List<String> noWholeArchiveInputs;
public void setRpathRoot(String rPathRoot) {
@@ -1142,6 +1151,10 @@ public class CppLinkActionBuilder {
this.wholeArchiveLinkerInputParams = wholeArchiveInputParams;
}
+ public void setWholeArchiveObjectFilesParams(List<String> wholeArchiveObjectFilesParams) {
+ this.wholeArchiveObjectFilesParams = wholeArchiveObjectFilesParams;
+ }
+
public void setNoWholeArchiveInputs(List<String> noWholeArchiveInputs) {
this.noWholeArchiveInputs = noWholeArchiveInputs;
}
@@ -1166,6 +1179,10 @@ public class CppLinkActionBuilder {
return wholeArchiveLinkerInputParams;
}
+ public List<String> getWholeArchiveObjectFilesParams() {
+ return wholeArchiveObjectFilesParams;
+ }
+
public List<String> getNoWholeArchiveInputs() {
return noWholeArchiveInputs;
}
@@ -1253,6 +1270,9 @@ public class CppLinkActionBuilder {
buildVariables.addSequenceVariable(
WHOLE_ARCHIVE_LINKER_INPUT_PARAMS_VARIABLE,
linkArgCollector.getWholeArchiveLinkerInputParams());
+ buildVariables.addSequenceVariable(
+ WHOLE_ARCHIVE_OBJECT_FILES_PARAMS_VARIABLE,
+ linkArgCollector.getWholeArchiveObjectFilesParams());
// global archive
if (needWholeArchive) {
@@ -1417,6 +1437,7 @@ public class CppLinkActionBuilder {
}
List<String> wholeArchiveInputParams = new ArrayList<>();
+ List<String> wholeArchiveObjectFilesParams = new ArrayList<>();
List<String> standardArchiveInputParams = new ArrayList<>();
for (LinkerInput input : linkerInputs) {
@@ -1434,7 +1455,11 @@ public class CppLinkActionBuilder {
input, standardArchiveInputParams, libOpts, solibDir, rpathRoot);
} else {
addStaticInputLinkOptions(
- input, wholeArchiveInputParams, standardArchiveInputParams, ltoMap);
+ input,
+ wholeArchiveInputParams,
+ wholeArchiveObjectFilesParams,
+ standardArchiveInputParams,
+ ltoMap);
}
}
@@ -1454,8 +1479,10 @@ public class CppLinkActionBuilder {
includeRuntimeSolibDir = true;
addDynamicInputLinkOptions(input, optionsList, libOpts, solibDir, rpathRoot);
} else {
- addStaticInputLinkOptions(input,
+ addStaticInputLinkOptions(
+ input,
needWholeArchive ? noWholeArchiveInputs : wholeArchiveInputParams,
+ needWholeArchive ? null : wholeArchiveObjectFilesParams,
needWholeArchive ? noWholeArchiveInputs : standardArchiveInputParams,
ltoMap);
}
@@ -1476,6 +1503,7 @@ public class CppLinkActionBuilder {
linkArgCollector.setLinkerInputParams(standardArchiveInputParams);
linkArgCollector.setWholeArchiveLinkerInputParams(wholeArchiveInputParams);
+ linkArgCollector.setWholeArchiveObjectFilesParams(wholeArchiveObjectFilesParams);
linkArgCollector.setNoWholeArchiveInputs(noWholeArchiveInputs);
if (ltoMap != null) {
@@ -1530,7 +1558,10 @@ public class CppLinkActionBuilder {
* be supplied for LTO final links.
*/
private void addStaticInputLinkOptions(
- LinkerInput input, List<String> wholeArchiveOptions, List<String> standardOptions,
+ LinkerInput input,
+ List<String> wholeArchiveOptions,
+ List<String> wholeArchiveObjectFilesOptions,
+ List<String> standardOptions,
@Nullable Map<Artifact, Artifact> ltoMap) {
Preconditions.checkState(!(input.getArtifactCategory() == ArtifactCategory.DYNAMIC_LIBRARY));
// If we had any LTO artifacts, ltoMap whould be non-null. In that case,
@@ -1575,10 +1606,19 @@ public class CppLinkActionBuilder {
return;
}
- if (input.isFake()) {
- options.add(Link.FAKE_OBJECT_PREFIX + inputArtifact.getExecPathString());
- } else {
- options.add(inputArtifact.getExecPathString());
+ final String fakePrefix = input.isFake() ? Link.FAKE_OBJECT_PREFIX : "";
+
+ options.add(fakePrefix + inputArtifact.getExecPathString());
+
+ if (input.containsObjectFiles() && inputNeedsWholeArchive(input)) {
+ for (Artifact objectFile : input.getObjectFiles()) {
+ if (ltoMap != null && ltoMap.remove(objectFile) != null) {
+ // The LTO artifacts that should be included in the final link
+ // are listed in the linkerParamsFile.
+ continue;
+ }
+ wholeArchiveObjectFilesOptions.add(fakePrefix + objectFile.getExecPathString());
+ }
}
}
}