Skip to content

Commit cc1d314

Browse files
author
Alex B
committed
Switch to relative return offsets
1 parent d7cff1b commit cc1d314

File tree

4 files changed

+38
-40
lines changed

4 files changed

+38
-40
lines changed

llvm/include/llvm/DebugInfo/GSYM/CallSiteInfo.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ struct CallSiteInfo {
4040
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue*/ ExternalCall),
4141
};
4242

43-
/// The return address of the call site.
44-
uint64_t ReturnAddress = 0;
43+
/// The return offset of the call site - relative to the function start.
44+
uint64_t ReturnOffset = 0;
4545

4646
/// Offsets into the string table for function names regex patterns.
4747
std::vector<uint32_t> MatchRegex;
@@ -110,15 +110,14 @@ class CallSiteInfoLoader {
110110

111111
/// Processes the parsed YAML functions and updates the `FuncMap` accordingly.
112112
///
113-
/// \param functionsYAML A constant reference to an llvm::yaml::FunctionsYAML
113+
/// \param FuncYAMLs A constant reference to an llvm::yaml::FunctionsYAML
114114
/// object containing parsed YAML data.
115115
/// \param FuncMap A reference to a StringMap mapping function names to
116116
/// FunctionInfo pointers.
117117
/// \returns An `llvm::Error` indicating success or describing any issues
118118
/// encountered during processing.
119-
llvm::Error
120-
processYAMLFunctions(const llvm::yaml::FunctionsYAML &functionsYAML,
121-
StringMap<FunctionInfo *> &FuncMap);
119+
llvm::Error processYAMLFunctions(const llvm::yaml::FunctionsYAML &FuncYAMLs,
120+
StringMap<FunctionInfo *> &FuncMap);
122121

123122
/// Reference to the parent Gsym Creator object.
124123
GsymCreator &GCreator;

llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace llvm;
2525
using namespace gsym;
2626

2727
Error CallSiteInfo::encode(FileWriter &O) const {
28-
O.writeU64(ReturnAddress);
28+
O.writeU64(ReturnOffset);
2929
O.writeU8(Flags);
3030
O.writeU32(MatchRegex.size());
3131
for (uint32_t Entry : MatchRegex)
@@ -37,11 +37,11 @@ Expected<CallSiteInfo> CallSiteInfo::decode(DataExtractor &Data,
3737
uint64_t &Offset) {
3838
CallSiteInfo CSI;
3939

40-
// Read ReturnAddress
40+
// Read ReturnOffset
4141
if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(uint64_t)))
4242
return createStringError(std::errc::io_error,
43-
"0x%8.8" PRIx64 ": missing ReturnAddress", Offset);
44-
CSI.ReturnAddress = Data.getU64(&Offset);
43+
"0x%8.8" PRIx64 ": missing ReturnOffset", Offset);
44+
CSI.ReturnOffset = Data.getU64(&Offset);
4545

4646
// Read Flags
4747
if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(uint8_t)))
@@ -138,8 +138,8 @@ template <> struct MappingTraits<FunctionYAML> {
138138
};
139139

140140
template <> struct MappingTraits<FunctionsYAML> {
141-
static void mapping(IO &io, FunctionsYAML &functionsYAML) {
142-
io.mapRequired("functions", functionsYAML.functions);
141+
static void mapping(IO &io, FunctionsYAML &FuncYAMLs) {
142+
io.mapRequired("functions", FuncYAMLs.functions);
143143
}
144144
};
145145

@@ -197,10 +197,9 @@ CallSiteInfoLoader::buildFunctionMap(std::vector<FunctionInfo> &Funcs) {
197197
}
198198

199199
Error CallSiteInfoLoader::processYAMLFunctions(
200-
const yaml::FunctionsYAML &functionsYAML,
201-
StringMap<FunctionInfo *> &FuncMap) {
200+
const yaml::FunctionsYAML &FuncYAMLs, StringMap<FunctionInfo *> &FuncMap) {
202201
// For each function in the YAML file
203-
for (const auto &FuncYAML : functionsYAML.functions) {
202+
for (const auto &FuncYAML : FuncYAMLs.functions) {
204203
auto It = FuncMap.find(FuncYAML.name);
205204
if (It == FuncMap.end())
206205
return createStringError(
@@ -216,7 +215,7 @@ Error CallSiteInfoLoader::processYAMLFunctions(
216215
CallSiteInfo CSI;
217216
// Since YAML has specifies relative return offsets, add the function
218217
// start address to make the offset absolute.
219-
CSI.ReturnAddress = FuncInfo->Range.start() + CallSiteYAML.return_offset;
218+
CSI.ReturnOffset = CallSiteYAML.return_offset;
220219
for (const auto &Regex : CallSiteYAML.match_regex) {
221220
uint32_t StrOffset = GCreator.insertString(Regex);
222221
CSI.MatchRegex.push_back(StrOffset);
@@ -241,7 +240,7 @@ Error CallSiteInfoLoader::processYAMLFunctions(
241240
}
242241

243242
raw_ostream &gsym::operator<<(raw_ostream &OS, const CallSiteInfo &CSI) {
244-
OS << " Return=" << HEX64(CSI.ReturnAddress);
243+
OS << " Return=" << HEX64(CSI.ReturnOffset);
245244
OS << " Flags=" << HEX8(CSI.Flags);
246245

247246
OS << " RegEx=";

llvm/lib/DebugInfo/GSYM/GsymReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ void GsymReader::dump(raw_ostream &OS, const MergedFunctionsInfo &MFI) {
424424
}
425425

426426
void GsymReader::dump(raw_ostream &OS, const CallSiteInfo &CSI) {
427-
OS << HEX64(CSI.ReturnAddress);
427+
OS << HEX16(CSI.ReturnOffset);
428428

429429
std::string Flags;
430430
auto addFlag = [&](const char *Flag) {
@@ -456,7 +456,7 @@ void GsymReader::dump(raw_ostream &OS, const CallSiteInfo &CSI) {
456456
}
457457

458458
void GsymReader::dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC) {
459-
OS << "CallSites (by return address):\n";
459+
OS << "CallSites (by relative return offset):\n";
460460
for (const auto &CS : CSIC.CallSites) {
461461
OS.indent(2);
462462
dump(OS, CS);

llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-callsite-info-obj.test

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@
88
// RUN: llvm-gsymutil %t/call_sites_obj.gsym | FileCheck --check-prefix=CHECK-GSYM %s
99

1010

11-
// CHECK-GSYM: FunctionInfo @ 0x[[#%x,]]: [0x[[#%x,]] - 0x[[#%x,]]) "func_mainBin_dec_call_everything"
11+
// CHECK-GSYM: FunctionInfo @ 0x[[#%x,FUNC_INFO:]]: [0x[[#%x,FUNC_START:]] - 0x[[#%x,FUNC_END:]]) "func_mainBin_dec_call_everything"
1212
// CHECK-GSYM-NEXT: LineTable:
1313
// func_mainBin_dec_call_everything() {
14-
// CHECK-GSYM-NEXT: 0x[[#%x,]] {{.*}}/call_sites.cpp:16
14+
// CHECK-GSYM-NEXT: 0x[[#%x,ENTRY:]] {{.*}}/call_sites.cpp:16
1515
// func_mainBin_dec_01();
16-
// CHECK-GSYM-NEXT: 0x[[ADDR_dec_01_call:[0-9a-f]+]] {{.*}}/call_sites.cpp:17
16+
// CHECK-GSYM-NEXT: 0x[[#%x,ADDR_DEC_01_CALL:]] {{.*}}/call_sites.cpp:17
1717
// func_mainBin_dec_02();
18-
// CHECK-GSYM-NEXT: 0x[[ADDR_dec_02_call:[0-9a-f]+]] {{.*}}/call_sites.cpp:18
18+
// CHECK-GSYM-NEXT: 0x[[#%x,ADDR_DEC_02_CALL:]] {{.*}}/call_sites.cpp:18
1919
// func_mainBin_dec_03();
20-
// CHECK-GSYM-NEXT: [[ADDR_dec_03_call:0x[0-9a-f]+]] {{.*}}/call_sites.cpp:19
20+
// CHECK-GSYM-NEXT: 0x[[#%x,ADDR_DEC_03_CALL:]] {{.*}}/call_sites.cpp:19
2121
// func_mainBin_inc_01();
22-
// CHECK-GSYM-NEXT: [[ADDR_inc_01_call:0x[0-9a-f]+]] {{.*}}/call_sites.cpp:21
22+
// CHECK-GSYM-NEXT: 0x[[#%x,ADDR_INC_01_CALL:]] {{.*}}/call_sites.cpp:21
2323
// func_mainBin_inc_02();
24-
// CHECK-GSYM-NEXT: [[ADDR_inc_02_call:0x[0-9a-f]+]] {{.*}}/call_sites.cpp:22
24+
// CHECK-GSYM-NEXT: 0x[[#%x,ADDR_INC_02_CALL:]] {{.*}}/call_sites.cpp:22
2525
// func_mainBin_inc_03();
26-
// CHECK-GSYM-NEXT: [[ADDR_inc_03_call:0x[0-9a-f]+]] {{.*}}/call_sites.cpp:23
26+
// CHECK-GSYM-NEXT: 0x[[#%x,ADDR_INC_03_CALL:]] {{.*}}/call_sites.cpp:23
2727
// g_func_ptr();
28-
// CHECK-GSYM-NEXT: [[ADDR_func_call:0x[0-9a-f]+]] {{.*}}/call_sites.cpp:25
28+
// CHECK-GSYM-NEXT: 0x[[#%x,ADDR_FUNC_CALL:]] {{.*}}/call_sites.cpp:25
2929
// g_extern_func_ptr();
30-
// CHECK-GSYM-NEXT: [[ADDR_extern_func_call:0x[0-9a-f]+]] {{.*}}/call_sites.cpp:26
30+
// CHECK-GSYM-NEXT: 0x[[#%x,ADDR_EXTERN_FUNC_CALL:]] {{.*}}/call_sites.cpp:26
3131
// g_volatile_var = 0;
32-
// CHECK-GSYM-NEXT: [[ADDR_var_assign:0x[0-9a-f]+]] {{.*}}/call_sites.cpp:28
32+
// CHECK-GSYM-NEXT: 0x[[#%x,ADDR_VAR_ASSIGN:]] {{.*}}/call_sites.cpp:28
3333
// }
34-
// CHECK-GSYM-NEXT: [[#%x,]] {{.*}}/call_sites.cpp:29
35-
// CHECK-GSYM-NEXT: CallSites (by return address):
36-
// CHECK-GSYM-NEXT: [[ADDR_dec_02_call]] Flags[InternalCall] MatchRegex[func_mainBin_dec_01]
37-
// CHECK-GSYM-NEXT: [[ADDR_dec_03_call]] Flags[InternalCall] MatchRegex[func_mainBin_dec_02]
38-
// CHECK-GSYM-NEXT: [[ADDR_inc_01_call]] Flags[InternalCall] MatchRegex[func_mainBin_dec_03]
39-
// CHECK-GSYM-NEXT: [[ADDR_inc_02_call]] Flags[InternalCall] MatchRegex[func_mainBin_inc_01]
40-
// CHECK-GSYM-NEXT: [[ADDR_inc_03_call]] Flags[InternalCall] MatchRegex[func_mainBin_inc_02]
41-
// CHECK-GSYM-NEXT: [[ADDR_func_call]] Flags[InternalCall] MatchRegex[func_mainBin_inc_03]
42-
// CHECK-GSYM-NEXT: [[ADDR_extern_func_call]] Flags[None] MatchRegex[.*func.*]
43-
// CHECK-GSYM-NEXT: [[ADDR_var_assign]] Flags[ExternalCall] MatchRegex[.*extern_func.*]
34+
// CHECK-GSYM-NEXT: 0x[[#%x,]] {{.*}}/call_sites.cpp:29
35+
// CHECK-GSYM-NEXT: CallSites (by relative return offset):
36+
// CHECK-GSYM-NEXT: 0x[[#%.4x,sub(ADDR_DEC_02_CALL,FUNC_START)]] Flags[InternalCall] MatchRegex[func_mainBin_dec_01]
37+
// CHECK-GSYM-NEXT: 0x[[#%.4x,sub(ADDR_DEC_03_CALL,FUNC_START)]] Flags[InternalCall] MatchRegex[func_mainBin_dec_02]
38+
// CHECK-GSYM-NEXT: 0x[[#%.4x,sub(ADDR_INC_01_CALL,FUNC_START)]] Flags[InternalCall] MatchRegex[func_mainBin_dec_03]
39+
// CHECK-GSYM-NEXT: 0x[[#%.4x,sub(ADDR_INC_02_CALL,FUNC_START)]] Flags[InternalCall] MatchRegex[func_mainBin_inc_01]
40+
// CHECK-GSYM-NEXT: 0x[[#%.4x,sub(ADDR_INC_03_CALL,FUNC_START)]] Flags[InternalCall] MatchRegex[func_mainBin_inc_02]
41+
// CHECK-GSYM-NEXT: 0x[[#%.4x,sub(ADDR_FUNC_CALL,FUNC_START)]] Flags[InternalCall] MatchRegex[func_mainBin_inc_03]
42+
// CHECK-GSYM-NEXT: 0x[[#%.4x,sub(ADDR_EXTERN_FUNC_CALL,FUNC_START)]] Flags[None] MatchRegex[.*func.*]
43+
// CHECK-GSYM-NEXT: 0x[[#%.4x,sub(ADDR_VAR_ASSIGN,FUNC_START)]] Flags[ExternalCall] MatchRegex[.*extern_func.*]
4444

4545

4646
//--- callsites.yaml

0 commit comments

Comments
 (0)