This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: Mix PE and ELF on ia32.


I'd like to link MS COFF relocatable object files under Linux to
generate ELF executables. But it doesn't work. I am enclosing
a testcase here. The problem is although PC relative relocations are
very similar between PE and non-PE formats, but they are off by
1 << howto->size bytes. See md_apply_fix3 () in gas/config/tc-i386.c.
When we link PE and non-PE object files together to generate a non-PE
executable, we have to compensate it somewhere. After discussing
it with Ian, we came up with this patch. It seems to work for me.
Any comments?

BTW, according to Ian, when linking to a PE output file, coff_i386_reloc
is not called.

Thanks.


-- 
H.J. Lu (hjl@gnu.org)
2000-06-14  H.J. Lu  <hjl@gnu.org>

	* coff-i386.c (coff_i386_reloc): Don't return in case of
	output_bfd == (bfd *) NULL if COFF_WITH_PE is defined.
	Compensate PE PC relative relocations when linking with
	non-PE object files to generate a non-PE executable.

--- /work/gnu/import/binutils/src/bfd/coff-i386.c	Wed Jan 26 15:11:47 2000
+++ ./coff-i386.c	Wed Jun 14 15:38:08 2000
@@ -73,8 +73,10 @@ coff_i386_reloc (abfd, reloc_entry, symb
 {
   symvalue diff;
 
+#ifndef COFF_WITH_PE
   if (output_bfd == (bfd *) NULL)
     return bfd_reloc_continue;
+#endif
 
   if (bfd_is_com_section (symbol->section))
     {
@@ -102,7 +104,19 @@ coff_i386_reloc (abfd, reloc_entry, symb
 	 ignores the addend for a COFF target when producing
 	 relocateable output.  This seems to be always wrong for 386
 	 COFF, so we handle the addend here instead.  */
-      diff = reloc_entry->addend;
+#ifdef COFF_WITH_PE
+      reloc_howto_type *howto = reloc_entry->howto;
+
+      if (howto->pc_relative == true && howto->pcrel_offset == true)
+	/* Although PC relative relocations are very similar between
+	   PE and non-PE formats, but they are off by 1 << howto->size
+	   bytes. See md_apply_fix3 () in gas/config/tc-i386.c. When we
+	   link PE and non-PE object files together to generate a
+	   non-PE executable, we have to compensate it here.  */
+	diff = -(1 << howto->size);
+      else
+#endif
+	diff = reloc_entry->addend;
     }
 
 #ifdef COFF_WITH_PE
begin 644 pe.tar.gz
M'XL(`#[.1CD``^V6WVO;,!#'\VK]%4>70L)B^6>2D35C;=X&(X,^#<)`MF7'
MK2T;RT[3COWODQPG:\NV/*6CXSX0Z7SWY4[8N;/C-.,.#7NGQ'9L>^+[/=M6
MUL1YO+=XKM>SIX[KC/VI[;A:[[EN#^R3GJJCD36K`'KKF^RONF/Q5PIYDXHP
M:R(.%[*.TH*N/Q"2BAIREHK!D'QO+S:L<N;V>T(,;<$<9-RHJ':4E1+$@[.5
M<%S/'Z\$_2TK<?9,#G%5Y,!D/C^/5L)L4:J1KM!**UXWE0!=]@?1Z)/HPBX,
M0-M,'X]TL@%[RX:M]%_?TE=%GKF,RM/6.-K__OAY_[NV@_W_$ABTYMN:&#3)
MBB!KVXOH948,+FJN[DS?WGK\W4AM<:SZMY%K`#CG04F,O-A`>R'+T1./$H=,
MN=B6&+().I<[TLI?.70T9%FF[+:MB<&BJ-/ZG9:)O2=6="D/=8-RG[(HX7"L
MC+,-!V@GB/;B1/@SG]DMC]4WP"EK'.W_Z:/W_V2J]1-OC/W_$BRO/BV67[[.
MB^`F+,I[LEC,DS`$,P%S22ZOY]9=4=U:09-FD96(Q@I2H7]-G6;2C'C0)%;"
MI%ER2ZV"WQ&B&GH&^K6BAHK5[D2O,XAWGYIMC!;$Z`\6BR&8!?0_0O\;F%?4
MVDEIL4M`I19=7A]$%X2$JKGU<*IR,.-6M<]'U'-4`?TTP_@!2DZ529.'IW4E
E[/_Q.!40!$$0!$$0!$$0!$$0!$$0!$$0!/F_^`G<R:.@`"@`````
`
end

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]