[PATCH] D111706: [lld-macho] Use StringRef's hash code as keys of loadedArchives

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 14 19:11:30 PDT 2021


oontvoo added inline comments.


================
Comment at: lld/MachO/Driver.cpp:355-357
   if (Optional<std::string> path = findFramework(name)) {
     if (auto *dylibFile = dyn_cast_or_null<DylibFile>(
             addFile(*path, /*forceLoadArchive=*/false, isExplicit))) {
----------------
oontvoo wrote:
> I think this is where the dangling reference is .
> 
> Could you add `saver.save(*path)` here? 
> (ie.,`addFile(saver.save(*path),/*forceLoadArchive=*/false, isExplicit))` )
> 
> Storing the strings themselves are probably better than hash_code.
> 
> 
P.S: Or perhaps the more general fix is to make `resolveDylibPath`[0] return an `Optional<StringRef>` (where it already "saves" the string's content into the saver).



[0] https://github.com/llvm/llvm-project/blob/d3cb6bf2d462958f2a6573e6390cca71d13dee6b/lld/MachO/DriverUtils.cpp#L186



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111706/new/

https://reviews.llvm.org/D111706



More information about the llvm-commits mailing list