| 1080 | // ====================== |
| 1081 | |
| 1082 | Error CodeHolder::flatten() noexcept { |
| 1083 | uint64_t offset = 0; |
| 1084 | for (Section* section : _sections_by_order) { |
| 1085 | uint64_t real_size = section->real_size(); |
| 1086 | if (real_size) { |
| 1087 | uint64_t aligned_offset = Support::align_up(offset, section->alignment()); |
| 1088 | if (ASMJIT_UNLIKELY(aligned_offset < offset)) { |
| 1089 | return make_error(Error::kTooLarge); |
| 1090 | } |
| 1091 | |
| 1092 | Support::FastUInt8 of = 0; |
| 1093 | offset = Support::add_overflow(aligned_offset, real_size, &of); |
| 1094 | |
| 1095 | if (ASMJIT_UNLIKELY(of)) { |
| 1096 | return make_error(Error::kTooLarge); |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | // Now we know that we can assign offsets of all sections properly. |
| 1102 | Section* prev = nullptr; |
| 1103 | offset = 0; |
| 1104 | for (Section* section : _sections_by_order) { |
| 1105 | uint64_t real_size = section->real_size(); |
| 1106 | if (real_size) { |
| 1107 | offset = Support::align_up(offset, section->alignment()); |
| 1108 | } |
| 1109 | section->_offset = offset; |
| 1110 | |
| 1111 | // Make sure the previous section extends a bit to cover the alignment. |
| 1112 | if (prev) { |
| 1113 | prev->_virtual_size = offset - prev->_offset; |
| 1114 | } |
| 1115 | |
| 1116 | prev = section; |
| 1117 | offset += real_size; |
| 1118 | } |
| 1119 | |
| 1120 | return Error::kOk; |
| 1121 | } |
| 1122 | |
| 1123 | size_t CodeHolder::code_size() const noexcept { |
| 1124 | Support::FastUInt8 of = 0; |