Skip to content

Commit a0740d0

Browse files
authored
debuginfo: improve robustness of code slightly (#57989)
I hit this iswindows assert locally while frobbing stuff, so I wanted to remove it and clean up the code slightly to be more careful here about verifying what it got from the file system.
1 parent 9d4e31f commit a0740d0

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/debuginfo.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ void JITDebugInfoRegistry::libc_frames_t::libc_deregister_frame(const char *Entr
568568
}
569569
#endif
570570

571-
static bool getObjUUID(llvm::object::MachOObjectFile *obj, uint8_t uuid[16]) JL_NOTSAFEPOINT
571+
static bool getObjUUID(const object::MachOObjectFile *obj, uint8_t uuid[16]) JL_NOTSAFEPOINT
572572
{
573573
for (auto Load : obj->load_commands())
574574
{
@@ -830,9 +830,6 @@ static objfileentry_t find_object_file(uint64_t fbase, StringRef fname) JL_NOTSA
830830
std::string debuginfopath;
831831
uint8_t uuid[16], uuid2[16];
832832
if (isdarwin) {
833-
// Hide Darwin symbols (e.g. CoreFoundation) from non-Darwin systems.
834-
#ifdef _OS_DARWIN_
835-
836833
size_t msize = (size_t)(((uint64_t)-1) - fbase);
837834
std::unique_ptr<MemoryBuffer> membuf = MemoryBuffer::getMemBuffer(
838835
StringRef((const char *)fbase, msize), "", false);
@@ -843,14 +840,18 @@ static objfileentry_t find_object_file(uint64_t fbase, StringRef fname) JL_NOTSA
843840
return entry;
844841
}
845842

846-
llvm::object::MachOObjectFile *morigobj = (llvm::object::MachOObjectFile*)
847-
origerrorobj.get().get();
843+
const object::MachOObjectFile *morigobj = dyn_cast<const object::MachOObjectFile>(
844+
origerrorobj.get().get());
848845

849846
// First find the uuid of the object file (we'll use this to make sure we find the
850847
// correct debug symbol file).
851-
if (!getObjUUID(morigobj, uuid))
848+
if (!morigobj || !getObjUUID(morigobj, uuid))
852849
return entry;
853850

851+
// Hide Darwin symbols (e.g. CoreFoundation) from non-Darwin systems.
852+
#ifndef _OS_DARWIN_
853+
return entry;
854+
#else
854855
// On macOS, debug symbols are not contained in the dynamic library.
855856
// Use DBGCopyFullDSYMURLForUUID from the private DebugSymbols framework
856857
// to make use of spotlight to find the dSYM file. If that fails, lookup
@@ -906,6 +907,7 @@ static objfileentry_t find_object_file(uint64_t fbase, StringRef fname) JL_NOTSA
906907
if (dsfmwkbundle) {
907908
CFRelease(dsfmwkbundle);
908909
}
910+
#endif
909911

910912
if (objpath.empty()) {
911913
// Fall back to simple path relative to the dynamic library.
@@ -915,7 +917,6 @@ static objfileentry_t find_object_file(uint64_t fbase, StringRef fname) JL_NOTSA
915917
debuginfopath += fname.substr(sep + 1);
916918
objpath = debuginfopath;
917919
}
918-
#endif
919920
}
920921
else {
921922
// On Linux systems we need to mmap another copy because of the permissions on the mmap'ed shared library.
@@ -974,15 +975,17 @@ static objfileentry_t find_object_file(uint64_t fbase, StringRef fname) JL_NOTSA
974975

975976
if (isdarwin) {
976977
// verify the UUID matches
977-
if (!getObjUUID((llvm::object::MachOObjectFile*)debugobj, uuid2) ||
978-
memcmp(uuid, uuid2, sizeof(uuid)) != 0) {
978+
if (!isa<const object::MachOObjectFile>(debugobj) ||
979+
!getObjUUID(cast<const object::MachOObjectFile>(debugobj), uuid2) ||
980+
memcmp(uuid, uuid2, sizeof(uuid)) != 0) {
979981
return entry;
980982
}
981983
}
982984

983985
int64_t slide = 0;
984986
if (auto *OF = dyn_cast<const object::COFFObjectFile>(debugobj)) {
985-
assert(iswindows);
987+
if (!iswindows) // the COFF parser accepts some garbage inputs (like empty files) that the other parsers correctly reject, so we can end up here even when we should not
988+
return entry;
986989
slide = OF->getImageBase() - fbase;
987990
}
988991
else {

0 commit comments

Comments
 (0)