Skip to content

[lld-macho] Implement ObjC category merging (-objc_category_merging) #82928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lld/MachO/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
resetOutputSegments();
resetWriter();
InputFile::resetIdCount();

objc::doCleanup();
};

ctx->e.logName = args::getFilenameWithoutExe(argsArr[0]);
Expand Down Expand Up @@ -1979,9 +1981,16 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
if (config->deadStrip)
markLive();

// Categories are not subject to dead-strip. The __objc_catlist section is
// marked as NO_DEAD_STRIP and that propagates into all category data.
if (args.hasArg(OPT_check_category_conflicts))
objc::checkCategories();

// Category merging uses "->live = false" to erase old category data, so
// it has to run after dead-stripping (markLive).
if (args.hasArg(OPT_objc_category_merging, OPT_no_objc_category_merging))
objc::mergeCategories();

// ICF assumes that all literals have been folded already, so we must run
// foldIdenticalLiterals before foldIdenticalSections.
foldIdenticalLiterals();
Expand Down
2 changes: 1 addition & 1 deletion lld/MachO/InputSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class InputSection {
// .subsections_via_symbols, there is typically only one element here.
llvm::TinyPtrVector<Defined *> symbols;

protected:
const Section &section;

protected:
const Defined *getContainingSymbol(uint64_t off) const;
};

Expand Down
Loading