Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
ab4e074
Documentation
LICENSES
arch
block
certs
crypto
drivers
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
accounting
arch
bootconfig
bpf
build
cgroup
debugging
edid
firewire
firmware
gpio
hv
iio
include
io_uring
kvm
laptop
leds
lib
memory-model
objtool
Documentation
arch
include
.gitignore
Build
Makefile
builtin-check.c
builtin-orc.c
check.c
elf.c
objtool.c
orc_dump.c
orc_gen.c
special.c
sync-check.sh
weak.c
pci
pcmcia
perf
power
scripts
spi
testing
thermal
time
usb
virtio
vm
wmi
Makefile
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
tools
/
objtool
/
orc_gen.c
Copy path
Blame
Blame
Latest commit
History
History
221 lines (187 loc) · 4.69 KB
Breadcrumbs
linux
/
tools
/
objtool
/
orc_gen.c
Top
File metadata and controls
Code
Blame
221 lines (187 loc) · 4.69 KB
Raw
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com> */ #include <stdlib.h> #include <string.h> #include <linux/objtool.h> #include <asm/orc_types.h> #include <objtool/check.h> #include <objtool/warn.h> #include <objtool/endianness.h> static int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi) { struct instruction *insn = container_of(cfi, struct instruction, cfi); struct cfi_reg *bp = &cfi->regs[CFI_BP]; memset(orc, 0, sizeof(*orc)); orc->end = cfi->end; if (cfi->cfa.base == CFI_UNDEFINED) { orc->sp_reg = ORC_REG_UNDEFINED; return 0; } switch (cfi->cfa.base) { case CFI_SP: orc->sp_reg = ORC_REG_SP; break; case CFI_SP_INDIRECT: orc->sp_reg = ORC_REG_SP_INDIRECT; break; case CFI_BP: orc->sp_reg = ORC_REG_BP; break; case CFI_BP_INDIRECT: orc->sp_reg = ORC_REG_BP_INDIRECT; break; case CFI_R10: orc->sp_reg = ORC_REG_R10; break; case CFI_R13: orc->sp_reg = ORC_REG_R13; break; case CFI_DI: orc->sp_reg = ORC_REG_DI; break; case CFI_DX: orc->sp_reg = ORC_REG_DX; break; default: WARN_FUNC("unknown CFA base reg %d", insn->sec, insn->offset, cfi->cfa.base); return -1; } switch (bp->base) { case CFI_UNDEFINED: orc->bp_reg = ORC_REG_UNDEFINED; break; case CFI_CFA: orc->bp_reg = ORC_REG_PREV_SP; break; case CFI_BP: orc->bp_reg = ORC_REG_BP; break; default: WARN_FUNC("unknown BP base reg %d", insn->sec, insn->offset, bp->base); return -1; } orc->sp_offset = cfi->cfa.offset; orc->bp_offset = bp->offset; orc->type = cfi->type; return 0; } static int write_orc_entry(struct elf *elf, struct section *orc_sec, struct section *ip_rsec, unsigned int idx, struct section *insn_sec, unsigned long insn_off, struct orc_entry *o) { struct orc_entry *orc; struct reloc *reloc; /* populate ORC data */ orc = (struct orc_entry *)orc_sec->data->d_buf + idx; memcpy(orc, o, sizeof(*orc)); orc->sp_offset = bswap_if_needed(orc->sp_offset); orc->bp_offset = bswap_if_needed(orc->bp_offset); /* populate reloc for ip */ reloc = malloc(sizeof(*reloc)); if (!reloc) { perror("malloc"); return -1; } memset(reloc, 0, sizeof(*reloc)); insn_to_reloc_sym_addend(insn_sec, insn_off, reloc); if (!reloc->sym) { WARN("missing symbol for insn at offset 0x%lx", insn_off); return -1; } reloc->type = R_X86_64_PC32; reloc->offset = idx * sizeof(int); reloc->sec = ip_rsec; elf_add_reloc(elf, reloc); return 0; } struct orc_list_entry { struct list_head list; struct orc_entry orc; struct section *insn_sec; unsigned long insn_off; }; static int orc_list_add(struct list_head *orc_list, struct orc_entry *orc, struct section *sec, unsigned long offset) { struct orc_list_entry *entry = malloc(sizeof(*entry)); if (!entry) { WARN("malloc failed"); return -1; } entry->orc = *orc; entry->insn_sec = sec; entry->insn_off = offset; list_add_tail(&entry->list, orc_list); return 0; } int orc_create(struct objtool_file *file) { struct section *sec, *ip_rsec, *orc_sec; unsigned int nr = 0, idx = 0; struct orc_list_entry *entry; struct list_head orc_list; struct orc_entry null = { .sp_reg = ORC_REG_UNDEFINED, .bp_reg = ORC_REG_UNDEFINED, .type = UNWIND_HINT_TYPE_CALL, }; /* Build a deduplicated list of ORC entries: */ INIT_LIST_HEAD(&orc_list); for_each_sec(file, sec) { struct orc_entry orc, prev_orc = {0}; struct instruction *insn; bool empty = true; if (!sec->text) continue; sec_for_each_insn(file, sec, insn) { if (init_orc_entry(&orc, &insn->cfi)) return -1; if (!memcmp(&prev_orc, &orc, sizeof(orc))) continue; if (orc_list_add(&orc_list, &orc, sec, insn->offset)) return -1; nr++; prev_orc = orc; empty = false; } /* Add a section terminator */ if (!empty) { orc_list_add(&orc_list, &null, sec, sec->len); nr++; } } if (!nr) return 0; /* Create .orc_unwind, .orc_unwind_ip and .rela.orc_unwind_ip sections: */ sec = find_section_by_name(file->elf, ".orc_unwind"); if (sec) { WARN("file already has .orc_unwind section, skipping"); return -1; } orc_sec = elf_create_section(file->elf, ".orc_unwind", 0, sizeof(struct orc_entry), nr); if (!orc_sec) return -1; sec = elf_create_section(file->elf, ".orc_unwind_ip", 0, sizeof(int), nr); if (!sec) return -1; ip_rsec = elf_create_reloc_section(file->elf, sec, SHT_RELA); if (!ip_rsec) return -1; /* Write ORC entries to sections: */ list_for_each_entry(entry, &orc_list, list) { if (write_orc_entry(file->elf, orc_sec, ip_rsec, idx++, entry->insn_sec, entry->insn_off, &entry->orc)) return -1; } if (elf_rebuild_reloc_section(file->elf, ip_rsec)) return -1; return 0; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
You can’t perform that action at this time.