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