Give user possibility to avoid passing -fuse-ld to cc with --linker=. (#3382)

This commit is contained in:
Johan Engelen 2020-03-24 00:12:33 +01:00 committed by GitHub
parent 336da83945
commit 1aa55f7879
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 5 deletions

View file

@ -577,7 +577,9 @@ void ArgsBuilder::addLinker() {
// Default to ld.gold on Linux due to ld.bfd issues with ThinLTO (see #2278) // Default to ld.gold on Linux due to ld.bfd issues with ThinLTO (see #2278)
// and older bfd versions stripping llvm.used symbols (e.g., ModuleInfo // and older bfd versions stripping llvm.used symbols (e.g., ModuleInfo
// refs) with --gc-sections (see #2870). // refs) with --gc-sections (see #2870).
args.push_back("-fuse-ld=gold"); // Can be overridden by `-linker=` (explicitly empty).
if (opts::linker.getNumOccurrences() == 0)
args.push_back("-fuse-ld=gold");
} }
} }

View file

@ -27,10 +27,12 @@
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
namespace opts { namespace opts {
llvm::cl::opt<std::string> llvm::cl::opt<std::string> linker(
linker("linker", llvm::cl::ZeroOrMore, llvm::cl::desc("Linker to use"), "linker", llvm::cl::ZeroOrMore,
llvm::cl::value_desc("lld-link|lld|gold|bfd|..."), llvm::cl::value_desc("lld-link|lld|gold|bfd|..."),
llvm::cl::cat(opts::linkingCategory)); llvm::cl::desc("Set the linker to use. When explicitly set to '' "
"(nothing), prevents LDC from passing `-fuse-ld` to `cc`."),
llvm::cl::cat(opts::linkingCategory));
} }
static llvm::cl::opt<std::string> static llvm::cl::opt<std::string>

View file

@ -0,0 +1,9 @@
// Check that the user can override LDC passing `-fuse-ld` to `cc`.
// REQUIRES: target_X86
// RUN: %ldc --gcc=echo --mtriple=x86_64-linux --linker= %s | FileCheck %s
// CHECK-NOT: -fuse-ld
// CHECK: linker_empty
// CHECK-NOT: -fuse-ld