@@ -806,26 +806,10 @@ void StubHelperSection::setUp() {
806
806
dyldPrivate->used = true ;
807
807
}
808
808
809
- ObjCStubsSection::ObjCStubsSection ()
810
- : SyntheticSection(segment_names::text, section_names::objcStubs) {
811
- flags = S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
812
- align = config->objcStubsMode == ObjCStubsMode::fast
813
- ? target->objcStubsFastAlignment
814
- : target->objcStubsSmallAlignment ;
815
- }
816
-
817
- bool ObjCStubsSection::isObjCStubSymbol (Symbol *sym) {
818
- return sym->getName ().starts_with (symbolPrefix);
819
- }
809
+ ObjCSelRefsSection::ObjCSelRefsSection ()
810
+ : SyntheticSection(segment_names::data, section_names::objcSelrefs) {}
820
811
821
- StringRef ObjCStubsSection::getMethname (Symbol *sym) {
822
- assert (isObjCStubSymbol (sym) && " not an objc stub" );
823
- auto name = sym->getName ();
824
- StringRef methname = name.drop_front (symbolPrefix.size ());
825
- return methname;
826
- }
827
-
828
- void ObjCStubsSection::initialize () {
812
+ void ObjCSelRefsSection::initialize () {
829
813
// Do not fold selrefs without ICF.
830
814
if (config->icfLevel == ICFLevel::none)
831
815
return ;
@@ -852,33 +836,62 @@ void ObjCStubsSection::initialize() {
852
836
}
853
837
}
854
838
839
+ ConcatInputSection *ObjCSelRefsSection::makeSelRef (StringRef methname) {
840
+ auto methnameOffset =
841
+ in.objcMethnameSection ->getStringOffset (methname).outSecOff ;
842
+
843
+ size_t wordSize = target->wordSize ;
844
+ uint8_t *selrefData = bAlloc ().Allocate <uint8_t >(wordSize);
845
+ write64le (selrefData, methnameOffset);
846
+ ConcatInputSection *objcSelref =
847
+ makeSyntheticInputSection (segment_names::data, section_names::objcSelrefs,
848
+ S_LITERAL_POINTERS | S_ATTR_NO_DEAD_STRIP,
849
+ ArrayRef<uint8_t >{selrefData, wordSize},
850
+ /* align=*/ wordSize);
851
+ objcSelref->live = true ;
852
+ objcSelref->relocs .push_back ({/* type=*/ target->unsignedRelocType ,
853
+ /* pcrel=*/ false , /* length=*/ 3 ,
854
+ /* offset=*/ 0 ,
855
+ /* addend=*/ static_cast <int64_t >(methnameOffset),
856
+ /* referent=*/ in.objcMethnameSection ->isec });
857
+ objcSelref->parent = ConcatOutputSection::getOrCreateForInput (objcSelref);
858
+ inputSections.push_back (objcSelref);
859
+ objcSelref->isFinal = true ;
860
+ methnameToSelref[CachedHashStringRef (methname)] = objcSelref;
861
+ return objcSelref;
862
+ }
863
+
864
+ ConcatInputSection *ObjCSelRefsSection::getSelRef (StringRef methname) {
865
+ auto it = methnameToSelref.find (CachedHashStringRef (methname));
866
+ if (it == methnameToSelref.end ())
867
+ return nullptr ;
868
+ return it->second ;
869
+ }
870
+
871
+ ObjCStubsSection::ObjCStubsSection ()
872
+ : SyntheticSection(segment_names::text, section_names::objcStubs) {
873
+ flags = S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
874
+ align = config->objcStubsMode == ObjCStubsMode::fast
875
+ ? target->objcStubsFastAlignment
876
+ : target->objcStubsSmallAlignment ;
877
+ }
878
+
879
+ bool ObjCStubsSection::isObjCStubSymbol (Symbol *sym) {
880
+ return sym->getName ().starts_with (symbolPrefix);
881
+ }
882
+
883
+ StringRef ObjCStubsSection::getMethname (Symbol *sym) {
884
+ assert (isObjCStubSymbol (sym) && " not an objc stub" );
885
+ auto name = sym->getName ();
886
+ StringRef methname = name.drop_front (symbolPrefix.size ());
887
+ return methname;
888
+ }
889
+
855
890
void ObjCStubsSection::addEntry (Symbol *sym) {
856
891
StringRef methname = getMethname (sym);
857
892
// We create a selref entry for each unique methname.
858
- if (!methnameToSelref.count (CachedHashStringRef (methname))) {
859
- auto methnameOffset =
860
- in.objcMethnameSection ->getStringOffset (methname).outSecOff ;
861
-
862
- size_t wordSize = target->wordSize ;
863
- uint8_t *selrefData = bAlloc ().Allocate <uint8_t >(wordSize);
864
- write64le (selrefData, methnameOffset);
865
- auto *objcSelref = makeSyntheticInputSection (
866
- segment_names::data, section_names::objcSelrefs,
867
- S_LITERAL_POINTERS | S_ATTR_NO_DEAD_STRIP,
868
- ArrayRef<uint8_t >{selrefData, wordSize},
869
- /* align=*/ wordSize);
870
- objcSelref->live = true ;
871
- objcSelref->relocs .push_back (
872
- {/* type=*/ target->unsignedRelocType ,
873
- /* pcrel=*/ false , /* length=*/ 3 ,
874
- /* offset=*/ 0 ,
875
- /* addend=*/ static_cast <int64_t >(methnameOffset),
876
- /* referent=*/ in.objcMethnameSection ->isec });
877
- objcSelref->parent = ConcatOutputSection::getOrCreateForInput (objcSelref);
878
- inputSections.push_back (objcSelref);
879
- objcSelref->isFinal = true ;
880
- methnameToSelref[CachedHashStringRef (methname)] = objcSelref;
881
- }
893
+ if (!in.objcSelRefs ->getSelRef (methname))
894
+ in.objcSelRefs ->makeSelRef (methname);
882
895
883
896
auto stubSize = config->objcStubsMode == ObjCStubsMode::fast
884
897
? target->objcStubsFastSize
@@ -927,9 +940,9 @@ void ObjCStubsSection::writeTo(uint8_t *buf) const {
927
940
Defined *sym = symbols[i];
928
941
929
942
auto methname = getMethname (sym);
930
- auto j = methnameToSelref. find ( CachedHashStringRef ( methname) );
931
- assert (j != methnameToSelref. end () );
932
- auto selrefAddr = j-> second ->getVA (0 );
943
+ InputSection *selRef = in. objcSelRefs -> getSelRef ( methname);
944
+ assert (selRef != nullptr && " no selref for methname " );
945
+ auto selrefAddr = selRef ->getVA (0 );
933
946
target->writeObjCMsgSendStub (buf + stubOffset, sym, in.objcStubs ->addr ,
934
947
stubOffset, selrefAddr, objcMsgSend);
935
948
}
0 commit comments