This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [PATCH] x86: adjust relocation overflow complaint types
- From: Michael Matz <matz at suse dot de>
- To: Jan Beulich <JBeulich at novell dot com>
- Cc: binutils at sources dot redhat dot com
- Date: Mon, 1 Aug 2005 11:13:31 +0200 (CEST)
- Subject: Re: [PATCH] x86: adjust relocation overflow complaint types
- References: <s2b126e7.064@lyle.provo.novell.com>
Hi Jan,
On Thu, 16 Jun 2005, Jan Beulich wrote:
> This fixes the overflow complaint types for three x86-64 and one i386
> relocation types.
I don't think this is correct for all cases.
> --- /home/jbeulich/src/binutils/mainline/2005-06-16/bfd/elf32-i386.c 2005-06-08 14:50:38.000000000 +0200
> +++ 2005-06-16/bfd/elf32-i386.c 2005-06-08 15:41:21.000000000 +0200
> @@ -95,7 +95,7 @@ static reloc_howto_type elf_howto_table[
> HOWTO(R_386_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
> bfd_elf_generic_reloc, "R_386_16",
> TRUE, 0xffff, 0xffff, FALSE),
> - HOWTO(R_386_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield,
> + HOWTO(R_386_PC16, 0, 1, 16, TRUE, 0, complain_overflow_signed,
This is too eager when compiling in .code16 mode, and breaks linking
current dosemu bios.S. It uses something like this:
% cat mm.s
.code16
.text
.globl bios_f000
bios_f000:
.org 0x420
int $0x42
lret $2
.org 0xf065
jmp bios_f000+((0x42) << 4)
which results in these relocs in the .o file:
% ./gas/as-new -o mm.o mm.s
% objdump -dr -m i8086 mm.o | tail -n 7
00000000 <bios_f000>:
...
420: cd 42 int $0x42
422: ca 02 00 lret $0x2
...
f065: e9 1e 04 jmp f486 <bios_f000+0xf486>
f066: R_386_PC16 bios_f000
But linking will fail:
% ./ld/ld-new -o mm -Ttext 0 -e bios_f000 mm.o
mm.o: In function `bios_f000':
: relocation truncated to fit: R_386_PC16 against symbol `bios_f000'
defined in .text section in mm.o
This is because bfd now thinks the jump is out of range. It _would_ be in
a 32bit segment, but in that we wouldn't use a PC16 relocation. Due to
16bit offset wrap around the jump to 0x420 is representable just fine.
When I revert this part of your patch I can link it and the result is:
% objdump -dr -m i8086 mm | tail -n 7
00000000 <bios_f000>:
...
420: cd 42 int $0x42
422: ca 02 00 lret $0x2
...
f065: e9 b8 13 jmp 420 <bios_f000+0x420>
I don't know how to teach bfd to make a difference between .code16 and
.code32 (or .code64 for that matter) in doing the overflow checking.
Ciao,
Michael.