[PATCH] D94882: [MC] Upgrade DWARF version to 5 upon .file 0
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 17 10:40:05 PST 2021
MaskRay created this revision.
MaskRay added reviewers: aprantl, dblaikie, probinson.
Herald added subscribers: hiraditya, emaste.
Herald added a reviewer: espindola.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Without `-dwarf-version`, llvm-mc uses the default `MCContext::DwarfVersion` 4.
Without `-gdwarf-N`, Clang cc1as uses `clang::driver::ToolChain::GetDefaultDwarfVersion`
which is 4 on many toolchains. Note: `clang -c` can synthesize .debug_info without -g.
There is currently a MCParser warning upon `.file 0` and MCParser errors upon
`.loc 0` if the DWARF version is less than 5. This causes friction to the
following usage:
clang -S -g -gdwarf-5 a.c
// MC warning due to .file 0, MC error due to .loc 0
clang -c a.s
llvm-mc -filetype=obj a.s
My idea is that we can just upgrade `MCContext::DwarfVersion` to 5 upon
`.file 0` to make the above commands work.
The downside is that for an explicit version `clang -c -gdwarf-4 a.s`, it can be
argued that the new behavior drops the probably intended diagnostic. I think the
downside is small because in most cases DWARF version for an assembly action
should either match the original compile action or be omitted.
Ongoing discussion taking a similar action for GNU as: https://sourceware.org/pipermail/binutils/2021-January/114980.html
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D94882
Files:
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/test/MC/ELF/dwarf-file0.s
llvm/test/MC/ELF/dwarf-loc0.s
Index: llvm/test/MC/ELF/dwarf-loc0.s
===================================================================
--- llvm/test/MC/ELF/dwarf-loc0.s
+++ llvm/test/MC/ELF/dwarf-loc0.s
@@ -1,8 +1,10 @@
# REQUIRES: default_triple
-# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+# RUN: llvm-mc -dwarf-version 5 --defsym FILE0=1 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
# RUN: not llvm-mc -dwarf-version 4 %s -filetype=asm -o - 2>&1 | FileCheck %s -check-prefix=ERR
# Show that ".loc 0" works in DWARF v5, gets an error for earlier versions.
+.ifdef FILE0
.file 0 "root.cpp"
+.endif
.file 1 "header.h"
.loc 0 10 0
.byte 0
Index: llvm/test/MC/ELF/dwarf-file0.s
===================================================================
--- llvm/test/MC/ELF/dwarf-file0.s
+++ llvm/test/MC/ELF/dwarf-file0.s
@@ -1,34 +1,22 @@
# REQUIRES: default_triple
-# RUN: llvm-mc -dwarf-version 4 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK,CHECK-4
-# RUN: llvm-mc -dwarf-version 4 %s -filetype=asm -o - | FileCheck %s --check-prefixes=ASM,ASM-4
-# RUN: llvm-mc -dwarf-version 4 %s -filetype=asm -o - 2>&1 | FileCheck %s --check-prefix=WARN
-# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK,CHECK-5
-# RUN: llvm-mc -dwarf-version 5 %s -filetype=asm -o - | FileCheck %s --check-prefixes=ASM,ASM-5
+# RUN: llvm-mc -dwarf-version 4 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+# RUN: llvm-mc -dwarf-version 4 %s --fatal-warnings -o - | FileCheck %s --check-prefix=ASM
+# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+# RUN: llvm-mc -dwarf-version 5 %s -o - | FileCheck %s --check-prefix=ASM
+
+## If the DWARF version is less than 5, .file 0 upgrades the version to 5.
.file 0 "/test" "root.cpp"
.file 1 "/include" "header.h"
.file 2 "/test" "root.cpp"
-# CHECK-5: include_directories[ 0] = "/test"
-# CHECK-4-NOT: include_directories[ 0]
-# CHECK: include_directories[ 1] = "/include"
-# CHECK-4: include_directories[ 2] = "/test"
-# CHECK-NOT: include_directories
-# CHECK-4-NOT: file_names[ 0]
-# CHECK-5: file_names[ 0]:
-# CHECK-5-NEXT: name: "root.cpp"
-# CHECK-5-NEXT: dir_index: 0
-# CHECK: file_names[ 1]:
-# CHECK-NEXT: name: "header.h"
-# CHECK-NEXT: dir_index: 1
-# CHECK-4: file_names[ 2]:
-# CHECK-4-NEXT: name: "root.cpp"
-# CHECK-4-NEXT: dir_index: 2
+# CHECK: include_directories[ 0] = "/test"
+# CHECK-NEXT: include_directories[ 1] = "/include"
+# CHECK: file_names[ 0]:
+# CHECK-NEXT: name: "root.cpp"
+# CHECK-NEXT: dir_index: 0
+# CHECK-NEXT: file_names[ 1]:
+# CHECK-NEXT: name: "header.h"
+# CHECK-NEXT: dir_index: 1
-# ASM-NOT: .file
-# ASM-5: .file 0 "/test" "root.cpp"
+# ASM: .file 0 "/test" "root.cpp"
# ASM: .file 1 "/include" "header.h"
-# ASM-4: .file 2 "/test" "root.cpp"
# ASM-NOT: .file
-
-# WARN: file 0 not supported prior to DWARF-5
-# WARN-NEXT: .file 0
-# WARN-NEXT: ^
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3485,8 +3485,9 @@
Source = StringRef(SourceBuf, SourceString.size());
}
if (FileNumber == 0) {
+ // Upgrade to Version 5 for assembly actions like clang -c a.s.
if (Ctx.getDwarfVersion() < 5)
- return Warning(DirectiveLoc, "file 0 not supported prior to DWARF-5");
+ Ctx.setDwarfVersion(5);
getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
} else {
Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94882.317232.patch
Type: text/x-patch
Size: 3922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210117/c2389f4d/attachment.bin>
More information about the llvm-commits
mailing list