ELFSectionProgBits.hxx revision fa06e91015017e8d0627d26a88e2a575643bec11
1/* 2 * Copyright 2011, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef ELF_SECTION_PROGBITS_HXX 18#define ELF_SECTION_PROGBITS_HXX 19 20#include "ELFTypes.h" 21#include "StubLayout.h" 22 23#include <llvm/Support/Format.h> 24#include <llvm/Support/raw_ostream.h> 25 26#include "utils/raw_ostream.h" 27 28#include <string.h> 29 30template <unsigned Bitwidth> 31template <typename Archiver> 32ELFSectionProgBits<Bitwidth> * 33ELFSectionProgBits<Bitwidth>::read(Archiver &AR, 34 ELFObjectTy *owner, 35 ELFSectionHeaderTy const *sh) { 36 37 llvm::OwningPtr<ELFSectionProgBits> result(new ELFSectionProgBits()); 38 39 // TODO: Not every section needs a stub. 40#ifdef __arm__ 41 // Count the extern function symbol 42 ELFSectionSymTabTy const *symtab = 43 static_cast<ELFSectionSymTabTy *>(owner->getSectionByName(".symtab")); 44 45 // TODO: May not call this function every progbits section. 46 size_t func_count = symtab->getExternFuncCount(); 47 48 StubLayout *stubs = result->getStubLayout(); 49 50 // TODO: May be too many stubs. 51 // Calculate additional stub size 52 size_t stub_size = stubs->calcStubTableSize(func_count); 53 54 // Allocate progbits section + stub 55 if (!result->chunk.allocate(sh->getSize() + stub_size)) { 56 return NULL; 57 } 58 59 stubs->initStubTable(result->chunk.getBuffer()+sh->getSize(), func_count); 60#else 61 // Allocate text section 62 if (!result->chunk.allocate(sh->getSize())) { 63 return NULL; 64 } 65#endif 66 67 result->sh = sh; 68 69 if (!result->serialize(AR)) { 70 // Unable to read the progbits section. 71 return NULL; 72 } 73 74 return result.take(); 75} 76 77#endif // ELF_SECTION_PROGBITS_HXX 78