003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
CodeGen
/
AsmPrinter
/
📁
..
📄
ARMException.cpp
(4.45 KB)
📄
AccelTable.cpp
(24.07 KB)
📄
AddressPool.cpp
(2.61 KB)
📄
AddressPool.h
(1.93 KB)
📄
AsmPrinter.cpp
(123.3 KB)
📄
AsmPrinterDwarf.cpp
(9.88 KB)
📄
AsmPrinterInlineAsm.cpp
(25.75 KB)
📄
ByteStreamer.h
(3.93 KB)
📄
CodeViewDebug.cpp
(115.03 KB)
📄
CodeViewDebug.h
(17.9 KB)
📄
DIE.cpp
(25.69 KB)
📄
DIEHash.cpp
(14.17 KB)
📄
DIEHash.h
(3.37 KB)
📄
DIEHashAttributes.def
(2.02 KB)
📄
DbgEntityHistoryCalculator.cpp
(14.88 KB)
📄
DebugHandlerBase.cpp
(10.8 KB)
📄
DebugLocEntry.h
(6.96 KB)
📄
DebugLocStream.cpp
(1.36 KB)
📄
DebugLocStream.h
(5.78 KB)
📄
DwarfCFIException.cpp
(6.1 KB)
📄
DwarfCompileUnit.cpp
(55.27 KB)
📄
DwarfCompileUnit.h
(13.61 KB)
📄
DwarfDebug.cpp
(128.56 KB)
📄
DwarfDebug.h
(27.39 KB)
📄
DwarfException.h
(3.23 KB)
📄
DwarfExpression.cpp
(21.36 KB)
📄
DwarfExpression.h
(15.03 KB)
📄
DwarfFile.cpp
(4.31 KB)
📄
DwarfFile.h
(5.86 KB)
📄
DwarfStringPool.cpp
(4.72 KB)
📄
DwarfStringPool.h
(2.07 KB)
📄
DwarfUnit.cpp
(64.61 KB)
📄
DwarfUnit.h
(14.34 KB)
📄
EHStreamer.cpp
(25.33 KB)
📄
EHStreamer.h
(5.66 KB)
📄
ErlangGCPrinter.cpp
(4.16 KB)
📄
OcamlGCPrinter.cpp
(6.38 KB)
📄
WasmException.cpp
(4.09 KB)
📄
WasmException.h
(1.32 KB)
📄
WinCFGuard.cpp
(3.62 KB)
📄
WinCFGuard.h
(1.77 KB)
📄
WinException.cpp
(50.88 KB)
📄
WinException.h
(4.1 KB)
Editing: WinCFGuard.cpp
//===-- CodeGen/AsmPrinter/WinCFGuard.cpp - Control Flow Guard Impl ------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file contains support for writing the metadata for Windows Control Flow // Guard, including address-taken functions, and valid longjmp targets. // //===----------------------------------------------------------------------===// #include "WinCFGuard.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineOperand.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Instructions.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCStreamer.h" #include <vector> using namespace llvm; WinCFGuard::WinCFGuard(AsmPrinter *A) : AsmPrinterHandler(), Asm(A) {} WinCFGuard::~WinCFGuard() {} void WinCFGuard::endFunction(const MachineFunction *MF) { // Skip functions without any longjmp targets. if (MF->getLongjmpTargets().empty()) return; // Copy the function's longjmp targets to a module-level list. LongjmpTargets.insert(LongjmpTargets.end(), MF->getLongjmpTargets().begin(), MF->getLongjmpTargets().end()); } /// Returns true if this function's address is escaped in a way that might make /// it an indirect call target. Function::hasAddressTaken gives different /// results when a function is called directly with a function prototype /// mismatch, which requires a cast. static bool isPossibleIndirectCallTarget(const Function *F) { SmallVector<const Value *, 4> Users{F}; while (!Users.empty()) { const Value *FnOrCast = Users.pop_back_val(); for (const Use &U : FnOrCast->uses()) { const User *FnUser = U.getUser(); if (isa<BlockAddress>(FnUser)) continue; if (const auto *Call = dyn_cast<CallBase>(FnUser)) { if (!Call->isCallee(&U)) return true; } else if (isa<Instruction>(FnUser)) { // Consider any other instruction to be an escape. This has some weird // consequences like no-op intrinsics being an escape or a store *to* a // function address being an escape. return true; } else if (const auto *C = dyn_cast<Constant>(FnUser)) { // If this is a constant pointer cast of the function, don't consider // this escape. Analyze the uses of the cast as well. This ensures that // direct calls with mismatched prototypes don't end up in the CFG // table. Consider other constants, such as vtable initializers, to // escape the function. if (C->stripPointerCasts() == F) Users.push_back(FnUser); else return true; } } } return false; } void WinCFGuard::endModule() { const Module *M = Asm->MMI->getModule(); std::vector<const Function *> Functions; for (const Function &F : *M) if (isPossibleIndirectCallTarget(&F)) Functions.push_back(&F); if (Functions.empty() && LongjmpTargets.empty()) return; auto &OS = *Asm->OutStreamer; OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGFIDsSection()); for (const Function *F : Functions) OS.EmitCOFFSymbolIndex(Asm->getSymbol(F)); // Emit the symbol index of each longjmp target. OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGLJMPSection()); for (const MCSymbol *S : LongjmpTargets) { OS.EmitCOFFSymbolIndex(S); } }
Upload File
Create Folder