Compiling via bitcode with debugging symbols

I'm working on a project at the moment around program slicing (a type of source-to-source transformation) of Swift and I'm hoping to be able to compare the performance of my source-level tool to that of a tool that operates at the LLVM bitcode level.

To do the comparison I'd like to compile a Swift file to an LLVM bitcode file, run the transformation on that bitcode file, and then retrieve the source lines that are still represented in the bitcode based on debugging info.

Ignoring the slicing for a moment, I'm just trying to get from source to bitcode to object and then retrieve source using debugging symbols. My current approach is:

  • Get the LLVM IR of the Swift file: swift -g -emit-bc -o test.bc test.swift
  • Get assembly from this slice using llc test.bc -o test.s
  • Assemble with as test.s -c -g -o test.o
  • Run dsymutil test.o -o test.o.dSYM (this fails with "no debug symbols in executable")
  • Objdump the object with gobjdump --source --line-numbers test.o to see the source

I'm not very familiar with these tools so I wonder if anybody could point me in the right direction of how to compile the .bc down to an object and hold on to debugging information.

Thanks in advance

The debug information used to generate DWARF is included in the LLVM bitcode. I suspect that running the assembler with "-g" may be causing you to get source line information for the assembly source instead of the Swift source. It would be easiest to skip going through the assembly source and emit the object file directly from llc using the "-filetype=obj" option.

1 Like