Skip to content

Commit c1ecca2

Browse files
brentleyjoneskeith
andauthored
Fix aggressive params file assumption (#14930)
Most programs that accept params files use the `@file` syntax. For Apple platform builds `@` can be the start of non-params file arguments as well, such as `-rpath @executable_path/Frameworks`. There is a small list of options where this is the case, so this new behavior no longer assumes params files if args start with `@`, they also have to not start with one of the 3 keywords used with this (from `man dyld` on macOS). This should always hold since params files generated by bazel should always start with `bazel-out`, if someone renames the symlinks to one of the keywords, they're on their own. Previously the workaround was to always make sure to pass the `-Wl,-rpath,@executable_path` form of these arguments, but this makes users not have to worry about this. In a few other places we check this by checking if the file exists, which is likely more accurate, but feels excessive and potentially dangerous in this context. Related: #13148 Fixes: #14316 Closes #14650. PiperOrigin-RevId: 430195929 (cherry picked from commit 24e8242) Co-authored-by: Keith Smiley <[email protected]>
1 parent e624aff commit c1ecca2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,36 +276,43 @@ CommandLine paramCmdLine() {
276276
paramFile, linkTargetType, forcedToolPath, featureConfiguration, actionName, variables);
277277
}
278278

279-
public static void extractArgumentsForStaticLinkParamFile(
279+
private static void extractArgumentsForStaticLinkParamFile(
280280
List<String> args, List<String> commandlineArgs, List<String> paramFileArgs) {
281281
commandlineArgs.add(args.get(0)); // ar command, must not be moved!
282282
int argsSize = args.size();
283283
for (int i = 1; i < argsSize; i++) {
284284
String arg = args.get(i);
285-
if (arg.startsWith("@")) {
285+
if (isLikelyParamFile(arg)) {
286286
commandlineArgs.add(arg); // params file, keep it in the command line
287287
} else {
288288
paramFileArgs.add(arg); // the rest goes to the params file
289289
}
290290
}
291291
}
292292

293-
public static void extractArgumentsForDynamicLinkParamFile(
293+
private static void extractArgumentsForDynamicLinkParamFile(
294294
List<String> args, List<String> commandlineArgs, List<String> paramFileArgs) {
295295
// Note, that it is not important that all linker arguments are extracted so that
296296
// they can be moved into a parameter file, but the vast majority should.
297297
commandlineArgs.add(args.get(0)); // gcc command, must not be moved!
298298
int argsSize = args.size();
299299
for (int i = 1; i < argsSize; i++) {
300300
String arg = args.get(i);
301-
if (arg.startsWith("@")) {
301+
if (isLikelyParamFile(arg)) {
302302
commandlineArgs.add(arg); // params file, keep it in the command line
303303
} else {
304304
paramFileArgs.add(arg); // the rest goes to the params file
305305
}
306306
}
307307
}
308308

309+
private static boolean isLikelyParamFile(String arg) {
310+
return arg.startsWith("@")
311+
&& !arg.startsWith("@rpath")
312+
&& !arg.startsWith("@loader_path")
313+
&& !arg.startsWith("@executable_path");
314+
}
315+
309316
/**
310317
* Returns a raw link command for the given link invocation, including both command and arguments
311318
* (argv). The version that uses the expander is preferred, but that one can't be used during

0 commit comments

Comments
 (0)