Here’s my code:
// Deal with MFs and MBBs in a ELF code section (.text) only
for (MCSection &Sec : Layout.getAssembler()) {
MCSectionELF &ELFSec = static_cast<MCSectionELF &>(Sec);
std::string tmpSN, sectionName = ELFSec.getSectionName();
if (sectionName.find(".text") == 0) {
unsigned totalOffset = 0, totalFixups = 0, totalAlignSize = 0;
int MFID, MBBID, prevMFID = -1;
std::string prevID, canFallThrough;
unsigned MBBSize, MBBOffset, numFixups, alignSize, MBBType;
std::set<std::string> countedMBBs;
// Per each fragment in a .text section
for (MCFragment &MCF : Sec) {
// Here MCDataFragment has combined with the following MCRelaxableFragment or MCAlignFragment
// Corner case: MCDataFragment with no instruction - just skip it
if (isa<MCDataFragment>(MCF) && MCF.hasInstructions()) {
// Update the MBB offset and MF Size for all collected MBBs in the MF
for (std::string ID : MCF.getAllMBBs()) {
if (ID.length() == 0 && std::get<0>(MAI->MachineBasicBlocks[ID]) > 0)
llvm_unreachable("[CCR-Error] MCAssembler(updateReorderInfoValues) - MCSomething went wrong in MCRelaxableFragment: MBB size > 0 with no parentID?");
if (countedMBBs.find(ID) == countedMBBs.end() && ID.length() > 0) {
bool isStartMF = false; // check if the new MF begins
std::tie(MFID, MBBID) = separateID(ID);
std::tie(MBBSize, MBBOffset, numFixups, alignSize, MBBType, tmpSN) = MAI->MachineBasicBlocks[ID];
if (tmpSN.length() > 0) continue;
MAI->MBBLayoutOrder.push_back(ID);
// Handle a corner case: see handleDirectEmitDirectives() in AsmParser.cpp
if (MAI->specialCntPriorToFunc > 0) {
MAI->updateByteCounter(ID, MAI->specialCntPriorToFunc, /*numFixups=*/ 0, /*isAlign=*/ false, /*isInline=*/ false);
MBBSize += MAI->specialCntPriorToFunc;
MAI->specialCntPriorToFunc = 0;
}
Here’s the error I’m getting
/home/pegasus/Documents/LLVM_Rust/CCR-master/llvm/lib/MC/MCAssembler.cpp:880:28: error: invalid ‘static_cast’ from type ‘llvm::MCSection’ to type ‘llvm::MCSectionELF&’
880 | MCSectionELF &ELFSec = static_cast<MCSectionELF &>(Sec);
I don’t know how to fix this.