@@ -2154,27 +2154,25 @@ ELFWriter<ELFT>::ELFWriter(Object &Obj, raw_ostream &Buf, bool WSH,
21542154 : Writer(Obj, Buf), WriteSectionHeaders(WSH && Obj.HadShdrs),
21552155 OnlyKeepDebug (OnlyKeepDebug) {}
21562156
2157- Error Object::updateSectionData (std::vector<SecPtr>::iterator It,
2158- ArrayRef<uint8_t > Data) {
2159- auto *OldSec = It->get ();
2160- if (!OldSec->hasContents ())
2157+ Error Object::updateSectionData (SecPtr &Sec, ArrayRef<uint8_t > Data) {
2158+ if (!Sec->hasContents ())
21612159 return createStringError (
21622160 errc::invalid_argument,
21632161 " section '%s' cannot be updated because it does not have contents" ,
2164- OldSec ->Name .c_str ());
2162+ Sec ->Name .c_str ());
21652163
2166- if (Data.size () > OldSec ->Size && OldSec ->ParentSegment )
2164+ if (Data.size () > Sec ->Size && Sec ->ParentSegment )
21672165 return createStringError (errc::invalid_argument,
21682166 " cannot fit data of size %zu into section '%s' "
21692167 " with size %" PRIu64 " that is part of a segment" ,
2170- Data.size (), OldSec ->Name .c_str (), OldSec ->Size );
2168+ Data.size (), Sec ->Name .c_str (), Sec ->Size );
21712169
2172- if (!OldSec ->ParentSegment ) {
2173- *It = std::make_unique<OwnedDataSection>(*OldSec , Data);
2170+ if (!Sec ->ParentSegment ) {
2171+ Sec = std::make_unique<OwnedDataSection>(*Sec , Data);
21742172 } else {
21752173 // The segment writer will be in charge of updating these contents.
2176- OldSec ->Size = Data.size ();
2177- UpdatedSections[OldSec ] = Data;
2174+ Sec ->Size = Data.size ();
2175+ UpdatedSections[Sec. get () ] = Data;
21782176 }
21792177
21802178 return Error::success ();
@@ -2186,14 +2184,14 @@ Error Object::updateSection(StringRef Name, ArrayRef<uint8_t> Data) {
21862184 if (It == Sections.end ())
21872185 return createStringError (errc::invalid_argument, " section '%s' not found" ,
21882186 Name.str ().c_str ());
2189- return updateSectionData (It, Data);
2187+ return updateSectionData (* It, Data);
21902188}
21912189
21922190Error Object::updateSectionData (SectionBase &S, ArrayRef<uint8_t > Data) {
21932191 auto It = llvm::find_if (Sections,
21942192 [&](const SecPtr &Sec) { return Sec.get () == &S; });
21952193 assert (It != Sections.end () && " The section should belong to the object" );
2196- return updateSectionData (It, Data);
2194+ return updateSectionData (* It, Data);
21972195}
21982196
21992197Error Object::removeSections (
0 commit comments