Commit e12839c
committed
XenonAnalyse: block walker uses switchMap to push successors at known bctrs
When Function::Analyze's block walker reaches an unconditional bctr
(PPC_OP_CTR, xop 528, BO bit 5 set) and switchMap is non-null and
contains an entry for the bctr's guest VA, the walker pushes every
label (and the default) as a successor block via the existing
SearchBlock-guarded emplace path. The walker then reaches those
blocks, their reachability propagates, and `fn.size` correctly
includes the switch-dispatched code.
Two guards match the existing `branchDest < base` guard for
unconditional `b` (tail-call pattern):
label < base → skip. Labels before the function base are
malformed or tail-call-style jumps; they
should not extend fn.size.
label >= base + size → skip. Labels outside the caller's window
cannot be walked safely; emplacing them
would compute an out-of-buffer data pointer
during RESTORE_DATA.
Discontinuity-pass suppression: when the walker pushes switch-label
successors (tracked via local `switchAwareTermination`), the end-of-
Analyze sort-and-erase pass skips the erase. Switch dispatch leaves
a legitimate address gap between bctr+4 (end of pre-switch block)
and the first case label — the jump-table bytes live in that gap,
and the generic discontinuity heuristic would erase every block past
it, including exactly the label blocks we just pushed.
The sort itself still runs, which is fine: fn.size is computed as
max(block.base + block.size) across all blocks afterward, so order
does not change the result.
Null-map safety: when switchMap is nullptr, the switch-aware branch
is skipped entirely; the walker's unconditional-bctr path falls
through to the legacy "pop without successors" behavior. Output is
byte-identical to pre-patch behavior for all callers that pass
nullptr (the default) at the Analyze call site.
A companion test commit adds synthetic hand-crafted PPC bytecode
fixtures covering the happy path + null-map safety + wrong-map miss.1 parent 6eaca7a commit e12839c
1 file changed
Lines changed: 90 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | 44 | | |
50 | 45 | | |
51 | 46 | | |
| |||
65 | 60 | | |
66 | 61 | | |
67 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 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 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
191 | 251 | | |
192 | 252 | | |
193 | 253 | | |
| |||
216 | 276 | | |
217 | 277 | | |
218 | 278 | | |
219 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
220 | 290 | | |
221 | 291 | | |
222 | 292 | | |
223 | 293 | | |
224 | 294 | | |
225 | 295 | | |
226 | 296 | | |
227 | | - | |
228 | | - | |
| 297 | + | |
229 | 298 | | |
230 | | - | |
| 299 | + | |
| 300 | + | |
231 | 301 | | |
232 | | - | |
233 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
234 | 306 | | |
235 | | - | |
236 | | - | |
237 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
238 | 310 | | |
239 | | - | |
240 | | - | |
241 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
242 | 315 | | |
243 | 316 | | |
244 | 317 | | |
| |||
0 commit comments