public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: John Reiser <jreiser@bitwagon.com>
To: binutils@sourceware.org
Subject: Re: Help needed to track down bug: linking Linux kernel with gold   creates  unbootable kernel
Date: Sun, 11 Apr 2010 18:25:00 -0000	[thread overview]
Message-ID: <4BC213FF.6090200@bitwagon.com> (raw)
In-Reply-To: <4BC07486.5070508@gmail.com>

> Here you go, looks like gold dropped 1/3 of the kernel:
> -rwxr-xr-x 1 edwin edwin 11M Apr 10 15:38 vmlinux.gold
> -rwxr-xr-x 1 edwin edwin 17M Apr 10 15:37 vmlinux.bfd

Not necessarily.  The 6M difference might be explained by a
combination of alignment in the file and/or symbol tables and/or
debugging information that need not be relevant to execution,
particularly for a kernel.

> [Nr] Name Type Addr Off Size ES Flags Lk Inf A
> -[ 1] .text PROGBITS ffffffff81000000 00001000 003d1c55 0 AX 0 0 4096
> +[ 1] .text PROGBITS ffffffff81000000 00200000 003d1c55 0 AX 0 0 4096

The difference in file offset between 0x1000 (4 KiB) and 0x200000 (2 MiB)
probably accounts for just under 2 MiB of zeroes in the file.  Such a
difference for file offset of Elf64_Shdr need not be relevant to execution
of a Linux kernel, as long as the 0x3d1c55 bytes of content are identical.

> alignment differences: [KEY:  -: gold;  +: ld]
> Program Headers:
>   Type   Offset           VirtAddr           PhysAddr  FileSiz   MemSiz Flg  Align
> - LOAD 0x001000 0xffffffff81000000 0x0000000001000000 0x5f2000 0x5f2000 R E 0x1000
> - LOAD 0x5f3000 0xffffffff81600000 0x0000000001600000 0x183220 0x183220 RWE 0x1000
> - LOAD 0x777000 0xffffffffff600000 0x0000000001784000 0x000888 0x000888 R E 0x1000
> - LOAD 0x778000 0x0000000000000000 0x0000000001785000 0x014628 0x014628 RW  0x1000
> - LOAD 0x78d000 0xffffffff8179a000 0x000000000179a000 0x071000 0x456d000 RWE 0x1000
> - NOTE 0x3d2c58 0xffffffff813d1c58 0x00000000013d1c58 0x00003c 0x00003c 0x4
> + LOAD 0x200000 0xffffffff81000000 0x0000000001000000 0x5ef000 0x5ef000 R E 0x200000
> + LOAD 0x800000 0xffffffff81600000 0x0000000001600000 0x183220 0x183220 RWE 0x200000
> + LOAD 0xa00000 0xffffffffff600000 0x0000000001784000 0x000888 0x000888 R E 0x200000
> + LOAD 0xc00000 0x0000000000000000 0x0000000001785000 0x014628 0x014628 RW  0x200000
> + LOAD 0xd9a000 0xffffffff8179a000 0x000000000179a000 0x071000 0x456d000 RWE 0x200000
> + NOTE 0x5d1c58 0xffffffff813d1c58 0x00000000013d1c58 0x000024 0x000024 0x4

The differing .p_align values of 0x1000 vs 0x200000 indicate that
gold has a bug interpreting the commands from the linker script
for alignment of Elf64_Phdr.  The .p_align applies to the .p_vaddr
and .p_paddr (which are related to address space at execution),
and not necessarily to .p_offset (which is related to file storage.)
For an ordinary ET_EXEC application or ET_DYN shared lib these are
connected by mmap(): the actual hardware page size must divide all
three of (.p_vaddr - .p_offset), (.p_paddr - .p_offset), .p_align.
For a Linux kernel they are connected by the boot loader: .p_vaddr
and .p_paddr must be divisible by the actual hardware page size,
but it could be OK for .p_offset to be anything as long as the
content (the interval of loaded bytes) was identical.  This looser
restriction requires a boot loader that processes each PT_LOAD
independently as "real bytes."  If the boot loader tries to do more
than one PT_LOAD at a time without carefully checking that the adjacency
in the input stream is compliant with the adjacency in the address space,
then that is a problem.  Also, if the boot loader is loading the
address space of some virtual machine by using mmap() on the host
machine, without a fallback for the case when mmap() fails, then
the more-stringent restrictions of "ordinary ET_EXEC" are relevant,
and thus gold's differing .p_align is an underlying bug.

The differing .p_filsz and .p_memsz of 0x3c vs 0x24 for the PT_NOTE
indicate that gold may have a bug there.  Examine the contents
(see Elf64_Nhdr in /usr/include/elf.h) to determine the added/omitted/
merged/changed content.

The differing .p_filesz and .p_memsz of 0x5f2000 vs 0x5ef000 for
the first PT_LOAD is a bug in gold.

-- 

  reply	other threads:[~2010-04-11 18:25 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-09 19:25 Török Edwin
2010-04-09 22:24 ` Ian Lance Taylor
2010-04-09 22:52   ` Doug Kwan (關振德)
2010-04-10 12:52   ` Török Edwin
2010-04-11 18:25     ` John Reiser [this message]
2010-04-12  9:39       ` Török Edwin
2010-04-12 15:17         ` John Reiser
2010-04-12 18:52           ` Török Edwin
2010-04-12 20:49             ` John Reiser
2010-04-13  5:27       ` Ian Lance Taylor
2010-04-22 21:10         ` H.J. Lu
2010-04-22 21:21           ` H.J. Lu
2010-04-22 21:27             ` Suresh Siddha
2010-04-23  0:00             ` Ian Lance Taylor
2010-04-23  0:24               ` H.J. Lu
2010-04-23  1:21                 ` Ian Lance Taylor
2010-04-23  1:46                   ` H.J. Lu
2010-04-23  1:58                     ` David Miller
2010-04-23  2:38                       ` H.J. Lu
2010-04-23  3:05                       ` Ian Lance Taylor
2010-04-23  4:27                         ` H.J. Lu
2010-04-22 21:25           ` John Reiser
2010-04-23  4:49             ` gold patch committed (Was: Re: Help needed to track down bug: linking Linux kernel with gold creates unbootable kernel) Ian Lance Taylor
2010-04-23 12:44               ` H.J. Lu
2010-04-23 14:12                 ` Ian Lance Taylor
2010-04-23 14:35                   ` H.J. Lu
2010-04-23 14:43                     ` Ian Lance Taylor
2010-04-23 14:47                       ` H.J. Lu
2010-04-23 15:31                         ` Ian Lance Taylor
2010-04-23 15:39                           ` H.J. Lu
2010-04-23 14:44                     ` H.J. Lu
2010-04-23 15:16                       ` Ian Lance Taylor
2010-04-23 15:30                         ` H.J. Lu
2010-04-23 15:50                           ` Ian Lance Taylor
2010-04-23 17:57                             ` H.J. Lu
2010-04-23 15:55                           ` John Reiser
2010-04-23 14:40                   ` John Reiser
2010-04-23 14:02               ` Török Edwin
2010-04-23 14:48                 ` H.J. Lu
2010-04-23 14:51                   ` Török Edwin
2010-04-23 23:30                 ` Ian Lance Taylor
2010-04-24  7:29                   ` Török Edwin
2010-04-22 23:57           ` Help needed to track down bug: linking Linux kernel with gold creates unbootable kernel Ian Lance Taylor
2010-04-12 17:48     ` Ian Lance Taylor
2010-04-12 18:04       ` Török Edwin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BC213FF.6090200@bitwagon.com \
    --to=jreiser@bitwagon.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).