@@ -159,15 +159,27 @@ Context::getImageIfLoaded(const Container &ctr, const typename Container::key_ty
159159 * Find an image from a name, caching in container, and using "paths" as potential prefixes for name
160160 */
161161std::shared_ptr<Elf::Object>
162- Context::getImageInPath (const std::vector<std::filesystem::path> &paths, NameMap &container, const std::filesystem::path &name, bool isDebug) {
162+ Context::getImageInPath (const std::vector<std::filesystem::path> &paths, NameMap &container, const std::filesystem::path &name, bool isDebug, bool resolveLink ) {
163163 std::optional<Elf::Object::sptr> cached = getImageIfLoaded (container, name, isDebug);
164164 if (cached)
165165 return *cached;
166166
167167 Elf::Object::sptr res;
168168 for (const auto &dir : paths) {
169+ auto path = dir/name;
170+ if (resolveLink) {
171+ char buf[PATH_MAX];
172+ char *p = realpath ( path.c_str (), buf );
173+ if (p) {
174+ path = p;
175+ } else if (errno == ENOENT) {
176+ return nullptr ;
177+ } else {
178+ *debug << " failed to resolve " << path << " : " << strerror (errno) << " \n " ;
179+ }
180+ }
169181 try {
170- res = std::make_shared<Elf::Object>(*this , std::make_shared<MmapReader>(*this ,dir / name ) , isDebug);
182+ res = std::make_shared<Elf::Object>(*this , std::make_shared<MmapReader>(*this , path ) , isDebug);
171183 break ;
172184 }
173185 catch (const std::exception &ex) {
@@ -189,7 +201,7 @@ Context::getImageInPath(const std::vector<std::filesystem::path> &paths, NameMap
189201 */
190202std::shared_ptr<Elf::Object>
191203Context::getImage (const std::filesystem::path &name) {
192- return getImageInPath (exePrefixes, imageByName, name, false );
204+ return getImageInPath (exePrefixes, imageByName, name, false , false );
193205}
194206
195207/*
@@ -224,7 +236,7 @@ std::shared_ptr<Elf::Object> Context::getImageImpl( const Elf::BuildID &bid, boo
224236
225237 std::filesystem::path bidpath = std::filesystem::path ( bucket.str () ) / std::filesystem::path ( rest.str () );
226238
227- Elf::Object::sptr res = getImageInPath (paths, nameContainer, bidpath, isDebug);
239+ Elf::Object::sptr res = getImageInPath (paths, nameContainer, bidpath, isDebug, true );
228240#ifdef DEBUGINFOD
229241 if (!res && debuginfod ()) {
230242 char *path;
@@ -255,7 +267,7 @@ std::shared_ptr<Elf::Object> Context::getImageImpl( const Elf::BuildID &bid, boo
255267
256268std::shared_ptr<Elf::Object>
257269Context::getDebugImage (const std::filesystem::path &name) {
258- return getImageInPath (debugPrefixes, debugImageByName, name, true );
270+ return getImageInPath (debugPrefixes, debugImageByName, name, true , false );
259271}
260272
261273#ifndef DEBUGINFOD
0 commit comments