Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 1 | //===- OutputSegment.h ------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 | [diff] [blame] | 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 |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLD_WASM_OUTPUT_SEGMENT_H |
| 10 | #define LLD_WASM_OUTPUT_SEGMENT_H |
| 11 | |
Sam Clegg | 5fa274b | 2018-01-10 01:13:34 | [diff] [blame] | 12 | #include "InputChunks.h" |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 13 | #include "lld/Common/ErrorHandler.h" |
| 14 | #include "llvm/Object/Wasm.h" |
| 15 | |
Sam Clegg | d32f71a | 2023-03-06 17:55:00 | [diff] [blame] | 16 | namespace lld::wasm { |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 17 | |
| 18 | class InputSegment; |
| 19 | |
| 20 | class OutputSegment { |
| 21 | public: |
Thomas Lively | 21143b9 | 2019-09-19 01:14:59 | [diff] [blame] | 22 | OutputSegment(StringRef n) : name(n) {} |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 23 | |
Sam Clegg | 5a9b25e | 2021-05-14 23:25:04 | [diff] [blame] | 24 | void addInputSegment(InputChunk *inSeg); |
Sam Clegg | 3b8d2be | 2021-02-27 00:09:32 | [diff] [blame] | 25 | void finalizeInputSegments(); |
Sam Clegg | 1eb79e7 | 2021-10-27 01:08:07 | [diff] [blame] | 26 | // In most circumstances BSS segments don't need to be written |
| 27 | // to the output binary. However if the memory is imported, and |
| 28 | // we can't use memory.fill during startup (due to lack of bulk |
| 29 | // memory feature) then we include BSS segments verbatim. |
Sam Clegg | 184c22d | 2024-01-18 23:01:21 | [diff] [blame] | 30 | bool requiredInBinary() const { return !isBss || ctx.emitBssSegments; } |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 31 | |
Sam Clegg | bda8b84 | 2021-05-07 03:29:05 | [diff] [blame] | 32 | bool isTLS() const { return name == ".tdata"; } |
| 33 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 34 | StringRef name; |
Thomas Lively | 190dacc | 2019-10-15 19:05:11 | [diff] [blame] | 35 | bool isBss = false; |
Thomas Lively | 21143b9 | 2019-09-19 01:14:59 | [diff] [blame] | 36 | uint32_t index = 0; |
Sam Clegg | 3b8d2be | 2021-02-27 00:09:32 | [diff] [blame] | 37 | uint32_t linkingFlags = 0; |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 38 | uint32_t initFlags = 0; |
| 39 | uint32_t sectionOffset = 0; |
Guillaume Chatelet | 1565317 | 2022-12-20 10:56:08 | [diff] [blame] | 40 | uint32_t alignment = 0; |
Wouter van Oortmerssen | 582fd47 | 2020-08-07 20:24:43 | [diff] [blame] | 41 | uint64_t startVA = 0; |
Sam Clegg | 5a9b25e | 2021-05-14 23:25:04 | [diff] [blame] | 42 | std::vector<InputChunk *> inputSegments; |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 43 | |
| 44 | // Sum of the size of the all the input segments |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 45 | uint32_t size = 0; |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 46 | |
| 47 | // Segment header |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 48 | std::string header; |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 49 | }; |
| 50 | |
Sam Clegg | d32f71a | 2023-03-06 17:55:00 | [diff] [blame] | 51 | } // namespace lld::wasm |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 52 | |
| 53 | #endif // LLD_WASM_OUTPUT_SEGMENT_H |