public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Török Edwin" <edwintorok@gmail.com>
To: binutils@sourceware.org
Subject: Re: Re: Help needed to track down bug: linking Linux kernel with   gold    creates  unbootable kernel
Date: Mon, 12 Apr 2010 18:52:00 -0000	[thread overview]
Message-ID: <4BC36BE3.6070707@gmail.com> (raw)
In-Reply-To: <4BC33985.9060000@bitwagon.com>

On 01/-10/-28163 09:59 PM, John Reiser wrote:
>> Not identical, difference starts at byte 230:
>> -vmlinux.gold: file format elf64-x86-64
>> +vmlinux.bfd: file format elf64-x86-64
> ...
>> It appears to be a difference in the address chosen for that global (and
>> other globals later on).
>
> Although the placement of globals chosen from a library need not be
> identical, it would be comforting to verify that this is the only reason.
> Try changing the link command to remove all *.a (extract and specify each
> *.o explicitly). Then there should be no difference.

There still is. The size of the .rodata is different, so probably the 
order is still different too.

Does gold do some optimizations that bfd ld doesn't do? (such as 
dropping unneeded globals, reordering the globals to not waste space due 
to alignment, if it can put another global inbetween, etc.)

This is the commandline I used (using /usr/bin/ld vs /usr/local/bin/ld):
/usr/bin/ld --build-id -m elf_x86_64  -o vmlinux.bfd -T 
arch/x86/kernel/vmlinux.lds arch/x86/kernel/head_64.o 
arch/x86/kernel/head64.o arch/x86/kernel/head.o 
arch/x86/kernel/init_task.o  init/built-in.o --start-group 
usr/built-in.o  arch/x86/built-in.o  kernel/built-in.o  mm/built-in.o 
fs/built-in.o  ipc/built-in.o  security/built-in.o  crypto/built-in.o 
block/built-in.o  as/*.o lib/built-in.o  arch/x86/lib/built-in.o 
drivers/built-in.o  sound/built-in.o  firmware/built-in.o 
arch/x86/pci/built-in.o  arch/x86/power/built-in.o 
arch/x86/video/built-in.o  net/built-in.o --end-group .tmp_kallsyms2.o

I still have differences:
-ffffffff810000e1:      48 01 2d 08 c0 46 00    add 
%rbp,0x46c008(%rip)        # ffffffff8146c0f0 <trampoline_level4_pgt>
-ffffffff810000e8:      48 01 2d f9 cf 46 00    add 
%rbp,0x46cff9(%rip)        # ffffffff8146d0e8 <trampoline_level4_pgt+0xff8>
+ffffffff810000e1:      48 01 2d 98 74 40 00    add 
%rbp,0x407498(%rip)        # ffffffff81407580 <trampoline_level4_pgt>
+ffffffff810000e8:      48 01 2d 89 84 40 00    add 
%rbp,0x408489(%rip)        # ffffffff81408578 <trampoline_level4_pgt+0xff8>

So I did this (the .s is obtained by objdump -d vmlinux.gold >gold.s)
sed -re 's/(# |0x)[a-z0-9]+/HEX/g' gold.s | colrm 1 47 >gold1.s

And diff those.

Then aside from some local symbol name differences:
-       cmp    HEX(%rip),%edx        HEX <.LC3>
+       cmp    HEX(%rip),%edx        HEX <kallsyms_token_index+HEX>

I have this diff (+ is bfd), which is coming from .notes (why does 
objdump think it needs to dump .notes as assembly though?):
+       add    $HEX,%al
+       add    %al,(%rax)
+       adc    $HEX,%al
+       add    %al,(%rax)
+       add    (%rax),%eax
+       add    %al,(%rax)
+       rex.RXB
+       rex.WRX push   %rbp
+       add    %dh,%bh
+       insb   (%dx),%es:(%rdi)
+       jle    ffffffff813d1250 <bad_to_user+HEX>
+       and    $HEX,%dl
+       (bad)
+       jge    ffffffff813d1331 <__start___ex_table+HEX>
+       cs
+       callq  ffffffff2bbe8fc1 <__crc___pskb_pull_tail+HEX>
+       stc
+       mov    $HEX,%ch
+       (bad)


>
>> ... there is also difference in padding:
>> gold uses 00 00 90 90 (add %al, (%rax) nop nop), while BFD uses 90 90 90
>> 90 (4 nops).
>
> That is a dispute over interpretation of the linker script:
> } :text=0x9090
> The original spec was from the days when 2==sizeof(int), so padding was
> a 16-bit value, thus 0x9090 was all that mattered. Check the spec
> for an update regarding width of padding. In the meantime, try changing
> the script to
> } :text=0x90909090
> which should remove this source of differences.

Yes that removes the differences from the nops.

>
>> If I read that correctly it means it uses hardware pages with a pagesize
>> of 2MB for kernel text.
>
> Yes.
>
>> Since gold aligns only to 0x1000 perhaps the rodata ends up in the same
>> hardware page as the .text.
>>
>> I think these are the relevant align commands from the vmlinux.lds ...
>
>> . = ALIGN((1 << 21));
>
> It is a bug that gold does not propagate that alignment constraint
> to the .p_align.
>
>> If the hw pagesize is 2MB, then its not divisible, so its a bug.
>> Should I open a bugreport, or are there some patches to gold that I
>> could try?
>
> Definitely open a bug report about ". = ALIGN((1 << 21));"

Opened bug 11490.

>
>> I think the .note difference is just due to gold embedding its version:
>> -Note section [ 2] '.notes' of 60 bytes at offset 0x3d2c58:
>> +Note section [ 2] '.notes' of 36 bytes at offset 0x5d1c58:
>> Owner Data size Type
>> - GNU 8 GNU_GOLD_VERSION
>> - Linker version: gold 1.9
>> GNU 20 GNU_BUILD_ID
>> - Build ID: a865af685f5222cdc17a28ea4e49d58b2185bc05
>> + Build ID: 07b53da4e169ad1079080043ad72384fb80d0ea3
>
> Again, it would be comforting to make a test run with GNU_GOLD_VERSION
> omitted, to see if the .text becomes identical (except for Build ID)
> with ld.
>

I did that (by editing gold source and returning from 
create_gold_note()), but as I've shown above there are still diffs due 
to global addresses...

Best regards,
--Edwin

  reply	other threads:[~2010-04-12 18:52 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
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 [this message]
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=4BC36BE3.6070707@gmail.com \
    --to=edwintorok@gmail.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).