Skip to content

Commit ff2d0ee

Browse files
Skip 32 bit relocation addend partitioning in MCCAS.
Relocations addednds do not deduplicate, to improve deduplication in MCCAS, we store those addends in an AddendsRef block. This is much more complicated to do in 32 bit architectures because of various corner cases and complexities with the MachO 32-bit relocation format Therefore we skip relocation partitioning for 32-bit architectures in MCCAS.
1 parent 51859f9 commit ff2d0ee

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
@@ -2445,6 +2445,15 @@ Error MCCASBuilder::buildFragments() {
24452445
continue;
24462446

24472447
SmallVector<char, 0> FinalFragmentContents;
2448+
// Set the RelocationBuffer to be an empty ArrayRef, and the
2449+
// RelocationBufferIndex to zero if the architecture is 32-bit, because we
2450+
// do not support relocation partitioning on 32-bit platforms. With this,
2451+
// partitionFragment will put all the fragment contents in the
2452+
// FinalFragmentContents, and the Addends buffer will be empty.
2453+
if (ObjectWriter.getAddressSize() == 4) {
2454+
RelocationBuffer = ArrayRef<MachO::any_relocation_info>();
2455+
RelocationBufferIndex = 0;
2456+
}
24482457
partitionFragment(Layout, Addends, FinalFragmentContents,
24492458
RelocationBuffer, F, RelocationBufferIndex,
24502459
ObjectWriter.Target.isLittleEndian());
@@ -2846,25 +2855,32 @@ MCCASReader::reconstructSection(SmallVectorImpl<char> &SectionBuffer,
28462855
/// copied the addend out of the Addends at a particular offset, we should
28472856
/// skip all relocations that matches the same offset.
28482857
int64_t PrevOffset = -1;
2849-
for (auto Reloc : Relocations.back()) {
2850-
auto RelocationOffsetInSection = getRelocationOffset(Reloc);
2851-
if (PrevOffset == RelocationOffsetInSection)
2852-
continue;
2853-
auto RelocationSize =
2854-
getRelocationSize(Reloc, getEndian() == endianness::little);
2855-
/// NumOfBytesToReloc: This denotes the number of bytes needed to be copied
2856-
/// into the \p SectionBuffer before we copy the next addend.
2857-
auto NumOfBytesToReloc = RelocationOffsetInSection - SectionBuffer.size();
2858-
// Copy the contents of the fragment till the next relocation.
2859-
SectionBuffer.append(FragmentBuffer.begin() + FragmentIndex,
2860-
FragmentBuffer.begin() + FragmentIndex +
2861-
NumOfBytesToReloc);
2862-
FragmentIndex += NumOfBytesToReloc;
2863-
// Copy the relocation addend.
2864-
SectionBuffer.append(Addends.begin() + AddendBufferIndex,
2865-
Addends.begin() + AddendBufferIndex + RelocationSize);
2866-
AddendBufferIndex += RelocationSize;
2867-
PrevOffset = RelocationOffsetInSection;
2858+
/// If the \p Addends buffer is empty, there was no AddendsRef for this
2859+
/// section, this is either because no \p Relocations exist in this section,
2860+
/// or this is 32-bit architecture, where we do not support relocation
2861+
/// partitioning.
2862+
if (!Addends.empty()) {
2863+
for (auto Reloc : Relocations.back()) {
2864+
auto RelocationOffsetInSection = getRelocationOffset(Reloc);
2865+
if (PrevOffset == RelocationOffsetInSection)
2866+
continue;
2867+
auto RelocationSize =
2868+
getRelocationSize(Reloc, getEndian() == endianness::little);
2869+
/// NumOfBytesToReloc: This denotes the number of bytes needed to be
2870+
/// copied into the \p SectionBuffer before we copy the next addend.
2871+
auto NumOfBytesToReloc = RelocationOffsetInSection - SectionBuffer.size();
2872+
// Copy the contents of the fragment till the next relocation.
2873+
SectionBuffer.append(FragmentBuffer.begin() + FragmentIndex,
2874+
FragmentBuffer.begin() + FragmentIndex +
2875+
NumOfBytesToReloc);
2876+
FragmentIndex += NumOfBytesToReloc;
2877+
// Copy the relocation addend.
2878+
SectionBuffer.append(Addends.begin() + AddendBufferIndex,
2879+
Addends.begin() + AddendBufferIndex +
2880+
RelocationSize);
2881+
AddendBufferIndex += RelocationSize;
2882+
PrevOffset = RelocationOffsetInSection;
2883+
}
28682884
}
28692885
// Copy any remaining bytes of the fragment into the SectionBuffer.
28702886
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)