1 //===- OutputSection.h ------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLD_MACHO_MERGED_OUTPUT_SECTION_H
10 #define LLD_MACHO_MERGED_OUTPUT_SECTION_H
12 #include "InputSection.h"
13 #include "OutputSection.h"
14 #include "lld/Common/LLVM.h"
15 #include "llvm/ADT/MapVector.h"
20 // Linking multiple files will inevitably mean resolving sections in different
21 // files that are labeled with the same segment and section name. This class
22 // contains all such sections and writes the data from each section sequentially
23 // in the final binary.
24 class MergedOutputSection : public OutputSection {
26 MergedOutputSection(StringRef name) : OutputSection(MergedKind, name) {}
28 const InputSection *firstSection() const { return inputs.front(); }
29 const InputSection *lastSection() const { return inputs.back(); }
31 // These accessors will only be valid after finalizing the section
32 uint64_t getSize() const override { return size; }
33 uint64_t getFileSize() const override { return fileSize; }
35 void mergeInput(InputSection *input);
36 void finalize() override;
38 void writeTo(uint8_t *buf) const override;
40 std::vector<InputSection *> inputs;
42 static bool classof(const OutputSection *sec) {
43 return sec->kind() == MergedKind;
47 void mergeFlags(uint32_t inputFlags);
50 uint64_t fileSize = 0;