Relocator.cpp revision f7ac0f19a1c8d0ad14bcf6456ce368b830fea886
1//===- Relocator.cpp ------------------------------------------------------===//
2//
3//                     The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#include <mcld/Fragment/Fragment.h>
10#include <mcld/LD/LDSymbol.h>
11#include <mcld/LD/Relocator.h>
12#include <mcld/LD/ResolveInfo.h>
13#include <mcld/LD/SectionData.h>
14#include <mcld/Module.h>
15
16using namespace mcld;
17
18//===----------------------------------------------------------------------===//
19// Relocator
20//===----------------------------------------------------------------------===//
21Relocator::~Relocator()
22{
23}
24
25void Relocator::partialScanRelocation(Relocation& pReloc,
26                                      Module& pModule,
27                                      const LDSection& pSection)
28{
29  // if we meet a section symbol
30  if (pReloc.symInfo()->type() == ResolveInfo::Section) {
31    LDSymbol* input_sym = pReloc.symInfo()->outSymbol();
32
33    // 1. update the relocation target offset
34    assert(input_sym->hasFragRef());
35    uint64_t offset = input_sym->fragRef()->getOutputOffset();
36    pReloc.target() += offset;
37
38    // 2. get output section symbol
39    // get the output LDSection which the symbol defined in
40    const LDSection& out_sect =
41                        input_sym->fragRef()->frag()->getParent()->getSection();
42    ResolveInfo* sym_info =
43                     pModule.getSectionSymbolSet().get(out_sect)->resolveInfo();
44    // set relocation target symbol to the output section symbol's resolveInfo
45    pReloc.setSymInfo(sym_info);
46  }
47}
48
49