ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.21k stars 261 forks source link

macOS: Pass `-no_deduplicate` to linker for non-optimized builds #3521

Open JohanEngelen opened 4 years ago

JohanEngelen commented 4 years ago

While researching ThreadSanitizer, I noticed that clang passes -no_deduplicate to the linker on macOS for debug builds:

/// Pass -no_deduplicate to ld64 under certain conditions:
///
/// - Either -O0 or -O1 is explicitly specified
/// - No -O option is specified *and* this is a compile+link (implicit -O0)
///
/// Also do *not* add -no_deduplicate when no -O option is specified and this
/// is just a link (we can't imply -O0)
static bool shouldLinkerNotDedup(bool IsLinkerOnlyAction, const ArgList &Args) {
  if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
    if (A->getOption().matches(options::OPT_O0))
      return true;
    if (A->getOption().matches(options::OPT_O))
      return llvm::StringSwitch<bool>(A->getValue())
                    .Case("1", true)
                    .Default(false);
    return false; // OPT_Ofast & OPT_O4
  }

  if (!IsLinkerOnlyAction) // Implicit -O0 for compile+linker only.
    return true;
  return false;
}

Passing the flag may speed up builds by quite a bit: https://jira.mongodb.org/browse/SERVER-31875

Someone care to test this on macOS with different programs and see if the flag has a big impact? If so: we should add something similar as clang is doing.

kinke commented 4 years ago

I've added something similar for MSVC (but only for -g[c] builds): https://github.com/ldc-developers/ldc/blob/10cf5f0a46195d4623745ef34326d11b4d717d18/driver/linker-msvc.cpp#L123-L125