Skip to content

Commit e50465e

Browse files
committed
[HIP] Fix -gsplit-dwarf option
when -gsplit option is used with clang driver, clang driver will create a filename with .dwo option based on the input file name and pass it to clang -cc1. This file is used for storing the debug info. Since HIP generate separate object files for different GPU arch's, this file should be different for different GPU arch. This patch adds _ and GPU arch to the stem of the dwo file. Differential Revision: https://reviews.llvm.org/D87791
1 parent 04cebd9 commit e50465e

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4810,7 +4810,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
48104810
(isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA) ||
48114811
isa<BackendJobAction>(JA));
48124812
if (SplitDWARF) {
4813-
const char *SplitDWARFOut = SplitDebugName(Args, Input, Output);
4813+
const char *SplitDWARFOut = SplitDebugName(JA, Args, Input, Output);
48144814
CmdArgs.push_back("-split-dwarf-file");
48154815
CmdArgs.push_back(SplitDWARFOut);
48164816
if (DwarfFission == DwarfFissionKind::Split) {
@@ -7047,7 +7047,7 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
70477047
if (getDebugFissionKind(D, Args, A) == DwarfFissionKind::Split &&
70487048
T.isOSBinFormatELF()) {
70497049
CmdArgs.push_back("-split-dwarf-output");
7050-
CmdArgs.push_back(SplitDebugName(Args, Input, Output));
7050+
CmdArgs.push_back(SplitDebugName(JA, Args, Input, Output));
70517051
}
70527052

70537053
assert(Input.isFilename() && "Invalid input.");

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,22 +902,31 @@ bool tools::areOptimizationsEnabled(const ArgList &Args) {
902902
return false;
903903
}
904904

905-
const char *tools::SplitDebugName(const ArgList &Args, const InputInfo &Input,
905+
const char *tools::SplitDebugName(const JobAction &JA, const ArgList &Args,
906+
const InputInfo &Input,
906907
const InputInfo &Output) {
908+
// Adds '_' and GPU arch to the stem of .dwo file for HIP, which is
909+
// expected by gdb.
910+
auto AddPostfix = [JA](auto &F) {
911+
if (JA.getOffloadingDeviceKind() == Action::OFK_HIP)
912+
F += (Twine("_") + JA.getOffloadingArch()).str();
913+
};
907914
if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
908915
if (StringRef(A->getValue()) == "single")
909916
return Args.MakeArgString(Output.getFilename());
910917

911918
Arg *FinalOutput = Args.getLastArg(options::OPT_o);
912919
if (FinalOutput && Args.hasArg(options::OPT_c)) {
913-
SmallString<128> T(FinalOutput->getValue());
920+
SmallString<128> T(llvm::sys::path::stem(FinalOutput->getValue()));
921+
AddPostfix(T);
914922
llvm::sys::path::replace_extension(T, "dwo");
915923
return Args.MakeArgString(T);
916924
} else {
917925
// Use the compilation dir.
918926
SmallString<128> T(
919927
Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
920928
SmallString<128> F(llvm::sys::path::stem(Input.getBaseInput()));
929+
AddPostfix(F);
921930
llvm::sys::path::replace_extension(F, "dwo");
922931
T += F;
923932
return Args.MakeArgString(F);

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
4949
llvm::opt::ArgStringList &CmdArgs,
5050
const llvm::opt::ArgList &Args);
5151

52-
const char *SplitDebugName(const llvm::opt::ArgList &Args,
52+
const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
5353
const InputInfo &Input, const InputInfo &Output);
5454

5555
void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
939939
if (Args.hasArg(options::OPT_gsplit_dwarf) &&
940940
getToolChain().getTriple().isOSLinux())
941941
SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
942-
SplitDebugName(Args, Inputs[0], Output));
942+
SplitDebugName(JA, Args, Inputs[0], Output));
943943
}
944944

945945
namespace {

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void tools::MinGW::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
5555

5656
if (Args.hasArg(options::OPT_gsplit_dwarf))
5757
SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
58-
SplitDebugName(Args, Inputs[0], Output));
58+
SplitDebugName(JA, Args, Inputs[0], Output));
5959
}
6060

6161
void tools::MinGW::Linker::AddLibGCC(const ArgList &Args,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// REQUIRES: zlib, clang-driver, amdgpu-registered-target
2+
3+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -c \
4+
// RUN: --offload-arch=gfx906:xnack+ %s -nogpulib -nogpuinc \
5+
// RUN: --offload-arch=gfx900 \
6+
// RUN: -ggdb -gsplit-dwarf 2>&1 | FileCheck %s
7+
8+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -c \
9+
// RUN: -fgpu-rdc --offload-arch=gfx906:xnack+ %s -nogpulib -nogpuinc \
10+
// RUN: --offload-arch=gfx900 \
11+
// RUN: -ggdb -gsplit-dwarf 2>&1 | FileCheck %s
12+
13+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
14+
// RUN: --offload-arch=gfx906:xnack+ %s -nogpulib -nogpuinc \
15+
// RUN: --offload-arch=gfx900 \
16+
// RUN: -ggdb -gsplit-dwarf 2>&1 | FileCheck %s
17+
18+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
19+
// RUN: -fgpu-rdc --offload-arch=gfx906:xnack+ %s -nogpulib -nogpuinc \
20+
// RUN: --offload-arch=gfx900 \
21+
// RUN: -ggdb -gsplit-dwarf 2>&1 | FileCheck %s
22+
23+
// CHECK-DAG: {{".*clang.*".* "-target-cpu" "gfx906".* "-split-dwarf-output" "hip-gsplit-dwarf-options_gfx906:xnack\+.dwo"}}
24+
// CHECK-DAG: {{".*clang.*".* "-target-cpu" "gfx900".* "-split-dwarf-output" "hip-gsplit-dwarf-options_gfx900.dwo"}}
25+
// CHECK-DAG: {{".*clang.*".* "-target-cpu" "x86-64".* "-split-dwarf-output" "hip-gsplit-dwarf-options.dwo"}}

0 commit comments

Comments
 (0)