llvm.org GIT mirror llvm / fcfd408
Fix a crash with assembler source and -g. llvm-mc or clang with -g normally produces debug info describing the assembler source itself; however, if that source already contains some .file/.loc directives, we should instead emit the debug info described by those directives. For certain assembler sources seen in the wild (particularly in the Chrome build) this was causing a crash due to incorrect assumptions about legal sequences of assembler source text. Fixes PR38994. Differential Revision: https://reviews.llvm.org/D63573 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364039 91177308-0d34-0410-b5e6-96231b3b80d8 Paul Robinson 4 months ago
3 changed file(s) with 35 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
260260 HasSource = Source.hasValue();
261261 }
262262
263 void resetFileTable() {
264 MCDwarfDirs.clear();
265 MCDwarfFiles.clear();
266 RootFile.Name.clear();
267 resetMD5Usage();
268 HasSource = false;
269 }
270
263271 private:
264272 void emitV2FileDirTables(MCStreamer *MCOS) const;
265273 void emitV5FileDirTables(MCStreamer *MCOS, Optional &LineStr) const;
325333 Header.HasSource = Source.hasValue();
326334 }
327335
328 void resetRootFile() {
329 assert(Header.MCDwarfFiles.empty());
330 Header.RootFile.Name.clear();
331 Header.resetMD5Usage();
332 Header.HasSource = false;
333 }
336 void resetFileTable() { Header.resetFileTable(); }
334337
335338 bool hasRootFile() const { return !Header.RootFile.Name.empty(); }
336339
33943394 } else {
33953395 // In case there is a -g option as well as debug info from directive .file,
33963396 // we turn off the -g option, directly use the existing debug info instead.
3397 // Also reset any implicit ".file 0" for the assembler source.
3397 // Throw away any implicit file table for the assembler source.
33983398 if (Ctx.getGenDwarfForAssembly()) {
3399 Ctx.getMCDwarfLineTable(0).resetRootFile();
3399 Ctx.getMCDwarfLineTable(0).resetFileTable();
34003400 Ctx.setGenDwarfForAssembly(false);
34013401 }
34023402
0 ## Make sure that using -g (or equivalent) on an asm file that already has
1 ## debug-info directives in it will correctly ignore the -g and produce
2 ## debug info corresponding to the directives in the source.
3 ## Note gcc accepts ".file 1" after a label, although not after an opcode.
4 ## If no other directives appear, gcc emits no debug info at all.
5
6 # RUN: llvm-mc -g -triple i386-unknown-unknown -filetype=obj %s -o %t
7 # RUN: llvm-dwarfdump -debug-info -debug-line %t | FileCheck %s
8
9 foo:
10 .file 1 "a.c"
11 .loc 1 1 1
12 nop
13
14 # CHECK: .debug_info
15 ## gcc does generate a DW_TAG_compile_unit in this case, with or without
16 ## -g on the command line, but we do not.
17 # CHECK-EMPTY:
18 # CHECK_NEXT: .debug_line
19 # CHECK: file_names[ 1]:
20 # CHECK-NEXT: name: "a.c"
21 # CHECK-NEXT: dir_index: 0
22 # CHECK: 0x{{0+}}0 1 1 1 0 0 is_stmt
23 # CHECK: 0x{{0+}}1 1 1 1 0 0 is_stmt end_sequence