[lld] [lld-macho] Implement support for ObjC relative method lists (PR #86231)

Kyungwoo Lee via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 25 10:13:57 PDT 2024


================
@@ -692,6 +692,53 @@ class InitOffsetsSection final : public SyntheticSection {
   std::vector<ConcatInputSection *> sections;
 };
 
+// This SyntheticSection is for the __objc_methlist section, which contains
+// relative method lists if the -objc_relative_method_lists option is enabled.
+class ObjCMethListSection final : public SyntheticSection {
+public:
+  ObjCMethListSection();
+
+  static bool isMethodList(const ConcatInputSection *isec);
+  void addInput(ConcatInputSection *isec) { inputs.push_back(isec); }
+  std::vector<ConcatInputSection *> getInputs() { return inputs; }
+
+  void setUp();
+  void finalize() override;
+  bool isNeeded() const override { return !inputs.empty(); }
+  uint64_t getSize() const override { return m_size; }
+  void writeTo(uint8_t *bufStart) const override;
+
+private:
+  static void readMethodListHeader(const uint8_t *buf,
+                                   uint32_t &structSizeAndFlags,
+                                   uint32_t &structCount);
+  static void writeMethodListHeader(uint8_t *buf, uint32_t structSizeAndFlags,
+                                    uint32_t structCount);
+  static uint32_t methodListSizeToRelativeMethodListSize(uint32_t iSecSize);
----------------
kyulee-com wrote:

I'd do something like `computeRelativeMethodListSize(uint32_t methodListSize)` where `methodListSize` can be `absoluteMethodListSize` or `originalMethodListSize`, etc.

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


More information about the llvm-commits mailing list