Skip to content

Commit e3bb359

Browse files
[clang][Toolchains][Gnu] pass -g through to assembler
We've been working around this for a long time in the Linux kernel; we bend over backwards to continue to support CC=clang (w/ -fno-integrated-as) for architectures where clang can't yet be used to assemble the kernel's assembler sources. Supporting debug info for the combination of CC=clang w/ GNU binutils as "GAS" has been painful. Fix this in clang so that we can work towards dropping complexity in the Linux kernel's build system, Kbuild, for supporting this combination of tools. GAS added support for -g in 2004 2.16 release via commit 329e276daf98 ("Add support for a -g switch to GAS") Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D136309
1 parent 1edc51b commit e3bb359

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,10 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
969969
for (const auto &II : Inputs)
970970
CmdArgs.push_back(II.getFilename());
971971

972+
if (Arg *A = Args.getLastArg(options::OPT_g_Flag, options::OPT_gN_Group))
973+
if (!A->getOption().matches(options::OPT_g0))
974+
Args.AddLastArg(CmdArgs, options::OPT_g_Flag);
975+
972976
const char *Exec =
973977
Args.MakeArgString(getToolChain().GetProgramPath(DefaultAssembler));
974978
C.addCommand(std::make_unique<Command>(JA, *this,

clang/test/Driver/as-options.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,13 @@
116116
// RUN: %clang -mrelax-all -fno-integrated-as -x c++ %s -S -o /dev/null 2>&1 \
117117
// RUN: | FileCheck --check-prefix=WARN --allow-empty %s
118118
// WARN: unused
119+
120+
// Test that -g is passed through to GAS.
121+
// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -g %s -### 2>&1 | \
122+
// RUN: FileCheck --check-prefix=DEBUG %s
123+
// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -g0 -g %s -### 2>&1 | \
124+
// RUN: FileCheck --check-prefix=DEBUG %s
125+
// DEBUG: "-g"
126+
// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -g -g0 %s -### 2>&1 | \
127+
// RUN: FileCheck --check-prefix=NODEBUG %s
128+
// NODEBUG-NOT: "-g"

clang/test/Driver/gcc_forward.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,3 @@
3434
// CHECK-NOT: "-Wall"
3535
// CHECK-NOT: "-Wdocumentation"
3636
// CHECK: "-o" "a.out"
37-
38-
// Check that we're not forwarding -g options to the assembler
39-
// RUN: %clang -g -target x86_64-unknown-linux-gnu -no-integrated-as -c %s -### 2>&1 \
40-
// RUN: | FileCheck --check-prefix=CHECK-ASM %s
41-
// CHECK-ASM: as
42-
// CHECK-ASM-NOT: "-g"

0 commit comments

Comments
 (0)