Skip to content

Commit c079606

Browse files
Merge pull request #8444 from rastogishubham/MCCAS32BitRelocStable
Skip 32 bit relocation addend partitioning in MCCAS.
2 parents ee64cff + a32b5fb commit c079606

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,15 @@ Error MCCASBuilder::buildFragments() {
24332433
continue;
24342434

24352435
SmallVector<char, 0> FinalFragmentContents;
2436+
// Set the RelocationBuffer to be an empty ArrayRef, and the
2437+
// RelocationBufferIndex to zero if the architecture is 32-bit, because we
2438+
// do not support relocation partitioning on 32-bit platforms. With this,
2439+
// partitionFragment will put all the fragment contents in the
2440+
// FinalFragmentContents, and the Addends buffer will be empty.
2441+
if (ObjectWriter.getAddressSize() == 4) {
2442+
RelocationBuffer = ArrayRef<MachO::any_relocation_info>();
2443+
RelocationBufferIndex = 0;
2444+
}
24362445
partitionFragment(Layout, Addends, FinalFragmentContents,
24372446
RelocationBuffer, F, RelocationBufferIndex,
24382447
ObjectWriter.Target.isLittleEndian());
@@ -2834,25 +2843,32 @@ MCCASReader::reconstructSection(SmallVectorImpl<char> &SectionBuffer,
28342843
/// copied the addend out of the Addends at a particular offset, we should
28352844
/// skip all relocations that matches the same offset.
28362845
int64_t PrevOffset = -1;
2837-
for (auto Reloc : Relocations.back()) {
2838-
auto RelocationOffsetInSection = getRelocationOffset(Reloc);
2839-
if (PrevOffset == RelocationOffsetInSection)
2840-
continue;
2841-
auto RelocationSize =
2842-
getRelocationSize(Reloc, getEndian() == support::little);
2843-
/// NumOfBytesToReloc: This denotes the number of bytes needed to be copied
2844-
/// into the \p SectionBuffer before we copy the next addend.
2845-
auto NumOfBytesToReloc = RelocationOffsetInSection - SectionBuffer.size();
2846-
// Copy the contents of the fragment till the next relocation.
2847-
SectionBuffer.append(FragmentBuffer.begin() + FragmentIndex,
2848-
FragmentBuffer.begin() + FragmentIndex +
2849-
NumOfBytesToReloc);
2850-
FragmentIndex += NumOfBytesToReloc;
2851-
// Copy the relocation addend.
2852-
SectionBuffer.append(Addends.begin() + AddendBufferIndex,
2853-
Addends.begin() + AddendBufferIndex + RelocationSize);
2854-
AddendBufferIndex += RelocationSize;
2855-
PrevOffset = RelocationOffsetInSection;
2846+
/// If the \p Addends buffer is empty, there was no AddendsRef for this
2847+
/// section, this is either because no \p Relocations exist in this section,
2848+
/// or this is 32-bit architecture, where we do not support relocation
2849+
/// partitioning.
2850+
if (!Addends.empty()) {
2851+
for (auto Reloc : Relocations.back()) {
2852+
auto RelocationOffsetInSection = getRelocationOffset(Reloc);
2853+
if (PrevOffset == RelocationOffsetInSection)
2854+
continue;
2855+
auto RelocationSize =
2856+
getRelocationSize(Reloc, getEndian() == support::little);
2857+
/// NumOfBytesToReloc: This denotes the number of bytes needed to be
2858+
/// copied into the \p SectionBuffer before we copy the next addend.
2859+
auto NumOfBytesToReloc = RelocationOffsetInSection - SectionBuffer.size();
2860+
// Copy the contents of the fragment till the next relocation.
2861+
SectionBuffer.append(FragmentBuffer.begin() + FragmentIndex,
2862+
FragmentBuffer.begin() + FragmentIndex +
2863+
NumOfBytesToReloc);
2864+
FragmentIndex += NumOfBytesToReloc;
2865+
// Copy the relocation addend.
2866+
SectionBuffer.append(Addends.begin() + AddendBufferIndex,
2867+
Addends.begin() + AddendBufferIndex +
2868+
RelocationSize);
2869+
AddendBufferIndex += RelocationSize;
2870+
PrevOffset = RelocationOffsetInSection;
2871+
}
28562872
}
28572873
// Copy any remaining bytes of the fragment into the SectionBuffer.
28582874
SectionBuffer.append(FragmentBuffer.begin() + FragmentIndex,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This test tests to make sure mccas can handle scattered relocations properly on 32 bit arm
2+
3+
# RUN: rm -rf %t && mkdir -p %t
4+
# RUN: llvm-mc --cas=%t/cas --cas-backend --mccas-verify -triple=armv7-apple-darwin10 -filetype=obj -o %t/reloc.o %s
5+
6+
movw r0, :lower16:(fn2-L1)
7+
L1:
8+
fn2:
9+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This test tests to make sure mccas can handle scattered relocations properly on 32 bit x86
2+
3+
# RUN: rm -rf %t && mkdir -p %t
4+
# RUN: llvm-mc --cas=%t/cas --cas-backend --mccas-verify -triple=i386-apple-macosx10.4 -filetype=obj -o %t/reloc.o %s
5+
movl y+4, %ecx
6+
.zerofill __DATA,__common,y,8,3

0 commit comments

Comments
 (0)