Skip to content

Conversation

p-x9
Copy link
Owner

@p-x9 p-x9 commented Aug 17, 2025

The linkedit data in iOS is stored together in a separate, independent cache.
(dyld_shared_cache_arm64e.65.dyldreadonly)

@p-x9 p-x9 requested a review from Copilot August 17, 2025 16:12
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the MachOKit library to properly handle linkedit data when reading from dyld cache files on iOS, where linkedit data is stored in a separate cache file (.0x.linkeditdata) rather than in the same cache as the main Mach-O data.

  • Introduces new methods _fileSliceForLinkEditData and _readLinkEditData to handle linkedit data reading from appropriate cache locations
  • Updates multiple properties to use the new linkedit data reading methods instead of direct file handle operations
  • Adds cached properties for DyldCache and FullDyldCache instances to improve performance

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
Sources/MachOKit/MachOFile.swift Core implementation with new linkedit data handling methods and updated properties
Sources/MachOKit/MachOFile+Symbols.swift Updated symbol loading to use new linkedit data methods
Sources/MachOKit/MachOFile+Strings.swift Added new initializer for Strings class
Sources/MachOKit/MachOFile+FunctionStarts.swift Updated function starts loading to use new linkedit data method
Sources/MachOKit/MachOFile+ExportTrie.swift Updated export trie loading to use new linkedit data method

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

.deletingPathExtension()
.deletingPathExtension()
)
}
Copy link
Preview

Copilot AI Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These computed properties will create new cache instances on every access. Consider implementing lazy stored properties or caching mechanisms to avoid repeated initialization overhead, especially since these caches are accessed multiple times throughout the codebase.

Suggested change
}
internal lazy var cache: DyldCache? = {
try? DyldCache(url: url)
}()
internal lazy var fullCache: FullDyldCache? = {
try? FullDyldCache(
url: url
.deletingPathExtension()
.deletingPathExtension()
)
}()

Copilot uses AI. Check for mistakes.

length: numericCast(symtab.strsize)
)
)!
Copy link
Preview

Copilot AI Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force unwrapping with ! can cause crashes if _fileSliceForLinkEditData returns nil. Consider using guard statements or proper error handling instead of force unwrapping.

Copilot uses AI. Check for mistakes.

length: numericCast(symtab.nsyms) * MemoryLayout<nlist_64>.size
)
)!
Copy link
Preview

Copilot AI Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force unwrapping with ! can cause crashes if _fileSliceForLinkEditData returns nil. Consider using guard statements or proper error handling instead of force unwrapping.

Copilot uses AI. Check for mistakes.

let stringsSlice = machO._fileSliceForLinkEditData(
offset: numericCast(symtab.stroff),
length: numericCast(symtab.strsize)
)!
Copy link
Preview

Copilot AI Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force unwrapping with ! can cause crashes if _fileSliceForLinkEditData returns nil. Consider using guard statements or proper error handling instead of force unwrapping.

Copilot uses AI. Check for mistakes.

let symbolsSlice = machO._fileSliceForLinkEditData(
offset: numericCast(symtab.symoff),
length: numericCast(symtab.nsyms) * MemoryLayout<nlist>.size
)!
Copy link
Preview

Copilot AI Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force unwrapping with ! can cause crashes if _fileSliceForLinkEditData returns nil. Consider using guard statements or proper error handling instead of force unwrapping.

Copilot uses AI. Check for mistakes.

length: functionStartsSize
)
)!
Copy link
Preview

Copilot AI Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force unwrapping with ! can cause crashes if _readLinkEditData returns nil. Consider using guard statements or proper error handling instead of force unwrapping.

Copilot uses AI. Check for mistakes.

length: exportSize
)
)!
Copy link
Preview

Copilot AI Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force unwrapping with ! can cause crashes if _readLinkEditData returns nil. Consider using guard statements or proper error handling instead of force unwrapping.

Copilot uses AI. Check for mistakes.

@p-x9 p-x9 merged commit 5daf12a into main Aug 18, 2025
2 checks passed
@p-x9 p-x9 deleted the feature/fix-linkeditdata-reading branch August 18, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant