@@ -2445,6 +2445,15 @@ Error MCCASBuilder::buildFragments() {
2445
2445
continue ;
2446
2446
2447
2447
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
+ }
2448
2457
partitionFragment (Layout, Addends, FinalFragmentContents,
2449
2458
RelocationBuffer, F, RelocationBufferIndex,
2450
2459
ObjectWriter.Target .isLittleEndian ());
@@ -2846,25 +2855,32 @@ MCCASReader::reconstructSection(SmallVectorImpl<char> &SectionBuffer,
2846
2855
// / copied the addend out of the Addends at a particular offset, we should
2847
2856
// / skip all relocations that matches the same offset.
2848
2857
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
+ }
2868
2884
}
2869
2885
// Copy any remaining bytes of the fragment into the SectionBuffer.
2870
2886
SectionBuffer.append (FragmentBuffer.begin () + FragmentIndex,
0 commit comments