[BPF] Remove relocation for patchable externs

Previously, patchable extern relocations are introduced to patch
external variables used for multi versioning in
compile once, run everywhere use case. The load instruction
will be converted into a move with an patchable immediate
which can be changed by bpf loader on the host.

The kernel verifier has evolved and is able to load
and propagate constant values, so compiler relocation
becomes unnecessary. This patch removed codes related to this.

Differential Revision: https://reviews.llvm.org/D68760

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374367 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Yonghong Song 2019-10-10 15:33:09 +00:00
parent 15a20c7ea2
commit bae72fac33
22 changed files with 36 additions and 467 deletions

View File

@ -93,8 +93,6 @@
namespace llvm {
const std::string BPFCoreSharedInfo::AmaAttr = "btf_ama";
const std::string BPFCoreSharedInfo::PatchableExtSecName =
".BPF.patchable_externs";
} // namespace llvm
using namespace llvm;

View File

@ -23,10 +23,8 @@ public:
MAX_FIELD_RELOC_KIND,
};
/// The attribute attached to globals representing a member offset
/// The attribute attached to globals representing a field access
static const std::string AmaAttr;
/// The section name to identify a patchable external global
static const std::string PatchableExtSecName;
};
} // namespace llvm

View File

@ -11,19 +11,15 @@
// 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
// Here @global should represent an AMA (abstruct member access).
// Such an access is 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>
// r1 = <calculated field_info>
// add r3, struct_base_reg, r1
//
//===----------------------------------------------------------------------===//
@ -120,15 +116,6 @@ bool BPFMISimplifyPatchable::removeLD() {
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";
}
}
}

View File

@ -39,13 +39,6 @@
/// struct SecFieldReloc for ELF section #2
/// A number of struct BPFFieldReloc 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
@ -63,7 +56,7 @@ enum : uint32_t { MAGIC = 0xeB9F, VERSION = 1 };
/// Sizes in bytes of various things in the BTF format.
enum {
HeaderSize = 24,
ExtHeaderSize = 40,
ExtHeaderSize = 32,
CommonTypeSize = 12,
BTFArraySize = 12,
BTFEnumSize = 8,
@ -73,11 +66,9 @@ enum {
SecFuncInfoSize = 8,
SecLineInfoSize = 8,
SecFieldRelocSize = 8,
SecExternRelocSize = 8,
BPFFuncInfoSize = 8,
BPFLineInfoSize = 16,
BPFFieldRelocSize = 16,
BPFExternRelocSize = 8,
};
/// The .BTF section header definition.
@ -215,8 +206,6 @@ struct ExtHeader {
uint32_t LineInfoLen; ///< Length of line info section
uint32_t FieldRelocOff; ///< Offset of offset reloc section
uint32_t FieldRelocLen; ///< 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.
@ -260,18 +249,6 @@ struct SecFieldReloc {
uint32_t NumFieldReloc; ///< 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.

View File

@ -752,9 +752,10 @@ void BTFDebug::emitBTFSection() {
}
void BTFDebug::emitBTFExtSection() {
// Do not emit section if empty FuncInfoTable and LineInfoTable.
// Do not emit section if empty FuncInfoTable and LineInfoTable
// and FieldRelocTable.
if (!FuncInfoTable.size() && !LineInfoTable.size() &&
!FieldRelocTable.size() && !ExternRelocTable.size())
!FieldRelocTable.size())
return;
MCContext &Ctx = OS.getContext();
@ -766,8 +767,8 @@ void BTFDebug::emitBTFExtSection() {
// Account for FuncInfo/LineInfo record size as well.
uint32_t FuncLen = 4, LineLen = 4;
// Do not account for optional FieldReloc/ExternReloc.
uint32_t FieldRelocLen = 0, ExternRelocLen = 0;
// Do not account for optional FieldReloc.
uint32_t FieldRelocLen = 0;
for (const auto &FuncSec : FuncInfoTable) {
FuncLen += BTF::SecFuncInfoSize;
FuncLen += FuncSec.second.size() * BTF::BPFFuncInfoSize;
@ -780,15 +781,9 @@ void BTFDebug::emitBTFExtSection() {
FieldRelocLen += BTF::SecFieldRelocSize;
FieldRelocLen += FieldRelocSec.second.size() * BTF::BPFFieldRelocSize;
}
for (const auto &ExternRelocSec : ExternRelocTable) {
ExternRelocLen += BTF::SecExternRelocSize;
ExternRelocLen += ExternRelocSec.second.size() * BTF::BPFExternRelocSize;
}
if (FieldRelocLen)
FieldRelocLen += 4;
if (ExternRelocLen)
ExternRelocLen += 4;
OS.EmitIntValue(0, 4);
OS.EmitIntValue(FuncLen, 4);
@ -796,8 +791,6 @@ void BTFDebug::emitBTFExtSection() {
OS.EmitIntValue(LineLen, 4);
OS.EmitIntValue(FuncLen + LineLen, 4);
OS.EmitIntValue(FieldRelocLen, 4);
OS.EmitIntValue(FuncLen + LineLen + FieldRelocLen, 4);
OS.EmitIntValue(ExternRelocLen, 4);
// Emit func_info table.
OS.AddComment("FuncInfo");
@ -848,22 +841,6 @@ void BTFDebug::emitBTFExtSection() {
}
}
}
// Emit extern reloc table.
if (ExternRelocLen) {
OS.AddComment("ExternReloc");
OS.EmitIntValue(BTF::BPFExternRelocSize, 4);
for (const auto &ExternRelocSec : ExternRelocTable) {
OS.AddComment("Extern reloc section string offset=" +
std::to_string(ExternRelocSec.first));
OS.EmitIntValue(ExternRelocSec.first, 4);
OS.EmitIntValue(ExternRelocSec.second.size(), 4);
for (const auto &ExternRelocInfo : ExternRelocSec.second) {
Asm->EmitLabelReference(ExternRelocInfo.Label, 4);
OS.EmitIntValue(ExternRelocInfo.ExternNameOff, 4);
}
}
}
}
void BTFDebug::beginFunctionImpl(const MachineFunction *MF) {
@ -1019,15 +996,6 @@ void BTFDebug::processLDimm64(const MachineInstr *MI) {
MDNode *MDN = GVar->getMetadata(LLVMContext::MD_preserve_access_index);
DIType *Ty = dyn_cast<DIType>(MDN);
generateFieldReloc(MI, ORSym, Ty, GVar->getName());
} else if (GVar && !GVar->hasInitializer() && GVar->hasExternalLinkage() &&
GVar->getSection() == BPFCoreSharedInfo::PatchableExtSecName) {
MCSymbol *ORSym = OS.getContext().createTempSymbol();
OS.EmitLabel(ORSym);
BTFExternReloc ExternReloc;
ExternReloc.Label = ORSym;
ExternReloc.ExternNameOff = addString(GVar->getName());
ExternRelocTable[SecNameOff].push_back(ExternReloc);
}
}
}
@ -1165,20 +1133,6 @@ bool BTFDebug::InstLower(const MachineInstr *MI, MCInst &OutMI) {
OutMI.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
OutMI.addOperand(MCOperand::createImm(Imm));
return true;
} else if (GVar && !GVar->hasInitializer() &&
GVar->hasExternalLinkage() &&
GVar->getSection() == BPFCoreSharedInfo::PatchableExtSecName) {
const IntegerType *IntTy = dyn_cast<IntegerType>(GVar->getValueType());
assert(IntTy);
// For patchable externals, emit "LD_imm64, ri, 0" if the external
// variable is 64bit width, emit "mov ri, 0" otherwise.
if (IntTy->getBitWidth() == 64)
OutMI.setOpcode(BPF::LD_imm64);
else
OutMI.setOpcode(BPF::MOV_ri);
OutMI.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
OutMI.addOperand(MCOperand::createImm(0));
return true;
}
}
}

View File

@ -231,12 +231,6 @@ struct BTFFieldReloc {
uint32_t RelocKind; ///< What to patch the instruction
};
/// 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;
@ -251,7 +245,6 @@ class BTFDebug : public DebugHandlerBase {
std::map<uint32_t, std::vector<BTFFuncInfo>> FuncInfoTable;
std::map<uint32_t, std::vector<BTFLineInfo>> LineInfoTable;
std::map<uint32_t, std::vector<BTFFieldReloc>> FieldRelocTable;
std::map<uint32_t, std::vector<BTFExternReloc>> ExternRelocTable;
StringMap<std::vector<std::string>> FileContent;
std::map<std::string, std::unique_ptr<BTFKindDataSec>> DataSecEntries;
std::vector<BTFTypeStruct *> StructTypes;

View File

@ -28,20 +28,18 @@ entry:
; CHECK: 0x00000060 696e7420 6628696e 74206129 207b2072
; CHECK: 0x00000070 65747572 6e20613b 207d00
; CHECK: '.BTF.ext'
; CHECK-EL: 0x00000000 9feb0100 28000000 00000000 14000000
; CHECK-EL: 0x00000000 9feb0100 20000000 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-EL: 0x00000020 08000000 09000000 01000000 00000000
; CHECK-EL: 0x00000030 03000000 10000000 09000000 02000000
; CHECK-EL: 0x00000040 00000000 0f000000 18000000 00040000
; CHECK-EL: 0x00000050 08000000 0f000000 18000000 10040000
; CHECK-EB: 0x00000000 eb9f0100 00000020 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
; CHECK-EB: 0x00000020 00000008 00000009 00000001 00000000
; CHECK-EB: 0x00000030 00000003 00000010 00000009 00000002
; CHECK-EB: 0x00000040 00000000 0000000f 00000018 00000400
; CHECK-EB: 0x00000050 00000008 0000000f 00000018 00000410
; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata) #1

View File

@ -43,15 +43,13 @@ define dso_local i32 @test() local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; 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 10 # FuncInfo section string offset=10
; CHECK-NEXT: .long 1

View File

@ -74,15 +74,13 @@ entry:
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; 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 11 # FuncInfo section string offset=11
; CHECK-NEXT: .long 1

View File

@ -48,15 +48,13 @@ define dso_local i32 @f1(i32 returned) local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; 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 11 # FuncInfo section string offset=11
; CHECK-NEXT: .long 1

View File

@ -43,15 +43,13 @@ entry:
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; 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 3 # FuncInfo section string offset=3
; CHECK-NEXT: .long 1

View File

@ -61,15 +61,13 @@ entry:
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; 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 20 # FuncInfo section string offset=20
; CHECK-NEXT: .long 1

View File

@ -48,15 +48,13 @@ define dso_local i32 @f1(i32) local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; 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 11 # FuncInfo section string offset=11
; CHECK-NEXT: .long 1

View File

@ -37,15 +37,13 @@ define dso_local void @f1() local_unnamed_addr #0 !dbg !7 {
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; 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 4 # FuncInfo section string offset=4
; CHECK-NEXT: .long 1

View File

@ -103,21 +103,19 @@ define dso_local i32 @bpf_prog(%struct.sk_buff*) local_unnamed_addr #0 !dbg !15
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 124
; CHECK-NEXT: .long 144
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 172
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK: .long 16 # FieldReloc
; CHECK-NEXT: .long 43 # Field reloc section string offset=43
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp2
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 86
; CHECK-NEXT: .long 0

View File

@ -111,21 +111,19 @@ define dso_local i32 @bpf_prog(%struct.sk_buff*) local_unnamed_addr #0 !dbg !15
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 76
; CHECK-NEXT: .long 96
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 124
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK: .long 16 # FieldReloc
; CHECK-NEXT: .long 57 # Field reloc section string offset=57
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp2
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 100
; CHECK-NEXT: .long 0

View File

@ -121,15 +121,13 @@ define dso_local i32 @bpf_prog(%struct.sk_buff*) local_unnamed_addr #0 !dbg !15
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 76
; CHECK-NEXT: .long 96
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 124
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK: .long 16 # FieldReloc

View File

@ -124,21 +124,19 @@ define dso_local i32 @bpf_prog(%struct.sk_buff*) local_unnamed_addr #0 !dbg !15
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 76
; CHECK-NEXT: .long 96
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 124
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK: .long 16 # FieldReloc
; CHECK-NEXT: .long 77 # Field reloc section string offset=77
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp2
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 120
; CHECK-NEXT: .long 0

View File

@ -127,21 +127,19 @@ define dso_local i32 @bpf_prog(%union.sk_buff*) local_unnamed_addr #0 !dbg !15 {
; CHECK-NEXT: .short 60319 # 0xeb9f
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 32
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 76
; CHECK-NEXT: .long 96
; CHECK-NEXT: .long 28
; CHECK-NEXT: .long 124
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK: .long 16 # FieldReloc
; CHECK-NEXT: .long 54 # Field reloc section string offset=54
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp2
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long 97
; CHECK-NEXT: .long 0

View File

@ -1,107 +0,0 @@
; 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:
; extern __attribute__((section(".BPF.patchable_externs"))) char a;
; int foo() { return a; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c
@a = external dso_local local_unnamed_addr global i8, section ".BPF.patchable_externs", align 1
; Function Attrs: norecurse nounwind readonly
define dso_local i32 @foo() local_unnamed_addr #0 !dbg !7 {
%1 = load i8, i8* @a, align 1, !dbg !11, !tbaa !12
%2 = sext i8 %1 to i32, !dbg !11
; CHECK: r0 = 0
; CHECK-NEXT: r0 <<= 56
; CHECK-NEXT: r0 s>>= 56
ret i32 %2, !dbg !15
}
; 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 40
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 54
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 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 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 "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 97 # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/home/yhs/work/tests/llvm/test.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 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 20
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 9 # FuncInfo section string offset=9
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 9 # LineInfo section string offset=9
; CHECK-NEXT: .long 2
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 17
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 2068 # Line 2 Col 20
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 17
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 2061 # Line 2 Col 13
; CHECK-NEXT: .long 8 # ExternReloc
; CHECK-NEXT: .long 9 # Extern reloc section string offset=9
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 15
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" }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 8.0.20181009 "}
!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !0, retainedNodes: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10}
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !DILocation(line: 2, column: 20, scope: !7)
!12 = !{!13, !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C/C++ TBAA"}
!15 = !DILocation(line: 2, column: 13, scope: !7)

View File

@ -1,102 +0,0 @@
; 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:
; extern __attribute__((section(".BPF.patchable_externs"))) unsigned a;
; int foo() { return a; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c
@a = external dso_local local_unnamed_addr global i32, section ".BPF.patchable_externs", align 4
; Function Attrs: norecurse nounwind readonly
define dso_local i32 @foo() local_unnamed_addr #0 !dbg !7 {
%1 = load i32, i32* @a, align 4, !dbg !11, !tbaa !12
; CHECK: r0 = 0
; CHECK-NEXT: exit
ret i32 %1, !dbg !16
}
; 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 40
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 49
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 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 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 "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 97 # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/yhs/work/tests/llvm/test.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 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 20
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 9 # FuncInfo section string offset=9
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 9 # LineInfo section string offset=9
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 17
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 2061 # Line 2 Col 13
; CHECK-NEXT: .long 8 # ExternReloc
; CHECK-NEXT: .long 9 # Extern reloc section string offset=9
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 15
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" }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: "/tmp/yhs/work/tests/llvm")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 8.0.20181009 "}
!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !0, retainedNodes: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10}
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !DILocation(line: 2, column: 20, scope: !7)
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !14, i64 0}
!14 = !{!"omnipotent char", !15, i64 0}
!15 = !{!"Simple C/C++ TBAA"}
!16 = !DILocation(line: 2, column: 13, scope: !7)

View File

@ -1,103 +0,0 @@
; 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:
; extern __attribute__((section(".BPF.patchable_externs"))) unsigned long long a;
; int foo() { return a; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c
@a = external dso_local local_unnamed_addr global i64, section ".BPF.patchable_externs", align 8
; Function Attrs: norecurse nounwind readonly
define dso_local i32 @foo() local_unnamed_addr #0 !dbg !7 {
%1 = load i64, i64* @a, align 8, !dbg !11, !tbaa !12
%2 = trunc i64 %1 to i32, !dbg !11
; CHECK: r0 = 0 ll
; CHECK-NEXT: exit
ret i32 %2, !dbg !16
}
; 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 40
; CHECK-NEXT: .long 40
; CHECK-NEXT: .long 54
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 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 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 "int" # string offset=1
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "foo" # string offset=5
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii ".text" # string offset=9
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .byte 97 # string offset=15
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "/tmp/home/yhs/work/tests/llvm/test.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 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 20
; CHECK-NEXT: .long 8 # FuncInfo
; CHECK-NEXT: .long 9 # FuncInfo section string offset=9
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Lfunc_begin0
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 16 # LineInfo
; CHECK-NEXT: .long 9 # LineInfo section string offset=9
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 17
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 2061 # Line 2 Col 13
; CHECK-NEXT: .long 8 # ExternReloc
; CHECK-NEXT: .long 9 # Extern reloc section string offset=9
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
; CHECK-NEXT: .long 15
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" }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 8.0.20181009 "}
!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !0, retainedNodes: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10}
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !DILocation(line: 2, column: 20, scope: !7)
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !14, i64 0}
!14 = !{!"omnipotent char", !15, i64 0}
!15 = !{!"Simple C/C++ TBAA"}
!16 = !DILocation(line: 2, column: 13, scope: !7)