/* * Copyright 2011, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ELF_SECTION_REL_TABLE_HXX #define ELF_SECTION_REL_TABLE_HXX #include "ELFReloc.h" template ELFSectionRelTable::~ELFSectionRelTable() { using namespace std; for (size_t i = 0; i < table.size(); ++i) { delete table[i]; } } template void ELFSectionRelTable::print() const { using namespace llvm; out() << '\n' << fillformat('=', 79) << '\n'; out().changeColor(raw_ostream::WHITE, true); out() << "Relocation Table" << '\n'; out().resetColor(); for (size_t i = 0; i < this->size(); ++i) { (*this)[i]->print(); } out() << fillformat('=', 79) << '\n'; } template template ELFSectionRelTable * ELFSectionRelTable::read(Archiver &AR, ELFSectionHeaderTy const *sh) { rsl_assert(sh->getType() == SHT_REL || sh->getType() == SHT_RELA); llvm::OwningPtr rt(new ELFSectionRelTable()); // Seek to the start of the table AR.seek(sh->getOffset(), true); // Count the relocation entries size_t size = sh->getSize() / sh->getEntrySize(); // Read every relocation entries if (sh->getType() == SHT_REL) { rsl_assert(sh->getEntrySize() == TypeTraits::size); for (size_t i = 0; i < size; ++i) { rt->table.push_back(ELFRelocTy::readRel(AR, i)); } } else { rsl_assert(sh->getEntrySize() == TypeTraits::size); for (size_t i = 0; i < size; ++i) { rt->table.push_back(ELFRelocTy::readRela(AR, i)); } } if (!AR) { // Unable to read the table. return 0; } return rt.take(); } #endif // ELF_SECTION_REL_TABLE_HXX