@@ -66,6 +66,7 @@ struct ObjectInfo {
66
66
const object::ObjectFile *object;
67
67
size_t SectionSize;
68
68
ptrdiff_t slide;
69
+ object::SectionRef Section;
69
70
DIContext *context;
70
71
};
71
72
@@ -411,7 +412,8 @@ class JuliaJITEventListener: public JITEventListener
411
412
ObjectInfo tmp = {&debugObj,
412
413
(size_t )SectionSize,
413
414
(ptrdiff_t )(SectionAddr - SectionLoadAddr),
414
- DWARFContext::create (debugObj).release (),
415
+ *Section,
416
+ nullptr ,
415
417
};
416
418
objectmap[SectionLoadAddr] = tmp;
417
419
first = false ;
@@ -483,13 +485,13 @@ JITEventListener *CreateJuliaJITEventListener()
483
485
// with for the current frame. here we'll try to expand it using debug info
484
486
// func_name and file_name are either NULL or malloc'd pointers
485
487
static int lookup_pointer (
486
- const object::ObjectFile *object , DIContext *context,
487
- jl_frame_t **frames, size_t pointer,
488
- int demangle, int noInline)
488
+ object::SectionRef Section , DIContext *context,
489
+ jl_frame_t **frames, size_t pointer, int64_t slide,
490
+ bool demangle, bool noInline)
489
491
{
490
492
// This function is not allowed to reference any TLS variables
491
493
// since it can be called from an unmanaged thread on OSX.
492
- if (!context || !object ) {
494
+ if (!context || !Section. getObject () ) {
493
495
if (demangle) {
494
496
char *oldname = (*frames)[0 ].func_name ;
495
497
if (oldname != NULL ) {
@@ -512,14 +514,14 @@ static int lookup_pointer(
512
514
DILineInfoSpecifier infoSpec (DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
513
515
DILineInfoSpecifier::FunctionNameKind::ShortName);
514
516
515
- auto inlineInfo = context->getInliningInfoForAddress (makeAddress (object , pointer), infoSpec);
517
+ auto inlineInfo = context->getInliningInfoForAddress (makeAddress (Section , pointer + slide ), infoSpec);
516
518
517
519
int fromC = (*frames)[0 ].fromC ;
518
520
int n_frames = inlineInfo.getNumberOfFrames ();
519
521
if (n_frames == 0 ) {
520
522
jl_mutex_unlock_maybe_nogc (&codegen_lock);
521
523
// no line number info available in the context, return without the context
522
- return lookup_pointer (NULL , NULL , frames, pointer, demangle, noInline);
524
+ return lookup_pointer (object::SectionRef () , NULL , frames, pointer, slide , demangle, noInline);
523
525
}
524
526
if (noInline)
525
527
n_frames = 1 ;
@@ -536,7 +538,7 @@ static int lookup_pointer(
536
538
info = inlineInfo.getFrame (i);
537
539
}
538
540
else {
539
- info = context->getLineInfoForAddress (makeAddress (object , pointer), infoSpec);
541
+ info = context->getLineInfoForAddress (makeAddress (Section , pointer + slide ), infoSpec);
540
542
}
541
543
542
544
jl_frame_t *frame = &(*frames)[i];
@@ -585,7 +587,6 @@ typedef struct {
585
587
const llvm::object::ObjectFile *obj;
586
588
DIContext *ctx;
587
589
int64_t slide;
588
- int64_t section_slide;
589
590
} objfileentry_t ;
590
591
typedef std::map<uint64_t , objfileentry_t , revcomp> obfiletype;
591
592
static obfiletype objfilemap;
@@ -750,9 +751,8 @@ static inline void ignoreError(T &err)
750
751
#endif
751
752
}
752
753
753
- static void get_function_name_and_base (const object::ObjectFile *object, bool insysimage,
754
- void **saddr, char **name, size_t pointer,
755
- int64_t slide, bool untrusted_dladdr)
754
+ static void get_function_name_and_base (llvm::object::SectionRef Section, size_t pointer, int64_t slide, bool insysimage,
755
+ void **saddr, char **name, bool untrusted_dladdr)
756
756
{
757
757
// Assume we only need base address for sysimg for now
758
758
if (!insysimage || !sysimg_fptrs.base )
@@ -779,10 +779,12 @@ static void get_function_name_and_base(const object::ObjectFile *object, bool in
779
779
}
780
780
#endif
781
781
}
782
- if (object && (needs_saddr || needs_name)) {
782
+ if (Section. getObject () && (needs_saddr || needs_name)) {
783
783
size_t distance = (size_t )-1 ;
784
784
SymRef sym_found;
785
- for (auto sym: object->symbols ()) {
785
+ for (auto sym : Section.getObject ()->symbols ()) {
786
+ if (!Section.containsSymbol (sym))
787
+ continue ;
786
788
auto addr = sym.getAddress ();
787
789
if (!addr)
788
790
continue ;
@@ -1009,11 +1011,9 @@ static objfileentry_t &find_object_file(uint64_t fbase, StringRef fname)
1009
1011
}
1010
1012
1011
1013
int64_t slide = 0 ;
1012
- int64_t section_slide = 0 ;
1013
1014
if (auto *OF = dyn_cast<const object::COFFObjectFile>(debugobj)) {
1014
1015
assert (iswindows);
1015
1016
slide = OF->getImageBase () - fbase;
1016
- section_slide = 0 ; // Since LLVM 3.8+ addresses are adjusted correctly
1017
1017
}
1018
1018
else {
1019
1019
slide = -(int64_t )fbase;
@@ -1024,7 +1024,7 @@ static objfileentry_t &find_object_file(uint64_t fbase, StringRef fname)
1024
1024
binary.first .release ();
1025
1025
binary.second .release ();
1026
1026
// update cache
1027
- entry = {debugobj, context, slide, section_slide };
1027
+ entry = {debugobj, context, slide};
1028
1028
}
1029
1029
else {
1030
1030
// TODO: report the error instead of silently consuming it?
@@ -1034,14 +1034,25 @@ static objfileentry_t &find_object_file(uint64_t fbase, StringRef fname)
1034
1034
return entry;
1035
1035
}
1036
1036
1037
+ // from llvm::SymbolizableObjectFile
1038
+ static object::SectionRef getModuleSectionForAddress (const object::ObjectFile *obj, uint64_t Address)
1039
+ {
1040
+ for (object::SectionRef Sec : obj->sections ()) {
1041
+ if (!Sec.isText () || Sec.isVirtual ())
1042
+ continue ;
1043
+ if (Address >= Sec.getAddress () && Address < Sec.getAddress () + Sec.getSize ())
1044
+ return Sec;
1045
+ }
1046
+ return object::SectionRef ();
1047
+ }
1048
+
1049
+
1037
1050
extern " C" void jl_refresh_dbg_module_list (void );
1038
- bool jl_dylib_DI_for_fptr (size_t pointer, const llvm:: object::ObjectFile **obj , llvm::DIContext **context, int64_t *slide, int64_t *section_slide ,
1051
+ bool jl_dylib_DI_for_fptr (size_t pointer, object::SectionRef *Section, int64_t *slide , llvm::DIContext **context,
1039
1052
bool onlySysImg, bool *isSysImg, void **saddr, char **name, char **filename)
1040
1053
{
1041
- *obj = NULL ;
1054
+ *Section = object::SectionRef () ;
1042
1055
*context = NULL ;
1043
- *slide = 0 ;
1044
- *section_slide = 0 ;
1045
1056
// On Windows and FreeBSD, `dladdr` (or its equivalent) returns the closest exported symbol
1046
1057
// without checking the size.
1047
1058
// This causes the lookup to return incorrect non-NULL result for local functions
@@ -1119,12 +1130,11 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj,
1119
1130
fname = dlinfo.dli_fname ;
1120
1131
#endif // ifdef _OS_WINDOWS_
1121
1132
auto &entry = find_object_file (fbase, fname);
1122
- *obj = entry.obj ;
1123
- *context = entry.ctx ;
1124
1133
*slide = entry.slide ;
1125
- *section_slide = entry.section_slide ;
1126
- get_function_name_and_base (entry.obj , insysimage, saddr, name, pointer, entry.slide ,
1127
- untrusted_dladdr);
1134
+ *context = entry.ctx ;
1135
+ if (entry.obj )
1136
+ *Section = getModuleSectionForAddress (entry.obj , pointer + entry.slide );
1137
+ get_function_name_and_base (*Section, pointer, entry.slide , insysimage, saddr, name, untrusted_dladdr);
1128
1138
return true ;
1129
1139
}
1130
1140
@@ -1153,12 +1163,12 @@ static int jl_getDylibFunctionInfo(jl_frame_t **frames, size_t pointer, int skip
1153
1163
}
1154
1164
jl_in_stackwalk = 0 ;
1155
1165
#endif
1156
- const object::ObjectFile *object ;
1166
+ object::SectionRef Section ;
1157
1167
llvm::DIContext *context = NULL ;
1168
+ int64_t slide;
1158
1169
bool isSysImg;
1159
1170
void *saddr;
1160
- int64_t slide, section_slide;
1161
- if (!jl_dylib_DI_for_fptr (pointer, &object, &context, &slide, §ion_slide, skipC, &isSysImg, &saddr, &frame0->func_name , &frame0->file_name )) {
1171
+ if (!jl_dylib_DI_for_fptr (pointer, &Section, &slide, &context, skipC, &isSysImg, &saddr, &frame0->func_name , &frame0->file_name )) {
1162
1172
frame0->fromC = 1 ;
1163
1173
return 1 ;
1164
1174
}
@@ -1180,26 +1190,24 @@ static int jl_getDylibFunctionInfo(jl_frame_t **frames, size_t pointer, int skip
1180
1190
}
1181
1191
}
1182
1192
}
1183
- return lookup_pointer (object , context, frames, pointer + slide, isSysImg, noInline);
1193
+ return lookup_pointer (Section , context, frames, pointer, slide, isSysImg, noInline);
1184
1194
}
1185
1195
1186
- int jl_DI_for_fptr (uint64_t fptr, uint64_t *symsize, int64_t *slide, int64_t *section_slide,
1187
- const object::ObjectFile **object,
1188
- llvm::DIContext **context
1189
- )
1196
+ int jl_DI_for_fptr (uint64_t fptr, uint64_t *symsize, int64_t *slide,
1197
+ object::SectionRef *Section, llvm::DIContext **context) JL_NOTSAFEPOINT
1190
1198
{
1191
1199
int found = 0 ;
1192
- *slide = 0 ;
1193
1200
std::map<size_t , ObjectInfo, revcomp> &objmap = jl_jit_events->getObjectMap ();
1194
1201
std::map<size_t , ObjectInfo, revcomp>::iterator fit = objmap.lower_bound (fptr);
1195
1202
1203
+ if (symsize)
1204
+ *symsize = 0 ;
1196
1205
if (fit != objmap.end () && fptr < fit->first + fit->second .SectionSize ) {
1197
- if (symsize)
1198
- *symsize = 0 ;
1199
- if (section_slide)
1200
- *section_slide = fit->second .slide ;
1201
- *object = fit->second .object ;
1206
+ *slide = fit->second .slide ;
1207
+ *Section = fit->second .Section ;
1202
1208
if (context) {
1209
+ if (fit->second .context == nullptr )
1210
+ fit->second .context = DWARFContext::create (*fit->second .object ).release ();
1203
1211
*context = fit->second .context ;
1204
1212
}
1205
1213
found = 1 ;
@@ -1208,54 +1216,6 @@ int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide, int64_t *se
1208
1216
return found;
1209
1217
}
1210
1218
1211
- extern " C"
1212
- JL_DLLEXPORT jl_value_t *jl_get_dobj_data (uint64_t fptr)
1213
- {
1214
- jl_ptls_t ptls = jl_get_ptls_states ();
1215
- // Used by Gallium.jl
1216
- const object::ObjectFile *object = NULL ;
1217
- DIContext *context;
1218
- int64_t slide, section_slide;
1219
- int8_t gc_state = jl_gc_safe_enter (ptls);
1220
- if (!jl_DI_for_fptr (fptr, NULL , &slide, NULL , &object, NULL ))
1221
- if (!jl_dylib_DI_for_fptr (fptr, &object, &context, &slide, §ion_slide, false , NULL , NULL , NULL , NULL )) {
1222
- jl_gc_safe_leave (ptls, gc_state);
1223
- return jl_nothing;
1224
- }
1225
- jl_gc_safe_leave (ptls, gc_state);
1226
- if (object == NULL )
1227
- return jl_nothing;
1228
- return (jl_value_t *)jl_ptr_to_array_1d ((jl_value_t *)jl_array_uint8_type,
1229
- const_cast <char *>(object->getData ().data ()),
1230
- object->getData ().size (), false );
1231
- }
1232
-
1233
- extern " C"
1234
- JL_DLLEXPORT uint64_t jl_get_section_start (uint64_t fptr)
1235
- {
1236
- jl_ptls_t ptls = jl_get_ptls_states ();
1237
- // Used by Gallium.jl
1238
- int8_t gc_state = jl_gc_safe_enter (ptls);
1239
- std::map<size_t , ObjectInfo, revcomp> &objmap = jl_jit_events->getObjectMap ();
1240
- std::map<size_t , ObjectInfo, revcomp>::iterator fit = objmap.lower_bound (fptr);
1241
-
1242
- uint64_t ret = 0 ;
1243
- if (fit != objmap.end () && fptr < fit->first + fit->second .SectionSize ) {
1244
- ret = fit->first ;
1245
- }
1246
- else {
1247
- obfiletype::iterator objit = objfilemap.lower_bound (fptr);
1248
- // Ideally we'd have a containment check here, but we can't really
1249
- // get the shared library size easily.
1250
- if (objit != objfilemap.end ()) {
1251
- ret = objit->first ;
1252
- }
1253
- }
1254
- uv_rwlock_rdunlock (&threadsafe);
1255
- jl_gc_safe_leave (ptls, gc_state);
1256
- return ret;
1257
- }
1258
-
1259
1219
// Set *name and *filename to either NULL or malloc'd string
1260
1220
int jl_getFunctionInfo (jl_frame_t **frames_out, size_t pointer, int skipC, int noInline) JL_NOTSAFEPOINT
1261
1221
{
@@ -1267,12 +1227,12 @@ int jl_getFunctionInfo(jl_frame_t **frames_out, size_t pointer, int skipC, int n
1267
1227
*frames_out = frames;
1268
1228
1269
1229
llvm::DIContext *context;
1270
- const object::ObjectFile *object;
1230
+ object::SectionRef Section;
1231
+ int64_t slide;
1271
1232
uint64_t symsize;
1272
- int64_t slide = 0 ;
1273
- if (jl_DI_for_fptr (pointer, &symsize, &slide, NULL , &object, &context)) {
1233
+ if (jl_DI_for_fptr (pointer, &symsize, &slide, &Section, &context)) {
1274
1234
frames[0 ].linfo = jl_jit_events->lookupLinfo (pointer);
1275
- int nf = lookup_pointer (object , context, frames_out, pointer+ slide, 1 , noInline);
1235
+ int nf = lookup_pointer (Section , context, frames_out, pointer, slide, true , noInline);
1276
1236
return nf;
1277
1237
}
1278
1238
return jl_getDylibFunctionInfo (frames_out, pointer, skipC, noInline);
0 commit comments