@@ -120,7 +120,7 @@ impl ObjArch for ObjArchMips {
120120 let mnemonic = instruction. opcode_name ( ) . to_string ( ) ;
121121 let is_branch = instruction. is_branch ( ) ;
122122 let branch_offset = instruction. branch_offset ( ) ;
123- let branch_dest = if is_branch {
123+ let mut branch_dest = if is_branch {
124124 cur_addr. checked_add_signed ( branch_offset) . map ( |a| a as u64 )
125125 } else {
126126 None
@@ -137,17 +137,18 @@ impl ObjArch for ObjArchMips {
137137 OperandType :: cpu_immediate
138138 | OperandType :: cpu_label
139139 | OperandType :: cpu_branch_target_label => {
140- if let Some ( branch_dest) = branch_dest {
141- args. push ( ObjInsArg :: BranchDest ( branch_dest) ) ;
142- } else if let Some ( reloc) = reloc {
140+ if let Some ( reloc) = reloc {
143141 if matches ! ( & reloc. target_section, Some ( s) if s == ".text" )
144142 && reloc. target . address > start_address
145143 && reloc. target . address < end_address
146144 {
147145 args. push ( ObjInsArg :: BranchDest ( reloc. target . address ) ) ;
148146 } else {
149147 push_reloc ( & mut args, reloc) ?;
148+ branch_dest = None ;
150149 }
150+ } else if let Some ( branch_dest) = branch_dest {
151+ args. push ( ObjInsArg :: BranchDest ( branch_dest) ) ;
151152 } else {
152153 args. push ( ObjInsArg :: Arg ( ObjInsArgValue :: Opaque (
153154 op. disassemble ( & instruction, None ) . into ( ) ,
@@ -225,6 +226,7 @@ impl ObjArch for ObjArchMips {
225226 }
226227 }
227228 RelocationFlags :: Elf { r_type : elf:: R_MIPS_26 } => ( ( addend & 0x03FFFFFF ) << 2 ) as i64 ,
229+ RelocationFlags :: Elf { r_type : elf:: R_MIPS_PC16 } => 0 , // PC-relative relocation
228230 flags => bail ! ( "Unsupported MIPS implicit relocation {flags:?}" ) ,
229231 } )
230232 }
@@ -235,6 +237,7 @@ impl ObjArch for ObjArchMips {
235237 elf:: R_MIPS_HI16 => Cow :: Borrowed ( "R_MIPS_HI16" ) ,
236238 elf:: R_MIPS_LO16 => Cow :: Borrowed ( "R_MIPS_LO16" ) ,
237239 elf:: R_MIPS_GOT16 => Cow :: Borrowed ( "R_MIPS_GOT16" ) ,
240+ elf:: R_MIPS_PC16 => Cow :: Borrowed ( "R_MIPS_PC16" ) ,
238241 elf:: R_MIPS_CALL16 => Cow :: Borrowed ( "R_MIPS_CALL16" ) ,
239242 elf:: R_MIPS_GPREL16 => Cow :: Borrowed ( "R_MIPS_GPREL16" ) ,
240243 elf:: R_MIPS_32 => Cow :: Borrowed ( "R_MIPS_32" ) ,
@@ -274,7 +277,7 @@ fn push_reloc(args: &mut Vec<ObjInsArg>, reloc: &ObjReloc) -> Result<()> {
274277 args. push ( ObjInsArg :: Reloc ) ;
275278 args. push ( ObjInsArg :: PlainText ( ")" . into ( ) ) ) ;
276279 }
277- elf:: R_MIPS_32 | elf:: R_MIPS_26 => {
280+ elf:: R_MIPS_32 | elf:: R_MIPS_26 | elf :: R_MIPS_PC16 => {
278281 args. push ( ObjInsArg :: Reloc ) ;
279282 }
280283 _ => bail ! ( "Unsupported ELF MIPS relocation type {r_type}" ) ,
0 commit comments