@@ -2433,6 +2433,15 @@ Error MCCASBuilder::buildFragments() {
2433
2433
continue ;
2434
2434
2435
2435
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
+ }
2436
2445
partitionFragment (Layout, Addends, FinalFragmentContents,
2437
2446
RelocationBuffer, F, RelocationBufferIndex,
2438
2447
ObjectWriter.Target .isLittleEndian ());
@@ -2834,25 +2843,32 @@ MCCASReader::reconstructSection(SmallVectorImpl<char> &SectionBuffer,
2834
2843
// / copied the addend out of the Addends at a particular offset, we should
2835
2844
// / skip all relocations that matches the same offset.
2836
2845
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
+ }
2856
2872
}
2857
2873
// Copy any remaining bytes of the fragment into the SectionBuffer.
2858
2874
SectionBuffer.append (FragmentBuffer.begin () + FragmentIndex,
0 commit comments