Skip to content

Commit 7612921

Browse files
Make sure we don't write non-partitioned data into align fragment
1 parent eb19d4a commit 7612921

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,8 +1947,13 @@ Error MCDataFragmentMerger::tryMerge(const MCFragment &F, unsigned Size,
19471947
}
19481948

19491949
static Error writeAlignFragment(MCCASBuilder &Builder, const MCFragment &AF,
1950-
raw_ostream &OS, unsigned FragmentSize) {
1951-
OS << StringRef(AF.getContents().data(), AF.getContents().size());
1950+
raw_ostream &OS, unsigned FragmentSize,
1951+
bool WriteFragmentContents = true) {
1952+
// Do not always write the contents of the FT_Align fragment into the OS, this
1953+
// is because that data can contain addend values as well and is undesirable
1954+
// when creating AlignFragment CAS Objects.
1955+
if (WriteFragmentContents)
1956+
OS << StringRef(AF.getContents().data(), AF.getContents().size());
19521957
uint64_t Count = (FragmentSize - AF.getFixedSize()) / AF.getAlignFillLen();
19531958
if (AF.hasAlignEmitNops()) {
19541959
if (!Builder.Asm.getBackend().writeNopData(OS, Count,
@@ -2006,8 +2011,14 @@ Error MCDataFragmentMerger::emitMergedFragments() {
20062011
#define MCFRAGMENT_ENCODED_FRAGMENT_ONLY
20072012
#include "llvm/MCCAS/MCCASObjectV1.def"
20082013
case MCFragment::FT_Align: {
2014+
// Since an FT_Align can contain Addend Values, only write the
2015+
// post-fragment partitioned contents into the FragmentData and make sure
2016+
// that the writeAlignFragment function doesn't write any of the fragment
2017+
// data into FragmentData.
2018+
FragmentData.append(CandidateContents);
20092019
if (auto E = writeAlignFragment(Builder, *Candidate.first, FragmentOS,
2010-
Candidate.second))
2020+
Candidate.second,
2021+
false /*WriteFragmentContents*/))
20112022
return E;
20122023
break;
20132024
}

0 commit comments

Comments
 (0)