Skip to content

Commit ea183e9

Browse files
aykevldeadprogram
authored andcommitted
compiler: add llvm.ident metadata
This metadata is emitted by Clang and I found it is important for source level debugging on MacOS. This patch does not get source level debugging to work yet (for that, it seems like packages need to be built separately), but it is a step in the right direction.
1 parent 74160c0 commit ea183e9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

builder/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
169169
CodeModel: config.CodeModel(),
170170
RelocationModel: config.RelocationModel(),
171171
SizeLevel: sizeLevel,
172+
TinyGoVersion: goenv.Version,
172173

173174
Scheduler: config.Scheduler(),
174175
AutomaticStackSize: config.AutomaticStackSize(),
@@ -305,7 +306,6 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
305306
actionID := packageAction{
306307
ImportPath: pkg.ImportPath,
307308
CompilerBuildID: string(compilerBuildID),
308-
TinyGoVersion: goenv.Version,
309309
LLVMVersion: llvm.Version,
310310
Config: compilerConfig,
311311
CFlags: pkg.CFlags,

compiler/compiler.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Config struct {
4747
CodeModel string
4848
RelocationModel string
4949
SizeLevel int
50+
TinyGoVersion string // for llvm.ident
5051

5152
// Various compiler options that determine how code is generated.
5253
Scheduler string
@@ -321,6 +322,14 @@ func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package,
321322
llvm.ConstInt(c.ctx.Int32Type(), 4, false).ConstantAsMetadata(),
322323
}),
323324
)
325+
if c.TinyGoVersion != "" {
326+
// It is necessary to set llvm.ident, otherwise debugging on MacOS
327+
// won't work.
328+
c.mod.AddNamedMetadataOperand("llvm.ident",
329+
c.ctx.MDNode(([]llvm.Metadata{
330+
c.ctx.MDString("TinyGo version " + c.TinyGoVersion),
331+
})))
332+
}
324333
c.dibuilder.Finalize()
325334
c.dibuilder.Destroy()
326335
}

0 commit comments

Comments
 (0)