Explorar o código

Force -fPIE for compiles (#5521)

In LLVM, CLANG_DEFAULT_PIE_ON_LINUX is
[configurable](https://github.com/llvm/llvm-project/blob/main/clang/test/CMakeLists.txt#L8),
so change lowering to specify a value.

Also, adjust how the target is set so that function_decl.carbon isn't
trying to overload every flag, and so that the target isn't forgotten
elsewhere.

This is fixing issues introduced by #5427; note #5520 is also a related
fix.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Jon Ross-Perkins hai 11 meses
pai
achega
65c1dcec5f

+ 9 - 3
toolchain/check/import_cpp.cpp

@@ -192,9 +192,15 @@ static auto GenerateAst(Context& context, llvm::StringRef importing_file_path,
   auto ast = clang::tooling::buildASTFromCodeWithArgs(
       GenerateCppIncludesHeaderCode(context, imports),
       // Parse C++ (and not C).
-      {"-x", "c++",
-       // Propagate the target to Clang.
-       "-target", target.str()},
+      {
+          "-x",
+          "c++",
+          // Propagate the target to Clang.
+          "-target",
+          target.str(),
+          // Require PIE. Note its default is configurable in Clang.
+          "-fPIE",
+      },
       (importing_file_path + ".generated.cpp_imports.h").str(), "clang-tool",
       std::make_shared<clang::PCHContainerOperations>(),
       clang::tooling::getClangStripDependencyFileAdjuster(),

+ 0 - 2
toolchain/lower/testdata/interop/cpp/function_decl.carbon

@@ -2,8 +2,6 @@
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-// ARGS: compile --phase=lower --dump-llvm-ir  --exclude-dump-file-prefix=%{core_package_dir} --target=x86_64-unknown-linux-gnu %s
-//
 // AUTOUPDATE
 // TIP: To test this file alone, run:
 // TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/interop/cpp/function_decl.carbon

+ 1 - 1
toolchain/testing/file_test.cpp

@@ -194,7 +194,7 @@ auto ToolchainFileTest::GetDefaultArgs() const
   } else if (component_ == "check") {
     args.push_back("--dump-sem-ir");
   } else if (component_ == "lower") {
-    args.push_back("--dump-llvm-ir");
+    args.insert(args.end(), {"--dump-llvm-ir", "--target=x86_64-linux-gnu"});
   } else {
     CARBON_FATAL("Unexpected test component {0}: {1}", component_, test_name());
   }