@@ -836,7 +836,7 @@ void ObjCStubsSection::initialize() {
836
836
for (ConcatInputSection *isec : inputSections) {
837
837
if (isec->shouldOmitFromOutput ())
838
838
continue ;
839
- if (isec->getName () != " __objc_selrefs " )
839
+ if (isec->getName () != section_names::objcSelrefs )
840
840
continue ;
841
841
// We expect a single relocation per selref entry to __objc_methname that
842
842
// might be aggregated.
@@ -846,21 +846,38 @@ void ObjCStubsSection::initialize() {
846
846
if (const auto *d = dyn_cast<Defined>(sym)) {
847
847
auto *cisec = cast<CStringInputSection>(d->isec );
848
848
auto methname = cisec->getStringRefAtOffset (d->value );
849
- methnameToselref[ methname] = isec;
849
+ methnameToSelref[ CachedHashStringRef ( methname) ] = isec;
850
850
}
851
851
}
852
852
}
853
853
}
854
854
855
855
void ObjCStubsSection::addEntry (Symbol *sym) {
856
856
StringRef methname = getMethname (sym);
857
- // We will create a selref entry for each unique methname.
858
- if (!methnameToselref.count (methname) &&
859
- !methnameToidxOffsetPair.count (methname)) {
857
+ // We create a selref entry for each unique methname.
858
+ if (!methnameToSelref.count (CachedHashStringRef (methname))) {
860
859
auto methnameOffset =
861
860
in.objcMethnameSection ->getStringOffset (methname).outSecOff ;
862
- auto selIndex = methnameToidxOffsetPair.size ();
863
- methnameToidxOffsetPair[methname] = {selIndex, methnameOffset};
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;
864
881
}
865
882
866
883
auto stubSize = config->objcStubsMode == ObjCStubsMode::fast
@@ -895,35 +912,6 @@ void ObjCStubsSection::setUp() {
895
912
if (!isa<Defined>(objcMsgSend))
896
913
in.stubs ->addEntry (objcMsgSend);
897
914
}
898
-
899
- size_t size = methnameToidxOffsetPair.size () * target->wordSize ;
900
- uint8_t *selrefsData = bAlloc ().Allocate <uint8_t >(size);
901
- for (const auto &[methname, idxOffsetPair] : methnameToidxOffsetPair) {
902
- const auto &[idx, offset] = idxOffsetPair;
903
- write64le (&selrefsData[idx * target->wordSize ], offset);
904
- }
905
-
906
- in.objcSelrefs =
907
- makeSyntheticInputSection (segment_names::data, section_names::objcSelrefs,
908
- S_LITERAL_POINTERS | S_ATTR_NO_DEAD_STRIP,
909
- ArrayRef<uint8_t >{selrefsData, size},
910
- /* align=*/ target->wordSize );
911
- in.objcSelrefs ->live = true ;
912
-
913
- for (const auto &[methname, idxOffsetPair] : methnameToidxOffsetPair) {
914
- const auto &[idx, offset] = idxOffsetPair;
915
- in.objcSelrefs ->relocs .push_back (
916
- {/* type=*/ target->unsignedRelocType ,
917
- /* pcrel=*/ false , /* length=*/ 3 ,
918
- /* offset=*/ static_cast <uint32_t >(idx * target->wordSize ),
919
- /* addend=*/ offset * in.objcMethnameSection ->align ,
920
- /* referent=*/ in.objcMethnameSection ->isec });
921
- }
922
-
923
- in.objcSelrefs ->parent =
924
- ConcatOutputSection::getOrCreateForInput (in.objcSelrefs );
925
- inputSections.push_back (in.objcSelrefs );
926
- in.objcSelrefs ->isFinal = true ;
927
915
}
928
916
929
917
uint64_t ObjCStubsSection::getSize () const {
@@ -934,29 +922,16 @@ uint64_t ObjCStubsSection::getSize() const {
934
922
}
935
923
936
924
void ObjCStubsSection::writeTo (uint8_t *buf) const {
937
- assert (in.objcSelrefs ->live );
938
- assert (in.objcSelrefs ->isFinal );
939
-
940
925
uint64_t stubOffset = 0 ;
941
926
for (size_t i = 0 , n = symbols.size (); i < n; ++i) {
942
927
Defined *sym = symbols[i];
943
- uint64_t selBaseAddr;
944
- uint64_t selIndex;
945
928
946
929
auto methname = getMethname (sym);
947
- auto j = methnameToselref.find (methname);
948
- if (j != methnameToselref.end ()) {
949
- selBaseAddr = j->second ->getVA (0 );
950
- selIndex = 0 ;
951
- } else {
952
- auto k = methnameToidxOffsetPair.find (methname);
953
- assert (k != methnameToidxOffsetPair.end ());
954
- selBaseAddr = in.objcSelrefs ->getVA ();
955
- selIndex = k->second .first ;
956
- }
930
+ auto j = methnameToSelref.find (CachedHashStringRef (methname));
931
+ assert (j != methnameToSelref.end ());
932
+ auto selrefAddr = j->second ->getVA (0 );
957
933
target->writeObjCMsgSendStub (buf + stubOffset, sym, in.objcStubs ->addr ,
958
- stubOffset, selBaseAddr, selIndex,
959
- objcMsgSend);
934
+ stubOffset, selrefAddr, 0 , objcMsgSend);
960
935
}
961
936
}
962
937
0 commit comments