@@ -120,7 +120,7 @@ impl ObjArch for ObjArchMips {
120
120
let mnemonic = instruction. opcode_name ( ) . to_string ( ) ;
121
121
let is_branch = instruction. is_branch ( ) ;
122
122
let branch_offset = instruction. branch_offset ( ) ;
123
- let branch_dest = if is_branch {
123
+ let mut branch_dest = if is_branch {
124
124
cur_addr. checked_add_signed ( branch_offset) . map ( |a| a as u64 )
125
125
} else {
126
126
None
@@ -137,17 +137,18 @@ impl ObjArch for ObjArchMips {
137
137
OperandType :: cpu_immediate
138
138
| OperandType :: cpu_label
139
139
| 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 {
143
141
if matches ! ( & reloc. target_section, Some ( s) if s == ".text" )
144
142
&& reloc. target . address > start_address
145
143
&& reloc. target . address < end_address
146
144
{
147
145
args. push ( ObjInsArg :: BranchDest ( reloc. target . address ) ) ;
148
146
} else {
149
147
push_reloc ( & mut args, reloc) ?;
148
+ branch_dest = None ;
150
149
}
150
+ } else if let Some ( branch_dest) = branch_dest {
151
+ args. push ( ObjInsArg :: BranchDest ( branch_dest) ) ;
151
152
} else {
152
153
args. push ( ObjInsArg :: Arg ( ObjInsArgValue :: Opaque (
153
154
op. disassemble ( & instruction, None ) . into ( ) ,
@@ -225,6 +226,7 @@ impl ObjArch for ObjArchMips {
225
226
}
226
227
}
227
228
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
228
230
flags => bail ! ( "Unsupported MIPS implicit relocation {flags:?}" ) ,
229
231
} )
230
232
}
@@ -235,6 +237,7 @@ impl ObjArch for ObjArchMips {
235
237
elf:: R_MIPS_HI16 => Cow :: Borrowed ( "R_MIPS_HI16" ) ,
236
238
elf:: R_MIPS_LO16 => Cow :: Borrowed ( "R_MIPS_LO16" ) ,
237
239
elf:: R_MIPS_GOT16 => Cow :: Borrowed ( "R_MIPS_GOT16" ) ,
240
+ elf:: R_MIPS_PC16 => Cow :: Borrowed ( "R_MIPS_PC16" ) ,
238
241
elf:: R_MIPS_CALL16 => Cow :: Borrowed ( "R_MIPS_CALL16" ) ,
239
242
elf:: R_MIPS_GPREL16 => Cow :: Borrowed ( "R_MIPS_GPREL16" ) ,
240
243
elf:: R_MIPS_32 => Cow :: Borrowed ( "R_MIPS_32" ) ,
@@ -274,7 +277,7 @@ fn push_reloc(args: &mut Vec<ObjInsArg>, reloc: &ObjReloc) -> Result<()> {
274
277
args. push ( ObjInsArg :: Reloc ) ;
275
278
args. push ( ObjInsArg :: PlainText ( ")" . into ( ) ) ) ;
276
279
}
277
- elf:: R_MIPS_32 | elf:: R_MIPS_26 => {
280
+ elf:: R_MIPS_32 | elf:: R_MIPS_26 | elf :: R_MIPS_PC16 => {
278
281
args. push ( ObjInsArg :: Reloc ) ;
279
282
}
280
283
_ => bail ! ( "Unsupported ELF MIPS relocation type {r_type}" ) ,
0 commit comments