Another relocation problem - and patch

Mikulas Patocka mikulas@artax.karlin.mff.cuni.cz
Mon Mar 5 07:25:00 GMT 2001


$ as
jmp a+b
a:
b=2
$ objdump --disassemble

a.out:     file format elf32-i386

Disassembly of section .text:

00000000 <a-0x2>:
   0:   eb 00                   jmp    2 <b>
$ as
b=2
jmp a+b
a:
$ objdump --disassemble

a.out:     file format elf32-i386

Disassembly of section .text:

00000000 <a-0x2>:
   0:   eb 02                   jmp    4 <b+0x2>
$


The problem is that jmp processing completely discards the expression and
uses only symbol and add number. The patch is below.

--- gas/config/tc-i386.c_	Sat Mar  3 14:00:22 2001
+++ gas/config/tc-i386.c	Sat Mar  3 14:16:25 2001
@@ -2274,6 +2274,9 @@
 	int code16;
 	int prefix;
 
+	symbolS *sym;
+	offsetT add_number;
+
 	code16 = 0;
 	if (flag_16bit_code)
 	  code16 = CODE16;
@@ -2307,14 +2310,24 @@
 	*p = i.tm.base_opcode;
 	/* 1 possible extra opcode + displacement go in var part.
 	   Pass reloc in fr_var.  */
+	if (i.op[0].disps->X_op == O_symbol)
+	  {
+	    sym = i.op[0].disps->X_add_symbol;
+	    add_number = i.op[0].disps->X_add_number;
+	  }
+	else
+	  {
+	    sym = make_expr_symbol(i.op[0].disps);
+	    add_number = 0;
+	  }
 	frag_var (rs_machine_dependent,
 		  1 + size,
 		  i.disp_reloc[0],
 		  ((unsigned char) *p == JUMP_PC_RELATIVE
 		   ? ENCODE_RELAX_STATE (UNCOND_JUMP, SMALL) | code16
 		   : ENCODE_RELAX_STATE (COND_JUMP, SMALL) | code16),
-		  i.op[0].disps->X_add_symbol,
-		  i.op[0].disps->X_add_number,
+		  sym,
+		  add_number,
 		  p);
       }
     else if (i.tm.opcode_modifier & (JumpByte | JumpDword))

After patch:

$ as
jmp a+b
a:
b=2
$ objdump --disassemble

a.out:     file format elf32-i386

Disassembly of section .text:

00000000 <a-0x5>:
   0:   e9 02 00 00 00          jmp    7 <a+0x2>
$


It doesn't use optimal length but at least it doesn't create broken code.
The relax is actually done in md_estimate_size_before_relax because the
section of expression symbol is different. Has anybody idea what to do
with it? Is there some function that evaluates the expression symbol and
converts it to symbol + constant value?

Mikulas



More information about the Binutils mailing list