Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -244,7 +244,16 @@ "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE) endif() -set(CLANG_DEFAULT_OBJCOPY "objcopy" CACHE STRING +# The CLANG_DEFAULT_OBJCOPY program must support these interfaces +# For the -gsplit-dwarf : +# --extract-dwo +# --strip-dwo +# +# And to work with the testsuite it should be called '*objcopy' +# +# llvm-objcopy is the most universal program. +# newer gnu objcopy also works. +set(CLANG_DEFAULT_OBJCOPY "llvm-objcopy" CACHE STRING "Default objcopy executable to use.") set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3020,16 +3020,13 @@ // -gsplit-dwarf should turn on -g and enable the backend dwarf // splitting and extraction. - // FIXME: Currently only works on Linux. - if (T.isOSLinux()) { - if (!SplitDWARFInlining) - CmdArgs.push_back("-fno-split-dwarf-inlining"); - - if (SplitDWARFArg) { - if (DebugInfoKind == codegenoptions::NoDebugInfo) - DebugInfoKind = codegenoptions::LimitedDebugInfo; - CmdArgs.push_back("-enable-split-dwarf"); - } + if (!SplitDWARFInlining) + CmdArgs.push_back("-fno-split-dwarf-inlining"); + + if (SplitDWARFArg) { + if (DebugInfoKind == codegenoptions::NoDebugInfo) + DebugInfoKind = codegenoptions::LimitedDebugInfo; + CmdArgs.push_back("-enable-split-dwarf"); } // After we've dealt with all combinations of things that could @@ -3616,7 +3613,7 @@ // Add the split debug info name to the command lines here so we // can propagate it to the backend. - bool SplitDWARF = SplitDWARFArg && RawTriple.isOSLinux() && + bool SplitDWARF = SplitDWARFArg && (isa(JA) || isa(JA) || isa(JA)); const char *SplitDWARFOut; @@ -4819,7 +4816,6 @@ // Handle the debug info splitting at object creation time if we're // creating an object. - // TODO: Currently only works on linux with newer objcopy. if (SplitDWARF && Output.getType() == types::TY_Object) SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDWARFOut); @@ -5487,9 +5483,7 @@ // Handle the debug info splitting at object creation time if we're // creating an object. - // TODO: Currently only works on linux with newer objcopy. - if (Args.hasArg(options::OPT_gsplit_dwarf) && - getToolChain().getTriple().isOSLinux()) + if (Args.hasArg(options::OPT_gsplit_dwarf)) SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDebugName(Args, Input)); } Index: lib/Driver/ToolChains/FreeBSD.cpp =================================================================== --- lib/Driver/ToolChains/FreeBSD.cpp +++ lib/Driver/ToolChains/FreeBSD.cpp @@ -115,6 +115,12 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); + + // Handle the debug info splitting at object creation time if we're + // creating an object. + if (Args.hasArg(options::OPT_gsplit_dwarf)) + SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, + SplitDebugName(Args, Inputs[0])); } void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, Index: lib/Driver/ToolChains/Gnu.cpp =================================================================== --- lib/Driver/ToolChains/Gnu.cpp +++ lib/Driver/ToolChains/Gnu.cpp @@ -784,9 +784,7 @@ // Handle the debug info splitting at object creation time if we're // creating an object. - // TODO: Currently only works on linux with newer objcopy. - if (Args.hasArg(options::OPT_gsplit_dwarf) && - getToolChain().getTriple().isOSLinux()) + if (Args.hasArg(options::OPT_gsplit_dwarf)) SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDebugName(Args, Inputs[0])); } Index: test/Driver/split-debug.c =================================================================== --- test/Driver/split-debug.c +++ test/Driver/split-debug.c @@ -1,17 +1,31 @@ // Check that we split debug output properly // +// Linux // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s // // CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo" // CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o" +// FreeBSD +// RUN: %clang -fno-integrated-as -target x86_64-unknown-freebsd11.0 -gsplit-dwarf -c -### %s 2> %t +// RUN: FileCheck -check-prefix=FREEBSD-NOIA-CHECK-ACTIONS < %t %s +// +// FREEBSD-NOIA-CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo" +// FREEBSD-NOIA-CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o" +// +// RUN: %clang -fintegrated-as -target x86_64-unknown-freebsd11.0 -gsplit-dwarf -c -### %s 2> %t +// RUN: FileCheck -check-prefix=FREEBSD-IA-CHECK-ACTIONS < %t %s +// +// FREEBSD-IA-CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo" +// FREEBSD-IA-CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o" +// Macosx // RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t -// RUN: FileCheck -check-prefix=CHECK-NO-ACTIONS < %t %s +// RUN: FileCheck -check-prefix=MACOSX-CHECK-ACTIONS < %t %s // -// CHECK-NO-ACTIONS-NOT: -split-dwarf - +// MACOSX-CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo" +// MACOSX-CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o" // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -o Bad.x -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-BAD < %t %s Index: test/Driver/split-debug.s =================================================================== --- test/Driver/split-debug.s +++ test/Driver/split-debug.s @@ -6,12 +6,17 @@ // CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo" // CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o" +// RUN: %clang -target x86_64-unknown-freebsd11.0 -gsplit-dwarf -c -### %s 2> %t +// RUN: FileCheck -check-prefix=FREEBSD-CHECK-ACTIONS < %t %s +// +// FREEBSD-CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo" +// FREEBSD-CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o" // RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t -// RUN: FileCheck -check-prefix=CHECK-NO-ACTIONS < %t %s +// RUN: FileCheck -check-prefix=MACOSX-CHECK-ACTIONS < %t %s // -// CHECK-NO-ACTIONS-NOT: -split-dwarf - +// MACOSX-CHECK-ACTIONS: objcopy{{.*}}--extract-dwo{{.*}}"split-debug.dwo" +// MACOSX-CHECK-ACTIONS: objcopy{{.*}}--strip-dwo{{.*}}"split-debug.o" // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -o Bad.x -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-BAD < %t %s