| 456 | } |
| 457 | |
| 458 | fn push_reloc( |
| 459 | reloc: &Relocation, |
| 460 | mut arg_cb: impl FnMut(InstructionPart) -> Result<()>, |
| 461 | ) -> Result<()> { |
| 462 | match reloc.flags { |
| 463 | RelocationFlags::Elf(r_type) => match r_type { |
| 464 | elf::R_MIPS_HI16 => { |
| 465 | arg_cb(InstructionPart::basic("%hi("))?; |
| 466 | arg_cb(InstructionPart::reloc())?; |
| 467 | arg_cb(InstructionPart::basic(")"))?; |
| 468 | } |
| 469 | elf::R_MIPS_LO16 => { |
| 470 | arg_cb(InstructionPart::basic("%lo("))?; |
| 471 | arg_cb(InstructionPart::reloc())?; |
| 472 | arg_cb(InstructionPart::basic(")"))?; |
| 473 | } |
| 474 | elf::R_MIPS_GOT16 => { |
| 475 | arg_cb(InstructionPart::basic("%got("))?; |
| 476 | arg_cb(InstructionPart::reloc())?; |
| 477 | arg_cb(InstructionPart::basic(")"))?; |
| 478 | } |
| 479 | elf::R_MIPS_CALL16 => { |
| 480 | arg_cb(InstructionPart::basic("%call16("))?; |
| 481 | arg_cb(InstructionPart::reloc())?; |
| 482 | arg_cb(InstructionPart::basic(")"))?; |
| 483 | } |
| 484 | elf::R_MIPS_GPREL16 => { |
| 485 | arg_cb(InstructionPart::basic("%gp_rel("))?; |
| 486 | arg_cb(InstructionPart::reloc())?; |
| 487 | arg_cb(InstructionPart::basic(")"))?; |
| 488 | } |
| 489 | elf::R_MIPS_32 |
| 490 | | elf::R_MIPS_26 |
| 491 | | elf::R_MIPS_LITERAL |
| 492 | | elf::R_MIPS_PC16 |
| 493 | | R_MIPS15_S3 => { |
| 494 | arg_cb(InstructionPart::reloc())?; |
| 495 | } |
| 496 | _ => bail!("Unsupported ELF MIPS relocation type {r_type}"), |
| 497 | }, |
| 498 | flags => panic!("Unsupported MIPS relocation flags {flags:?}"), |
| 499 | } |
| 500 | Ok(()) |
| 501 | } |