@@ -183,133 +183,6 @@ std::string CheriCapRelocLocation::toString(Ctx &ctx) const {
183183 return SymbolAndOffset (section, offset).verboseToString (ctx);
184184}
185185
186- template <class ELFT >
187- void CheriCapRelocsSection::processSection (InputSectionBase *s) {
188- // TODO: sort by offset (or is that always true?
189- const auto rels = s->relsOrRelas <ELFT>().relas ;
190- for (auto i = rels.begin (), end = rels.end (); i != end; ++i) {
191- const auto &locationRel = *i;
192- ++i;
193- const auto &targetRel = *i;
194- if ((locationRel.r_offset % entsize) != 0 ) {
195- error (
196- " corrupted __cap_relocs: expected Relocation offset to be a "
197- " multiple of " +
198- Twine (entsize) + " but got " + Twine (locationRel.r_offset ));
199- return ;
200- }
201- constexpr unsigned fieldSize = InMemoryCapRelocEntry<ELFT>::fieldSize;
202- if (targetRel.r_offset != locationRel.r_offset + fieldSize) {
203- error (" corrupted __cap_relocs: expected target relocation (" +
204- Twine (targetRel.r_offset ) +
205- " to directly follow location relocation (" +
206- Twine (locationRel.r_offset ) + " )" );
207- return ;
208- }
209- if (locationRel.r_addend < 0 ) {
210- Msg (ctx) << " corrupted __cap_relocs: addend is less than zero in" << *s
211- << " : " << Twine (locationRel.r_addend );
212- return ;
213- }
214- uint64_t capRelocsOffset = locationRel.r_offset ;
215- assert (capRelocsOffset + entsize <= s->getSize ());
216- if (ctx.arg .emachine == EM_MIPS) {
217- if (locationRel.getType (ctx.arg .isMips64EL ) != R_MIPS_64) {
218- error (" Exptected a R_MIPS_64 relocation in __cap_relocs but got " +
219- toString (locationRel.getType (ctx.arg .isMips64EL )));
220- continue ;
221- }
222- if (targetRel.getType (ctx.arg .isMips64EL ) != R_MIPS_64) {
223- error (" Exptected a R_MIPS_64 relocation in __cap_relocs but got " +
224- toString (targetRel.getType (ctx.arg .isMips64EL )));
225- continue ;
226- }
227- } else {
228- if (locationRel.getType (ctx.arg .isMips64EL ) !=
229- *ctx.target ->absPointerRel ) {
230- error (
231- " Exptected an absolute pointer relocation in __cap_relocs "
232- " but got " +
233- toString (locationRel.getType (ctx.arg .isMips64EL )));
234- continue ;
235- }
236- if (targetRel.getType (ctx.arg .isMips64EL ) != *ctx.target ->absPointerRel ) {
237- error (
238- " Exptected an absolute pointer relocation in __cap_relocs "
239- " but got " +
240- toString (targetRel.getType (ctx.arg .isMips64EL )));
241- continue ;
242- }
243- }
244- Symbol *locationSym = &s->getFile <ELFT>()->getRelocTargetSym (locationRel);
245- Symbol &targetSym = s->getFile <ELFT>()->getRelocTargetSym (targetRel);
246-
247- if (locationSym->file != s->file ) {
248- Err (ctx) << " Expected capability relocation to point to " << *s->file
249- << " but got " << *locationSym->file ;
250- continue ;
251- }
252- // errs() << "Adding cap reloc at " << toString(LocationSym) << " type "
253- // << Twine((int)LocationSym.Type) << " against "
254- // << toString(TargetSym) << "\n";
255- auto *rawInput = reinterpret_cast <const InMemoryCapRelocEntry<ELFT> *>(
256- s->content ().begin () + capRelocsOffset);
257- int64_t targetCapabilityOffset = (int64_t )rawInput->offset ;
258- assert (rawInput->size == 0 &&
259- " Clang should not have set size in __cap_relocs" );
260- if (!isa<Defined>(locationSym)) {
261- error (" Unhandled symbol kind for cap_reloc: " +
262- Twine (locationSym->kind ()));
263- continue ;
264- }
265-
266- const SymbolAndOffset relocLocation{locationSym, locationRel.r_addend };
267- const SymbolAndOffset relocTarget{&targetSym, targetRel.r_addend };
268- SymbolAndOffset realLocation = relocLocation.findRealSymbol (ctx);
269- SymbolAndOffset realTarget = relocTarget.findRealSymbol (ctx);
270- if (ctx.arg .verboseCapRelocs ) {
271- message (" Adding capability relocation at " +
272- realLocation.verboseToString (ctx) + " \n against " +
273- realTarget.verboseToString (ctx));
274- }
275-
276- bool targetNeedsDynReloc = false ;
277- if (targetSym.isPreemptible ) {
278- // Do we need this?
279- // TargetNeedsDynReloc = true;
280- }
281- switch (targetSym.kind ()) {
282- case Symbol::DefinedKind:
283- break ;
284- case Symbol::SharedKind:
285- if (!hasDynamicLinker (ctx)) {
286- error (
287- " cannot create a capability relocation against a shared symbol"
288- " when linking statically" );
289- continue ;
290- }
291- targetNeedsDynReloc = true ;
292- break ;
293- case Symbol::UndefinedKind:
294- // addCapReloc() will add an error if we are building an executable
295- // instead of a shlib
296- // TODO: we really should add a dynamic SIZE relocation as well
297- targetNeedsDynReloc = true ;
298- break ;
299- default :
300- error (" Unhandled symbol kind for cap_reloc target: " +
301- Twine (targetSym.kind ()));
302- continue ;
303- }
304- assert (locationSym->isSection ());
305- auto *locationDef = cast<Defined>(locationSym);
306- auto *locationSec = cast<InputSectionBase>(locationDef->section );
307- addCapReloc<ELFT>({locationSec, (uint64_t )locationRel.r_addend }, realTarget,
308- targetNeedsDynReloc, targetCapabilityOffset,
309- realLocation.sym ());
310- }
311- }
312-
313186template <class ELFT >
314187void CheriCapRelocsSection::addCapReloc (CheriCapRelocLocation loc,
315188 const SymbolAndOffset &target,
0 commit comments