482 changes: 482 additions & 0 deletions llvm/lib/Target/BPF/BPFAbstrctMemberAccess.cpp

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions llvm/lib/Target/BPF/BPFAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BPFAsmPrinter : public AsmPrinter {
public:
explicit BPFAsmPrinter(TargetMachine &TM,
std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, std::move(Streamer)) {}
: AsmPrinter(TM, std::move(Streamer)), BTF(nullptr) {}

StringRef getPassName() const override { return "BPF Assembly Printer"; }
bool doInitialization(Module &M) override;
Expand All @@ -49,6 +49,9 @@ class BPFAsmPrinter : public AsmPrinter {
const char *ExtraCode, raw_ostream &O) override;

void EmitInstruction(const MachineInstr *MI) override;

private:
BTFDebug *BTF;
};
} // namespace

Expand All @@ -57,8 +60,10 @@ bool BPFAsmPrinter::doInitialization(Module &M) {

// Only emit BTF when debuginfo available.
if (MAI->doesSupportDebugInformation() && !empty(M.debug_compile_units())) {
Handlers.emplace_back(llvm::make_unique<BTFDebug>(this), "emit",
"Debug Info Emission", "BTF", "BTF Emission");
BTF = new BTFDebug(this);
Handlers.push_back(HandlerInfo(std::unique_ptr<BTFDebug>(BTF), "emit",
"Debug Info Emission", "BTF",
"BTF Emission"));
}

return false;
Expand Down Expand Up @@ -133,11 +138,12 @@ bool BPFAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
}

void BPFAsmPrinter::EmitInstruction(const MachineInstr *MI) {

BPFMCInstLower MCInstLowering(OutContext, *this);

MCInst TmpInst;
MCInstLowering.Lower(MI, TmpInst);

if (!BTF || !BTF->InstLower(MI, TmpInst)) {
BPFMCInstLower MCInstLowering(OutContext, *this);
MCInstLowering.Lower(MI, TmpInst);
}
EmitToStreamer(*OutStreamer, TmpInst);
}

Expand Down
24 changes: 24 additions & 0 deletions llvm/lib/Target/BPF/BPFCORE.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===- BPFCORE.h - Common info for Compile-Once Run-EveryWhere -*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_TARGET_BPF_BPFCORE_H
#define LLVM_LIB_TARGET_BPF_BPFCORE_H

namespace llvm {

class BPFCoreSharedInfo {
public:
/// The attribute attached to globals representing a member offset
static const std::string AmaAttr;
/// The section name to identify a patchable external global
static const std::string PatchableExtSecName;
};

} // namespace llvm

#endif
163 changes: 163 additions & 0 deletions llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
//===----- BPFMISimplifyPatchable.cpp - MI Simplify Patchable Insts -------===//
//
// 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 pass targets a subset of instructions like below
// ld_imm64 r1, @global
// ldd r2, r1, 0
// add r3, struct_base_reg, r2
//
// Here @global should either present a AMA (abstruct member access) or
// a patchable extern variable. And these two kinds of accesses
// are subject to bpf load time patching. After this pass, the
// code becomes
// ld_imm64 r1, @global
// add r3, struct_base_reg, r1
//
// Eventually, at BTF output stage, a relocation record will be generated
// for ld_imm64 which should be replaced later by bpf loader:
// r1 = <calculated offset> or <to_be_patched_extern_val>
// add r3, struct_base_reg, r1
// or
// ld_imm64 r1, <to_be_patched_extern_val>
// add r3, struct_base_reg, r1
//
//===----------------------------------------------------------------------===//

#include "BPF.h"
#include "BPFCORE.h"
#include "BPFInstrInfo.h"
#include "BPFTargetMachine.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"

using namespace llvm;

#define DEBUG_TYPE "bpf-mi-simplify-patchable"

namespace {

struct BPFMISimplifyPatchable : public MachineFunctionPass {

static char ID;
const BPFInstrInfo *TII;
MachineFunction *MF;

BPFMISimplifyPatchable() : MachineFunctionPass(ID) {
initializeBPFMISimplifyPatchablePass(*PassRegistry::getPassRegistry());
}

private:
// Initialize class variables.
void initialize(MachineFunction &MFParm);

bool removeLD(void);

public:
// Main entry point for this pass.
bool runOnMachineFunction(MachineFunction &MF) override {
if (!skipFunction(MF.getFunction())) {
initialize(MF);
}
return removeLD();
}
};

// Initialize class variables.
void BPFMISimplifyPatchable::initialize(MachineFunction &MFParm) {
MF = &MFParm;
TII = MF->getSubtarget<BPFSubtarget>().getInstrInfo();
LLVM_DEBUG(dbgs() << "*** BPF simplify patchable insts pass ***\n\n");
}

/// Remove unneeded Load instructions.
bool BPFMISimplifyPatchable::removeLD() {
MachineRegisterInfo *MRI = &MF->getRegInfo();
MachineInstr *ToErase = nullptr;
bool Changed = false;

for (MachineBasicBlock &MBB : *MF) {
for (MachineInstr &MI : MBB) {
if (ToErase) {
ToErase->eraseFromParent();
ToErase = nullptr;
}

// Ensure the register format is LOAD <reg>, <reg>, 0
if (MI.getOpcode() != BPF::LDD && MI.getOpcode() != BPF::LDW &&
MI.getOpcode() != BPF::LDH && MI.getOpcode() != BPF::LDB &&
MI.getOpcode() != BPF::LDW32 && MI.getOpcode() != BPF::LDH32 &&
MI.getOpcode() != BPF::LDB32)
continue;

if (!MI.getOperand(0).isReg() || !MI.getOperand(1).isReg())
continue;

if (!MI.getOperand(2).isImm() || MI.getOperand(2).getImm())
continue;

unsigned DstReg = MI.getOperand(0).getReg();
unsigned SrcReg = MI.getOperand(1).getReg();
int64_t ImmVal = MI.getOperand(2).getImm();

MachineInstr *DefInst = MRI->getUniqueVRegDef(SrcReg);
if (!DefInst)
continue;

bool IsCandidate = false;
if (DefInst->getOpcode() == BPF::LD_imm64) {
const MachineOperand &MO = DefInst->getOperand(1);
if (MO.isGlobal()) {
const GlobalValue *GVal = MO.getGlobal();
auto *GVar = dyn_cast<GlobalVariable>(GVal);
if (GVar) {
// Global variables representing structure offset or
// patchable extern globals.
if (GVar->hasAttribute(BPFCoreSharedInfo::AmaAttr)) {
assert(ImmVal == 0);
IsCandidate = true;
} else if (!GVar->hasInitializer() && GVar->hasExternalLinkage() &&
GVar->getSection() ==
BPFCoreSharedInfo::PatchableExtSecName) {
if (ImmVal == 0)
IsCandidate = true;
else
errs() << "WARNING: unhandled patchable extern "
<< GVar->getName() << " with load offset " << ImmVal
<< "\n";
}
}
}
}

if (!IsCandidate)
continue;

auto Begin = MRI->use_begin(DstReg), End = MRI->use_end();
decltype(End) NextI;
for (auto I = Begin; I != End; I = NextI) {
NextI = std::next(I);
I->setReg(SrcReg);
}

ToErase = &MI;
Changed = true;
}
}

return Changed;
}

} // namespace

INITIALIZE_PASS(BPFMISimplifyPatchable, DEBUG_TYPE,
"BPF PreEmit SimplifyPatchable", false, false)

char BPFMISimplifyPatchable::ID = 0;
FunctionPass *llvm::createBPFMISimplifyPatchablePass() {
return new BPFMISimplifyPatchable();
}
12 changes: 12 additions & 0 deletions llvm/lib/Target/BPF/BPFTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern "C" void LLVMInitializeBPFTarget() {
RegisterTargetMachine<BPFTargetMachine> Z(getTheBPFTarget());

PassRegistry &PR = *PassRegistry::getPassRegistry();
initializeBPFAbstractMemberAccessPass(PR);
initializeBPFMIPeepholePass(PR);
}

Expand Down Expand Up @@ -68,6 +69,7 @@ BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT,
static_cast<BPFMCAsmInfo *>(const_cast<MCAsmInfo *>(AsmInfo.get()));
MAI->setDwarfUsesRelocationsAcrossSections(!Subtarget.getUseDwarfRIS());
}

namespace {
// BPF Code Generator Pass Configuration Options.
class BPFPassConfig : public TargetPassConfig {
Expand All @@ -79,6 +81,7 @@ class BPFPassConfig : public TargetPassConfig {
return getTM<BPFTargetMachine>();
}

void addIRPasses() override;
bool addInstSelector() override;
void addMachineSSAOptimization() override;
void addPreEmitPass() override;
Expand All @@ -89,6 +92,13 @@ TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) {
return new BPFPassConfig(*this, PM);
}

void BPFPassConfig::addIRPasses() {

addPass(createBPFAbstractMemberAccess());

TargetPassConfig::addIRPasses();
}

// Install an instruction selector pass using
// the ISelDag to gen BPF code.
bool BPFPassConfig::addInstSelector() {
Expand All @@ -98,6 +108,8 @@ bool BPFPassConfig::addInstSelector() {
}

void BPFPassConfig::addMachineSSAOptimization() {
addPass(createBPFMISimplifyPatchablePass());

// The default implementation must be called first as we want eBPF
// Peephole ran at last.
TargetPassConfig::addMachineSSAOptimization();
Expand Down
63 changes: 55 additions & 8 deletions llvm/lib/Target/BPF/BTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
///
/// The binary layout for .BTF.ext section:
/// struct ExtHeader
/// FuncInfo and LineInfo subsections
/// FuncInfo, LineInfo, OffsetReloc and ExternReloc subsections
/// The FuncInfo subsection is defined as below:
/// BTFFuncInfo Size
/// struct SecFuncInfo for ELF section #1
Expand All @@ -32,6 +32,20 @@
/// struct SecLineInfo for ELF section #2
/// A number of struct BPFLineInfo for ELF section #2
/// ...
/// The OffsetReloc subsection is defined as below:
/// BPFOffsetReloc Size
/// struct SecOffsetReloc for ELF section #1
/// A number of struct BPFOffsetReloc for ELF section #1
/// struct SecOffsetReloc for ELF section #2
/// A number of struct BPFOffsetReloc for ELF section #2
/// ...
/// The ExternReloc subsection is defined as below:
/// BPFExternReloc Size
/// struct SecExternReloc for ELF section #1
/// A number of struct BPFExternReloc for ELF section #1
/// struct SecExternReloc for ELF section #2
/// A number of struct BPFExternReloc for ELF section #2
/// ...
///
/// The section formats are also defined at
/// https://github.com/torvalds/linux/blob/master/include/uapi/linux/btf.h
Expand All @@ -49,7 +63,7 @@ enum : uint32_t { MAGIC = 0xeB9F, VERSION = 1 };
/// Sizes in bytes of various things in the BTF format.
enum {
HeaderSize = 24,
ExtHeaderSize = 24,
ExtHeaderSize = 40,
CommonTypeSize = 12,
BTFArraySize = 12,
BTFEnumSize = 8,
Expand All @@ -58,8 +72,12 @@ enum {
BTFDataSecVarSize = 12,
SecFuncInfoSize = 8,
SecLineInfoSize = 8,
SecOffsetRelocSize = 8,
SecExternRelocSize = 8,
BPFFuncInfoSize = 8,
BPFLineInfoSize = 16
BPFLineInfoSize = 16,
BPFOffsetRelocSize = 12,
BPFExternRelocSize = 8,
};

/// The .BTF section header definition.
Expand Down Expand Up @@ -191,10 +209,14 @@ struct ExtHeader {
uint8_t Flags;
uint32_t HdrLen;

uint32_t FuncInfoOff; ///< Offset of func info section
uint32_t FuncInfoLen; ///< Length of func info section
uint32_t LineInfoOff; ///< Offset of line info section
uint32_t LineInfoLen; ///< Length of line info section
uint32_t FuncInfoOff; ///< Offset of func info section
uint32_t FuncInfoLen; ///< Length of func info section
uint32_t LineInfoOff; ///< Offset of line info section
uint32_t LineInfoLen; ///< Length of line info section
uint32_t OffsetRelocOff; ///< Offset of offset reloc section
uint32_t OffsetRelocLen; ///< Length of offset reloc section
uint32_t ExternRelocOff; ///< Offset of extern reloc section
uint32_t ExternRelocLen; ///< Length of extern reloc section
};

/// Specifying one function info.
Expand All @@ -220,10 +242,35 @@ struct BPFLineInfo {

/// Specifying line info's in one section.
struct SecLineInfo {
uint32_t SecNameOff; ///< Section name index in the .BTF string tble
uint32_t SecNameOff; ///< Section name index in the .BTF string table
uint32_t NumLineInfo; ///< Number of line info's in this section
};

/// Specifying one offset relocation.
struct BPFOffsetReloc {
uint32_t InsnOffset; ///< Byte offset in this section
uint32_t TypeID; ///< TypeID for the relocation
uint32_t OffsetNameOff; ///< The string to traverse types
};

/// Specifying offset relocation's in one section.
struct SecOffsetReloc {
uint32_t SecNameOff; ///< Section name index in the .BTF string table
uint32_t NumOffsetReloc; ///< Number of offset reloc's in this section
};

/// Specifying one offset relocation.
struct BPFExternReloc {
uint32_t InsnOffset; ///< Byte offset in this section
uint32_t ExternNameOff; ///< The string for external variable
};

/// Specifying extern relocation's in one section.
struct SecExternReloc {
uint32_t SecNameOff; ///< Section name index in the .BTF string table
uint32_t NumExternReloc; ///< Number of extern reloc's in this section
};

} // End namespace BTF.
} // End namespace llvm.

Expand Down
489 changes: 456 additions & 33 deletions llvm/lib/Target/BPF/BTFDebug.cpp

Large diffs are not rendered by default.

63 changes: 56 additions & 7 deletions llvm/lib/Target/BPF/BTFDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class MachineFunction;
class BTFTypeBase {
protected:
uint8_t Kind;
bool IsCompleted;
uint32_t Id;
struct BTF::CommonType BTFType;

public:
BTFTypeBase() : IsCompleted(false) {}
virtual ~BTFTypeBase() = default;
void setId(uint32_t Id) { this->Id = Id; }
uint32_t getId() { return Id; }
Expand All @@ -54,11 +56,13 @@ class BTFTypeBase {
/// volatile, typedef and restrict.
class BTFTypeDerived : public BTFTypeBase {
const DIDerivedType *DTy;
bool NeedsFixup;

public:
BTFTypeDerived(const DIDerivedType *Ty, unsigned Tag);
BTFTypeDerived(const DIDerivedType *Ty, unsigned Tag, bool NeedsFixup);
void completeType(BTFDebug &BDebug);
void emitType(MCStreamer &OS);
void setPointeeType(uint32_t PointeeType);
};

/// Handle struct or union forward declaration.
Expand Down Expand Up @@ -100,13 +104,15 @@ class BTFTypeEnum : public BTFTypeBase {

/// Handle array type.
class BTFTypeArray : public BTFTypeBase {
uint32_t ElemSize;
struct BTF::BTFArray ArrayInfo;

public:
BTFTypeArray(uint32_t ElemTypeId, uint32_t NumElems);
BTFTypeArray(uint32_t ElemTypeId, uint32_t ElemSize, uint32_t NumElems);
uint32_t getSize() { return BTFTypeBase::getSize() + BTF::BTFArraySize; }
void completeType(BTFDebug &BDebug);
void emitType(MCStreamer &OS);
void getLocInfo(uint32_t Loc, uint32_t &LocOffset, uint32_t &ElementTypeId);
};

/// Handle struct/union type.
Expand All @@ -123,6 +129,9 @@ class BTFTypeStruct : public BTFTypeBase {
}
void completeType(BTFDebug &BDebug);
void emitType(MCStreamer &OS);
std::string getName();
void getMemberInfo(uint32_t Loc, uint32_t &Offset, uint32_t &MemberType);
uint32_t getStructSize();
};

/// Handle function pointer.
Expand Down Expand Up @@ -218,21 +227,41 @@ struct BTFLineInfo {
uint32_t ColumnNum; ///< the column number
};

/// Represent one offset relocation.
struct BTFOffsetReloc {
const MCSymbol *Label; ///< MCSymbol identifying insn for the reloc
uint32_t TypeID; ///< Type ID
uint32_t OffsetNameOff; ///< The string to traverse types
};

/// Represent one extern relocation.
struct BTFExternReloc {
const MCSymbol *Label; ///< MCSymbol identifying insn for the reloc
uint32_t ExternNameOff; ///< The extern variable name
};

/// Collect and emit BTF information.
class BTFDebug : public DebugHandlerBase {
MCStreamer &OS;
bool SkipInstruction;
bool LineInfoGenerated;
uint32_t SecNameOff;
uint32_t ArrayIndexTypeId;
bool MapDefNotCollected;
BTFStringTable StringTable;
std::vector<std::unique_ptr<BTFTypeBase>> TypeEntries;
std::unordered_map<const DIType *, uint32_t> DIToIdMap;
std::map<uint32_t, std::vector<BTFFuncInfo>> FuncInfoTable;
std::map<uint32_t, std::vector<BTFLineInfo>> LineInfoTable;
std::map<uint32_t, std::vector<BTFOffsetReloc>> OffsetRelocTable;
std::map<uint32_t, std::vector<BTFExternReloc>> ExternRelocTable;
StringMap<std::vector<std::string>> FileContent;
std::map<std::string, std::unique_ptr<BTFKindDataSec>>
DataSecEntries;
std::map<std::string, std::unique_ptr<BTFKindDataSec>> DataSecEntries;
std::vector<BTFTypeStruct *> StructTypes;
std::vector<BTFTypeArray *> ArrayTypes;
std::map<std::string, int64_t> AccessOffsets;
std::map<StringRef, std::pair<bool, std::vector<BTFTypeDerived *>>>
FixupDerivedTypes;

/// Add types to TypeEntries.
/// @{
Expand All @@ -245,7 +274,8 @@ class BTFDebug : public DebugHandlerBase {
/// IR type visiting functions.
/// @{
void visitTypeEntry(const DIType *Ty);
void visitTypeEntry(const DIType *Ty, uint32_t &TypeId);
void visitTypeEntry(const DIType *Ty, uint32_t &TypeId, bool CheckPointer,
bool SeenPointer);
void visitBasicType(const DIBasicType *BTy, uint32_t &TypeId);
void visitSubroutineType(
const DISubroutineType *STy, bool ForSubprog,
Expand All @@ -258,7 +288,9 @@ class BTFDebug : public DebugHandlerBase {
uint32_t &TypeId);
void visitArrayType(const DICompositeType *ATy, uint32_t &TypeId);
void visitEnumType(const DICompositeType *ETy, uint32_t &TypeId);
void visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId);
void visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId,
bool CheckPointer, bool SeenPointer);
void visitMapDefType(const DIType *Ty, uint32_t &TypeId);
/// @}

/// Get the file content for the subprogram. Certain lines of the file
Expand All @@ -270,7 +302,21 @@ class BTFDebug : public DebugHandlerBase {
uint32_t Column);

/// Generate types and variables for globals.
void processGlobals(void);
void processGlobals(bool ProcessingMapDef);

/// Generate one offset relocation record.
void generateOffsetReloc(const MachineInstr *MI, const MCSymbol *ORSym,
DIType *RootTy, StringRef AccessPattern);

/// Set the to-be-traversed Struct/Array Type based on TypeId.
void setTypeFromId(uint32_t TypeId, BTFTypeStruct **PrevStructType,
BTFTypeArray **PrevArrayType);

/// Populating unprocessed struct type.
unsigned populateStructType(const DIType *Ty);

/// Process LD_imm64 instructions.
void processLDimm64(const MachineInstr *MI);

/// Emit common header of .BTF and .BTF.ext sections.
void emitCommonHeader();
Expand All @@ -291,6 +337,9 @@ class BTFDebug : public DebugHandlerBase {
public:
BTFDebug(AsmPrinter *AP);

///
bool InstLower(const MachineInstr *MI, MCInst &OutMI);

/// Get the special array index type id.
uint32_t getArrayIndexTypeId() {
assert(ArrayIndexTypeId);
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/BPF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tablegen(LLVM BPFGenSubtargetInfo.inc -gen-subtarget)
add_public_tablegen_target(BPFCommonTableGen)

add_llvm_target(BPFCodeGen
BPFAbstrctMemberAccess.cpp
BPFAsmPrinter.cpp
BPFFrameLowering.cpp
BPFInstrInfo.cpp
Expand All @@ -25,6 +26,7 @@ add_llvm_target(BPFCodeGen
BPFTargetMachine.cpp
BPFMIPeephole.cpp
BPFMIChecking.cpp
BPFMISimplifyPatchable.cpp
BTFDebug.cpp
)

Expand Down
44 changes: 23 additions & 21 deletions llvm/test/CodeGen/BPF/BTF/binary-format.ll
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,33 @@ entry:

; CHECK: '.BTF'
; CHECK-EL: 0x00000000 9feb0100 18000000 00000000 30000000
; CHECK-EL: 0x00000010 30000000 33000000 2b000000 00000001
; CHECK-EL: 0x00000010 30000000 33000000 01000000 00000001
; CHECK-EL: 0x00000020 04000000 20000001 00000000 0100000d
; CHECK-EL: 0x00000030 01000000 2f000000 01000000 31000000
; CHECK-EL: 0x00000040 0000000c 02000000 002e7465 7874002f
; CHECK-EL: 0x00000030 01000000 05000000 01000000 07000000
; CHECK-EL: 0x00000040 0000000c 02000000 00696e74 00610066
; CHECK-EB: 0x00000000 eb9f0100 00000018 00000000 00000030
; CHECK-EB: 0x00000010 00000030 00000033 0000002b 01000000
; CHECK-EB: 0x00000010 00000030 00000033 00000001 01000000
; CHECK-EB: 0x00000020 00000004 01000020 00000000 0d000001
; CHECK-EB: 0x00000030 00000001 0000002f 00000001 00000031
; CHECK-EB: 0x00000040 0c000000 00000002 002e7465 7874002f
; CHECK: 0x00000050 746d702f 742e6300 696e7420 6628696e
; CHECK: 0x00000060 74206129 207b2072 65747572 6e20613b
; CHECK: 0x00000070 207d0069 6e740061 006600
; CHECK-EB: 0x00000030 00000001 00000005 00000001 00000007
; CHECK-EB: 0x00000040 0c000000 00000002 00696e74 00610066
; CHECK: 0x00000050 002e7465 7874002f 746d702f 742e6300
; CHECK: 0x00000060 696e7420 6628696e 74206129 207b2072
; CHECK: 0x00000070 65747572 6e20613b 207d00
; CHECK: '.BTF.ext'
; CHECK-EL: 0x00000000 9feb0100 18000000 00000000 14000000
; CHECK-EL: 0x00000010 14000000 2c000000 08000000 01000000
; CHECK-EL: 0x00000020 01000000 00000000 03000000 10000000
; CHECK-EL: 0x00000030 01000000 02000000 00000000 07000000
; CHECK-EL: 0x00000040 10000000 00040000 08000000 07000000
; CHECK-EL: 0x00000050 10000000 10040000
; CHECK-EB: 0x00000000 eb9f0100 00000018 00000000 00000014
; CHECK-EB: 0x00000010 00000014 0000002c 00000008 00000001
; CHECK-EB: 0x00000020 00000001 00000000 00000003 00000010
; CHECK-EB: 0x00000030 00000001 00000002 00000000 00000007
; CHECK-EB: 0x00000040 00000010 00000400 00000008 00000007
; CHECK-EB: 0x00000050 00000010 00000410
; CHECK-EL: 0x00000000 9feb0100 28000000 00000000 14000000
; CHECK-EL: 0x00000010 14000000 2c000000 40000000 00000000
; CHECK-EL: 0x00000020 40000000 00000000 08000000 09000000
; CHECK-EL: 0x00000030 01000000 00000000 03000000 10000000
; CHECK-EL: 0x00000040 09000000 02000000 00000000 0f000000
; CHECK-EL: 0x00000050 18000000 00040000 08000000 0f000000
; CHECK-EL: 0x00000060 18000000 10040000
; CHECK-EB: 0x00000000 eb9f0100 00000028 00000000 00000014
; CHECK-EB: 0x00000010 00000014 0000002c 00000040 00000000
; CHECK-EB: 0x00000020 00000040 00000000 00000008 00000009
; CHECK-EB: 0x00000030 00000001 00000000 00000003 00000010
; CHECK-EB: 0x00000040 00000009 00000002 00000000 0000000f
; CHECK-EB: 0x00000050 00000018 00000400 00000008 0000000f
; CHECK-EB: 0x00000060 00000018 00000410

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/BPF/BTF/extern-global-var.ll
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 5 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=44
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=48
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=15
; CHECK-NEXT: .byte 0

attributes #0 = { norecurse nounwind readonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
Expand Down
24 changes: 14 additions & 10 deletions llvm/test/CodeGen/BPF/BTF/filename.ll
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,45 @@ define dso_local i32 @test() local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 26 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 30 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 5 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/ttmp/t.c" # string offset=7
; CHECK-NEXT: .ascii "test" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=26
; CHECK-NEXT: .ascii ".text" # string offset=10
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "test" # string offset=30
; CHECK-NEXT: .ascii "/home/yhs/ttmp/t.c" # string offset=16
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .section .BTF.ext,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 1 # FuncInfo section string offset=1
; CHECK-NEXT: .long 10 # FuncInfo section string offset=10
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin{{[0-9]+}}
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 1 # LineInfo section string offset=1
; CHECK-NEXT: .long 10 # LineInfo section string offset=10
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 16
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 1038 # Line 1 Col 14

Expand Down
30 changes: 17 additions & 13 deletions llvm/test/CodeGen/BPF/BTF/func-func-ptr.ll
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ entry:
; CHECK-NEXT: .long 104
; CHECK-NEXT: .long 104
; CHECK-NEXT: .long 32
; CHECK-NEXT: .long 16 # BTF_KIND_INT(id = 1)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 1)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 2)
; CHECK-NEXT: .long 218103809 # 0xd000001
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 5
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 23 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 8 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 4)
Expand All @@ -54,17 +54,17 @@ entry:
; CHECK-NEXT: .long 8
; CHECK-NEXT: .long 29
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 0 # 0x0
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=7
; CHECK-NEXT: .ascii "p2" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=16
; CHECK-NEXT: .ascii "f1" # string offset=8
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "p2" # string offset=20
; CHECK-NEXT: .ascii ".text" # string offset=11
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "f1" # string offset=23
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=17
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "t1" # string offset=26
; CHECK-NEXT: .byte 0
Expand All @@ -74,21 +74,25 @@ entry:
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 1 # FuncInfo section string offset=1
; CHECK-NEXT: .long 11 # FuncInfo section string offset=11
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 1 # LineInfo section string offset=1
; CHECK-NEXT: .long 11 # LineInfo section string offset=11
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 17
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 3091 # Line 3 Col 19

Expand Down
30 changes: 17 additions & 13 deletions llvm/test/CodeGen/BPF/BTF/func-non-void.ll
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,56 @@ define dso_local i32 @f1(i32 returned) local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 26
; CHECK-NEXT: .long 16 # BTF_KIND_INT(id = 1)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 1)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 2)
; CHECK-NEXT: .long 218103809 # 0xd000001
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 5
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 23 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 8 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=7
; CHECK-NEXT: .ascii "a1" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=16
; CHECK-NEXT: .ascii "f1" # string offset=8
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "a1" # string offset=20
; CHECK-NEXT: .ascii ".text" # string offset=11
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "f1" # string offset=23
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=17
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .section .BTF.ext,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 44
; CHECK-NEXT: .long 64
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 64
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 1 # FuncInfo section string offset=1
; CHECK-NEXT: .long 11 # FuncInfo section string offset=11
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 1 # LineInfo section string offset=1
; CHECK-NEXT: .long 11 # LineInfo section string offset=11
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 17
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 1024 # Line 1 Col 0
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 17
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 1042 # Line 1 Col 18

Expand Down
24 changes: 14 additions & 10 deletions llvm/test/CodeGen/BPF/BTF/func-source.ll
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,42 @@ entry:
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 33 # BTF_KIND_FUNC(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_FUNC(id = 2)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .byte 102 # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=7
; CHECK-NEXT: .ascii ".text" # string offset=3
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "void f(void) { }" # string offset=16
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 102 # string offset=33
; CHECK-NEXT: .ascii "void f(void) { }" # string offset=18
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .section .BTF.ext,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 1 # FuncInfo section string offset=1
; CHECK-NEXT: .long 3 # FuncInfo section string offset=3
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 1 # LineInfo section string offset=1
; CHECK-NEXT: .long 3 # LineInfo section string offset=3
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 16
; CHECK-NEXT: .long 9
; CHECK-NEXT: .long 18
; CHECK-NEXT: .long 1040 # Line 1 Col 16

attributes #0 = { norecurse nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
Expand Down
39 changes: 22 additions & 17 deletions llvm/test/CodeGen/BPF/BTF/func-typedef.ll
Original file line number Diff line number Diff line change
Expand Up @@ -24,65 +24,70 @@ entry:
; CHECK-NEXT: .long 72
; CHECK-NEXT: .long 72
; CHECK-NEXT: .long 35
; CHECK-NEXT: .long 16 # BTF_KIND_TYPEDEF(id = 1)
; CHECK-NEXT: .long 1 # BTF_KIND_TYPEDEF(id = 1)
; CHECK-NEXT: .long 134217728 # 0x8000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 22 # BTF_KIND_TYPEDEF(id = 2)
; CHECK-NEXT: .long 7 # BTF_KIND_TYPEDEF(id = 2)
; CHECK-NEXT: .long 134217728 # 0x8000000
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 27 # BTF_KIND_INT(id = 3)
; CHECK-NEXT: .long 12 # BTF_KIND_INT(id = 3)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 4)
; CHECK-NEXT: .long 218103809 # 0xd000001
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 31
; CHECK-NEXT: .long 16
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 33 # BTF_KIND_FUNC(id = 5)
; CHECK-NEXT: .long 18 # BTF_KIND_FUNC(id = 5)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "__int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=7
; CHECK-NEXT: .ascii "_int" # string offset=7
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "__int" # string offset=16
; CHECK-NEXT: .ascii "int" # string offset=12
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "_int" # string offset=22
; CHECK-NEXT: .byte 97 # string offset=16
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=27
; CHECK-NEXT: .byte 102 # string offset=18
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 97 # string offset=31
; CHECK-NEXT: .ascii ".text" # string offset=20
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 102 # string offset=33
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=26
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .section .BTF.ext,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 44
; CHECK-NEXT: .long 64
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 64
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 1 # FuncInfo section string offset=1
; CHECK-NEXT: .long 20 # FuncInfo section string offset=20
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 5
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 1 # LineInfo section string offset=1
; CHECK-NEXT: .long 20 # LineInfo section string offset=20
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 26
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 3072 # Line 3 Col 0
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 26
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 3092 # Line 3 Col 20


; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata) #1

Expand Down
28 changes: 16 additions & 12 deletions llvm/test/CodeGen/BPF/BTF/func-unused-arg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,52 @@ define dso_local i32 @f1(i32) local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 26
; CHECK-NEXT: .long 16 # BTF_KIND_INT(id = 1)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 1)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 2)
; CHECK-NEXT: .long 218103809 # 0xd000001
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 5
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 23 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 8 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=7
; CHECK-NEXT: .ascii "a1" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=16
; CHECK-NEXT: .ascii "f1" # string offset=8
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "a1" # string offset=20
; CHECK-NEXT: .ascii ".text" # string offset=11
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "f1" # string offset=23
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=17
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .section .BTF.ext,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 1 # FuncInfo section string offset=1
; CHECK-NEXT: .long 11 # FuncInfo section string offset=11
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 1 # LineInfo section string offset=1
; CHECK-NEXT: .long 11 # LineInfo section string offset=11
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 17
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 1042 # Line 1 Col 18

Expand Down
20 changes: 12 additions & 8 deletions llvm/test/CodeGen/BPF/BTF/func-void.ll
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,39 @@ define dso_local void @f1() local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 16 # BTF_KIND_FUNC(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_FUNC(id = 2)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "f1" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=7
; CHECK-NEXT: .ascii ".text" # string offset=4
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "f1" # string offset=16
; CHECK-NEXT: .ascii "/tmp/t.c" # string offset=10
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .section .BTF.ext,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 48
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 1 # FuncInfo section string offset=1
; CHECK-NEXT: .long 4 # FuncInfo section string offset=4
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 1 # LineInfo section string offset=1
; CHECK-NEXT: .long 4 # LineInfo section string offset=4
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 10
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 1040 # Line 1 Col 16

Expand Down
20 changes: 10 additions & 10 deletions llvm/test/CodeGen/BPF/BTF/local-var.ll
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ define dso_local i32 @foo(i8 signext) local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .long 64
; CHECK-NEXT: .long 64
; CHECK-NEXT: .long 59
; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 1)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 1)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 16777224 # 0x1000008
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 2)
; CHECK-NEXT: .long 218103809 # 0xd000001
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 49
; CHECK-NEXT: .long 6
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 51 # BTF_KIND_INT(id = 3)
; CHECK-NEXT: .long 8 # BTF_KIND_INT(id = 3)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 55 # BTF_KIND_FUNC(id = 4)
; CHECK-NEXT: .long 12 # BTF_KIND_FUNC(id = 4)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "char" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7
; CHECK-NEXT: .byte 97 # string offset=6
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "char" # string offset=44
; CHECK-NEXT: .ascii "int" # string offset=8
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 97 # string offset=49
; CHECK-NEXT: .ascii "foo" # string offset=12
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=51
; CHECK-NEXT: .ascii ".text" # string offset=16
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=55
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=22
; CHECK-NEXT: .byte 0

; Function Attrs: nounwind readnone speculatable
Expand Down
120 changes: 120 additions & 0 deletions llvm/test/CodeGen/BPF/BTF/map-def.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s

; Source code:
; struct key_type {
; int a;
; int b;
; };
; struct map_type {
; struct key_type *key;
; unsigned *value;
; };
; struct map_type __attribute__((section(".maps"))) hash_map;
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm t.c

%struct.map_type = type { %struct.key_type*, i32* }
%struct.key_type = type { i32, i32 }

@hash_map = dso_local local_unnamed_addr global %struct.map_type zeroinitializer, section ".maps", align 8, !dbg !0

; CHECK: .section .BTF,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 168
; CHECK-NEXT: .long 168
; CHECK-NEXT: .long 65
; CHECK-NEXT: .long 1 # BTF_KIND_STRUCT(id = 1)
; CHECK-NEXT: .long 67108866 # 0x4000002
; CHECK-NEXT: .long 16
; CHECK-NEXT: .long 10
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 0 # 0x0
; CHECK-NEXT: .long 14
; CHECK-NEXT: .long 5
; CHECK-NEXT: .long 64 # 0x40
; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 2)
; CHECK-NEXT: .long 33554432 # 0x2000000
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 20 # BTF_KIND_STRUCT(id = 3)
; CHECK-NEXT: .long 67108866 # 0x4000002
; CHECK-NEXT: .long 8
; CHECK-NEXT: .long 29
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 0 # 0x0
; CHECK-NEXT: .long 31
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 32 # 0x20
; CHECK-NEXT: .long 33 # BTF_KIND_INT(id = 4)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 5)
; CHECK-NEXT: .long 33554432 # 0x2000000
; CHECK-NEXT: .long 6
; CHECK-NEXT: .long 37 # BTF_KIND_INT(id = 6)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 32 # 0x20
; CHECK-NEXT: .long 50 # BTF_KIND_VAR(id = 7)
; CHECK-NEXT: .long 234881024 # 0xe000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 59 # BTF_KIND_DATASEC(id = 8)
; CHECK-NEXT: .long 251658241 # 0xf000001
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long hash_map
; CHECK-NEXT: .long 16
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii "map_type" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "key" # string offset=10
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "value" # string offset=14
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "key_type" # string offset=20
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 97 # string offset=29
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 98 # string offset=31
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=33
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "unsigned int" # string offset=37
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "hash_map" # string offset=50
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii ".maps" # string offset=59
; CHECK-NEXT: .byte 0

!llvm.dbg.cu = !{!2}
!llvm.module.flags = !{!18, !19, !20}
!llvm.ident = !{!21}

!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "hash_map", scope: !2, file: !3, line: 9, type: !6, isLocal: false, isDefinition: true)
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 9.0.0 (trunk 364157) (llvm/trunk 364156)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
!3 = !DIFile(filename: "t.c", directory: "/tmp/home/yhs/work/tests/llvm")
!4 = !{}
!5 = !{!0}
!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "map_type", file: !3, line: 5, size: 128, elements: !7)
!7 = !{!8, !15}
!8 = !DIDerivedType(tag: DW_TAG_member, name: "key", scope: !6, file: !3, line: 6, baseType: !9, size: 64)
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64)
!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "key_type", file: !3, line: 1, size: 64, elements: !11)
!11 = !{!12, !14}
!12 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !10, file: !3, line: 2, baseType: !13, size: 32)
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!14 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !10, file: !3, line: 3, baseType: !13, size: 32, offset: 32)
!15 = !DIDerivedType(tag: DW_TAG_member, name: "value", scope: !6, file: !3, line: 7, baseType: !16, size: 64, offset: 64)
!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64)
!17 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
!18 = !{i32 2, !"Dwarf Version", i32 4}
!19 = !{i32 2, !"Debug Info Version", i32 3}
!20 = !{i32 1, !"wchar_size", i32 4}
!21 = !{!"clang version 9.0.0 (trunk 364157) (llvm/trunk 364156)"}
84 changes: 84 additions & 0 deletions llvm/test/CodeGen/BPF/BTF/ptr-prune-type.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s

; Source code:
; struct t {
; int a;
; };
; struct t2 {
; struct t *f1;
; };
; struct t2 __attribute__((section("prune_types"))) g;
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm t.c

%struct.t2 = type { %struct.t* }
%struct.t = type { i32 }

@g = dso_local local_unnamed_addr global %struct.t2 zeroinitializer, section "prune_types", align 8, !dbg !0

; CHECK: .section .BTF,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 88
; CHECK-NEXT: .long 88
; CHECK-NEXT: .long 23
; CHECK-NEXT: .long 1 # BTF_KIND_STRUCT(id = 1)
; CHECK-NEXT: .long 67108865 # 0x4000001
; CHECK-NEXT: .long 8
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 0 # 0x0
; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 2)
; CHECK-NEXT: .long 33554432 # 0x2000000
; CHECK-NEXT: .long 5
; CHECK-NEXT: .long 7 # BTF_KIND_VAR(id = 3)
; CHECK-NEXT: .long 234881024 # 0xe000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 9 # BTF_KIND_DATASEC(id = 4)
; CHECK-NEXT: .long 251658241 # 0xf000001
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long g
; CHECK-NEXT: .long 8
; CHECK-NEXT: .long 21 # BTF_KIND_FWD(id = 5)
; CHECK-NEXT: .long 117440512 # 0x7000000
; CHECK-NEXT: .long 0
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii "t2" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "f1" # string offset=4
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 103 # string offset=7
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "prune_types" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 116 # string offset=21
; CHECK-NEXT: .byte 0

!llvm.dbg.cu = !{!2}
!llvm.module.flags = !{!14, !15, !16}
!llvm.ident = !{!17}

!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 7, type: !6, isLocal: false, isDefinition: true)
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 9.0.0 (trunk 364157) (llvm/trunk 364156)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
!3 = !DIFile(filename: "t.c", directory: "/tmp/home/yhs/work/tests/llvm")
!4 = !{}
!5 = !{!0}
!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t2", file: !3, line: 4, size: 64, elements: !7)
!7 = !{!8}
!8 = !DIDerivedType(tag: DW_TAG_member, name: "f1", scope: !6, file: !3, line: 5, baseType: !9, size: 64)
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64)
!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t", file: !3, line: 1, size: 32, elements: !11)
!11 = !{!12}
!12 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !10, file: !3, line: 2, baseType: !13, size: 32)
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!14 = !{i32 2, !"Dwarf Version", i32 4}
!15 = !{i32 2, !"Debug Info Version", i32 3}
!16 = !{i32 1, !"wchar_size", i32 4}
!17 = !{!"clang version 9.0.0 (trunk 364157) (llvm/trunk 364156)"}
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/BPF/BTF/static-var-derived-type.ll
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ define dso_local i64 @foo() local_unnamed_addr #0 !dbg !27 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 45 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 8
; CHECK-NEXT: .long 16777280 # 0x1000040
; CHECK-NEXT: .long 54 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 10 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4)
Expand Down Expand Up @@ -116,13 +116,13 @@ define dso_local i64 @foo() local_unnamed_addr #0 !dbg !27 {
; CHECK-NEXT: .long v4
; CHECK-NEXT: .long 8
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "long int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bugs/test.c" # string offset=7
; CHECK-NEXT: .ascii "foo" # string offset=10
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "long int" # string offset=45
; CHECK-NEXT: .ascii ".text" # string offset=14
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=54
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bugs/test.c" # string offset=20
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=58
; CHECK-NEXT: .byte 0
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/BPF/BTF/static-var-inited-sec.ll
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 5 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4)
Expand Down Expand Up @@ -74,13 +74,13 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long a
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=44
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=48
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "short" # string offset=52
; CHECK-NEXT: .byte 0
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/BPF/BTF/static-var-inited.ll
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 5 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4)
Expand Down Expand Up @@ -74,13 +74,13 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long a
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=44
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=48
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "short" # string offset=52
; CHECK-NEXT: .byte 0
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 5 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 0 # BTF_KIND_CONST(id = 4)
Expand Down Expand Up @@ -80,13 +80,13 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long a
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=44
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=48
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "short" # string offset=52
; CHECK-NEXT: .byte 0
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/BPF/BTF/static-var-readonly.ll
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 5 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 0 # BTF_KIND_CONST(id = 4)
Expand Down Expand Up @@ -80,13 +80,13 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long a
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=44
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=48
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "short" # string offset=52
; CHECK-NEXT: .byte 0
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/BPF/BTF/static-var-sec.ll
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 5 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4)
Expand Down Expand Up @@ -74,13 +74,13 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long a
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=44
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=48
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "short" # string offset=52
; CHECK-NEXT: .byte 0
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/BPF/BTF/static-var-zerolen-array.ll
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ define dso_local i32 @test() local_unnamed_addr #0 !dbg !21 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 5 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4)
Expand Down Expand Up @@ -79,13 +79,13 @@ define dso_local i32 @test() local_unnamed_addr #0 !dbg !21 {
; CHECK-NEXT: .long sv
; CHECK-NEXT: .long 20
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7
; CHECK-NEXT: .ascii "test" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=44
; CHECK-NEXT: .ascii ".text" # string offset=10
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "test" # string offset=48
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=16
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 116 # string offset=53
; CHECK-NEXT: .byte 0
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/BPF/BTF/static-var.ll
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 5 # BTF_KIND_FUNC(id = 3)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4)
Expand Down Expand Up @@ -74,13 +74,13 @@ define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
; CHECK-NEXT: .long a
; CHECK-NEXT: .long 1
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii ".text" # string offset=1
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=44
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=48
; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "short" # string offset=52
; CHECK-NEXT: .byte 0
Expand Down
186 changes: 186 additions & 0 deletions llvm/test/CodeGen/BPF/CORE/offset-reloc-basic.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; Source code:
; struct sk_buff {
; int i;
; struct net_device *dev;
; };
; #define _(x) (__builtin_preserve_access_index(x))
; static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr)
; = (void *) 4;
;
; int bpf_prog(struct sk_buff *ctx) {
; struct net_device *dev = 0;
; bpf_probe_read(&dev, sizeof(dev), _(&ctx->dev));
; return dev != 0;
; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c

%struct.sk_buff = type { i32, %struct.net_device* }
%struct.net_device = type opaque

; Function Attrs: nounwind
define dso_local i32 @bpf_prog(%struct.sk_buff*) local_unnamed_addr #0 !dbg !15 {
%2 = alloca %struct.net_device*, align 8
call void @llvm.dbg.value(metadata %struct.sk_buff* %0, metadata !26, metadata !DIExpression()), !dbg !28
%3 = bitcast %struct.net_device** %2 to i8*, !dbg !29
call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %3) #4, !dbg !29
call void @llvm.dbg.value(metadata %struct.net_device* null, metadata !27, metadata !DIExpression()), !dbg !28
store %struct.net_device* null, %struct.net_device** %2, align 8, !dbg !30, !tbaa !31
%4 = tail call %struct.net_device** @llvm.preserve.struct.access.index.p0p0s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff* %0, i32 1, i32 1), !dbg !35, !llvm.preserve.access.index !19
%5 = bitcast %struct.net_device** %4 to i8*, !dbg !35
%6 = call i32 inttoptr (i64 4 to i32 (i8*, i32, i8*)*)(i8* nonnull %3, i32 8, i8* %5) #4, !dbg !36
%7 = load %struct.net_device*, %struct.net_device** %2, align 8, !dbg !37, !tbaa !31
call void @llvm.dbg.value(metadata %struct.net_device* %7, metadata !27, metadata !DIExpression()), !dbg !28
%8 = icmp ne %struct.net_device* %7, null, !dbg !38
%9 = zext i1 %8 to i32, !dbg !38
call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %3) #4, !dbg !39
ret i32 %9, !dbg !40
}

; CHECK: .section .BTF,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 120
; CHECK-NEXT: .long 120
; CHECK-NEXT: .long 90
; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 1)
; CHECK-NEXT: .long 33554432 # 0x2000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 1 # BTF_KIND_STRUCT(id = 2)
; CHECK-NEXT: .long 67108866 # 0x4000002
; CHECK-NEXT: .long 16
; CHECK-NEXT: .long 9
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 0 # 0x0
; CHECK-NEXT: .long 11
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 64 # 0x40
; CHECK-NEXT: .long 15 # BTF_KIND_INT(id = 3)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 4)
; CHECK-NEXT: .long 33554432 # 0x2000000
; CHECK-NEXT: .long 5
; CHECK-NEXT: .long 19 # BTF_KIND_FWD(id = 5)
; CHECK-NEXT: .long 117440512 # 0x7000000
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 6)
; CHECK-NEXT: .long 218103809 # 0xd000001
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 30
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 34 # BTF_KIND_FUNC(id = 7)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 6
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii "sk_buff" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 105 # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "dev" # string offset=11
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "net_device" # string offset=19
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "ctx" # string offset=30
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "bpf_prog" # string offset=34
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii ".text" # string offset=43
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/home/yhs/work/tests/llvm/test.c" # string offset=49
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "0:1" # string offset=86
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .section .BTF.ext,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 124
; CHECK-NEXT: .long 144
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 168
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo

; CHECK: .long 12 # OffsetReloc
; CHECK-NEXT: .long 43 # Offset reloc section string offset=43
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp2
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 86

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1

; Function Attrs: nounwind readnone
declare %struct.net_device** @llvm.preserve.struct.access.index.p0p0s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff*, i32 immarg, i32 immarg) #2

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata) #3

attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { argmemonly nounwind }
attributes #2 = { nounwind readnone }
attributes #3 = { nounwind readnone speculatable }
attributes #4 = { nounwind }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!11, !12, !13}
!llvm.ident = !{!14}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")
!2 = !{}
!3 = !{!4}
!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())
!5 = distinct !DIGlobalVariable(name: "bpf_probe_read", scope: !0, file: !1, line: 6, type: !6, isLocal: true, isDefinition: true)
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
!7 = !DISubroutineType(types: !8)
!8 = !{!9, !10, !9, !10}
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
!11 = !{i32 2, !"Dwarf Version", i32 4}
!12 = !{i32 2, !"Debug Info Version", i32 3}
!13 = !{i32 1, !"wchar_size", i32 4}
!14 = !{!"clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)"}
!15 = distinct !DISubprogram(name: "bpf_prog", scope: !1, file: !1, line: 9, type: !16, scopeLine: 9, flags: DIFlagPrototyped, isLocal: false, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !25)
!16 = !DISubroutineType(types: !17)
!17 = !{!9, !18}
!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
!19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "sk_buff", file: !1, line: 1, size: 128, elements: !20)
!20 = !{!21, !22}
!21 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !19, file: !1, line: 2, baseType: !9, size: 32)
!22 = !DIDerivedType(tag: DW_TAG_member, name: "dev", scope: !19, file: !1, line: 3, baseType: !23, size: 64, offset: 64)
!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !24, size: 64)
!24 = !DICompositeType(tag: DW_TAG_structure_type, name: "net_device", file: !1, line: 3, flags: DIFlagFwdDecl)
!25 = !{!26, !27}
!26 = !DILocalVariable(name: "ctx", arg: 1, scope: !15, file: !1, line: 9, type: !18)
!27 = !DILocalVariable(name: "dev", scope: !15, file: !1, line: 10, type: !23)
!28 = !DILocation(line: 0, scope: !15)
!29 = !DILocation(line: 10, column: 3, scope: !15)
!30 = !DILocation(line: 10, column: 22, scope: !15)
!31 = !{!32, !32, i64 0}
!32 = !{!"any pointer", !33, i64 0}
!33 = !{!"omnipotent char", !34, i64 0}
!34 = !{!"Simple C/C++ TBAA"}
!35 = !DILocation(line: 11, column: 37, scope: !15)
!36 = !DILocation(line: 11, column: 3, scope: !15)
!37 = !DILocation(line: 12, column: 10, scope: !15)
!38 = !DILocation(line: 12, column: 14, scope: !15)
!39 = !DILocation(line: 13, column: 1, scope: !15)
!40 = !DILocation(line: 12, column: 3, scope: !15)
197 changes: 197 additions & 0 deletions llvm/test/CodeGen/BPF/CORE/offset-reloc-multilevel.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; Source code:
; struct net_device {
; int dev_id;
; int others;
; };
; struct sk_buff {
; int i;
; struct net_device dev;
; };
; #define _(x) (__builtin_preserve_access_index(x))
; static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr)
; = (void *) 4;
;
; int bpf_prog(struct sk_buff *ctx) {
; int dev_id;
; bpf_probe_read(&dev_id, sizeof(int), _(&ctx->dev.dev_id));
; return dev_id;
; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c

%struct.sk_buff = type { i32, %struct.net_device }
%struct.net_device = type { i32, i32 }

; Function Attrs: nounwind
define dso_local i32 @bpf_prog(%struct.sk_buff*) local_unnamed_addr #0 !dbg !15 {
%2 = alloca i32, align 4
call void @llvm.dbg.value(metadata %struct.sk_buff* %0, metadata !28, metadata !DIExpression()), !dbg !30
%3 = bitcast i32* %2 to i8*, !dbg !31
call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %3) #4, !dbg !31
%4 = tail call %struct.net_device* @llvm.preserve.struct.access.index.p0s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff* %0, i32 1, i32 1), !dbg !32, !llvm.preserve.access.index !19
%5 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.net_devices(%struct.net_device* %4, i32 0, i32 0), !dbg !32, !llvm.preserve.access.index !23
%6 = bitcast i32* %5 to i8*, !dbg !32
%7 = call i32 inttoptr (i64 4 to i32 (i8*, i32, i8*)*)(i8* nonnull %3, i32 4, i8* %6) #4, !dbg !33
%8 = load i32, i32* %2, align 4, !dbg !34, !tbaa !35
call void @llvm.dbg.value(metadata i32 %8, metadata !29, metadata !DIExpression()), !dbg !30
call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %3) #4, !dbg !39
ret i32 %8, !dbg !40
}

; CHECK: .section .BTF,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 132
; CHECK-NEXT: .long 132
; CHECK-NEXT: .long 106
; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 1)
; CHECK-NEXT: .long 33554432 # 0x2000000
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 1 # BTF_KIND_STRUCT(id = 2)
; CHECK-NEXT: .long 67108866 # 0x4000002
; CHECK-NEXT: .long 12
; CHECK-NEXT: .long 9
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 0 # 0x0
; CHECK-NEXT: .long 11
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 32 # 0x20
; CHECK-NEXT: .long 15 # BTF_KIND_INT(id = 3)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 19 # BTF_KIND_STRUCT(id = 4)
; CHECK-NEXT: .long 67108866 # 0x4000002
; CHECK-NEXT: .long 8
; CHECK-NEXT: .long 30
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 0 # 0x0
; CHECK-NEXT: .long 37
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 32 # 0x20
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 5)
; CHECK-NEXT: .long 218103809 # 0xd000001
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 44
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 6)
; CHECK-NEXT: .long 201326592 # 0xc000000
; CHECK-NEXT: .long 5
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii "sk_buff" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 105 # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "dev" # string offset=11
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "int" # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "net_device" # string offset=19
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "dev_id" # string offset=30
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "others" # string offset=37
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "ctx" # string offset=44
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "bpf_prog" # string offset=48
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii ".text" # string offset=57
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/home/yhs/work/tests/llvm/test.c" # string offset=63
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "0:1:0" # string offset=100
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .section .BTF.ext,"",@progbits
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 76
; CHECK-NEXT: .long 96
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 120
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo

; CHECK: .long 12 # OffsetReloc
; CHECK-NEXT: .long 57 # Offset reloc section string offset=57
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp2
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 100

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1

; Function Attrs: nounwind readnone
declare %struct.net_device* @llvm.preserve.struct.access.index.p0s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff*, i32 immarg, i32 immarg) #2

; Function Attrs: nounwind readnone
declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.net_devices(%struct.net_device*, i32 immarg, i32 immarg) #2

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata) #3

attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { argmemonly nounwind }
attributes #2 = { nounwind readnone }
attributes #3 = { nounwind readnone speculatable }
attributes #4 = { nounwind }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!11, !12, !13}
!llvm.ident = !{!14}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")
!2 = !{}
!3 = !{!4}
!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())
!5 = distinct !DIGlobalVariable(name: "bpf_probe_read", scope: !0, file: !1, line: 10, type: !6, isLocal: true, isDefinition: true)
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
!7 = !DISubroutineType(types: !8)
!8 = !{!9, !10, !9, !10}
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
!11 = !{i32 2, !"Dwarf Version", i32 4}
!12 = !{i32 2, !"Debug Info Version", i32 3}
!13 = !{i32 1, !"wchar_size", i32 4}
!14 = !{!"clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)"}
!15 = distinct !DISubprogram(name: "bpf_prog", scope: !1, file: !1, line: 13, type: !16, scopeLine: 13, flags: DIFlagPrototyped, isLocal: false, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !27)
!16 = !DISubroutineType(types: !17)
!17 = !{!9, !18}
!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
!19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "sk_buff", file: !1, line: 5, size: 96, elements: !20)
!20 = !{!21, !22}
!21 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !19, file: !1, line: 6, baseType: !9, size: 32)
!22 = !DIDerivedType(tag: DW_TAG_member, name: "dev", scope: !19, file: !1, line: 7, baseType: !23, size: 64, offset: 32)
!23 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "net_device", file: !1, line: 1, size: 64, elements: !24)
!24 = !{!25, !26}
!25 = !DIDerivedType(tag: DW_TAG_member, name: "dev_id", scope: !23, file: !1, line: 2, baseType: !9, size: 32)
!26 = !DIDerivedType(tag: DW_TAG_member, name: "others", scope: !23, file: !1, line: 3, baseType: !9, size: 32, offset: 32)
!27 = !{!28, !29}
!28 = !DILocalVariable(name: "ctx", arg: 1, scope: !15, file: !1, line: 13, type: !18)
!29 = !DILocalVariable(name: "dev_id", scope: !15, file: !1, line: 14, type: !9)
!30 = !DILocation(line: 0, scope: !15)
!31 = !DILocation(line: 14, column: 3, scope: !15)
!32 = !DILocation(line: 15, column: 40, scope: !15)
!33 = !DILocation(line: 15, column: 3, scope: !15)
!34 = !DILocation(line: 16, column: 10, scope: !15)
!35 = !{!36, !36, i64 0}
!36 = !{!"int", !37, i64 0}
!37 = !{!"omnipotent char", !38, i64 0}
!38 = !{!"Simple C/C++ TBAA"}
!39 = !DILocation(line: 17, column: 1, scope: !15)
!40 = !DILocation(line: 16, column: 3, scope: !15)
Loading