[lld] [lld-macho] icf objc stubs (PR #79730)

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 16:51:19 PST 2024


================
@@ -332,10 +333,17 @@ class ObjCStubsSection final : public SyntheticSection {
   void setUp();
 
   static constexpr llvm::StringLiteral symbolPrefix = "_objc_msgSend$";
+  static bool isObjCStubSymbol(Symbol *sym);
+  static StringRef getMethName(Symbol *sym);
 
 private:
   std::vector<Defined *> symbols;
-  std::vector<uint32_t> offsets;
+  // Existing mapping from methname to selref (0 index is assumed).
+  llvm::StringMap<InputSection *> methnameToselref;
+  // Newly created mapping from methname to the pair of index (selref) and
+  // offset (methname).
+  llvm::MapVector<StringRef, std::pair<uint32_t, uint32_t>>
+      methnameToidxOffsetPair;
----------------
int3 wrote:

More general comment: I wonder if the code could be simplified by creating a new InputSection for each selref, instead of having one big InputSection and this offset thing. Then we could just have `methnameToselref` contain all selref mappings.

It might also make ICF work automatically without the need for extra logic, since ICF can dedup the individual selrefs

The downside is that it would be less efficient at link time, but maybe that's not too much of an issue? Depends on how many selrefs we have...

I've also thought about going in the opposite direction and having a new `PointerLiteralInputSection`, similar to the `WordLiteralInputSection` but for pointers instead of constant values. That would also give us a uniform interface and be more efficient, but is probably a bunch of work to implement.

Anyway I would love it if we could try the former approach for now (make every selref an InputSection)

https://github.com/llvm/llvm-project/pull/79730


More information about the llvm-commits mailing list