Skip to content

Commit a07a6be

Browse files
author
Yonghong Song
committed
Generate .llvm_jump_table_sizes section
For example, [ 6] .rodata PROGBITS 0000000000000000 000740 0000d6 00 A 0 0 8 [ 7] .rel.rodata REL 0000000000000000 003860 000080 10 I 39 6 8 [ 8] .llvm_jump_table_sizes LLVM_JT_SIZES 0000000000000000 000816 000010 00 0 0 1 [ 9] .rel.llvm_jump_table_sizes REL 0000000000000000 0038e0 000010 10 I 39 8 8 ... [14] .llvm_jump_table_sizes LLVM_JT_SIZES 0000000000000000 000958 000010 00 0 0 1 [15] .rel.llvm_jump_table_sizes REL 0000000000000000 003970 000010 10 I 39 14 8 With llvm-readelf dump section 8 and 14: $ llvm-readelf -x 8 user_ringbuf_success.bpf.o Hex dump of section '.llvm_jump_table_sizes': 0x00000000 00000000 00000000 04000000 00000000 ................ $ llvm-readelf -x 14 user_ringbuf_success.bpf.o Hex dump of section '.llvm_jump_table_sizes': 0x00000000 20000000 00000000 04000000 00000000 ............... You can see. There are two jump tables: jump table 1: offset 0, size 4 (4 labels) jump table 2: offset 0x20, size 4 (4 labels) Check sections 9 and 15, we can find the corresponding section: Relocation section '.rel.llvm_jump_table_sizes' at offset 0x38e0 contains 1 entries: Offset Info Type Symbol's Value Symbol's Name 0000000000000000 0000000a00000002 R_BPF_64_ABS64 0000000000000000 .rodata Relocation section '.rel.llvm_jump_table_sizes' at offset 0x3970 contains 1 entries: Offset Info Type Symbol's Value Symbol's Name 0000000000000000 0000000a00000002 R_BPF_64_ABS64 0000000000000000 .rodata and confirmed that the relocation is against '.rodata'. Dump .rodata section: 0x00000000 a8000000 00000000 10010000 00000000 ................ 0x00000010 b8000000 00000000 c8000000 00000000 ................ 0x00000020 28040000 00000000 00050000 00000000 (............... 0x00000030 70040000 00000000 b8040000 00000000 p............... 0x00000040 44726169 6e207265 7475726e 65643a20 Drain returned: So we can get two jump tables: .rodata offset 0, # of lables 4: 0x00000000 a8000000 00000000 10010000 00000000 ................ 0x00000010 b8000000 00000000 c8000000 00000000 ................ .rodata offset 0x200, # of lables 4: 0x00000020 28040000 00000000 00050000 00000000 (............... 0x00000030 70040000 00000000 b8040000 00000000 p............... This way, you just need to scan related code section. As long as it matches one of jump tables (.rodata relocation, offset also matching), you do not need to care about gotox at all in libbpf.
1 parent f5d08fc commit a07a6be

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
#include "llvm/CodeGen/StackMaps.h"
2727
#include "llvm/DebugInfo/CodeView/CodeView.h"
2828
#include "llvm/IR/InlineAsm.h"
29+
#include "llvm/Support/CommandLine.h"
2930
#include "llvm/Support/ErrorHandling.h"
3031
#include <cstdint>
3132
#include <memory>
3233
#include <utility>
3334
#include <vector>
3435

3536
namespace llvm {
37+
extern cl::opt<bool> EmitJumpTableSizesSection;
3638

3739
class AddrLabelMap;
3840
class AsmPrinterHandler;

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static cl::opt<bool> BBAddrMapSkipEmitBBEntries(
168168
"unnecessary for some PGOAnalysisMap features."),
169169
cl::Hidden, cl::init(false));
170170

171-
static cl::opt<bool> EmitJumpTableSizesSection(
171+
cl::opt<bool> llvm::EmitJumpTableSizesSection(
172172
"emit-jump-table-sizes-section",
173173
cl::desc("Emit a section containing jump table addresses and sizes"),
174174
cl::Hidden, cl::init(false));

llvm/lib/Target/BPF/BPFAsmPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class BPFAsmPrinter : public AsmPrinter {
5757
} // namespace
5858

5959
bool BPFAsmPrinter::doInitialization(Module &M) {
60+
EmitJumpTableSizesSection = true;
6061
AsmPrinter::doInitialization(M);
6162

6263
// Only emit BTF when debuginfo available.

0 commit comments

Comments
 (0)