Bug 13019 - "error: load segment overlap" when linking Linux kernel
Summary: "error: load segment overlap" when linking Linux kernel
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: Ian Lance Taylor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-23 13:50 UTC by Octoploid
Modified: 2016-03-27 18:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
output of "readelf -lSW ./vmlinux" (1.36 KB, text/plain)
2011-07-23 13:50 UTC, Octoploid
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Octoploid 2011-07-23 13:50:41 UTC
Created attachment 5857 [details]
output of "readelf -lSW ./vmlinux"

When I try to build the latest kernel git tree with gold I get this error:

  ld -m elf_x86_64 --build-id -o vmlinux -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  lib/lib.a  arch/x86/lib/lib.a  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/video/built-in.o  net/built-in.o --end-group .tmp_kallsyms2.o
ld: error: dot may not move backward
ld: error: dot may not move backward
ld: error: load segment overlap [0x1800000 -> 0x18940e0] and [0x1893000 -> 0x1893c10]

ld.bfd links without any problems.

The output of "readelf -lSW ./vmlinux" is attached.


Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x200000 0xffffffff81000000 0x0000000001000000 0x7d1000 0x7d1000 R E 0x200000
  LOAD           0xa00000 0xffffffff81800000 0x0000000001800000 0x0940e0 0x0940e0 RW  0x200000
  LOAD           0xc00000 0xffffffffff600000 0x0000000001893000 0x001000 0x001000 R E 0x200000
  LOAD           0xe00000 0x0000000000000000 0x0000000001895000 0x012500 0x012500 RW  0x200000
  LOAD           0xea8000 0xffffffff818a8000 0x00000000018a8000 0x085000 0x152000 RWE 0x200000
  NOTE           0x71bb34 0xffffffff8151bb34 0x000000000151bb34 0x000024 0x000024     0x4
Comment 1 Andy Lutomirski 2011-07-23 17:14:52 UTC
(I'm the author of the kernel patch that triggered this.)

It looks like two phdrs do indeed overlap.  The fix to the linker script is trivial.

The errors "ld: error: dot may not move backward" are still there, though.  It would be nice if gold (or ld.bfd, for that matter) would give some context for the error...
Comment 2 Ian Lance Taylor 2011-07-23 17:33:43 UTC
What is the change to the linker script that causes this to happen?
Comment 3 Andy Lutomirski 2011-07-23 17:42:24 UTC
(In reply to comment #2)
> What is the change to the linker script that causes this to happen?

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=9fd67b4ed0714ab718f1f9bd14c344af336a6df7

The segment overlap error is correct and I'll fix it in the linker script.  The dot error looks like a bug.

This construct in SECTIONS is the problem, I think:

.vsyscall {
 *(.vsyscall_0)

 . = 1024;
 *(.vsyscall_1)
}

AFAICT the bfd linker thinks that assignments to . inside a section are section-relative but gold thinks they're absolute.  The documentation reference is escaping me at the moment.
Comment 4 Andy Lutomirski 2011-07-23 18:50:49 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > What is the change to the linker script that causes this to happen?
> 
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=9fd67b4ed0714ab718f1f9bd14c344af336a6df7
> 
> The segment overlap error is correct and I'll fix it in the linker script.  The
> dot error looks like a bug.
> 
> This construct in SECTIONS is the problem, I think:
> 
> .vsyscall {
>  *(.vsyscall_0)
> 
>  . = 1024;
>  *(.vsyscall_1)
> }
> 
> AFAICT the bfd linker thinks that assignments to . inside a section are
> section-relative but gold thinks they're absolute.  The documentation reference
> is escaping me at the moment.

I filed bug 13023 for the dot problem.  I'm not convinced that the segment overlap is a real bug as opposed to gold just being a little stricter than the bfd linker.
Comment 5 Cary Coutant 2016-03-27 18:06:14 UTC
With the dot problem split out as a separate bug (and fixed), and the segment overlap problem acknowledged as a problem with the script, I think this bug can be closed.