1 //===- OutputSection.h ------------------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLD_MACHO_MERGED_OUTPUT_SECTION_H 10 #define LLD_MACHO_MERGED_OUTPUT_SECTION_H 11 12 #include "InputSection.h" 13 #include "OutputSection.h" 14 #include "lld/Common/LLVM.h" 15 #include "llvm/ADT/MapVector.h" 16 17 namespace lld { 18 namespace macho { 19 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 { 25 public: MergedOutputSection(StringRef name)26 MergedOutputSection(StringRef name) : OutputSection(MergedKind, name) {} 27 firstSection()28 const InputSection *firstSection() const { return inputs.front(); } lastSection()29 const InputSection *lastSection() const { return inputs.back(); } 30 31 // These accessors will only be valid after finalizing the section getSize()32 uint64_t getSize() const override { return size; } getFileSize()33 uint64_t getFileSize() const override { return fileSize; } 34 35 void mergeInput(InputSection *input); 36 void finalize() override; 37 38 void writeTo(uint8_t *buf) const override; 39 40 std::vector<InputSection *> inputs; 41 classof(const OutputSection * sec)42 static bool classof(const OutputSection *sec) { 43 return sec->kind() == MergedKind; 44 } 45 46 private: 47 void mergeFlags(uint32_t inputFlags); 48 49 size_t size = 0; 50 uint64_t fileSize = 0; 51 }; 52 53 } // namespace macho 54 } // namespace lld 55 56 #endif 57