[lld] [lld-macho][NFC] Refactor ObjCSelRefsSection out of ObjCStubsSection (PR #83878)

Vincent Lee via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 8 23:35:55 PST 2024


================
@@ -852,33 +836,62 @@ void ObjCStubsSection::initialize() {
   }
 }
 
+ConcatInputSection *ObjCSelRefsSection::makeSelRef(StringRef methName) {
+  auto methnameOffset =
+      in.objcMethnameSection->getStringOffset(methName).outSecOff;
+
+  size_t wordSize = target->wordSize;
+  uint8_t *selrefData = bAlloc().Allocate<uint8_t>(wordSize);
+  write64le(selrefData, methnameOffset);
+  ConcatInputSection *objcSelref =
+      makeSyntheticInputSection(segment_names::data, section_names::objcSelrefs,
+                                S_LITERAL_POINTERS | S_ATTR_NO_DEAD_STRIP,
+                                ArrayRef<uint8_t>{selrefData, wordSize},
+                                /*align=*/wordSize);
+  objcSelref->live = true;
+  objcSelref->relocs.push_back({/*type=*/target->unsignedRelocType,
+                                /*pcrel=*/false, /*length=*/3,
+                                /*offset=*/0,
+                                /*addend=*/static_cast<int64_t>(methnameOffset),
+                                /*referent=*/in.objcMethnameSection->isec});
+  objcSelref->parent = ConcatOutputSection::getOrCreateForInput(objcSelref);
+  inputSections.push_back(objcSelref);
+  objcSelref->isFinal = true;
+  methnameToSelref[CachedHashStringRef(methName)] = objcSelref;
+  return objcSelref;
+}
+
+ConcatInputSection *ObjCSelRefsSection::getSelRef(StringRef methName) {
----------------
thevinster wrote:

Same here. `methName` -> `methname`. 

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


More information about the llvm-commits mailing list