Path: blob/main/contrib/llvm-project/lld/MachO/OutputSection.h
34878 views
//===- OutputSection.h ------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLD_MACHO_OUTPUT_SECTION_H9#define LLD_MACHO_OUTPUT_SECTION_H1011#include "Symbols.h"12#include "lld/Common/LLVM.h"13#include "llvm/ADT/DenseMap.h"14#include "llvm/ADT/TinyPtrVector.h"1516#include <limits>1718namespace lld::macho {1920class Defined;21class InputSection;22class OutputSegment;2324// The default order value for OutputSections that are not constructed from25// InputSections (i.e. SyntheticSections). We make it less than INT_MAX in order26// not to conflict with the ordering of zerofill sections, which must always be27// placed at the end of their segment.28constexpr int UnspecifiedInputOrder = std::numeric_limits<int>::max() - 1024;2930// Output sections represent the finalized sections present within the final31// linked executable. They can represent special sections (like the symbol32// table), or represent coalesced sections from the various inputs given to the33// linker with the same segment / section name.34class OutputSection {35public:36enum Kind {37ConcatKind,38SyntheticKind,39};4041OutputSection(Kind kind, StringRef name) : name(name), sectionKind(kind) {}42virtual ~OutputSection() = default;43Kind kind() const { return sectionKind; }4445// These accessors will only be valid after finalizing the section.46uint64_t getSegmentOffset() const;4748// How much space the section occupies in the address space.49virtual uint64_t getSize() const = 0;50// How much space the section occupies in the file. Most sections are copied51// as-is so their file size is the same as their address space size.52virtual uint64_t getFileSize() const { return getSize(); }5354// Hidden sections omit header content, but body content may still be present.55virtual bool isHidden() const { return false; }56// Unneeded sections are omitted entirely (header and body).57virtual bool isNeeded() const { return true; }5859// The implementations of this method can assume that it is only called right60// before addresses get assigned to this particular OutputSection. In61// particular, this means that it gets called only after addresses have been62// assigned to output sections that occur earlier in the output binary.63// Naturally, this means different sections' finalize() methods cannot execute64// concurrently with each other. As such, avoid using this method for65// operations that do not require this strict sequential guarantee.66//67// Operations that need to occur late in the linking process, but which do not68// need the sequential guarantee, should be named `finalizeContents()`. See69// e.g. LinkEditSection::finalizeContents() and70// CStringSection::finalizeContents().71virtual void finalize() {}7273virtual void writeTo(uint8_t *buf) const = 0;7475// Handle section$start$ and section$end$ symbols.76void assignAddressesToStartEndSymbols();7778StringRef name;79llvm::TinyPtrVector<Defined *> sectionStartSymbols;80llvm::TinyPtrVector<Defined *> sectionEndSymbols;81OutputSegment *parent = nullptr;82// For output sections that don't have explicit ordering requirements, their83// output order should be based on the order of the input sections they84// contain.85int inputOrder = UnspecifiedInputOrder;8687uint32_t index = 0;88uint64_t addr = 0;89uint64_t fileOff = 0;90uint32_t align = 1;91uint32_t flags = 0;92uint32_t reserved1 = 0;93uint32_t reserved2 = 0;9495private:96Kind sectionKind;97};9899} // namespace lld::macho100101#endif102103104