summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h
blob: 45e0aff1f187b887e43300a48ab57f7cce504df6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//===--------- lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h -------------===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_ELF_ARM_ARM_EXECUTABLE_WRITER_H
#define LLD_READER_WRITER_ELF_ARM_ARM_EXECUTABLE_WRITER_H

#include "ExecutableWriter.h"
#include "ARMELFWriters.h"
#include "ARMLinkingContext.h"
#include "ARMTargetHandler.h"

namespace lld {
namespace elf {

class ARMExecutableWriter : public ARMELFWriter<ExecutableWriter<ELF32LE>> {
public:
  ARMExecutableWriter(ARMLinkingContext &ctx, ARMTargetLayout &layout);

protected:
  // Add any runtime files and their atoms to the output
  void createImplicitFiles(std::vector<std::unique_ptr<File>> &) override;

  void processUndefinedSymbol(StringRef symName,
                              RuntimeFile<ELF32LE> &file) const override;

private:
  ARMLinkingContext &_ctx;
};

ARMExecutableWriter::ARMExecutableWriter(ARMLinkingContext &ctx,
                                         ARMTargetLayout &layout)
    : ARMELFWriter(ctx, layout), _ctx(ctx) {}

void ARMExecutableWriter::createImplicitFiles(
    std::vector<std::unique_ptr<File>> &result) {
  ExecutableWriter::createImplicitFiles(result);
  // Add default atoms for ARM.
  if (_ctx.isDynamic()) {
    auto file = llvm::make_unique<RuntimeFile<ELF32LE>>(_ctx, "ARM exec file");
    file->addAbsoluteAtom(gotSymbol);
    file->addAbsoluteAtom(dynamicSymbol);
    result.push_back(std::move(file));
  }
}

void ARMExecutableWriter::processUndefinedSymbol(
    StringRef symName, RuntimeFile<ELF32LE> &file) const {
  if (symName == gotSymbol) {
    file.addAbsoluteAtom(gotSymbol);
  } else if (symName.startswith("__exidx")) {
    file.addAbsoluteAtom("__exidx_start");
    file.addAbsoluteAtom("__exidx_end");
  } else if (symName == "__ehdr_start") {
    file.addAbsoluteAtom("__ehdr_start");
  }
}

} // namespace elf
} // namespace lld

#endif // LLD_READER_WRITER_ELF_ARM_ARM_EXECUTABLE_WRITER_H
OpenPOWER on IntegriCloud