/// printInstruction - This method is automatically generated by tablegen/// from the instruction set description.void MYRISCVXInstPrinter::printInstruction(const MCInst *MI, raw_ostream &O) {
staticconstchar AsmStrs[] = {
...
}
/// Select the MYRISCVX Architecture Feature for the given triple and cpu name./// The function will be called at command 'llvm-objdump -d' for MYRISCVX elf input.static StringRef selectMYRISCVXArchFeature(const Triple &TT, StringRef CPU) {
if (TT.getArch() == Triple::ArchType::myriscvx64) {
return"+64bit";
} elseif (TT.getArch() == Triple::ArchType::myriscvx32) {
return"-64bit";
}
return"";
}
static MCSubtargetInfo *createMYRISCVXMCSubtargetInfo(const Triple &TT,
StringRef CPU, StringRef FS) {
std::string ArchFS = selectMYRISCVXArchFeature(TT, CPU);
if (!FS.empty()) {
if (!ArchFS.empty())
ArchFS = ArchFS + "," + FS.str();
else
ArchFS = FS;
}
// createMYRISCVXMCSubtargetInfoImpl defined in MYRISCVXGenSubtargetInfo.increturn createMYRISCVXMCSubtargetInfoImpl(TT, CPU, ArchFS);
}
/// InitializeAllTargets - The main program should call this function if it/// wants access to all available target machines that LLVM is configured to/// support, to make them available via the TargetRegistry.////// It is legal for a client to make multiple calls to this function.inlinevoid InitializeAllTargets() {
// FIXME: Remove this, clients should do it.
InitializeAllTargetInfos();
#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();#include "llvm/Config/Targets.def"
}
まずは、InitializeAllTargetInfos()が呼ばれる。
namespace llvm {
/// InitializeAllTargetInfos - The main program should call this function if/// it wants access to all available targets that LLVM is configured to/// support, to make them available via the TargetRegistry.////// It is legal for a client to make multiple calls to this function.inlinevoid InitializeAllTargetInfos() {
#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();#include "llvm/Config/Targets.def"
}
./bin/llc -march=mips -mcpu=help
...
Available features for this target:
mips1 - Mips I ISA Support [highly experimental].
mips16 - Mips16 mode.
mips2 - Mips II ISA Support [highly experimental].
mips3 - MIPS III ISA Support [highly experimental].
mips32 - Mips32 ISA Support.
...
noabicalls - Disable SVR4-style position-independent code.
...
void target() {
printf("You overflowed successfully, gg");
exit(0);
}
void vulnerable(char* str1) {
char buf[5];
strcpy(buf, str1);
}
int main() {
vulnerable("ffffffffffffffff\xf0\x03\x02\x01");
printf("This only prints in normal control flow");
}
xSIGというのは、「クロス・シグ」と読むらしく、「The 3rd cross-disciplinary Workshop on Computing Systems, Infrastructures, and Programming」つまり「コンピューティングシステム・インフラ・プログラミングの分野間交流ワークショップ」ということでしょうか。
// Defines symbolic names for MYRISCVX registers. This defines a mapping from// register name to register number.#define GET_REGINFO_ENUM#include "MYRISCVXGenRegisterInfo.inc"// Defines symbolic names for the MYRISCVX instructions.#define GET_INSTRINFO_ENUM#include "MYRISCVXGenInstrInfo.inc"#define GET_SUBTARGETINFO_ENUM#include "MYRISCVXGenSubtargetInfo.inc"
class MYRISCVXABIInfo {
public:
enumclass ABI { Unknown, LP32 };
protected:
ABI ThisABI;
public:
MYRISCVXABIInfo(ABI ThisABI) : ThisABI(ThisABI) {}
static MYRISCVXABIInfo Unknown() { return MYRISCVXABIInfo(ABI::Unknown); }
static MYRISCVXABIInfo LP32() { return MYRISCVXABIInfo(ABI::LP32); }
static MYRISCVXABIInfo computeTargetABI();
bool IsKnown() const { return ThisABI != ABI::Unknown; }
bool IsLP32 () const { return ThisABI == ABI::LP32; }
ABI GetEnumValue() const { return ThisABI; }
/// The registers to use for byval arguments.
ArrayRef<MCPhysReg> GetByValArgRegs() const;
/// The registers to use for the variable argument list.
ArrayRef<MCPhysReg> GetVarArgRegs() const;
/// Obtain the size of the area allocated by the callee for arguments./// CallingConv::FastCall affects the value for O32.unsigned GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const;
/// Ordering of ABI's/// MYRISCVXGenSubtargetInfo.inc will use this to resolve conflicts when given/// multiple ABI options.booloperator<(const MYRISCVXABIInfo Other) const {
return ThisABI < Other.GetEnumValue();
}
unsigned GetStackPtr() const;
unsigned GetFramePtr() const;
unsigned GetNullPtr() const;
unsigned GetEhDataReg(unsigned I) const;
int EhDataRegSize() const;
};