llvm.org GIT mirror llvm / a92f085
[JITLink] Don't under-align zero-fill sections. If content sections have lower alignment than zero-fill sections then bump the overall segment alignment to avoid under-aligning the zero-fill sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370072 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 1 year, 3 months ago
2 changed file(s) with 27 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
237237
238238 // Calculate segment content size.
239239 size_t SegContentSize = 0;
240 uint32_t SegContentAlign = 1;
240241 for (auto &SI : SegLayout.ContentSections) {
241242 assert(!SI.S->atoms_empty() && "Sections in layout must not be empty");
242243 assert(!SI.Atoms.empty() && "Section layouts must not be empty");
243244
244245 // Bump to section alignment before processing atoms.
245246 SegContentSize = alignTo(SegContentSize, SI.S->getAlignment());
247 SegContentAlign = std::max(SegContentAlign, SI.S->getAlignment());
246248
247249 for (auto *DA : SI.Atoms) {
248250 SegContentSize = alignTo(SegContentSize, DA->getAlignment());
249251 SegContentSize += DA->getSize();
252 SegContentAlign = std::max(SegContentAlign, DA->getAlignment());
250253 }
251 }
252
253 // Get segment content alignment.
254 unsigned SegContentAlign = 1;
255 if (!SegLayout.ContentSections.empty()) {
256 auto &FirstContentSection = SegLayout.ContentSections.front();
257 SegContentAlign =
258 std::max(FirstContentSection.S->getAlignment(),
259 FirstContentSection.Atoms.front()->getAlignment());
260254 }
261255
262256 // Calculate segment zero-fill size.
263257 uint64_t SegZeroFillSize = 0;
258 uint32_t SegZeroFillAlign = 1;
259
264260 for (auto &SI : SegLayout.ZeroFillSections) {
265261 assert(!SI.S->atoms_empty() && "Sections in layout must not be empty");
266262 assert(!SI.Atoms.empty() && "Section layouts must not be empty");
267263
268264 // Bump to section alignment before processing atoms.
269265 SegZeroFillSize = alignTo(SegZeroFillSize, SI.S->getAlignment());
266 SegZeroFillAlign = std::max(SegZeroFillAlign, SI.S->getAlignment());
270267
271268 for (auto *DA : SI.Atoms) {
272269 SegZeroFillSize = alignTo(SegZeroFillSize, DA->getAlignment());
273270 SegZeroFillSize += DA->getSize();
271 SegZeroFillAlign = std::max(SegZeroFillAlign, SI.S->getAlignment());
274272 }
275273 }
276274
277 // Calculate segment zero-fill alignment.
278 uint32_t SegZeroFillAlign = 1;
279
280 if (!SegLayout.ZeroFillSections.empty()) {
281 auto &FirstZeroFillSection = SegLayout.ZeroFillSections.front();
282 SegZeroFillAlign =
283 std::max(FirstZeroFillSection.S->getAlignment(),
284 FirstZeroFillSection.Atoms.front()->getAlignment());
285 }
286
287 if (SegContentSize == 0)
288 SegContentAlign = SegZeroFillAlign;
289
290 if (SegContentAlign % SegZeroFillAlign != 0)
291 return make_error("First content atom alignment does not "
292 "accommodate first zero-fill atom "
293 "alignment");
275 assert(isPowerOf2_32(SegContentAlign) &&
276 "Expected content alignment to be power of 2");
277 assert(isPowerOf2_32(SegZeroFillAlign) &&
278 "Expected zero-fill alignment to be power of 2");
279 // Round content alignment up to segment alignment.
280 SegContentAlign = std::max(SegContentAlign, SegZeroFillAlign);
294281
295282 Segments[Prot] = {SegContentSize, SegContentAlign, SegZeroFillSize,
296283 SegZeroFillAlign};
0 # RUN: rm -rf %t && mkdir -p %t
1 # RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t/macho_zero_fill_align.o %s
2 # RUN: llvm-jitlink -noexec %t/macho_zero_fill_align.o -entry higher_zero_fill_align
3
4 .section __DATA,__data
5 .globl low_aligned_data
6 .p2align 0
7 low_aligned_data:
8 .byte 42
9
10 .globl higher_zero_fill_align
11 .zerofill __DATA,__zero_fill,higher_zero_fill_align,8,3
12
13 .subsections_via_symbols