mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 22:00:10 +00:00
f2efb5742c
In lit tests, we run each LLD invocation twice (LLD_IN_TEST=2), without shutting down the process in-between. This ensures a full cleanup is properly done between runs. Only active for the COFF driver for now. Other drivers still use LLD_IN_TEST=1 which executes just one iteration with full cleanup, like before. When the environment variable LLD_IN_TEST is unset, a shortcut is taken, only one iteration is executed, no cleanup for faster exit, like before. A public API, lld::safeLldMain(), is also available when using LLD as a library. Differential Revision: https://reviews.llvm.org/D70378
89 lines
2.6 KiB
C++
89 lines
2.6 KiB
C++
//===- Writer.h -------------------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLD_COFF_WRITER_H
|
|
#define LLD_COFF_WRITER_H
|
|
|
|
#include "Chunks.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Object/COFF.h"
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
namespace lld {
|
|
namespace coff {
|
|
static const int pageSize = 4096;
|
|
|
|
void writeResult();
|
|
|
|
class PartialSection {
|
|
public:
|
|
PartialSection(StringRef n, uint32_t chars)
|
|
: name(n), characteristics(chars) {}
|
|
StringRef name;
|
|
unsigned characteristics;
|
|
std::vector<Chunk *> chunks;
|
|
};
|
|
|
|
// OutputSection represents a section in an output file. It's a
|
|
// container of chunks. OutputSection and Chunk are 1:N relationship.
|
|
// Chunks cannot belong to more than one OutputSections. The writer
|
|
// creates multiple OutputSections and assign them unique,
|
|
// non-overlapping file offsets and RVAs.
|
|
class OutputSection {
|
|
public:
|
|
OutputSection(llvm::StringRef n, uint32_t chars) : name(n) {
|
|
header.Characteristics = chars;
|
|
}
|
|
void addChunk(Chunk *c);
|
|
void insertChunkAtStart(Chunk *c);
|
|
void merge(OutputSection *other);
|
|
void setPermissions(uint32_t c);
|
|
uint64_t getRVA() { return header.VirtualAddress; }
|
|
uint64_t getFileOff() { return header.PointerToRawData; }
|
|
void writeHeaderTo(uint8_t *buf);
|
|
void addContributingPartialSection(PartialSection *sec);
|
|
|
|
// Clear the output sections static container.
|
|
static void clear();
|
|
|
|
// Returns the size of this section in an executable memory image.
|
|
// This may be smaller than the raw size (the raw size is multiple
|
|
// of disk sector size, so there may be padding at end), or may be
|
|
// larger (if that's the case, the loader reserves spaces after end
|
|
// of raw data).
|
|
uint64_t getVirtualSize() { return header.VirtualSize; }
|
|
|
|
// Returns the size of the section in the output file.
|
|
uint64_t getRawSize() { return header.SizeOfRawData; }
|
|
|
|
// Set offset into the string table storing this section name.
|
|
// Used only when the name is longer than 8 bytes.
|
|
void setStringTableOff(uint32_t v) { stringTableOff = v; }
|
|
|
|
// N.B. The section index is one based.
|
|
uint32_t sectionIndex = 0;
|
|
|
|
llvm::StringRef name;
|
|
llvm::object::coff_section header = {};
|
|
|
|
std::vector<Chunk *> chunks;
|
|
std::vector<Chunk *> origChunks;
|
|
|
|
std::vector<PartialSection *> contribSections;
|
|
|
|
private:
|
|
uint32_t stringTableOff = 0;
|
|
};
|
|
|
|
} // namespace coff
|
|
} // namespace lld
|
|
|
|
#endif
|