Skip to content

Commit e8844f5

Browse files
author
Yonghong Song
committed
[LLVM] Emit dwarf data for changed-signature and new functions
Add a new pass EmitChangedFuncDebugInfo which will add dwarf for additional functions including functions with signature change and new functions. The previous approach in [1] tries to add debuginfo for those optimization passes which cause signature changes. Based on discussion in [1], it is preferred to have a specific pass to add debuginfo and later on dwarf generation can include those new debuginfo. The following is an example: Source: $ cat test.c struct t { int a; }; char *tar(struct t *a, struct t *d); __attribute__((noinline)) static char * foo(struct t *a, struct t *d, int b) { return tar(a, d); } char *bar(struct t *a, struct t *d) { return foo(a, d, 1); } Compiled and dump dwarf with: clang -O2 -c -g test.c llvm-dwarfdump test.o 0x0000005c: DW_TAG_subprogram DW_AT_low_pc (0x0000000000000010) DW_AT_high_pc (0x0000000000000015) DW_AT_frame_base (DW_OP_reg7 RSP) DW_AT_linkage_name ("foo") DW_AT_name ("foo") DW_AT_decl_file ("/home/yhs/tests/sig-change/deadarg/test.c") DW_AT_decl_line (3) DW_AT_type (0x000000bb "char *") DW_AT_artificial (true) DW_AT_external (true) 0x0000006c: DW_TAG_formal_parameter DW_AT_location (DW_OP_reg5 RDI) DW_AT_decl_file ("/home/yhs/tests/sig-change/deadarg/test.c") DW_AT_decl_line (3) DW_AT_type (0x000000c4 "t *") 0x00000075: DW_TAG_formal_parameter DW_AT_location (DW_OP_reg4 RSI) DW_AT_decl_file ("/home/yhs/tests/sig-change/deadarg/test.c") DW_AT_decl_line (3) DW_AT_type (0x000000c4 "t *") 0x0000007e: DW_TAG_inlined_subroutine DW_AT_abstract_origin (0x0000009a "foo") DW_AT_low_pc (0x0000000000000010) DW_AT_high_pc (0x0000000000000015) DW_AT_call_file ("/home/yhs/tests/sig-change/deadarg/test.c") DW_AT_call_line (0) 0x0000008a: DW_TAG_formal_parameter DW_AT_location (DW_OP_reg5 RDI) DW_AT_abstract_origin (0x000000a2 "a") 0x00000091: DW_TAG_formal_parameter DW_AT_location (DW_OP_reg4 RSI) DW_AT_abstract_origin (0x000000aa "d") 0x00000098: NULL 0x00000099: NULL 0x0000009a: DW_TAG_subprogram DW_AT_name ("foo") DW_AT_decl_file ("/home/yhs/tests/sig-change/deadarg/test.c") DW_AT_decl_line (3) DW_AT_prototyped (true) DW_AT_type (0x000000bb "char *") DW_AT_inline (DW_INL_inlined) 0x000000a2: DW_TAG_formal_parameter DW_AT_name ("a") DW_AT_decl_file ("/home/yhs/tests/sig-change/deadarg/test.c") DW_AT_decl_line (3) DW_AT_type (0x000000c4 "t *") 0x000000aa: DW_TAG_formal_parameter DW_AT_name ("d") DW_AT_decl_file ("/home/yhs/tests/sig-change/deadarg/test.c") DW_AT_decl_line (3) DW_AT_type (0x000000c4 "t *") 0x000000b2: DW_TAG_formal_parameter DW_AT_name ("b") DW_AT_decl_file ("/home/yhs/tests/sig-change/deadarg/test.c") DW_AT_decl_line (3) DW_AT_type (0x000000d8 "int") 0x000000ba: NULL There are some restrictions in the current implementation: - Only C language is supported - BPF target is excluded as one of main goals for this pull request is to generate proper vmlinux BTF for arch's like x86_64/arm64 etc. - Function must not be a intrinsic, decl only, return value size more than arch register size and func with variable arguments. I have tested this patch set by building latest bpf-next linux kernel. For no-lto case: 65341 original number of functions 1085 new functions with this patch For thin-lto case: 65595 original number of functions 2492 new functions with this patch [1] #127855
1 parent 0a87115 commit e8844f5

14 files changed

+972
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===- EmitChangedFuncDebugInfo.h - Emit Additional Debug Info -*- C++ --*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
/// \file
10+
/// Emit debug info for changed or new funcs.
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_TRANSFORMS_UTILS_EMITCHANGEDFUNCDEBUGINFO_H
14+
#define LLVM_TRANSFORMS_UTILS_EMITCHANGEDFUNCDEBUGINFO_H
15+
16+
#include "llvm/IR/PassManager.h"
17+
18+
namespace llvm {
19+
20+
class Module;
21+
22+
// Pass that emits late dwarf.
23+
class EmitChangedFuncDebugInfoPass
24+
: public PassInfoMixin<EmitChangedFuncDebugInfoPass> {
25+
public:
26+
EmitChangedFuncDebugInfoPass() = default;
27+
28+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
29+
};
30+
31+
} // end namespace llvm
32+
33+
#endif // LLVM_TRANSFORMS_UTILS_EMITCHANGEDFUNCDEBUGINFO_H

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@
350350
#include "llvm/Transforms/Utils/DXILUpgrade.h"
351351
#include "llvm/Transforms/Utils/Debugify.h"
352352
#include "llvm/Transforms/Utils/DeclareRuntimeLibcalls.h"
353+
#include "llvm/Transforms/Utils/EmitChangedFuncDebugInfo.h"
353354
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
354355
#include "llvm/Transforms/Utils/FixIrreducible.h"
355356
#include "llvm/Transforms/Utils/HelloWorld.h"

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
136136
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
137137
#include "llvm/Transforms/Utils/CountVisits.h"
138+
#include "llvm/Transforms/Utils/EmitChangedFuncDebugInfo.h"
138139
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
139140
#include "llvm/Transforms/Utils/ExtraPassManager.h"
140141
#include "llvm/Transforms/Utils/InjectTLIMappings.h"
@@ -1640,9 +1641,12 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
16401641
if (PTO.CallGraphProfile && !LTOPreLink)
16411642
MPM.addPass(CGProfilePass(isLTOPostLink(LTOPhase)));
16421643

1643-
// RelLookupTableConverterPass runs later in LTO post-link pipeline.
1644-
if (!LTOPreLink)
1644+
// RelLookupTableConverterPass and EmitChangedFuncDebugInfoPass run later in
1645+
// LTO post-link pipeline.
1646+
if (!LTOPreLink) {
16451647
MPM.addPass(RelLookupTableConverterPass());
1648+
MPM.addPass(EmitChangedFuncDebugInfoPass());
1649+
}
16461650

16471651
return MPM;
16481652
}

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ MODULE_PASS("dfsan", DataFlowSanitizerPass())
7575
MODULE_PASS("dot-callgraph", CallGraphDOTPrinterPass())
7676
MODULE_PASS("dxil-upgrade", DXILUpgradePass())
7777
MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
78+
MODULE_PASS("emit-changed-func-debuginfo", EmitChangedFuncDebugInfoPass())
7879
MODULE_PASS("extract-blocks", BlockExtractorPass({}, false))
7980
MODULE_PASS("expand-variadics",
8081
ExpandVariadicsPass(ExpandVariadicsMode::Disable))

llvm/lib/Transforms/Utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ add_llvm_component_library(LLVMTransformUtils
2323
DebugSSAUpdater.cpp
2424
DeclareRuntimeLibcalls.cpp
2525
DemoteRegToStack.cpp
26+
EmitChangedFuncDebugInfo.cpp
2627
DXILUpgrade.cpp
2728
EntryExitInstrumenter.cpp
2829
EscapeEnumerator.cpp

0 commit comments

Comments
 (0)