@@ -172,19 +172,16 @@ Process::load()
172172 auto auxv = getAUXV ();
173173 if (auxv)
174174 processAUXV (*auxv);
175-
176- // by now, we should know what executable was loaded for the process.
177- if (!execImage)
178- throw (Exception () << " no executable image located for process" );
179-
180175 try {
181- Elf::Addr r_debug_addr = findRDebugAddr ();
182- bool isStatic = r_debug_addr == 0 || r_debug_addr == Elf::Addr (-1 );
176+ findRDebugAddr ();
177+ bool isStatic = dt_debug == 0 || dt_debug == Elf::Addr (-1 );
183178
184- if (isStatic)
185- addElfObject (" " , execImage, 0 );
186- else
187- loadSharedObjects (r_debug_addr);
179+ if (isStatic) {
180+ if (execImage)
181+ addElfObject (" " , execImage, 0 );
182+ } else {
183+ loadSharedObjects (dt_debug);
184+ }
188185 }
189186 catch (const Exception &) {
190187 // We were unable to read the link map.
@@ -297,13 +294,14 @@ Process::processAUXV(const Reader &auxio)
297294
298295 break ;
299296 }
297+
300298#endif
301299 case AT_PHDR:
302- phOff = hdr;
303- break ;
300+ phOff = hdr;
301+ break ;
304302 case AT_PHNUM:
305- phNum = hdr;
306- break ;
303+ phNum = hdr;
304+ break ;
307305 default :
308306 break ;
309307 }
@@ -820,13 +818,17 @@ Process::loadSharedObjects(Elf::Addr rdebugAddr)
820818 // If we see the executable, just add it in and avoid going through the path
821819 // replacement work
822820 if (mapAddr == Elf::Addr (rDebug.r_map )) {
823- auto loadAddr = entry - execImage->getHeader ().e_entry ;
824- if (loadAddr != map.l_addr ) {
825- *context.debug << " calculated load address for executable from process entrypoint ("
826- << std::hex << loadAddr << " ) does not match link map (" << map.l_addr
827- << " ). Trusting link-map\n " << std::dec;
821+ if (execImage) {
822+ if (execBase == 0 ) {
823+ execBase = entry - execImage->getHeader ().e_entry ;
824+ }
825+ if (execBase != map.l_addr ) {
826+ *context.debug << " calculated load address for executable from process entrypoint ("
827+ << std::hex << execBase << " ) does not match link map (" << map.l_addr
828+ << " ). Trusting link-map\n " << std::dec;
829+ }
830+ addElfObject (" (exe)" , execImage, map.l_addr );
828831 }
829- addElfObject (" (exe)" , execImage, map.l_addr );
830832 continue ;
831833 }
832834 // If we've loaded the VDSO, and we see it in the link map, just skip it.
@@ -869,7 +871,7 @@ Process::findRDebugAddr()
869871 * the difference is the load address.
870872 */
871873
872- if (dt_debug == 0 ) {
874+ if (dt_debug == 0 && execImage ) {
873875 // Iterate over the PT_DYNAMIC segment of the loaded executable. (We
874876 // should not get here, as we should have found the program headers in
875877 // the AT_PHDR auxv entry, and done this already
@@ -884,7 +886,7 @@ Process::findRDebugAddr()
884886 * library, which doesn't have an _r_debug symbol. Use the address of
885887 * _r_debug in the interpreter
886888 */
887- if (dt_debug == 0 && interpBase && execImage->getInterpreter () != " " ) {
889+ if (dt_debug == 0 && execImage && interpBase && execImage->getInterpreter () != " " ) {
888890 try {
889891 addElfObject (execImage->getInterpreter (), nullptr , interpBase);
890892 dt_debug = resolveSymbol (" _r_debug" , false ,
@@ -909,7 +911,7 @@ Process::findSegment(Elf::Addr addr)
909911 if (it != objects.begin ()) {
910912 --it;
911913 auto obj = it->second .object (context);
912- if (it->first + obj->endVA () >= addr) {
914+ if (obj && it->first + obj->endVA () >= addr) {
913915 auto segment = obj->getSegmentForAddress (addr - it->first );
914916 if (segment)
915917 return std::make_tuple (it->first , obj, segment);
@@ -926,6 +928,8 @@ Process::resolveSymbolDetail(const char *name, bool includeDebug,
926928 if (!match (loaded.second .name ()))
927929 continue ;
928930 auto obj = loaded.second .object (context);
931+ if (!obj)
932+ continue ;
929933 auto [sym,idx] = obj->findDynamicSymbol (name);
930934 if (sym.st_shndx != SHN_UNDEF)
931935 return std::make_tuple (obj, loaded.first , sym);
0 commit comments