Bug 10744 - Linker failed to build ia64 kernel
Summary: Linker failed to build ia64 kernel
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-07 18:13 UTC by H.J. Lu
Modified: 2009-10-08 01:22 UTC (History)
1 user (show)

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


Attachments
A testcase for Linux/ia64 (5.64 KB, application/octet-stream)
2009-10-07 18:18 UTC, H.J. Lu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2009-10-07 18:13:09 UTC
I got

/usr/local/bin/ld:arch/ia64/kernel/gate.lds:898: PHDRS and FILEHDR are only
permitted for the first PT_LOAD segment
Comment 1 H.J. Lu 2009-10-07 18:18:28 UTC
Created attachment 4260 [details]
A testcase for Linux/ia64

Working linker:

[hjl@gnu-14 kernel]$ ld -o gate-syms.o -T gate.lds  gate.o
[hjl@gnu-14 kernel]$ ld -shared -s -soname=linux-gate.so.1 -o gate.so  -T
gate.lds gate.o
[hjl@gnu-14 kernel]$ readelf -l gate.so

Elf file type is DYN (Shared object file)
Entry point 0xa000000000010640
There are 4 program headers, starting at offset 64

Program Headers:
  Type		 Offset 	    VirtAddr	       PhysAddr
		 FileSiz	    MemSiz		Flags  Align
  LOAD		 0x0000000000000000 0xa000000000000000 0xa000000000000000
		 0x0000000000000610 0x0000000000000610	R      10000
  LOAD		 0x0000000000000000 0xa000000000010000 0xa000000000010000
		 0x00000000000009b0 0x00000000000009b0	  E    10000
  DYNAMIC	 0x0000000000000268 0xa000000000000268 0xa000000000000268
		 0x0000000000000140 0x0000000000000140	R      8
  IA_64_UNWIND	 0x00000000000005c8 0xa0000000000005c8 0xa0000000000005c8
		 0x0000000000000048 0x0000000000000048	R      8

 Section to Segment mapping:
  Segment Sections...
   00	  .hash .dynsym .dynstr .gnu.version .gnu.version_d .dynamic
.data.patch .IA_64.unwind_info .IA_64.unwind 
   01	  .text 
   02	  .dynamic 
   03	  .IA_64.unwind 
[hjl@gnu-14 kernel]$ 

Bad linker:

[hjl@gnu-14 kernel]$ ./ld -o gate-syms.o -T gate.lds  gate.o./ld:gate.lds:898:
PHDRS and FILEHDR are only permitted for the first PT_LOAD segment
[hjl@gnu-14 kernel]$ ./ld -shared -s -soname=linux-gate.so.1 -o gate.so  -T
gate.lds gate.o 
./ld:gate.lds:898: PHDRS and FILEHDR are only permitted for the first PT_LOAD
segment
[hjl@gnu-14 kernel]$
Comment 2 H.J. Lu 2009-10-07 18:22:03 UTC
It is caused by

http://sourceware.org/ml/binutils-cvs/2009-10/msg00056.html
Comment 3 H.J. Lu 2009-10-07 22:45:22 UTC
The reasons ia64 kernel does are

1. EPC segment has to be marked PF_X without PF_R.
2. We can only have one PT_LOAD segment in vDSO.

ia64 kernel uses

PHDRS
{
  readable PT_LOAD FILEHDR PHDRS FLAGS(4); /* PF_R */
  epc PT_LOAD FILEHDR PHDRS FLAGS FLAGS(1); /* PF_X */
  dynamic PT_DYNAMIC FLAGS(4); /* PF_R */
  unwind 0x70000001; /* PT_IA_64_UNWIND, but ld doesn't match the name */
}

so that ld.so can treat readable and epc segments as a single
segment with data and text. ld.so can map a single segment with
data and text parts.


Comment 4 H.J. Lu 2009-10-08 00:51:49 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2009-10/msg00182.html
Comment 5 cvs-commit@gcc.gnu.org 2009-10-08 01:00:44 UTC
Subject: Bug 10744

CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2009-10-08 01:00:27

Modified files:
	ld             : ChangeLog ldlang.c ld.texinfo 

Log message:
	PR ld/10744
	* ldlang.c (lang_new_phdr): Allow FILEHDR/PHDRS on more than the
	first PT_LOAD header.
	* ld.texinfo: Update.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2059&r2=1.2060
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ldlang.c.diff?cvsroot=src&r1=1.321&r2=1.322
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ld.texinfo.diff?cvsroot=src&r1=1.249&r2=1.250

Comment 6 cvs-commit@gcc.gnu.org 2009-10-08 01:12:15 UTC
Subject: Bug 10744

CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2009-10-08 01:11:57

Modified files:
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-scripts: phdrs3.d 

Log message:
	PR ld/10744
	* ld-scripts/phdrs3.d: Update.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1178&r2=1.1179
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/phdrs3.d.diff?cvsroot=src&r1=1.1&r2=1.2

Comment 7 Alan Modra 2009-10-08 01:22:31 UTC
patch applied
Comment 8 cvs-commit@gcc.gnu.org 2009-10-08 02:38:42 UTC
Subject: Bug 10744

CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2009-10-08 02:38:26

Modified files:
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-scripts: phdrs3.exp 
Added files:
	ld/testsuite/ld-scripts: phdrs3a.d phdrs3a.t 

Log message:
	2009-10-07  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/10744
	* ld-scripts/phdrs3.exp: Run phdrs3a.
	
	* ld-scripts/phdrs3a.d: New.
	* ld-scripts/phdrs3a.t: Likewise.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1179&r2=1.1180
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/phdrs3a.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/phdrs3a.t.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/phdrs3.exp.diff?cvsroot=src&r1=1.1&r2=1.2